From b442ab0bd24886608dd996aef67780e51fe0d754 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 8 Aug 2012 04:44:17 +0200 Subject: [PATCH 01/31] Refactored mathematics module Added AABBs Added code examples Added experimental support for texture arrays (1D/2D) Added initialisers (new way of initialising modules) Added global headers (Plus a global header generator script) Added pattern support for directory Added support for spinlocks critical section on Windows Added NzRenderWindow::SetFramerateLimit Core project now includes Mathematics files Fixed color implementation using double Fixed declaration needing renderer include Fixed MLT not clearing nextFree(File/Line) after Free Fixed move operators not being noexcept Fixed thread-safety (Now working correctly - If I'm lucky) Moved Resource to core New interface for modules New interface for the renderer Put some global functions to anonymous namespace Removed empty modules Renamed ThreadCondition to ConditionVariable Replaced redirect to cerr log option by duplicate to cout Setting mouse position relative to a window will make this window ignore the event Shaders sending methods no longer takes the uniform variable name (it's using ID instead) Using new OpenGL 4.3 header --- .../include/Nazara/ModuleName/ModuleName.hpp | 12 +- .../src/Nazara/ModuleName/ModuleName.cpp | 52 +- build/Build CodeBlocks + examples.bat | 1 + build/Build Visual Studio 2010 + examples.bat | 1 + build/Generate Headers.bat | 2 + build/scripts/actions/examples.lua | 10 + build/scripts/actions/headergenerator.lua | 54 + build/scripts/common.lua | 5 +- build/scripts/common_examples.lua | 33 + build/scripts/module/audio.lua | 31 - build/scripts/module/core.lua | 2 + build/scripts/module/network.lua | 35 - examples/AnimatedMesh/build.lua | 23 + examples/AnimatedMesh/main.cpp | 623 ++++++++ examples/ListSequences/build.lua | 23 + examples/ListSequences/main.cpp | 49 + include/GL3/{gl3.h => glcorearb.h} | 1262 +++++++++++++++-- include/GL3/glext.h | 1029 +++++++++++++- include/Nazara/Audio/Debug.hpp | 11 - include/Nazara/Core.hpp | 60 + include/Nazara/Core/ByteArray.hpp | 15 +- include/Nazara/Core/Clock.hpp | 2 +- include/Nazara/Core/Color.inl | 24 +- ...eadCondition.hpp => ConditionVariable.hpp} | 16 +- include/Nazara/Core/Config.hpp | 34 +- include/Nazara/Core/Core.hpp | 29 + include/Nazara/Core/Directory.hpp | 8 +- include/Nazara/Core/DynLib.hpp | 2 +- include/Nazara/Core/File.hpp | 6 +- include/Nazara/Core/HashDigest.hpp | 4 +- include/Nazara/Core/Initializer.hpp | 26 + include/Nazara/Core/Initializer.inl | 35 + include/Nazara/Core/Log.hpp | 2 +- include/Nazara/Core/Mutex.hpp | 4 +- include/Nazara/{Utility => Core}/Resource.hpp | 0 include/Nazara/Core/String.hpp | 17 +- include/Nazara/Core/StringStream.hpp | 2 +- include/Nazara/Core/Thread.hpp | 4 +- .../{Network/DebugOff.hpp => Debug.hpp} | 8 +- include/Nazara/{Audio => }/DebugOff.hpp | 6 +- .../Nazara/{Network/Config.hpp => Math.hpp} | 23 +- include/Nazara/Math/Basic.inl | 42 +- include/Nazara/Math/Config.hpp | 12 +- include/Nazara/Math/Cube.hpp | 12 +- include/Nazara/Math/Cube.inl | 138 +- include/Nazara/Math/EulerAngles.hpp | 22 +- include/Nazara/Math/EulerAngles.inl | 62 +- .../{Audio/Config.hpp => Math/Math.hpp} | 14 +- include/Nazara/Math/Matrix4.hpp | 49 +- include/Nazara/Math/Matrix4.inl | 729 ++++++---- include/Nazara/Math/Quaternion.hpp | 15 +- include/Nazara/Math/Quaternion.inl | 201 +-- include/Nazara/Math/Rect.hpp | 11 +- include/Nazara/Math/Rect.inl | 96 +- include/Nazara/Math/Vector2.hpp | 24 +- include/Nazara/Math/Vector2.inl | 146 +- include/Nazara/Math/Vector3.hpp | 33 +- include/Nazara/Math/Vector3.inl | 174 ++- include/Nazara/Math/Vector4.hpp | 27 +- include/Nazara/Math/Vector4.inl | 186 ++- include/Nazara/Network/Debug.hpp | 11 - include/Nazara/Noise.hpp | 39 + include/Nazara/Noise/Config.hpp | 4 - include/Nazara/Noise/Noise.hpp | 14 +- include/Nazara/Prerequesites.hpp | 15 +- include/Nazara/Renderer.hpp | 40 + include/Nazara/Renderer/Config.hpp | 3 - include/Nazara/Renderer/Enums.hpp | 9 + include/Nazara/Renderer/OpenGL.hpp | 11 +- include/Nazara/Renderer/RenderWindow.hpp | 15 +- include/Nazara/Renderer/Renderer.hpp | 109 +- include/Nazara/Renderer/Shader.hpp | 31 +- include/Nazara/Utility.hpp | 53 + include/Nazara/Utility/Animation.hpp | 2 +- include/Nazara/Utility/AxisAlignedBox.hpp | 50 + include/Nazara/Utility/Buffer.hpp | 2 +- include/Nazara/Utility/Config.hpp | 12 +- include/Nazara/Utility/Enums.hpp | 31 +- include/Nazara/Utility/Event.hpp | 67 +- include/Nazara/Utility/Image.hpp | 12 +- include/Nazara/Utility/IndexBuffer.hpp | 2 +- include/Nazara/Utility/Mesh.hpp | 10 +- include/Nazara/Utility/Mouse.hpp | 2 +- include/Nazara/Utility/PixelFormat.inl | 2 +- include/Nazara/Utility/StaticMesh.hpp | 13 +- include/Nazara/Utility/SubMesh.hpp | 4 +- include/Nazara/Utility/Utility.hpp | 12 +- include/Nazara/Utility/VertexBuffer.hpp | 2 +- include/Nazara/Utility/VertexDeclaration.hpp | 6 +- include/Nazara/Utility/Window.hpp | 16 +- src/Nazara/Audio/Debug/Leaks.cpp | 29 - src/Nazara/Core/Clock.cpp | 33 +- ...eadCondition.cpp => ConditionVariable.cpp} | 20 +- src/Nazara/Core/Core.cpp | 39 + src/Nazara/Core/Debug/MemoryLeakTracker.cpp | 14 +- src/Nazara/Core/Directory.cpp | 78 +- src/Nazara/Core/Error.cpp | 2 +- src/Nazara/Core/File.cpp | 12 +- src/Nazara/Core/Hash/MD5.cpp | 2 +- src/Nazara/Core/Hash/SHA/Internal.cpp | 216 +-- src/Nazara/Core/HashDigest.cpp | 4 +- src/Nazara/Core/Log.cpp | 14 +- src/Nazara/{Utility => Core}/Resource.cpp | 8 +- src/Nazara/Core/String.cpp | 59 +- ...tionImpl.cpp => ConditionVariableImpl.cpp} | 24 +- ...tionImpl.hpp => ConditionVariableImpl.hpp} | 18 +- src/Nazara/Core/Win32/FileImpl.cpp | 8 +- src/Nazara/Core/Win32/MutexImpl.cpp | 4 + src/Nazara/Core/Win32/MutexImpl.hpp | 4 +- src/Nazara/Core/Win32/Time.cpp | 24 + src/Nazara/Core/Win32/Time.hpp | 19 +- src/Nazara/Network/Debug/Leaks.cpp | 29 - src/Nazara/Noise/Noise.cpp | 54 +- src/Nazara/Renderer/GLSLShader.cpp | 332 +++-- src/Nazara/Renderer/GLSLShader.hpp | 34 +- src/Nazara/Renderer/HardwareBuffer.cpp | 10 +- src/Nazara/Renderer/OcclusionQuery.cpp | 2 +- src/Nazara/Renderer/OpenGL.cpp | 36 +- src/Nazara/Renderer/RenderTarget.cpp | 8 +- src/Nazara/Renderer/RenderWindow.cpp | 40 +- src/Nazara/Renderer/Renderer.cpp | 557 +++++--- src/Nazara/Renderer/Shader.cpp | 246 +++- src/Nazara/Renderer/ShaderImpl.hpp | 28 +- src/Nazara/Renderer/Texture.cpp | 127 +- src/Nazara/Utility/AxisAlignedBox.cpp | 162 +++ src/Nazara/Utility/Buffer.cpp | 3 +- src/Nazara/Utility/Image.cpp | 65 +- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 13 +- src/Nazara/Utility/Loaders/MD2/Mesh.cpp | 34 +- src/Nazara/Utility/Loaders/MD2/Mesh.hpp | 5 +- src/Nazara/Utility/Loaders/PCX/Loader.cpp | 2 +- src/Nazara/Utility/Mesh.cpp | 49 + src/Nazara/Utility/Mouse.cpp | 7 + src/Nazara/Utility/PixelFormat.cpp | 2 +- src/Nazara/Utility/StaticMesh.cpp | 65 +- src/Nazara/Utility/SubMesh.cpp | 4 +- src/Nazara/Utility/Utility.cpp | 57 +- src/Nazara/Utility/VertexDeclaration.cpp | 28 +- src/Nazara/Utility/Win32/InputImpl.cpp | 2 +- src/Nazara/Utility/Win32/WindowImpl.cpp | 290 ++-- src/Nazara/Utility/Win32/WindowImpl.hpp | 22 +- src/Nazara/Utility/Window.cpp | 66 +- 142 files changed, 6861 insertions(+), 2326 deletions(-) create mode 100644 build/Build CodeBlocks + examples.bat create mode 100644 build/Build Visual Studio 2010 + examples.bat create mode 100644 build/Generate Headers.bat create mode 100644 build/scripts/actions/examples.lua create mode 100644 build/scripts/actions/headergenerator.lua create mode 100644 build/scripts/common_examples.lua delete mode 100644 build/scripts/module/audio.lua delete mode 100644 build/scripts/module/network.lua create mode 100644 examples/AnimatedMesh/build.lua create mode 100644 examples/AnimatedMesh/main.cpp create mode 100644 examples/ListSequences/build.lua create mode 100644 examples/ListSequences/main.cpp rename include/GL3/{gl3.h => glcorearb.h} (79%) delete mode 100644 include/Nazara/Audio/Debug.hpp create mode 100644 include/Nazara/Core.hpp rename include/Nazara/Core/{ThreadCondition.hpp => ConditionVariable.hpp} (58%) create mode 100644 include/Nazara/Core/Core.hpp create mode 100644 include/Nazara/Core/Initializer.hpp create mode 100644 include/Nazara/Core/Initializer.inl rename include/Nazara/{Utility => Core}/Resource.hpp (100%) rename include/Nazara/{Network/DebugOff.hpp => Debug.hpp} (50%) rename include/Nazara/{Audio => }/DebugOff.hpp (63%) rename include/Nazara/{Network/Config.hpp => Math.hpp} (69%) rename include/Nazara/{Audio/Config.hpp => Math/Math.hpp} (77%) delete mode 100644 include/Nazara/Network/Debug.hpp create mode 100644 include/Nazara/Noise.hpp create mode 100644 include/Nazara/Renderer.hpp create mode 100644 include/Nazara/Utility.hpp create mode 100644 include/Nazara/Utility/AxisAlignedBox.hpp delete mode 100644 src/Nazara/Audio/Debug/Leaks.cpp rename src/Nazara/Core/{ThreadCondition.cpp => ConditionVariable.cpp} (52%) create mode 100644 src/Nazara/Core/Core.cpp rename src/Nazara/{Utility => Core}/Resource.cpp (88%) rename src/Nazara/Core/Win32/{ThreadConditionImpl.cpp => ConditionVariableImpl.cpp} (80%) rename src/Nazara/Core/Win32/{ThreadConditionImpl.hpp => ConditionVariableImpl.hpp} (67%) create mode 100644 src/Nazara/Core/Win32/Time.cpp delete mode 100644 src/Nazara/Network/Debug/Leaks.cpp create mode 100644 src/Nazara/Utility/AxisAlignedBox.cpp diff --git a/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp b/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp index 70d8f6918..54bc0f3b8 100644 --- a/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp +++ b/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp @@ -8,20 +8,22 @@ #define NAZARA_MODULENAME_HPP #include +#include class NAZARA_API NzModuleName { public: - NzModuleName(); - ~NzModuleName(); + NzModuleName() = delete; + ~NzModuleName() = delete; - bool Initialize(); - void Uninitialize(); + static bool Initialize(); static bool IsInitialized(); + static void Uninitialize(); + private: - static bool s_initialized; + static unsigned int s_moduleReferenceCouter; }; #endif // NAZARA_MODULENAME_HPP diff --git a/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp b/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp index f6cbd4530..7c600b5de 100644 --- a/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp +++ b/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp @@ -3,55 +3,47 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include +#include #include #include -NzModuleName::NzModuleName() -{ -} - -NzModuleName::~NzModuleName() -{ - if (s_initialized) - Uninitialize(); -} - bool NzModuleName::Initialize() { - #if NAZARA_MODULENAME_SAFE - if (s_initialized) + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation des dépendances + if (!NzCore::Initialize()) { - NazaraError("ModuleName already initialized"); - return true; + NazaraError("Failed to initialize core module"); + return false; } - #endif // Initialisation du module - s_initialized = true; + NazaraNotice("Initialized: ModuleName module"); return true; } +bool NzModuleName::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + void NzModuleName::Uninitialize() { - #if NAZARA_MODULENAME_SAFE - if (!s_initialized) - { - NazaraError("ModuleName not initialized"); - return; - } - #endif + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé // Libération du module - s_initialized = false; + NazaraNotice("Uninitialized: ModuleName module"); + + // Libération des dépendances + NzCore::Uninitialize(); } -bool NzModuleName::IsInitialized() -{ - return s_initialized; -} - -bool NzModuleName::s_initialized = false; +unsigned int NzModuleName::s_moduleReferenceCouter = 0; diff --git a/build/Build CodeBlocks + examples.bat b/build/Build CodeBlocks + examples.bat new file mode 100644 index 000000000..d56d06eac --- /dev/null +++ b/build/Build CodeBlocks + examples.bat @@ -0,0 +1 @@ +premake4 --with-examples codeblocks \ No newline at end of file diff --git a/build/Build Visual Studio 2010 + examples.bat b/build/Build Visual Studio 2010 + examples.bat new file mode 100644 index 000000000..b6e707acd --- /dev/null +++ b/build/Build Visual Studio 2010 + examples.bat @@ -0,0 +1 @@ +premake4 --with-examples vs2010 \ No newline at end of file diff --git a/build/Generate Headers.bat b/build/Generate Headers.bat new file mode 100644 index 000000000..41ac7b82a --- /dev/null +++ b/build/Generate Headers.bat @@ -0,0 +1,2 @@ +premake4 generateheaders +pause \ No newline at end of file diff --git a/build/scripts/actions/examples.lua b/build/scripts/actions/examples.lua new file mode 100644 index 000000000..0cb6d9ef7 --- /dev/null +++ b/build/scripts/actions/examples.lua @@ -0,0 +1,10 @@ +function examples() + dofile("../examples/build/common.lua") +end + +newaction +{ + trigger = "examples", + description = "Generate examples", + execute = examples +} \ No newline at end of file diff --git a/build/scripts/actions/headergenerator.lua b/build/scripts/actions/headergenerator.lua new file mode 100644 index 000000000..0553807f4 --- /dev/null +++ b/build/scripts/actions/headergenerator.lua @@ -0,0 +1,54 @@ +function generateHeaders() + local modules = os.matchdirs("../include/Nazara/*") + for k, modulePath in pairs(modules) do + local moduleName = modulePath:match(".*/(.*)") + print(moduleName) + + local config, err = io.open(modulePath .. "/Config.hpp", "r") + local head = "" + if (not config) then + error("Failed to read config file: " .. err) + end + + for line in config:lines() do + head = head .. line .. "\n" + if (line == "#pragma once") then -- On s'arrête au #pragma once, qu'on inclut quand même + break + end + end + + config:close() + + local header, err = io.open(modulePath .. ".hpp", "w+") + if (not header) then + error("Failed to create header file: " .. err) + end + + header:write("// This file was automatically generated by Nazara\n\n") + header:write(head .. "\n") + + local files = os.matchfiles(modulePath .. "/*.hpp") + local count = 0 + for k, filePath in pairs(files) do + local include, fileName = filePath:match(".*(Nazara/.*/(.*))") + if (fileName ~= "Debug.hpp" and + fileName ~= "DebugOff.hpp" and + fileName ~= "ThreadSafety.hpp" and + fileName ~= "ThreadSafetyOff.hpp") then + header:write("#include <" .. include .. ">\n") + count = count + 1 + end + end + + print(string.format("-# of includes: %d", count)) + + header:close() + end +end + +newaction +{ + trigger = "generateheaders", + description = "Generate a global header for each module", + execute = generateHeaders +} \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index d2df3aa9a..75b85d056 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -9,11 +9,14 @@ configurations defines "NAZARA_BUILD" language "C++" +location(_ACTION) + includedirs { "../include", "../src/" } + libdirs "../lib" targetdir "../lib" @@ -22,7 +25,7 @@ configuration "Debug*" flags "Symbols" configuration "Release*" - flags { "Optimize", "OptimizeSpeed" } + flags { "EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI" } configuration "*Static" defines "NAZARA_STATIC" diff --git a/build/scripts/common_examples.lua b/build/scripts/common_examples.lua new file mode 100644 index 000000000..0fcc880f7 --- /dev/null +++ b/build/scripts/common_examples.lua @@ -0,0 +1,33 @@ +-- Configuration générale +configurations +{ + "DebugStatic", + "ReleaseStatic", + "DebugDLL", + "ReleaseDLL" +} + +language "C++" +location("../examples/build/" .. _ACTION) + +includedirs +{ + "../include" +} + +debugdir "../examples/bin" +libdirs "../lib" +targetdir "../examples/bin" + +configuration "Debug*" + defines "NAZARA_DEBUG" + flags "Symbols" + +configuration "Release*" + flags { "EnableSSE2", "Optimize", "OptimizeSpeed", "NoFramePointer", "NoRTTI" } + +configuration "*Static" + defines "NAZARA_STATIC" + +configuration "gmake" + buildoptions "-std=c++11" diff --git a/build/scripts/module/audio.lua b/build/scripts/module/audio.lua deleted file mode 100644 index f8a123635..000000000 --- a/build/scripts/module/audio.lua +++ /dev/null @@ -1,31 +0,0 @@ -project "NazaraAudio" - -files -{ - "../include/Nazara/Audio/**.hpp", - "../include/Nazara/Audio/**.inl", - "../src/Nazara/Audio/**.hpp", - "../src/Nazara/Audio/**.cpp" -} - -if (os.is("windows")) then - excludes { "../src/Nazara/Audio/Posix/*.hpp", "../src/Nazara/Audio/Posix/*.cpp" } -else - excludes { "../src/Nazara/Audio/Win32/*.hpp", "../src/Nazara/Audio/Win32/*.cpp" } -end - -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraAudiod" - -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraAudio" - -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraAudiod" - -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraAudio" \ No newline at end of file diff --git a/build/scripts/module/core.lua b/build/scripts/module/core.lua index d2842982b..4efb6b578 100644 --- a/build/scripts/module/core.lua +++ b/build/scripts/module/core.lua @@ -5,6 +5,8 @@ files "../include/Nazara/Prerequesites.hpp", "../include/Nazara/Core/**.hpp", "../include/Nazara/Core/**.inl", + "../include/Nazara/Math/**.hpp", + "../include/Nazara/Math/**.inl", "../src/Nazara/Core/**.hpp", "../src/Nazara/Core/**.cpp" } diff --git a/build/scripts/module/network.lua b/build/scripts/module/network.lua deleted file mode 100644 index 49ba48744..000000000 --- a/build/scripts/module/network.lua +++ /dev/null @@ -1,35 +0,0 @@ -project "NazaraNetwork" - -if (os.is("windows")) then - links "ws2_32" -end - -files -{ - "../include/Nazara/Network/**.hpp", - "../include/Nazara/Network/**.inl", - "../src/Nazara/Network/**.hpp", - "../src/Nazara/Network/**.cpp" -} - -if (os.is("windows")) then - excludes { "../src/Nazara/Network/Posix/*.hpp", "../src/Nazara/Network/Posix/*.cpp" } -else - excludes { "../src/Nazara/Network/Win32/*.hpp", "../src/Nazara/Network/Win32/*.cpp" } -end - -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraNetworkd" - -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraNetwork" - -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraNetworkd" - -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraNetwork" \ No newline at end of file diff --git a/examples/AnimatedMesh/build.lua b/examples/AnimatedMesh/build.lua new file mode 100644 index 000000000..4d93b53c9 --- /dev/null +++ b/examples/AnimatedMesh/build.lua @@ -0,0 +1,23 @@ +kind "ConsoleApp" + +files "main.cpp" + +configuration "DebugStatic" + links "NazaraCored-s" + links "NazaraRendererd-s" + links "NazaraUtilityd-s" + +configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraRenderer-s" + links "NazaraUtility-s" + +configuration "DebugDLL" + links "NazaraCored" + links "NazaraRendererd" + links "NazaraUtilityd" + +configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraRenderer" + links "NazaraUtility" \ No newline at end of file diff --git a/examples/AnimatedMesh/main.cpp b/examples/AnimatedMesh/main.cpp new file mode 100644 index 000000000..0617aaa5d --- /dev/null +++ b/examples/AnimatedMesh/main.cpp @@ -0,0 +1,623 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Une structure pour contenir nos informations (Cette structure est très simpliste) +struct Model +{ + NzMatrix4f matrix; // Les transformations subies par le modèle + NzMesh mesh; // Le mesh + NzTexture texture; // Sa texture +}; + +struct AnimatedModel : public Model +{ + // Quelques variables pour l'animation + const NzSequence* currentSequence = nullptr; // La séquence en cours + float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) + unsigned int currentFrame = 0; // La première frame + unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là +}; + +void AnimateModel(AnimatedModel& moedel, float elapsed); +bool CreateCheckerTexture(NzTexture* texture); +bool CreateFloorMesh(NzMesh* mesh); +void DrawModel(const Model& model); +void SetSequence(AnimatedModel& model, const NzString& name); + +int main() +{ + // Tout d'abord on affiche les instructions + std::cout << "Camera controls: ZQSD" << std::endl; + std::cout << "Dr. Freak controls: Up, down, left and right" << std::endl; + std::cout << "Escape to quit" << std::endl; + + // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) + NzContextParameters::defaultCompatibilityProfile = true; + + // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utlitaire) + // Cette étape est obligatoire pour beaucoup de classes + NzInitializer renderer; + if (!renderer) + { + // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log + std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + // 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 + // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] + // Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters + NzMeshParams parameters; + + // Le loader doit-il automatiquement charger les animations ? + // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. + // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné + // qu'elles sont fourniees avec le mesh. + // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut + // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés + parameters.loadAnimations = true; // Vaut true par défaut + + // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de + // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. + parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut + + AnimatedModel drfreak; + if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. + { + // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. + std::cout << "Failed to load mesh" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? + { + // Cette démo n'a aucun intérêt sans animations + std::cout << "Mesh has no animation" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + SetSequence(drfreak, "stand"); + + // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture + if (drfreak.mesh.HasSkin()) + { + // Contrairement aux autres ressources, la texture n'est pas critique + if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin())) + drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire + else + std::cout << "Failed to load texture" << std::endl; + } + + if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée + { + std::cout << "Creating checker texture for mesh" << std::endl; + + if (!CreateCheckerTexture(&drfreak.texture)) + { + std::cout << "Failed to create mesh texture" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + } + + // Nous créons maintenant notre sol + Model floor; + if (!CreateFloorMesh(&floor.mesh)) + { + std::cout << "Failed to create floor" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + if (!CreateCheckerTexture(&floor.texture)) + { + std::cout << "Failed to create floor texture" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Le sol ne subit aucune transformation + floor.matrix.MakeIdentity(); + + // Pour effectuer un rendu, il faut que la carte graphique sache quoi faire. + // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors du pipeline. + // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! + // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. + // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL + // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. + NzShader shader; + if (!shader.Create(nzShaderLanguage_GLSL)) + { + std::cout << "Failed to load shader" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders + // Pour notre exemple nous prendrons un shader très simple + // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader + if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag")) + { + std::cout << "Failed to load fragment shader from file" << std::endl; + // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Maintenant le vertex shader + if (!shader.LoadFromFile(nzShaderType_Vertex, "shaders/basic.vert")) + { + std::cout << "Failed to load vertex shader from file" << std::endl; + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Une fois le code source de nos shaders chargé, nous pouvons le compiler, afin de le rendre utilisable + if (!shader.Compile()) + { + std::cout << "Failed to compile shader" << std::endl; + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça + // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow + // Tout d'abord, sa taille, disons celle du bureau divisé par deux + NzVideoMode mode = NzVideoMode::GetDesktopMode(); + mode.width /= 2; + mode.height /= 2; + + NzString title = "Nazara Demo - AnimatedMesh"; + + NzRenderWindow window; + // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède des bordures elle sera légèrement plus grande) + // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle + // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. + // Attention que cela permet à la fenêtre d'envoyer des évènements, et de changer sa taille + // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) + if (!window.Create(mode, title, nzWindowStyle_Default)) + { + std::cout << "Failed to create window" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // On cache le curseur + window.SetCursor(nzWindowCursor_None); + + // Nous limitons les FPS à 100 + window.SetFramerateLimit(100); + + // La matrice de projection définit la transformation du vertice 3D à un point 2D + NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(window.GetWidth())/window.GetHeight(), 1.f, 1000.f)); + + // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements + NzClock secondClock, updateClock; // Des horloges pour gérer le temps + unsigned int fps = 0; // Compteur de FPS + + // Quelques variables pour notre improvisation de physique + float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Pas très exact + NzVector3f modelPos(0.f, groundPos, -50.f); + NzVector3f modelVel(0.f, 0.f, 0.f); + NzQuaternionf modelRot(NzEulerAnglesf(0.f, 0.f, 0.f)); // Les angles d'eulers sont bien plus facile à se représenter + float speed = 60.f; + + // Nous initialisons la matrice + drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); + + // Notre caméra + NzVector3f camPos(0.f, 25.f, -20.f); + NzEulerAnglesf camRot(0.f, 0.f, 0.f); + NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos); + float camSpeed = 2.f; + float sensitivity = 0.5; + + // Dernière étape, nos touches + + // Chaque touche fera bouger + struct Movement + { + NzVector3f direction; // La direction + NzQuaternionf rotation; // La rotation du modèle + }; + + std::map movements; + movements[NzKeyboard::Up] = Movement{NzVector3f(0.f, 0.f, -1.f), NzQuaternionf(NzEulerAnglesf(0.f, 180.f, 0.f))}; + movements[NzKeyboard::Down] = Movement{NzVector3f(0.f, 0.f, 1.f), NzQuaternionf(NzEulerAnglesf(0.f, 0.f, 0.f))}; + movements[NzKeyboard::Left] = Movement{NzVector3f(-1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, 90.f, 0.f))}; + movements[NzKeyboard::Right] = Movement{NzVector3f(1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, -90.f, 0.f))}; + NzKeyboard::Key currentKey = NzKeyboard::Undefined; + + // Quelques booléens + bool camMode = true; + bool windowOpen = true; + while (windowOpen) + { + // Ici nous gérons les évènements + NzEvent event; + while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? + { + // Nous avons un évènement + switch (event.type) // De quel type est cet évènement ? + { + case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution + windowOpen = false; // Nous fermons alors la boucle + break; + + case nzEventType_MouseMoved: + { + // Si nous ne sommes pas en mode caméra, on ne traite pas l'évènement + if (!camMode) + break; + + // On modifie l'angle de la caméra grâce au déplacement relatif de la souris + camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity); + + // Pour éviter les loopings, on restreint les angles + camRot.pitch = NzClamp(camRot.pitch + event.mouseMove.deltaY*sensitivity, -90.f, 90.f); + + // La matrice vue représente les transformations effectuées par la caméra + // On recalcule la matrice de la caméra et on l'envoie au renderer + NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot)); + + // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre + NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window); + break; + } + + case nzEventType_MouseButtonPressed: + if (event.mouseButton.button == NzMouse::Left) + { + // L'utilisateur vient d'appuyer sur le bouton left de la souris + // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence + if (camMode) + { + camMode = false; + window.SetCursor(nzWindowCursor_Default); + } + else + { + camMode = true; + window.SetCursor(nzWindowCursor_None); + } + + } + break; + + case nzEventType_Resized: // L'utilisateur a changé notre taille, le coquin ! + NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage + + // Il nous faut aussi mettre à jour notre matrice de projection + NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(event.size.width)/event.size.height, 1.f, 1000.f)); + break; + + case nzEventType_KeyPressed: + if (!event.key.repeated) // Si la touche n'est pas répétée + { + auto it = movements.find(event.key.code); + if (it != movements.end()) + { + // Si la touche est une touche de mouvement + SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement + + modelRot = it->second.rotation; // On change la rotation du modèle + drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); // On recalcule sa matrice + modelVel = it->second.direction * speed; // On change la vitesse de déplacement + currentKey = event.key.code; + } + } + + if (event.key.code == NzKeyboard::Escape) + windowOpen = false; + + break; + + case nzEventType_KeyReleased: + if (event.key.code == currentKey) + { + SetSequence(drfreak, "stand"); + modelVel = NzVector3f(0.f); // On arrête le déplacement + break; + } + + break; + + default: // Les autres évènements, on s'en fiche + break; + } + } + + // On active le shader et paramètrons le rendu + NzRenderer::SetShader(&shader); + NzRenderer::Enable(nzRendererParameter_DepthTest, true); + + NzRenderer::SetClearColor(128, 128, 128); + NzRenderer::Clear(nzRendererClear_Color | nzRendererClear_Depth); + + if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde + { + float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour + + // Déplacement de la caméra + static const NzVector3f forward(NzVector3f::UnitZ()); + static const NzVector3f left(NzVector3f::UnitX()); + static const NzVector3f up(NzVector3f::UnitY()); + + // Notre rotation sous forme de quaternion nous permet de tourner un vecteur + NzQuaternionf quaternion(camRot); + + // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" + if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) + camPos += quaternion * forward * camSpeed; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) + camPos -= quaternion * forward * camSpeed; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) + camPos += quaternion * left * camSpeed; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) + camPos -= quaternion * left * camSpeed; + + // En revanche, ici la hauteur est toujours la même, peu importe notre orientation + if (NzKeyboard::IsKeyPressed(NzKeyboard::Space)) + camPos += up * camSpeed; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl)) + camPos -= up * camSpeed; + + // Oui le quaternion et la matrice sont calculés même si la caméra ne bouge pas + // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés + NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot)); + + // Animation + AnimateModel(drfreak, elapsedTime); + updateClock.Restart(); + + // "Physique" + if (modelVel != NzVector3f::Zero()) + { + modelPos += modelVel * elapsedTime; + /*if (jumping) + { + velocity.y -= 500.f * elapsedTime; // Un simulacre de gravité + if (modelPos.y <= groundPos) + { + // On stoppe net + modelPos.y = groundPos; + velocity.y = 0.f; + jumping = false; + SetSequence(drfreak, "stand"); + } + }*/ + + // Mise à jour de la matrice + drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); + } + } + + // Affichage des meshs + DrawModel(floor); + + // Notre Dr. Freak possède des normales, nous pouvons alors culler les faces qu'on ne voit pas + NzRenderer::Enable(nzRendererParameter_FaceCulling, true); + + DrawModel(drfreak); + + NzRenderer::Enable(nzRendererParameter_FaceCulling, false); + + window.Display(); // Nous mettons à jour l'écran + + fps++; + + // Toutes les secondes + if (secondClock.GetMilliseconds() >= 1000) + { + window.SetTitle(title + " (FPS: " + NzString::Number(fps) + ')'); + fps = 0; + secondClock.Restart(); + } + } + + return EXIT_SUCCESS; +} + +void AnimateModel(AnimatedModel& model, float elapsed) +{ + model.interpolation += model.currentSequence->framePerSecond * elapsed; + while (model.interpolation > 1.f) + { + model.interpolation -= 1.f; + + model.currentFrame = model.nextFrame; + if (++model.nextFrame > model.currentSequence->lastFrame) + model.nextFrame = model.currentSequence->firstFrame; + } + + model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation); +} + +bool CreateCheckerTexture(NzTexture* texture) +{ + NzImage image; + // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) + if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16)) + { + // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) + std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl; + return false; + } + + // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel + // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. + unsigned int blockCountX = image.GetWidth()/16; + unsigned int blockCountY = image.GetHeight()/16; + for (unsigned int x = 0; x < blockCountX; ++x) + { + for (unsigned int y = 0; y < blockCountY; ++y) + { + // Une belle texture de damier + NzColor color = (x%2 == y%2) ? NzColor::White : NzColor::Black; + // Fill remplit une zone de la texture avec une couleur + image.Fill(color, NzRectui(x*16, y*16, 16, 16)); + } + } + + if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image + { + // Nous n'avons vraiment pas beaucoup de chance.. + std::cout << "Failed to load image" << std::endl; + return false; + } + + texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture + texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée + + return true; +} + +bool CreateFloorMesh(NzMesh* mesh) +{ + // Cette fonction créé un mesh statique simpliste pour servir de sol + + // Nous créons un mesh statique + if (!mesh->Create(nzAnimationType_Static)) + { + // L'échec est techniquement impossible mais le moteur étant en constante évolution ... + std::cout << "Failed to create mesh" << std::endl; + return false; + } + + // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer + // Elles sont composées de VertexElement, chacun décrivant un élément du buffer + NzVertexDeclaration* declaration = new NzVertexDeclaration; + + // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) + // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) + // -Usage: Comment cette donnée doit-elle être envoyée au shader + // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) + // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) + // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. + NzVertexElement elements[2]; + elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices + elements[0].offset = 0; // Celles-ci sont placées au début + elements[0].type = nzElementType_Float3; // Sont composées de trois flottants + + elements[1].usage = nzElementUsage_TexCoord; + elements[1].offset = 3*sizeof(float); + elements[1].type = nzElementType_Float2; + + if (!declaration->Create(elements, 2)) + { + // Nos éléments sont invalides ! + std::cout << "Failed to create vertex declaration" << std::endl; + return false; + } + + // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage + // Et nous indiquons que nous n'y toucherons plus + NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static); + + // Doit respecter la declaration + float vertices[] = + { + // Vertex 1 + -1000.f, 0.f, -1000.f, // Position + 0.f, 0.f, // UV + + // Vertex 2 + -1000.f, 0.f, 1000.f, // Position + 0.f, 10.f, // UV + + // Vertex 3 + 1000.f, 0.f, -1000.f, // Position + 10.f, 0.f, // UV + + // Vertex 4 + 1000.f, 0.f, 1000.f, // Position + 10.f, 10.f // UV + }; + + // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) + if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices + { + std::cout << "Failed to fill buffer" << std::endl; + return false; + } + + NzStaticMesh* subMesh = new NzStaticMesh(mesh); + if (!subMesh->Create(declaration, buffer)) + { + std::cout << "Failed to create subMesh" << std::endl; + return false; + } + + subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip); + + // On ajoute le submesh au mesh + mesh->AddSubMesh(subMesh); + + // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. + // Les ressources seront donc automatiquement libérées lorsque plus aucune classe n'en aura besoin + buffer->SetPersistent(false); + declaration->SetPersistent(false); + subMesh->SetPersistent(false); // Pour le submesh, c'est déjà à false à la base + + return true; +} + +void DrawModel(const Model& model) +{ + // La matrice world est celle qui représente les transformations du modèle + NzRenderer::SetMatrix(nzMatrixType_World, model.matrix); + + NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu + shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture); + + // Un mesh est divisé en plusieurs submeshes + unsigned int subMeshCount = model.mesh.GetSubMeshCount(); + for (unsigned int i = 0; i < subMeshCount; ++i) + { + // On récupère le submesh + const NzSubMesh* subMesh = model.mesh.GetSubMesh(i); + + // On paramètre le Renderer avec ses données + NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer()); + NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer()); + NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration()); + + // On fait le rendu + NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount()); + } +} + +void SetSequence(AnimatedModel& model, const NzString& sequenceName) +{ + // On récupère l'animation du mesh + const NzAnimation* animation = model.mesh.GetAnimation(); + + // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) + model.currentSequence = animation->GetSequence(sequenceName); + + // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame + model.nextFrame = model.currentSequence->firstFrame; +} diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua new file mode 100644 index 000000000..4d93b53c9 --- /dev/null +++ b/examples/ListSequences/build.lua @@ -0,0 +1,23 @@ +kind "ConsoleApp" + +files "main.cpp" + +configuration "DebugStatic" + links "NazaraCored-s" + links "NazaraRendererd-s" + links "NazaraUtilityd-s" + +configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraRenderer-s" + links "NazaraUtility-s" + +configuration "DebugDLL" + links "NazaraCored" + links "NazaraRendererd" + links "NazaraUtilityd" + +configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraRenderer" + links "NazaraUtility" \ No newline at end of file diff --git a/examples/ListSequences/main.cpp b/examples/ListSequences/main.cpp new file mode 100644 index 000000000..5544e82eb --- /dev/null +++ b/examples/ListSequences/main.cpp @@ -0,0 +1,49 @@ +#include +#include +#include + +int main() +{ + // Pour charger des ressources, il est impératif d'initialiser le module utilitaire + NzInitializer utility; + if (!utility) + { + // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log + std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + // Le Renderer n'étant pas chargé, nous devons indiquer que nous désirons un stockage software de notre mesh + NzMeshParams parameters; + parameters.storage = nzBufferStorage_Software; + + NzMesh drfreak; + if (!drfreak.LoadFromFile("resources/drfreak.md2", parameters)) + { + std::cout << "Failed to load Dr. Freak's mesh" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + if (drfreak.HasAnimation()) // Si le mesh possède des animations + { + std::cout << "Mesh has animation" << std::endl; + + // Un objet NzAnimation représente un ensemble d'informations sur des animations + const NzAnimation* animation = drfreak.GetAnimation(); + + // Une séquence définit une "action", chaque séquence possède un nom, une frame de départ, une d'arrivée ainsi qu'un framerate + unsigned int sequenceCount = animation->GetSequenceCount(); + std::cout << sequenceCount << " sequences:" << std::endl; + for (unsigned int i = 0; i < sequenceCount; ++i) + std::cout << "-" << (i+1) << ": " << animation->GetSequence(i)->name << std::endl; + } + else + std::cout << "Mesh has no animation" << std::endl; + + std::getchar(); // Une attente pour avoir le temps de lire :-) + + // Le module utilitaire et le mesh sont déchargés automatiquement + return EXIT_SUCCESS; +} diff --git a/include/GL3/gl3.h b/include/GL3/glcorearb.h similarity index 79% rename from include/GL3/gl3.h rename to include/GL3/glcorearb.h index 9c17d418c..df7ca48bc 100644 --- a/include/GL3/gl3.h +++ b/include/GL3/glcorearb.h @@ -1,5 +1,5 @@ -#ifndef __gl3_h_ -#define __gl3_h_ +#ifndef __glcorearb_h_ +#define __glcorearb_h_ #ifdef __cplusplus extern "C" { @@ -28,41 +28,29 @@ extern "C" { ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. */ -/* This is a draft release of gl3.h, a header for use with OpenGL 3.1, and - * 3.2 and later core profile implementations. The current version is - * available at http://www.opengl.org/registry/ . Please don't package - * gl3.h for release with other software until it's out of draft status. - * The structure of the file may change significantly, and the details - * will probably change slightly as we make sure exactly the right set - * of interfaces is included. +/* glcorearb.h replaces gl3.h. It is for use with OpenGL core + * profile implementations. * - * gl3.h last updated on $Date: 2012-06-18 11:26:35 -0700 (Mon, 18 Jun 2012) $ + * glcorearb.h last updated on $Date: 2012-08-06 01:59:22 -0700 (Mon, 06 Aug 2012) $ * - * RELEASE NOTES - 2012/06/18 + * RELEASE NOTES - 2012/08/06 * - * gl3.h should be placed under a directory 'GL3' and included as - * ''. + * glcorearb.h should be placed in the same directory as gl.h and + * included as + * ''. * - * gl3.h is supposed to only include APIs in a OpenGL 3.1 (without - * GL_ARB_compatibility) or OpenGL 3.2-4.2 (inclusive) core profile - * implementation, as well as interfaces for newer ARB extensions which + * gl3.h includes only APIs in the latest OpenGL core profile + * implementation together with APIs in newer ARB extensions which can be * can be supported by the core profile. It does not, and never will * include functionality removed from the core profile, such as * fixed-function vertex and fragment processing. * - * Implementations of OpenGL 3.1 supporting the optional - * GL_ARB_compatibility extension continue to provide that functionality, - * as do implementations of the OpenGL 3.2+ compatibility profiles, and - * source code requiring it should use the traditional and - * headers instead of . - * - * It is not possible to #include both and either of + * It is not possible to #include both and either of * or in the same source file. * - * We welcome feedback on gl3.h. Please register for the Khronos Bugzilla - * (www.khronos.org/bugzilla) and file issues there under product - * "OpenGL", category "Registry". Feedback on the opengl.org forums - * may not be responded to in a timely fashion. + * Feedback can be given by register for the Khronos Bugzilla + * (www.khronos.org/bugzilla) and filing issues there under product + * "OpenGL", category "Registry". */ /* Function declaration macros - to move into glplatform.h */ @@ -250,6 +238,9 @@ typedef void GLvoid; #define GL_UNSIGNED_INT 0x1405 #define GL_FLOAT 0x1406 #define GL_DOUBLE 0x140A +/* ErrorCode */ +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 /* LogicOp */ #define GL_CLEAR 0x1500 #define GL_AND 0x1501 @@ -1251,6 +1242,290 @@ typedef void GLvoid; /* reuse GL_TEXTURE_IMMUTABLE_FORMAT */ #endif +#ifndef GL_VERSION_4_3 +#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 +#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E +/* Reuse tokens from ARB_arrays_of_arrays (none, GLSL only) */ +/* Reuse tokens from ARB_fragment_layer_viewport (none, GLSL only) */ +/* Reuse tokens from ARB_shader_image_size (none, GLSL only) */ +/* Reuse tokens from ARB_ES3_compatibility */ +/* reuse GL_COMPRESSED_RGB8_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_ETC2 */ +/* reuse GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_RGBA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_R11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_R11_EAC */ +/* reuse GL_COMPRESSED_RG11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_RG11_EAC */ +/* reuse GL_PRIMITIVE_RESTART_FIXED_INDEX */ +/* reuse GL_ANY_SAMPLES_PASSED_CONSERVATIVE */ +/* reuse GL_MAX_ELEMENT_INDEX */ +/* Reuse tokens from ARB_clear_buffer_object (none) */ +/* Reuse tokens from ARB_compute_shader */ +/* reuse GL_COMPUTE_SHADER */ +/* reuse GL_MAX_COMPUTE_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_COMPUTE_IMAGE_UNIFORMS */ +/* reuse GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */ +/* reuse GL_MAX_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTERS */ +/* reuse GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_LOCAL_INVOCATIONS */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_COUNT */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_SIZE */ +/* reuse GL_COMPUTE_LOCAL_WORK_SIZE */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_copy_image (none) */ +/* Reuse tokens from KHR_debug */ +/* reuse GL_DEBUG_OUTPUT_SYNCHRONOUS */ +/* reuse GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH */ +/* reuse GL_DEBUG_CALLBACK_FUNCTION */ +/* reuse GL_DEBUG_CALLBACK_USER_PARAM */ +/* reuse GL_DEBUG_SOURCE_API */ +/* reuse GL_DEBUG_SOURCE_WINDOW_SYSTEM */ +/* reuse GL_DEBUG_SOURCE_SHADER_COMPILER */ +/* reuse GL_DEBUG_SOURCE_THIRD_PARTY */ +/* reuse GL_DEBUG_SOURCE_APPLICATION */ +/* reuse GL_DEBUG_SOURCE_OTHER */ +/* reuse GL_DEBUG_TYPE_ERROR */ +/* reuse GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_PORTABILITY */ +/* reuse GL_DEBUG_TYPE_PERFORMANCE */ +/* reuse GL_DEBUG_TYPE_OTHER */ +/* reuse GL_MAX_DEBUG_MESSAGE_LENGTH */ +/* reuse GL_MAX_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_SEVERITY_HIGH */ +/* reuse GL_DEBUG_SEVERITY_MEDIUM */ +/* reuse GL_DEBUG_SEVERITY_LOW */ +/* reuse GL_DEBUG_TYPE_MARKER */ +/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ +/* reuse GL_DEBUG_TYPE_POP_GROUP */ +/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ +/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_BUFFER */ +/* reuse GL_SHADER */ +/* reuse GL_PROGRAM */ +/* reuse GL_QUERY */ +/* reuse GL_PROGRAM_PIPELINE */ +/* reuse GL_SAMPLER */ +/* reuse GL_DISPLAY_LIST */ +/* reuse GL_MAX_LABEL_LENGTH */ +/* reuse GL_DEBUG_OUTPUT */ +/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +/* Reuse tokens from ARB_explicit_uniform_location */ +/* reuse GL_MAX_UNIFORM_LOCATIONS */ +/* Reuse tokens from ARB_framebuffer_no_attachments */ +/* reuse GL_FRAMEBUFFER_DEFAULT_WIDTH */ +/* reuse GL_FRAMEBUFFER_DEFAULT_HEIGHT */ +/* reuse GL_FRAMEBUFFER_DEFAULT_LAYERS */ +/* reuse GL_FRAMEBUFFER_DEFAULT_SAMPLES */ +/* reuse GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_MAX_FRAMEBUFFER_WIDTH */ +/* reuse GL_MAX_FRAMEBUFFER_HEIGHT */ +/* reuse GL_MAX_FRAMEBUFFER_LAYERS */ +/* reuse GL_MAX_FRAMEBUFFER_SAMPLES */ +/* Reuse tokens from ARB_internalformat_query2 */ +/* reuse GL_INTERNALFORMAT_SUPPORTED */ +/* reuse GL_INTERNALFORMAT_PREFERRED */ +/* reuse GL_INTERNALFORMAT_RED_SIZE */ +/* reuse GL_INTERNALFORMAT_GREEN_SIZE */ +/* reuse GL_INTERNALFORMAT_BLUE_SIZE */ +/* reuse GL_INTERNALFORMAT_ALPHA_SIZE */ +/* reuse GL_INTERNALFORMAT_DEPTH_SIZE */ +/* reuse GL_INTERNALFORMAT_STENCIL_SIZE */ +/* reuse GL_INTERNALFORMAT_SHARED_SIZE */ +/* reuse GL_INTERNALFORMAT_RED_TYPE */ +/* reuse GL_INTERNALFORMAT_GREEN_TYPE */ +/* reuse GL_INTERNALFORMAT_BLUE_TYPE */ +/* reuse GL_INTERNALFORMAT_ALPHA_TYPE */ +/* reuse GL_INTERNALFORMAT_DEPTH_TYPE */ +/* reuse GL_INTERNALFORMAT_STENCIL_TYPE */ +/* reuse GL_MAX_WIDTH */ +/* reuse GL_MAX_HEIGHT */ +/* reuse GL_MAX_DEPTH */ +/* reuse GL_MAX_LAYERS */ +/* reuse GL_MAX_COMBINED_DIMENSIONS */ +/* reuse GL_COLOR_COMPONENTS */ +/* reuse GL_DEPTH_COMPONENTS */ +/* reuse GL_STENCIL_COMPONENTS */ +/* reuse GL_COLOR_RENDERABLE */ +/* reuse GL_DEPTH_RENDERABLE */ +/* reuse GL_STENCIL_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE_LAYERED */ +/* reuse GL_FRAMEBUFFER_BLEND */ +/* reuse GL_READ_PIXELS */ +/* reuse GL_READ_PIXELS_FORMAT */ +/* reuse GL_READ_PIXELS_TYPE */ +/* reuse GL_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_TEXTURE_IMAGE_TYPE */ +/* reuse GL_GET_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_GET_TEXTURE_IMAGE_TYPE */ +/* reuse GL_MIPMAP */ +/* reuse GL_MANUAL_GENERATE_MIPMAP */ +/* reuse GL_AUTO_GENERATE_MIPMAP */ +/* reuse GL_COLOR_ENCODING */ +/* reuse GL_SRGB_READ */ +/* reuse GL_SRGB_WRITE */ +/* reuse GL_FILTER */ +/* reuse GL_VERTEX_TEXTURE */ +/* reuse GL_TESS_CONTROL_TEXTURE */ +/* reuse GL_TESS_EVALUATION_TEXTURE */ +/* reuse GL_GEOMETRY_TEXTURE */ +/* reuse GL_FRAGMENT_TEXTURE */ +/* reuse GL_COMPUTE_TEXTURE */ +/* reuse GL_TEXTURE_SHADOW */ +/* reuse GL_TEXTURE_GATHER */ +/* reuse GL_TEXTURE_GATHER_SHADOW */ +/* reuse GL_SHADER_IMAGE_LOAD */ +/* reuse GL_SHADER_IMAGE_STORE */ +/* reuse GL_SHADER_IMAGE_ATOMIC */ +/* reuse GL_IMAGE_TEXEL_SIZE */ +/* reuse GL_IMAGE_COMPATIBILITY_CLASS */ +/* reuse GL_IMAGE_PIXEL_FORMAT */ +/* reuse GL_IMAGE_PIXEL_TYPE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_SIZE */ +/* reuse GL_CLEAR_BUFFER */ +/* reuse GL_TEXTURE_VIEW */ +/* reuse GL_VIEW_COMPATIBILITY_CLASS */ +/* reuse GL_FULL_SUPPORT */ +/* reuse GL_CAVEAT_SUPPORT */ +/* reuse GL_IMAGE_CLASS_4_X_32 */ +/* reuse GL_IMAGE_CLASS_2_X_32 */ +/* reuse GL_IMAGE_CLASS_1_X_32 */ +/* reuse GL_IMAGE_CLASS_4_X_16 */ +/* reuse GL_IMAGE_CLASS_2_X_16 */ +/* reuse GL_IMAGE_CLASS_1_X_16 */ +/* reuse GL_IMAGE_CLASS_4_X_8 */ +/* reuse GL_IMAGE_CLASS_2_X_8 */ +/* reuse GL_IMAGE_CLASS_1_X_8 */ +/* reuse GL_IMAGE_CLASS_11_11_10 */ +/* reuse GL_IMAGE_CLASS_10_10_10_2 */ +/* reuse GL_VIEW_CLASS_128_BITS */ +/* reuse GL_VIEW_CLASS_96_BITS */ +/* reuse GL_VIEW_CLASS_64_BITS */ +/* reuse GL_VIEW_CLASS_48_BITS */ +/* reuse GL_VIEW_CLASS_32_BITS */ +/* reuse GL_VIEW_CLASS_24_BITS */ +/* reuse GL_VIEW_CLASS_16_BITS */ +/* reuse GL_VIEW_CLASS_8_BITS */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGB */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT3_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT5_RGBA */ +/* reuse GL_VIEW_CLASS_RGTC1_RED */ +/* reuse GL_VIEW_CLASS_RGTC2_RG */ +/* reuse GL_VIEW_CLASS_BPTC_UNORM */ +/* reuse GL_VIEW_CLASS_BPTC_FLOAT */ +/* Reuse tokens from ARB_invalidate_subdata (none) */ +/* Reuse tokens from ARB_multi_draw_indirect (none) */ +/* Reuse tokens from ARB_program_interface_query */ +/* reuse GL_UNIFORM */ +/* reuse GL_UNIFORM_BLOCK */ +/* reuse GL_PROGRAM_INPUT */ +/* reuse GL_PROGRAM_OUTPUT */ +/* reuse GL_BUFFER_VARIABLE */ +/* reuse GL_SHADER_STORAGE_BLOCK */ +/* reuse GL_VERTEX_SUBROUTINE */ +/* reuse GL_TESS_CONTROL_SUBROUTINE */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE */ +/* reuse GL_GEOMETRY_SUBROUTINE */ +/* reuse GL_FRAGMENT_SUBROUTINE */ +/* reuse GL_COMPUTE_SUBROUTINE */ +/* reuse GL_VERTEX_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_CONTROL_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE_UNIFORM */ +/* reuse GL_GEOMETRY_SUBROUTINE_UNIFORM */ +/* reuse GL_FRAGMENT_SUBROUTINE_UNIFORM */ +/* reuse GL_COMPUTE_SUBROUTINE_UNIFORM */ +/* reuse GL_TRANSFORM_FEEDBACK_VARYING */ +/* reuse GL_ACTIVE_RESOURCES */ +/* reuse GL_MAX_NAME_LENGTH */ +/* reuse GL_MAX_NUM_ACTIVE_VARIABLES */ +/* reuse GL_MAX_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_NAME_LENGTH */ +/* reuse GL_TYPE */ +/* reuse GL_ARRAY_SIZE */ +/* reuse GL_OFFSET */ +/* reuse GL_BLOCK_INDEX */ +/* reuse GL_ARRAY_STRIDE */ +/* reuse GL_MATRIX_STRIDE */ +/* reuse GL_IS_ROW_MAJOR */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_INDEX */ +/* reuse GL_BUFFER_BINDING */ +/* reuse GL_BUFFER_DATA_SIZE */ +/* reuse GL_NUM_ACTIVE_VARIABLES */ +/* reuse GL_ACTIVE_VARIABLES */ +/* reuse GL_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_REFERENCED_BY_GEOMETRY_SHADER */ +/* reuse GL_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_TOP_LEVEL_ARRAY_SIZE */ +/* reuse GL_TOP_LEVEL_ARRAY_STRIDE */ +/* reuse GL_LOCATION */ +/* reuse GL_LOCATION_INDEX */ +/* reuse GL_IS_PER_PATCH */ +/* Reuse tokens from ARB_robust_buffer_access_behavior (none) */ +/* Reuse tokens from ARB_shader_storage_buffer_object */ +/* reuse GL_SHADER_STORAGE_BUFFER */ +/* reuse GL_SHADER_STORAGE_BUFFER_BINDING */ +/* reuse GL_SHADER_STORAGE_BUFFER_START */ +/* reuse GL_SHADER_STORAGE_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS */ +/* reuse GL_MAX_SHADER_STORAGE_BLOCK_SIZE */ +/* reuse GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_SHADER_STORAGE_BARRIER_BIT */ +/* reuse GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES */ +/* Reuse tokens from ARB_stencil_texturing */ +/* reuse GL_DEPTH_STENCIL_TEXTURE_MODE */ +/* Reuse tokens from ARB_texture_buffer_range */ +/* reuse GL_TEXTURE_BUFFER_OFFSET */ +/* reuse GL_TEXTURE_BUFFER_SIZE */ +/* reuse GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT */ +/* Reuse tokens from ARB_texture_query_levels (none) */ +/* Reuse tokens from ARB_texture_storage_multisample (none) */ +/* Reuse tokens from ARB_texture_view */ +/* reuse GL_TEXTURE_VIEW_MIN_LEVEL */ +/* reuse GL_TEXTURE_VIEW_NUM_LEVELS */ +/* reuse GL_TEXTURE_VIEW_MIN_LAYER */ +/* reuse GL_TEXTURE_VIEW_NUM_LAYERS */ +/* reuse GL_TEXTURE_IMMUTABLE_LEVELS */ +/* Reuse tokens from ARB_vertex_attrib_binding */ +/* reuse GL_VERTEX_ATTRIB_BINDING */ +/* reuse GL_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_VERTEX_BINDING_DIVISOR */ +/* reuse GL_VERTEX_BINDING_OFFSET */ +/* reuse GL_VERTEX_BINDING_STRIDE */ +/* reuse GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_MAX_VERTEX_ATTRIB_BINDINGS */ +#endif + #ifndef GL_ARB_depth_buffer_float #define GL_DEPTH_COMPONENT32F 0x8CAC #define GL_DEPTH32F_STENCIL8 0x8CAD @@ -1940,6 +2215,414 @@ typedef void GLvoid; #define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F #endif +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD +#endif + +#ifndef GL_KHR_debug +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_BUFFER 0x82E0 +#define GL_SHADER 0x82E1 +#define GL_PROGRAM 0x82E2 +#define GL_QUERY 0x82E3 +#define GL_PROGRAM_PIPELINE 0x82E4 +#define GL_SAMPLER 0x82E6 +#define GL_DISPLAY_LIST 0x82E7 +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +#endif + +#ifndef GL_ARB_arrays_of_arrays +#endif + +#ifndef GL_ARB_clear_buffer_object +#endif + +#ifndef GL_ARB_compute_shader +#define GL_COMPUTE_SHADER 0x91B9 +#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB +#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC +#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD +#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 +#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 +#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 +#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 +#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 +#define GL_MAX_COMPUTE_LOCAL_INVOCATIONS 0x90EB +#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE +#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF +#define GL_COMPUTE_LOCAL_WORK_SIZE 0x8267 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED +#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE +#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF +#define GL_COMPUTE_SHADER_BIT 0x00000020 +#endif + +#ifndef GL_ARB_copy_image +#endif + +#ifndef GL_ARB_debug_group +/* reuse GL_DEBUG_TYPE_MARKER */ +/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ +/* reuse GL_DEBUG_TYPE_POP_GROUP */ +/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ +/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +#endif + +#ifndef GL_ARB_debug_label +/* reuse GL_BUFFER */ +/* reuse GL_SHADER */ +/* reuse GL_PROGRAM */ +/* reuse GL_QUERY */ +/* reuse GL_PROGRAM_PIPELINE */ +/* reuse GL_SAMPLER */ +/* DISPLAY_LIST used in compatibility profile only */ +/* reuse GL_DISPLAY_LIST */ +/* reuse GL_MAX_LABEL_LENGTH */ +/* reuse GL_VERTEX_ARRAY */ +#endif + +#ifndef GL_ARB_debug_output2 +/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ +/* reuse GL_DEBUG_OUTPUT */ +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_MAX_UNIFORM_LOCATIONS 0x826E +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 +#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 +#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 +#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 +#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 +#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 +#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 +#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 +#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 +#endif + +#ifndef GL_ARB_internalformat_query2 +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ +/* reuse GL_NUM_SAMPLE_COUNTS */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_SAMPLES */ +/* reuse GL_TEXTURE_1D */ +/* reuse GL_TEXTURE_1D_ARRAY */ +/* reuse GL_TEXTURE_2D */ +/* reuse GL_TEXTURE_2D_ARRAY */ +/* reuse GL_TEXTURE_3D */ +/* reuse GL_TEXTURE_CUBE_MAP */ +/* reuse GL_TEXTURE_CUBE_MAP_ARRAY */ +/* reuse GL_TEXTURE_RECTANGLE */ +/* reuse GL_TEXTURE_BUFFER */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_COMPRESSED */ +#define GL_INTERNALFORMAT_SUPPORTED 0x826F +#define GL_INTERNALFORMAT_PREFERRED 0x8270 +#define GL_INTERNALFORMAT_RED_SIZE 0x8271 +#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 +#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 +#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 +#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 +#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 +#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 +#define GL_INTERNALFORMAT_RED_TYPE 0x8278 +#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 +#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A +#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B +#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C +#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D +#define GL_MAX_WIDTH 0x827E +#define GL_MAX_HEIGHT 0x827F +#define GL_MAX_DEPTH 0x8280 +#define GL_MAX_LAYERS 0x8281 +#define GL_MAX_COMBINED_DIMENSIONS 0x8282 +#define GL_COLOR_COMPONENTS 0x8283 +#define GL_DEPTH_COMPONENTS 0x8284 +#define GL_STENCIL_COMPONENTS 0x8285 +#define GL_COLOR_RENDERABLE 0x8286 +#define GL_DEPTH_RENDERABLE 0x8287 +#define GL_STENCIL_RENDERABLE 0x8288 +#define GL_FRAMEBUFFER_RENDERABLE 0x8289 +#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A +#define GL_FRAMEBUFFER_BLEND 0x828B +#define GL_READ_PIXELS 0x828C +#define GL_READ_PIXELS_FORMAT 0x828D +#define GL_READ_PIXELS_TYPE 0x828E +#define GL_TEXTURE_IMAGE_FORMAT 0x828F +#define GL_TEXTURE_IMAGE_TYPE 0x8290 +#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 +#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 +#define GL_MIPMAP 0x8293 +#define GL_MANUAL_GENERATE_MIPMAP 0x8294 +#define GL_AUTO_GENERATE_MIPMAP 0x8295 +#define GL_COLOR_ENCODING 0x8296 +#define GL_SRGB_READ 0x8297 +#define GL_SRGB_WRITE 0x8298 +#define GL_SRGB_DECODE_ARB 0x8299 +#define GL_FILTER 0x829A +#define GL_VERTEX_TEXTURE 0x829B +#define GL_TESS_CONTROL_TEXTURE 0x829C +#define GL_TESS_EVALUATION_TEXTURE 0x829D +#define GL_GEOMETRY_TEXTURE 0x829E +#define GL_FRAGMENT_TEXTURE 0x829F +#define GL_COMPUTE_TEXTURE 0x82A0 +#define GL_TEXTURE_SHADOW 0x82A1 +#define GL_TEXTURE_GATHER 0x82A2 +#define GL_TEXTURE_GATHER_SHADOW 0x82A3 +#define GL_SHADER_IMAGE_LOAD 0x82A4 +#define GL_SHADER_IMAGE_STORE 0x82A5 +#define GL_SHADER_IMAGE_ATOMIC 0x82A6 +#define GL_IMAGE_TEXEL_SIZE 0x82A7 +#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 +#define GL_IMAGE_PIXEL_FORMAT 0x82A9 +#define GL_IMAGE_PIXEL_TYPE 0x82AA +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF +#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 +#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 +#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 +#define GL_CLEAR_BUFFER 0x82B4 +#define GL_TEXTURE_VIEW 0x82B5 +#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 +#define GL_FULL_SUPPORT 0x82B7 +#define GL_CAVEAT_SUPPORT 0x82B8 +#define GL_IMAGE_CLASS_4_X_32 0x82B9 +#define GL_IMAGE_CLASS_2_X_32 0x82BA +#define GL_IMAGE_CLASS_1_X_32 0x82BB +#define GL_IMAGE_CLASS_4_X_16 0x82BC +#define GL_IMAGE_CLASS_2_X_16 0x82BD +#define GL_IMAGE_CLASS_1_X_16 0x82BE +#define GL_IMAGE_CLASS_4_X_8 0x82BF +#define GL_IMAGE_CLASS_2_X_8 0x82C0 +#define GL_IMAGE_CLASS_1_X_8 0x82C1 +#define GL_IMAGE_CLASS_11_11_10 0x82C2 +#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 +#define GL_VIEW_CLASS_128_BITS 0x82C4 +#define GL_VIEW_CLASS_96_BITS 0x82C5 +#define GL_VIEW_CLASS_64_BITS 0x82C6 +#define GL_VIEW_CLASS_48_BITS 0x82C7 +#define GL_VIEW_CLASS_32_BITS 0x82C8 +#define GL_VIEW_CLASS_24_BITS 0x82C9 +#define GL_VIEW_CLASS_16_BITS 0x82CA +#define GL_VIEW_CLASS_8_BITS 0x82CB +#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC +#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD +#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE +#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF +#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 +#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 +#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 +#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 +#endif + +#ifndef GL_ARB_invalidate_subdata +#endif + +#ifndef GL_ARB_multi_draw_indirect +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_UNIFORM 0x92E1 +#define GL_UNIFORM_BLOCK 0x92E2 +#define GL_PROGRAM_INPUT 0x92E3 +#define GL_PROGRAM_OUTPUT 0x92E4 +#define GL_BUFFER_VARIABLE 0x92E5 +#define GL_SHADER_STORAGE_BLOCK 0x92E6 +/* reuse GL_ATOMIC_COUNTER_BUFFER */ +#define GL_VERTEX_SUBROUTINE 0x92E8 +#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 +#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA +#define GL_GEOMETRY_SUBROUTINE 0x92EB +#define GL_FRAGMENT_SUBROUTINE 0x92EC +#define GL_COMPUTE_SUBROUTINE 0x92ED +#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE +#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF +#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 +#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 +#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 +#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 +#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 +#define GL_ACTIVE_RESOURCES 0x92F5 +#define GL_MAX_NAME_LENGTH 0x92F6 +#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 +#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 +#define GL_NAME_LENGTH 0x92F9 +#define GL_TYPE 0x92FA +#define GL_ARRAY_SIZE 0x92FB +#define GL_OFFSET 0x92FC +#define GL_BLOCK_INDEX 0x92FD +#define GL_ARRAY_STRIDE 0x92FE +#define GL_MATRIX_STRIDE 0x92FF +#define GL_IS_ROW_MAJOR 0x9300 +#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 +#define GL_BUFFER_BINDING 0x9302 +#define GL_BUFFER_DATA_SIZE 0x9303 +#define GL_NUM_ACTIVE_VARIABLES 0x9304 +#define GL_ACTIVE_VARIABLES 0x9305 +#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 +#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 +#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 +#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 +#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A +#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B +#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C +#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D +#define GL_LOCATION 0x930E +#define GL_LOCATION_INDEX 0x930F +#define GL_IS_PER_PATCH 0x92E7 +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#endif + +#ifndef GL_ARB_shader_image_size +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_SHADER_STORAGE_BUFFER 0x90D2 +#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 +#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 +#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 +#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 +#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 +#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 +#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 +#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA +#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB +#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC +#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD +#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE +#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF +#define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 +#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS +/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_TEXTURE_BUFFER_OFFSET 0x919D +#define GL_TEXTURE_BUFFER_SIZE 0x919E +#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F +#endif + +#ifndef GL_ARB_texture_query_levels +#endif + +#ifndef GL_ARB_texture_storage_multisample +#endif + +#ifndef GL_ARB_texture_view +#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB +#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC +#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD +#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_VERTEX_ATTRIB_BINDING 0x82D4 +#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 +#define GL_VERTEX_BINDING_DIVISOR 0x82D6 +#define GL_VERTEX_BINDING_OFFSET 0x82D7 +#define GL_VERTEX_BINDING_STRIDE 0x82D8 +#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 +#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA +#endif + +#ifndef GL_ARB_robustness_isolation +#endif + /*************************************************************/ @@ -2039,13 +2722,17 @@ typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLen typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); #endif +#ifndef GL_KHR_debug +typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + #ifndef GL_NV_vdpau_interop typedef GLintptr GLvdpauSurfaceNV; #endif #ifndef GL_VERSION_1_0 #define GL_VERSION_1_0 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glCullFace (GLenum mode); GLAPI void APIENTRY glFrontFace (GLenum mode); GLAPI void APIENTRY glHint (GLenum target, GLenum mode); @@ -2094,7 +2781,7 @@ GLAPI void APIENTRY glGetTexLevelParameteriv (GLenum target, GLint level, GLenum GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); GLAPI void APIENTRY glDepthRange (GLdouble near, GLdouble far); GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode); typedef void (APIENTRYP PFNGLFRONTFACEPROC) (GLenum mode); typedef void (APIENTRYP PFNGLHINTPROC) (GLenum target, GLenum mode); @@ -2147,7 +2834,7 @@ typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLs #ifndef GL_VERSION_1_1 #define GL_VERSION_1_1 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); GLAPI void APIENTRY glGetPointerv (GLenum pname, GLvoid* *params); @@ -2162,7 +2849,7 @@ GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); GLAPI GLboolean APIENTRY glIsTexture (GLuint texture); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count); typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); typedef void (APIENTRYP PFNGLGETPOINTERVPROC) (GLenum pname, GLvoid* *params); @@ -2181,14 +2868,14 @@ typedef GLboolean (APIENTRYP PFNGLISTEXTUREPROC) (GLuint texture); #ifndef GL_VERSION_1_2 #define GL_VERSION_1_2 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); GLAPI void APIENTRY glBlendEquation (GLenum mode); GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); @@ -2199,7 +2886,7 @@ typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, #ifndef GL_VERSION_1_3 #define GL_VERSION_1_3 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glActiveTexture (GLenum texture); GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); @@ -2209,7 +2896,7 @@ GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert); typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); @@ -2223,18 +2910,18 @@ typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint le #ifndef GL_VERSION_1_4 #define GL_VERSION_1_4 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); @@ -2243,7 +2930,7 @@ typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *p #ifndef GL_VERSION_1_5 #define GL_VERSION_1_5 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); GLAPI GLboolean APIENTRY glIsQuery (GLuint id); @@ -2263,7 +2950,7 @@ GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); @@ -2287,7 +2974,7 @@ typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname #ifndef GL_VERSION_2_0 #define GL_VERSION_2_0 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); @@ -2381,7 +3068,7 @@ GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); @@ -2479,14 +3166,14 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, #ifndef GL_VERSION_2_1 #define GL_VERSION_2_1 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); @@ -2501,7 +3188,7 @@ typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei co /* ARB_framebuffer_object */ /* ARB_map_buffer_range */ /* ARB_vertex_array_object */ -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); @@ -2560,7 +3247,7 @@ GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLu GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); @@ -2626,14 +3313,14 @@ typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint ind /* OpenGL 3.1 also reuses entry points from these extensions: */ /* ARB_copy_buffer */ /* ARB_uniform_buffer_object */ -#ifdef GL3_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); -#endif /* GL3_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); #endif @@ -2645,11 +3332,11 @@ typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); /* ARB_provoking_vertex */ /* ARB_sync */ /* ARB_texture_multisample */ -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); @@ -2667,9 +3354,9 @@ typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum atta /* ARB_texture_swizzle (no entry points) */ /* ARB_timer_query */ /* ARB_vertex_type_2_10_10_10_rev */ -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); #endif @@ -2687,13 +3374,13 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divi /* ARB_texture_gather (no entry points) */ /* ARB_transform_feedback2 */ /* ARB_transform_feedback3 */ -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glMinSampleShading (GLfloat value); GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value); typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); @@ -2728,13 +3415,43 @@ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, /* ARB_texture_storage */ #endif +#ifndef GL_VERSION_4_3 +#define GL_VERSION_4_3 1 +/* OpenGL 4.3 reuses entry points from these extensions: */ +/* ARB_arrays_of_arrays (no entry points, GLSL only) */ +/* ARB_fragment_layer_viewport (no entry points, GLSL only) */ +/* ARB_shader_image_size (no entry points, GLSL only) */ +/* ARB_ES3_compatibility (no entry points) */ +/* ARB_clear_buffer_object */ +/* ARB_compute_shader */ +/* ARB_copy_image */ +/* ARB_debug_group */ +/* ARB_debug_label */ +/* KHR_debug (ARB_debug_output promoted to KHR without suffixes) */ +/* ARB_debug_output2 (no entry points) */ +/* ARB_explicit_uniform_location (no entry points) */ +/* ARB_framebuffer_no_attachments */ +/* ARB_internalformat_query2 */ +/* ARB_invalidate_subdata */ +/* ARB_multi_draw_indirect */ +/* ARB_program_interface_query */ +/* ARB_robust_buffer_access_behavior (no entry points) */ +/* ARB_shader_storage_buffer_object */ +/* ARB_stencil_texturing (no entry points) */ +/* ARB_texture_buffer_range */ +/* ARB_texture_query_levels (no entry points) */ +/* ARB_texture_storage_multisample */ +/* ARB_texture_view */ +/* ARB_vertex_attrib_binding */ +#endif + #ifndef GL_ARB_depth_buffer_float #define GL_ARB_depth_buffer_float 1 #endif #ifndef GL_ARB_framebuffer_object #define GL_ARB_framebuffer_object 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); @@ -2755,7 +3472,7 @@ GLAPI void APIENTRY glGenerateMipmap (GLenum target); GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); @@ -2788,10 +3505,10 @@ typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum #ifndef GL_ARB_map_buffer_range #define GL_ARB_map_buffer_range 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); #endif @@ -2806,12 +3523,12 @@ typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintpt #ifndef GL_ARB_vertex_array_object #define GL_ARB_vertex_array_object 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBindVertexArray (GLuint array); GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); @@ -2820,7 +3537,7 @@ typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); #ifndef GL_ARB_uniform_buffer_object #define GL_ARB_uniform_buffer_object 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); @@ -2828,7 +3545,7 @@ GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *unif GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); @@ -2840,9 +3557,9 @@ typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint un #ifndef GL_ARB_copy_buffer #define GL_ARB_copy_buffer 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); #endif @@ -2852,16 +3569,16 @@ typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum w #ifndef GL_ARB_draw_elements_base_vertex #define GL_ARB_draw_elements_base_vertex 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); -GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, const GLint *basevertex); -#endif /* GL3_PROTOTYPES */ +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, const GLint *basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); #endif #ifndef GL_ARB_fragment_coord_conventions @@ -2870,9 +3587,9 @@ typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, cons #ifndef GL_ARB_provoking_vertex #define GL_ARB_provoking_vertex 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glProvokingVertex (GLenum mode); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); #endif @@ -2882,7 +3599,7 @@ typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); #ifndef GL_ARB_sync #define GL_ARB_sync 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); GLAPI GLboolean APIENTRY glIsSync (GLsync sync); GLAPI void APIENTRY glDeleteSync (GLsync sync); @@ -2890,7 +3607,7 @@ GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); @@ -2902,12 +3619,12 @@ typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei #ifndef GL_ARB_texture_multisample #define GL_ARB_texture_multisample 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); @@ -2920,12 +3637,12 @@ typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); #ifndef GL_ARB_draw_buffers_blend #define GL_ARB_draw_buffers_blend 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); @@ -2934,9 +3651,9 @@ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcR #ifndef GL_ARB_sample_shading #define GL_ARB_sample_shading 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); #endif @@ -2954,14 +3671,14 @@ typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); #ifndef GL_ARB_shading_language_include #define GL_ARB_shading_language_include 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); @@ -2976,10 +3693,10 @@ typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLch #ifndef GL_ARB_blend_func_extended #define GL_ARB_blend_func_extended 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); #endif @@ -2994,7 +3711,7 @@ typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLcha #ifndef GL_ARB_sampler_objects #define GL_ARB_sampler_objects 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); @@ -3009,7 +3726,7 @@ GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); @@ -3040,11 +3757,11 @@ typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenu #ifndef GL_ARB_timer_query #define GL_ARB_timer_query 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); @@ -3052,7 +3769,7 @@ typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, #ifndef GL_ARB_vertex_type_2_10_10_10_rev #define GL_ARB_vertex_type_2_10_10_10_rev 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); @@ -3091,7 +3808,7 @@ GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean nor GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); @@ -3134,10 +3851,10 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, #ifndef GL_ARB_draw_indirect #define GL_ARB_draw_indirect 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); #endif @@ -3148,7 +3865,7 @@ typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type #ifndef GL_ARB_gpu_shader_fp64 #define GL_ARB_gpu_shader_fp64 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); @@ -3167,7 +3884,7 @@ GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboole GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); @@ -3190,7 +3907,7 @@ typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, #ifndef GL_ARB_shader_subroutine #define GL_ARB_shader_subroutine 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); @@ -3199,7 +3916,7 @@ GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); @@ -3212,10 +3929,10 @@ typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shad #ifndef GL_ARB_tessellation_shader #define GL_ARB_tessellation_shader 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); #endif @@ -3226,7 +3943,7 @@ typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat #ifndef GL_ARB_transform_feedback2 #define GL_ARB_transform_feedback2 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); @@ -3234,7 +3951,7 @@ GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); GLAPI void APIENTRY glPauseTransformFeedback (void); GLAPI void APIENTRY glResumeTransformFeedback (void); GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); @@ -3246,12 +3963,12 @@ typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id) #ifndef GL_ARB_transform_feedback3 #define GL_ARB_transform_feedback3 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); @@ -3260,13 +3977,13 @@ typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index #ifndef GL_ARB_ES2_compatibility #define GL_ARB_ES2_compatibility 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glReleaseShaderCompiler (void); GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f); GLAPI void APIENTRY glClearDepthf (GLfloat d); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); @@ -3276,11 +3993,11 @@ typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d); #ifndef GL_ARB_get_program_binary #define GL_ARB_get_program_binary 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); @@ -3288,7 +4005,7 @@ typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pnam #ifndef GL_ARB_separate_shader_objects #define GL_ARB_separate_shader_objects 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* const *strings); @@ -3349,7 +4066,7 @@ GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* const *strings); @@ -3414,7 +4131,7 @@ typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GL #ifndef GL_ARB_vertex_attrib_64bit #define GL_ARB_vertex_attrib_64bit 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); @@ -3425,7 +4142,7 @@ GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); @@ -3440,7 +4157,7 @@ typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname #ifndef GL_ARB_viewport_array #define GL_ARB_viewport_array 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); @@ -3451,7 +4168,7 @@ GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdou GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f); GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); @@ -3466,20 +4183,20 @@ typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLd #ifndef GL_ARB_cl_event #define GL_ARB_cl_event 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); #endif #ifndef GL_ARB_debug_output #define GL_ARB_debug_output 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); @@ -3488,7 +4205,7 @@ typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei #ifndef GL_ARB_robustness #define GL_ARB_robustness 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); @@ -3509,7 +4226,7 @@ GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); @@ -3538,14 +4255,14 @@ typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint locati #ifndef GL_ARB_base_instance #define GL_ARB_base_instance 1 -#ifdef GL3_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei primcount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLint basevertex, GLuint baseinstance); -#endif /* GL3_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLint basevertex, GLuint baseinstance); +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); #endif #ifndef GL_ARB_shading_language_420pack @@ -3554,12 +4271,12 @@ typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (G #ifndef GL_ARB_transform_feedback_instanced #define GL_ARB_transform_feedback_instanced 1 -#ifdef GL3_PROTOTYPES -GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei primcount); -GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei primcount); -#endif /* GL3_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei primcount); +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); +GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); #endif #ifndef GL_ARB_compressed_texture_pixel_storage @@ -3572,9 +4289,9 @@ typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum m #ifndef GL_ARB_internalformat_query #define GL_ARB_internalformat_query 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); #endif @@ -3584,18 +4301,18 @@ typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum int #ifndef GL_ARB_shader_atomic_counters #define GL_ARB_shader_atomic_counters 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); #endif #ifndef GL_ARB_shader_image_load_store #define GL_ARB_shader_image_load_store 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); #endif @@ -3606,14 +4323,14 @@ typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); #ifndef GL_ARB_texture_storage #define GL_ARB_texture_storage 1 -#ifdef GL3_PROTOTYPES +#ifdef GLCOREARB_PROTOTYPES GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -#endif /* GL3_PROTOTYPES */ +#endif /* GLCOREARB_PROTOTYPES */ typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); @@ -3622,6 +4339,257 @@ typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum ta typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); #endif +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_KHR_texture_compression_astc_ldr 1 +#endif + +#ifndef GL_KHR_debug +#define GL_KHR_debug 1 +/* KHR_debug also reuses entry points from ARB_debug_group and ARB_debug_label */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); +GLAPI void APIENTRY glPopDebugGroup (void); +GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); +typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); +typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif + +#ifndef GL_ARB_arrays_of_arrays +#define GL_ARB_arrays_of_arrays 1 +#endif + +#ifndef GL_ARB_clear_buffer_object +#define GL_ARB_clear_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif + +#ifndef GL_ARB_compute_shader +#define GL_ARB_compute_shader 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); +#endif + +#ifndef GL_ARB_copy_image +#define GL_ARB_copy_image 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif + +#ifndef GL_ARB_debug_group +#define GL_ARB_debug_group 1 +/* ARB_debug_group reuses entry points from KHR_debug */ +#endif + +#ifndef GL_ARB_debug_label +#define GL_ARB_debug_label 1 +/* ARB_debug_label reuses entry points from KHR_debug */ +#endif + +#ifndef GL_ARB_debug_output2 +#define GL_ARB_debug_output2 1 +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_ARB_ES3_compatibility 1 +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_ARB_explicit_uniform_location 1 +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#define GL_ARB_fragment_layer_viewport 1 +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_ARB_framebuffer_no_attachments 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); +GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_internalformat_query2 +#define GL_ARB_internalformat_query2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif + +#ifndef GL_ARB_invalidate_subdata +#define GL_ARB_invalidate_subdata 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); +GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); +GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); +GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_ARB_multi_draw_indirect +#define GL_ARB_multi_draw_indirect 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_ARB_program_interface_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#define GL_ARB_robust_buffer_access_behavior 1 +#endif + +#ifndef GL_ARB_shader_image_size +#define GL_ARB_shader_image_size 1 +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_ARB_shader_storage_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_ARB_stencil_texturing 1 +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_ARB_texture_buffer_range 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_texture_query_levels +#define GL_ARB_texture_query_levels 1 +#endif + +#ifndef GL_ARB_texture_storage_multisample +#define GL_ARB_texture_storage_multisample 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif + +#ifndef GL_ARB_texture_view +#define GL_ARB_texture_view 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_ARB_vertex_attrib_binding 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif + +#ifndef GL_ARB_robustness_isolation +#define GL_ARB_robustness_isolation 1 +#endif + #ifdef __cplusplus } diff --git a/include/GL3/glext.h b/include/GL3/glext.h index 90e013421..6175ad450 100644 --- a/include/GL3/glext.h +++ b/include/GL3/glext.h @@ -29,9 +29,9 @@ extern "C" { */ /* Header file version number, required by OpenGL ABI for Linux */ -/* glext.h last updated $Date: 2012-06-18 11:26:35 -0700 (Mon, 18 Jun 2012) $ */ +/* glext.h last updated $Date: 2012-08-06 02:01:01 -0700 (Mon, 06 Aug 2012) $ */ /* Current version at http://www.opengl.org/registry/ */ -#define GL_GLEXT_VERSION 82 +#define GL_GLEXT_VERSION 83 /* Function declaration macros - to move into glplatform.h */ #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) @@ -1164,6 +1164,290 @@ extern "C" { /* reuse GL_TEXTURE_IMMUTABLE_FORMAT */ #endif +#ifndef GL_VERSION_4_3 +#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 +#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E +/* Reuse tokens from ARB_arrays_of_arrays (none, GLSL only) */ +/* Reuse tokens from ARB_fragment_layer_viewport (none, GLSL only) */ +/* Reuse tokens from ARB_shader_image_size (none, GLSL only) */ +/* Reuse tokens from ARB_ES3_compatibility */ +/* reuse GL_COMPRESSED_RGB8_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_ETC2 */ +/* reuse GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_RGBA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_R11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_R11_EAC */ +/* reuse GL_COMPRESSED_RG11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_RG11_EAC */ +/* reuse GL_PRIMITIVE_RESTART_FIXED_INDEX */ +/* reuse GL_ANY_SAMPLES_PASSED_CONSERVATIVE */ +/* reuse GL_MAX_ELEMENT_INDEX */ +/* Reuse tokens from ARB_clear_buffer_object (none) */ +/* Reuse tokens from ARB_compute_shader */ +/* reuse GL_COMPUTE_SHADER */ +/* reuse GL_MAX_COMPUTE_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_COMPUTE_IMAGE_UNIFORMS */ +/* reuse GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */ +/* reuse GL_MAX_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTERS */ +/* reuse GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_LOCAL_INVOCATIONS */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_COUNT */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_SIZE */ +/* reuse GL_COMPUTE_LOCAL_WORK_SIZE */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_copy_image (none) */ +/* Reuse tokens from KHR_debug */ +/* reuse GL_DEBUG_OUTPUT_SYNCHRONOUS */ +/* reuse GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH */ +/* reuse GL_DEBUG_CALLBACK_FUNCTION */ +/* reuse GL_DEBUG_CALLBACK_USER_PARAM */ +/* reuse GL_DEBUG_SOURCE_API */ +/* reuse GL_DEBUG_SOURCE_WINDOW_SYSTEM */ +/* reuse GL_DEBUG_SOURCE_SHADER_COMPILER */ +/* reuse GL_DEBUG_SOURCE_THIRD_PARTY */ +/* reuse GL_DEBUG_SOURCE_APPLICATION */ +/* reuse GL_DEBUG_SOURCE_OTHER */ +/* reuse GL_DEBUG_TYPE_ERROR */ +/* reuse GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_PORTABILITY */ +/* reuse GL_DEBUG_TYPE_PERFORMANCE */ +/* reuse GL_DEBUG_TYPE_OTHER */ +/* reuse GL_MAX_DEBUG_MESSAGE_LENGTH */ +/* reuse GL_MAX_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_SEVERITY_HIGH */ +/* reuse GL_DEBUG_SEVERITY_MEDIUM */ +/* reuse GL_DEBUG_SEVERITY_LOW */ +/* reuse GL_DEBUG_TYPE_MARKER */ +/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ +/* reuse GL_DEBUG_TYPE_POP_GROUP */ +/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ +/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_BUFFER */ +/* reuse GL_SHADER */ +/* reuse GL_PROGRAM */ +/* reuse GL_QUERY */ +/* reuse GL_PROGRAM_PIPELINE */ +/* reuse GL_SAMPLER */ +/* reuse GL_DISPLAY_LIST */ +/* reuse GL_MAX_LABEL_LENGTH */ +/* reuse GL_DEBUG_OUTPUT */ +/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +/* Reuse tokens from ARB_explicit_uniform_location */ +/* reuse GL_MAX_UNIFORM_LOCATIONS */ +/* Reuse tokens from ARB_framebuffer_no_attachments */ +/* reuse GL_FRAMEBUFFER_DEFAULT_WIDTH */ +/* reuse GL_FRAMEBUFFER_DEFAULT_HEIGHT */ +/* reuse GL_FRAMEBUFFER_DEFAULT_LAYERS */ +/* reuse GL_FRAMEBUFFER_DEFAULT_SAMPLES */ +/* reuse GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_MAX_FRAMEBUFFER_WIDTH */ +/* reuse GL_MAX_FRAMEBUFFER_HEIGHT */ +/* reuse GL_MAX_FRAMEBUFFER_LAYERS */ +/* reuse GL_MAX_FRAMEBUFFER_SAMPLES */ +/* Reuse tokens from ARB_internalformat_query2 */ +/* reuse GL_INTERNALFORMAT_SUPPORTED */ +/* reuse GL_INTERNALFORMAT_PREFERRED */ +/* reuse GL_INTERNALFORMAT_RED_SIZE */ +/* reuse GL_INTERNALFORMAT_GREEN_SIZE */ +/* reuse GL_INTERNALFORMAT_BLUE_SIZE */ +/* reuse GL_INTERNALFORMAT_ALPHA_SIZE */ +/* reuse GL_INTERNALFORMAT_DEPTH_SIZE */ +/* reuse GL_INTERNALFORMAT_STENCIL_SIZE */ +/* reuse GL_INTERNALFORMAT_SHARED_SIZE */ +/* reuse GL_INTERNALFORMAT_RED_TYPE */ +/* reuse GL_INTERNALFORMAT_GREEN_TYPE */ +/* reuse GL_INTERNALFORMAT_BLUE_TYPE */ +/* reuse GL_INTERNALFORMAT_ALPHA_TYPE */ +/* reuse GL_INTERNALFORMAT_DEPTH_TYPE */ +/* reuse GL_INTERNALFORMAT_STENCIL_TYPE */ +/* reuse GL_MAX_WIDTH */ +/* reuse GL_MAX_HEIGHT */ +/* reuse GL_MAX_DEPTH */ +/* reuse GL_MAX_LAYERS */ +/* reuse GL_MAX_COMBINED_DIMENSIONS */ +/* reuse GL_COLOR_COMPONENTS */ +/* reuse GL_DEPTH_COMPONENTS */ +/* reuse GL_STENCIL_COMPONENTS */ +/* reuse GL_COLOR_RENDERABLE */ +/* reuse GL_DEPTH_RENDERABLE */ +/* reuse GL_STENCIL_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE_LAYERED */ +/* reuse GL_FRAMEBUFFER_BLEND */ +/* reuse GL_READ_PIXELS */ +/* reuse GL_READ_PIXELS_FORMAT */ +/* reuse GL_READ_PIXELS_TYPE */ +/* reuse GL_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_TEXTURE_IMAGE_TYPE */ +/* reuse GL_GET_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_GET_TEXTURE_IMAGE_TYPE */ +/* reuse GL_MIPMAP */ +/* reuse GL_MANUAL_GENERATE_MIPMAP */ +/* reuse GL_AUTO_GENERATE_MIPMAP */ +/* reuse GL_COLOR_ENCODING */ +/* reuse GL_SRGB_READ */ +/* reuse GL_SRGB_WRITE */ +/* reuse GL_FILTER */ +/* reuse GL_VERTEX_TEXTURE */ +/* reuse GL_TESS_CONTROL_TEXTURE */ +/* reuse GL_TESS_EVALUATION_TEXTURE */ +/* reuse GL_GEOMETRY_TEXTURE */ +/* reuse GL_FRAGMENT_TEXTURE */ +/* reuse GL_COMPUTE_TEXTURE */ +/* reuse GL_TEXTURE_SHADOW */ +/* reuse GL_TEXTURE_GATHER */ +/* reuse GL_TEXTURE_GATHER_SHADOW */ +/* reuse GL_SHADER_IMAGE_LOAD */ +/* reuse GL_SHADER_IMAGE_STORE */ +/* reuse GL_SHADER_IMAGE_ATOMIC */ +/* reuse GL_IMAGE_TEXEL_SIZE */ +/* reuse GL_IMAGE_COMPATIBILITY_CLASS */ +/* reuse GL_IMAGE_PIXEL_FORMAT */ +/* reuse GL_IMAGE_PIXEL_TYPE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_SIZE */ +/* reuse GL_CLEAR_BUFFER */ +/* reuse GL_TEXTURE_VIEW */ +/* reuse GL_VIEW_COMPATIBILITY_CLASS */ +/* reuse GL_FULL_SUPPORT */ +/* reuse GL_CAVEAT_SUPPORT */ +/* reuse GL_IMAGE_CLASS_4_X_32 */ +/* reuse GL_IMAGE_CLASS_2_X_32 */ +/* reuse GL_IMAGE_CLASS_1_X_32 */ +/* reuse GL_IMAGE_CLASS_4_X_16 */ +/* reuse GL_IMAGE_CLASS_2_X_16 */ +/* reuse GL_IMAGE_CLASS_1_X_16 */ +/* reuse GL_IMAGE_CLASS_4_X_8 */ +/* reuse GL_IMAGE_CLASS_2_X_8 */ +/* reuse GL_IMAGE_CLASS_1_X_8 */ +/* reuse GL_IMAGE_CLASS_11_11_10 */ +/* reuse GL_IMAGE_CLASS_10_10_10_2 */ +/* reuse GL_VIEW_CLASS_128_BITS */ +/* reuse GL_VIEW_CLASS_96_BITS */ +/* reuse GL_VIEW_CLASS_64_BITS */ +/* reuse GL_VIEW_CLASS_48_BITS */ +/* reuse GL_VIEW_CLASS_32_BITS */ +/* reuse GL_VIEW_CLASS_24_BITS */ +/* reuse GL_VIEW_CLASS_16_BITS */ +/* reuse GL_VIEW_CLASS_8_BITS */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGB */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT3_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT5_RGBA */ +/* reuse GL_VIEW_CLASS_RGTC1_RED */ +/* reuse GL_VIEW_CLASS_RGTC2_RG */ +/* reuse GL_VIEW_CLASS_BPTC_UNORM */ +/* reuse GL_VIEW_CLASS_BPTC_FLOAT */ +/* Reuse tokens from ARB_invalidate_subdata (none) */ +/* Reuse tokens from ARB_multi_draw_indirect (none) */ +/* Reuse tokens from ARB_program_interface_query */ +/* reuse GL_UNIFORM */ +/* reuse GL_UNIFORM_BLOCK */ +/* reuse GL_PROGRAM_INPUT */ +/* reuse GL_PROGRAM_OUTPUT */ +/* reuse GL_BUFFER_VARIABLE */ +/* reuse GL_SHADER_STORAGE_BLOCK */ +/* reuse GL_VERTEX_SUBROUTINE */ +/* reuse GL_TESS_CONTROL_SUBROUTINE */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE */ +/* reuse GL_GEOMETRY_SUBROUTINE */ +/* reuse GL_FRAGMENT_SUBROUTINE */ +/* reuse GL_COMPUTE_SUBROUTINE */ +/* reuse GL_VERTEX_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_CONTROL_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE_UNIFORM */ +/* reuse GL_GEOMETRY_SUBROUTINE_UNIFORM */ +/* reuse GL_FRAGMENT_SUBROUTINE_UNIFORM */ +/* reuse GL_COMPUTE_SUBROUTINE_UNIFORM */ +/* reuse GL_TRANSFORM_FEEDBACK_VARYING */ +/* reuse GL_ACTIVE_RESOURCES */ +/* reuse GL_MAX_NAME_LENGTH */ +/* reuse GL_MAX_NUM_ACTIVE_VARIABLES */ +/* reuse GL_MAX_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_NAME_LENGTH */ +/* reuse GL_TYPE */ +/* reuse GL_ARRAY_SIZE */ +/* reuse GL_OFFSET */ +/* reuse GL_BLOCK_INDEX */ +/* reuse GL_ARRAY_STRIDE */ +/* reuse GL_MATRIX_STRIDE */ +/* reuse GL_IS_ROW_MAJOR */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_INDEX */ +/* reuse GL_BUFFER_BINDING */ +/* reuse GL_BUFFER_DATA_SIZE */ +/* reuse GL_NUM_ACTIVE_VARIABLES */ +/* reuse GL_ACTIVE_VARIABLES */ +/* reuse GL_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_REFERENCED_BY_GEOMETRY_SHADER */ +/* reuse GL_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_TOP_LEVEL_ARRAY_SIZE */ +/* reuse GL_TOP_LEVEL_ARRAY_STRIDE */ +/* reuse GL_LOCATION */ +/* reuse GL_LOCATION_INDEX */ +/* reuse GL_IS_PER_PATCH */ +/* Reuse tokens from ARB_robust_buffer_access_behavior (none) */ +/* Reuse tokens from ARB_shader_storage_buffer_object */ +/* reuse GL_SHADER_STORAGE_BUFFER */ +/* reuse GL_SHADER_STORAGE_BUFFER_BINDING */ +/* reuse GL_SHADER_STORAGE_BUFFER_START */ +/* reuse GL_SHADER_STORAGE_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS */ +/* reuse GL_MAX_SHADER_STORAGE_BLOCK_SIZE */ +/* reuse GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_SHADER_STORAGE_BARRIER_BIT */ +/* reuse GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES */ +/* Reuse tokens from ARB_stencil_texturing */ +/* reuse GL_DEPTH_STENCIL_TEXTURE_MODE */ +/* Reuse tokens from ARB_texture_buffer_range */ +/* reuse GL_TEXTURE_BUFFER_OFFSET */ +/* reuse GL_TEXTURE_BUFFER_SIZE */ +/* reuse GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT */ +/* Reuse tokens from ARB_texture_query_levels (none) */ +/* Reuse tokens from ARB_texture_storage_multisample (none) */ +/* Reuse tokens from ARB_texture_view */ +/* reuse GL_TEXTURE_VIEW_MIN_LEVEL */ +/* reuse GL_TEXTURE_VIEW_NUM_LEVELS */ +/* reuse GL_TEXTURE_VIEW_MIN_LAYER */ +/* reuse GL_TEXTURE_VIEW_NUM_LAYERS */ +/* reuse GL_TEXTURE_IMMUTABLE_LEVELS */ +/* Reuse tokens from ARB_vertex_attrib_binding */ +/* reuse GL_VERTEX_ATTRIB_BINDING */ +/* reuse GL_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_VERTEX_BINDING_DIVISOR */ +/* reuse GL_VERTEX_BINDING_OFFSET */ +/* reuse GL_VERTEX_BINDING_STRIDE */ +/* reuse GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_MAX_VERTEX_ATTRIB_BINDINGS */ +#endif + #ifndef GL_ARB_multitexture #define GL_TEXTURE0_ARB 0x84C0 #define GL_TEXTURE1_ARB 0x84C1 @@ -2399,6 +2683,414 @@ extern "C" { #define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F #endif +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD +#endif + +#ifndef GL_KHR_debug +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_BUFFER 0x82E0 +#define GL_SHADER 0x82E1 +#define GL_PROGRAM 0x82E2 +#define GL_QUERY 0x82E3 +#define GL_PROGRAM_PIPELINE 0x82E4 +#define GL_SAMPLER 0x82E6 +#define GL_DISPLAY_LIST 0x82E7 +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +#endif + +#ifndef GL_ARB_arrays_of_arrays +#endif + +#ifndef GL_ARB_clear_buffer_object +#endif + +#ifndef GL_ARB_compute_shader +#define GL_COMPUTE_SHADER 0x91B9 +#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB +#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC +#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD +#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 +#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 +#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 +#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 +#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 +#define GL_MAX_COMPUTE_LOCAL_INVOCATIONS 0x90EB +#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE +#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF +#define GL_COMPUTE_LOCAL_WORK_SIZE 0x8267 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED +#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE +#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF +#define GL_COMPUTE_SHADER_BIT 0x00000020 +#endif + +#ifndef GL_ARB_copy_image +#endif + +#ifndef GL_ARB_debug_group +/* reuse GL_DEBUG_TYPE_MARKER */ +/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ +/* reuse GL_DEBUG_TYPE_POP_GROUP */ +/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ +/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +#endif + +#ifndef GL_ARB_debug_label +/* reuse GL_BUFFER */ +/* reuse GL_SHADER */ +/* reuse GL_PROGRAM */ +/* reuse GL_QUERY */ +/* reuse GL_PROGRAM_PIPELINE */ +/* reuse GL_SAMPLER */ +/* DISPLAY_LIST used in compatibility profile only */ +/* reuse GL_DISPLAY_LIST */ +/* reuse GL_MAX_LABEL_LENGTH */ +/* reuse GL_VERTEX_ARRAY */ +#endif + +#ifndef GL_ARB_debug_output2 +/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ +/* reuse GL_DEBUG_OUTPUT */ +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_MAX_UNIFORM_LOCATIONS 0x826E +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 +#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 +#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 +#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 +#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 +#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 +#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 +#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 +#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 +#endif + +#ifndef GL_ARB_internalformat_query2 +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ +/* reuse GL_NUM_SAMPLE_COUNTS */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_SAMPLES */ +/* reuse GL_TEXTURE_1D */ +/* reuse GL_TEXTURE_1D_ARRAY */ +/* reuse GL_TEXTURE_2D */ +/* reuse GL_TEXTURE_2D_ARRAY */ +/* reuse GL_TEXTURE_3D */ +/* reuse GL_TEXTURE_CUBE_MAP */ +/* reuse GL_TEXTURE_CUBE_MAP_ARRAY */ +/* reuse GL_TEXTURE_RECTANGLE */ +/* reuse GL_TEXTURE_BUFFER */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_COMPRESSED */ +#define GL_INTERNALFORMAT_SUPPORTED 0x826F +#define GL_INTERNALFORMAT_PREFERRED 0x8270 +#define GL_INTERNALFORMAT_RED_SIZE 0x8271 +#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 +#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 +#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 +#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 +#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 +#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 +#define GL_INTERNALFORMAT_RED_TYPE 0x8278 +#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 +#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A +#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B +#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C +#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D +#define GL_MAX_WIDTH 0x827E +#define GL_MAX_HEIGHT 0x827F +#define GL_MAX_DEPTH 0x8280 +#define GL_MAX_LAYERS 0x8281 +#define GL_MAX_COMBINED_DIMENSIONS 0x8282 +#define GL_COLOR_COMPONENTS 0x8283 +#define GL_DEPTH_COMPONENTS 0x8284 +#define GL_STENCIL_COMPONENTS 0x8285 +#define GL_COLOR_RENDERABLE 0x8286 +#define GL_DEPTH_RENDERABLE 0x8287 +#define GL_STENCIL_RENDERABLE 0x8288 +#define GL_FRAMEBUFFER_RENDERABLE 0x8289 +#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A +#define GL_FRAMEBUFFER_BLEND 0x828B +#define GL_READ_PIXELS 0x828C +#define GL_READ_PIXELS_FORMAT 0x828D +#define GL_READ_PIXELS_TYPE 0x828E +#define GL_TEXTURE_IMAGE_FORMAT 0x828F +#define GL_TEXTURE_IMAGE_TYPE 0x8290 +#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 +#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 +#define GL_MIPMAP 0x8293 +#define GL_MANUAL_GENERATE_MIPMAP 0x8294 +#define GL_AUTO_GENERATE_MIPMAP 0x8295 +#define GL_COLOR_ENCODING 0x8296 +#define GL_SRGB_READ 0x8297 +#define GL_SRGB_WRITE 0x8298 +#define GL_SRGB_DECODE_ARB 0x8299 +#define GL_FILTER 0x829A +#define GL_VERTEX_TEXTURE 0x829B +#define GL_TESS_CONTROL_TEXTURE 0x829C +#define GL_TESS_EVALUATION_TEXTURE 0x829D +#define GL_GEOMETRY_TEXTURE 0x829E +#define GL_FRAGMENT_TEXTURE 0x829F +#define GL_COMPUTE_TEXTURE 0x82A0 +#define GL_TEXTURE_SHADOW 0x82A1 +#define GL_TEXTURE_GATHER 0x82A2 +#define GL_TEXTURE_GATHER_SHADOW 0x82A3 +#define GL_SHADER_IMAGE_LOAD 0x82A4 +#define GL_SHADER_IMAGE_STORE 0x82A5 +#define GL_SHADER_IMAGE_ATOMIC 0x82A6 +#define GL_IMAGE_TEXEL_SIZE 0x82A7 +#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 +#define GL_IMAGE_PIXEL_FORMAT 0x82A9 +#define GL_IMAGE_PIXEL_TYPE 0x82AA +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF +#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 +#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 +#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 +#define GL_CLEAR_BUFFER 0x82B4 +#define GL_TEXTURE_VIEW 0x82B5 +#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 +#define GL_FULL_SUPPORT 0x82B7 +#define GL_CAVEAT_SUPPORT 0x82B8 +#define GL_IMAGE_CLASS_4_X_32 0x82B9 +#define GL_IMAGE_CLASS_2_X_32 0x82BA +#define GL_IMAGE_CLASS_1_X_32 0x82BB +#define GL_IMAGE_CLASS_4_X_16 0x82BC +#define GL_IMAGE_CLASS_2_X_16 0x82BD +#define GL_IMAGE_CLASS_1_X_16 0x82BE +#define GL_IMAGE_CLASS_4_X_8 0x82BF +#define GL_IMAGE_CLASS_2_X_8 0x82C0 +#define GL_IMAGE_CLASS_1_X_8 0x82C1 +#define GL_IMAGE_CLASS_11_11_10 0x82C2 +#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 +#define GL_VIEW_CLASS_128_BITS 0x82C4 +#define GL_VIEW_CLASS_96_BITS 0x82C5 +#define GL_VIEW_CLASS_64_BITS 0x82C6 +#define GL_VIEW_CLASS_48_BITS 0x82C7 +#define GL_VIEW_CLASS_32_BITS 0x82C8 +#define GL_VIEW_CLASS_24_BITS 0x82C9 +#define GL_VIEW_CLASS_16_BITS 0x82CA +#define GL_VIEW_CLASS_8_BITS 0x82CB +#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC +#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD +#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE +#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF +#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 +#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 +#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 +#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 +#endif + +#ifndef GL_ARB_invalidate_subdata +#endif + +#ifndef GL_ARB_multi_draw_indirect +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_UNIFORM 0x92E1 +#define GL_UNIFORM_BLOCK 0x92E2 +#define GL_PROGRAM_INPUT 0x92E3 +#define GL_PROGRAM_OUTPUT 0x92E4 +#define GL_BUFFER_VARIABLE 0x92E5 +#define GL_SHADER_STORAGE_BLOCK 0x92E6 +/* reuse GL_ATOMIC_COUNTER_BUFFER */ +#define GL_VERTEX_SUBROUTINE 0x92E8 +#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 +#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA +#define GL_GEOMETRY_SUBROUTINE 0x92EB +#define GL_FRAGMENT_SUBROUTINE 0x92EC +#define GL_COMPUTE_SUBROUTINE 0x92ED +#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE +#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF +#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 +#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 +#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 +#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 +#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 +#define GL_ACTIVE_RESOURCES 0x92F5 +#define GL_MAX_NAME_LENGTH 0x92F6 +#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 +#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 +#define GL_NAME_LENGTH 0x92F9 +#define GL_TYPE 0x92FA +#define GL_ARRAY_SIZE 0x92FB +#define GL_OFFSET 0x92FC +#define GL_BLOCK_INDEX 0x92FD +#define GL_ARRAY_STRIDE 0x92FE +#define GL_MATRIX_STRIDE 0x92FF +#define GL_IS_ROW_MAJOR 0x9300 +#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 +#define GL_BUFFER_BINDING 0x9302 +#define GL_BUFFER_DATA_SIZE 0x9303 +#define GL_NUM_ACTIVE_VARIABLES 0x9304 +#define GL_ACTIVE_VARIABLES 0x9305 +#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 +#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 +#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 +#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 +#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A +#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B +#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C +#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D +#define GL_LOCATION 0x930E +#define GL_LOCATION_INDEX 0x930F +#define GL_IS_PER_PATCH 0x92E7 +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#endif + +#ifndef GL_ARB_shader_image_size +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_SHADER_STORAGE_BUFFER 0x90D2 +#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 +#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 +#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 +#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 +#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 +#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 +#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 +#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA +#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB +#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC +#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD +#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE +#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF +#define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 +#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS +/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_TEXTURE_BUFFER_OFFSET 0x919D +#define GL_TEXTURE_BUFFER_SIZE 0x919E +#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F +#endif + +#ifndef GL_ARB_texture_query_levels +#endif + +#ifndef GL_ARB_texture_storage_multisample +#endif + +#ifndef GL_ARB_texture_view +#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB +#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC +#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD +#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_VERTEX_ATTRIB_BINDING 0x82D4 +#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 +#define GL_VERTEX_BINDING_DIVISOR 0x82D6 +#define GL_VERTEX_BINDING_OFFSET 0x82D7 +#define GL_VERTEX_BINDING_STRIDE 0x82D8 +#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 +#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA +#endif + +#ifndef GL_ARB_robustness_isolation +#endif + #ifndef GL_EXT_abgr #define GL_ABGR_EXT 0x8000 #endif @@ -5583,6 +6275,10 @@ typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLen typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); #endif +#ifndef GL_KHR_debug +typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + #ifndef GL_NV_vdpau_interop typedef GLintptr GLvdpauSurfaceNV; #endif @@ -5783,16 +6479,16 @@ typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); #define GL_VERSION_1_4 1 #ifdef GL_GLEXT_PROTOTYPES GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); #endif /* GL_GLEXT_PROTOTYPES */ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); @@ -6267,13 +6963,13 @@ typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint ind /* ARB_copy_buffer */ /* ARB_uniform_buffer_object */ #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); #endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); #endif @@ -6368,6 +7064,36 @@ typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, /* ARB_texture_storage */ #endif +#ifndef GL_VERSION_4_3 +#define GL_VERSION_4_3 1 +/* OpenGL 4.3 reuses entry points from these extensions: */ +/* ARB_arrays_of_arrays (no entry points, GLSL only) */ +/* ARB_fragment_layer_viewport (no entry points, GLSL only) */ +/* ARB_shader_image_size (no entry points, GLSL only) */ +/* ARB_ES3_compatibility (no entry points) */ +/* ARB_clear_buffer_object */ +/* ARB_compute_shader */ +/* ARB_copy_image */ +/* ARB_debug_group */ +/* ARB_debug_label */ +/* KHR_debug (ARB_debug_output promoted to KHR without suffixes) */ +/* ARB_debug_output2 (no entry points) */ +/* ARB_explicit_uniform_location (no entry points) */ +/* ARB_framebuffer_no_attachments */ +/* ARB_internalformat_query2 */ +/* ARB_invalidate_subdata */ +/* ARB_multi_draw_indirect */ +/* ARB_program_interface_query */ +/* ARB_robust_buffer_access_behavior (no entry points) */ +/* ARB_shader_storage_buffer_object */ +/* ARB_stencil_texturing (no entry points) */ +/* ARB_texture_buffer_range */ +/* ARB_texture_query_levels (no entry points) */ +/* ARB_texture_storage_multisample */ +/* ARB_texture_view */ +/* ARB_vertex_attrib_binding */ +#endif + #ifndef GL_ARB_multitexture #define GL_ARB_multitexture 1 #ifdef GL_GLEXT_PROTOTYPES @@ -7122,13 +7848,13 @@ typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum w #ifdef GL_GLEXT_PROTOTYPES GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); -GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, const GLint *basevertex); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); #endif /* GL_GLEXT_PROTOTYPES */ typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, const GLint *basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); #endif #ifndef GL_ARB_fragment_coord_conventions @@ -7806,13 +8532,13 @@ typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint locati #ifndef GL_ARB_base_instance #define GL_ARB_base_instance 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei primcount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLint basevertex, GLuint baseinstance); +GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); #endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount, GLint basevertex, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); #endif #ifndef GL_ARB_shading_language_420pack @@ -7822,11 +8548,11 @@ typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (G #ifndef GL_ARB_transform_feedback_instanced #define GL_ARB_transform_feedback_instanced 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei primcount); -GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei primcount); +GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); +GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); #endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); #endif #ifndef GL_ARB_compressed_texture_pixel_storage @@ -7889,6 +8615,257 @@ typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum ta typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); #endif +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_KHR_texture_compression_astc_ldr 1 +#endif + +#ifndef GL_KHR_debug +#define GL_KHR_debug 1 +/* KHR_debug also reuses entry points from ARB_debug_group and ARB_debug_label */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); +GLAPI void APIENTRY glPopDebugGroup (void); +GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); +typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); +typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif + +#ifndef GL_ARB_arrays_of_arrays +#define GL_ARB_arrays_of_arrays 1 +#endif + +#ifndef GL_ARB_clear_buffer_object +#define GL_ARB_clear_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif + +#ifndef GL_ARB_compute_shader +#define GL_ARB_compute_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); +#endif + +#ifndef GL_ARB_copy_image +#define GL_ARB_copy_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif + +#ifndef GL_ARB_debug_group +#define GL_ARB_debug_group 1 +/* ARB_debug_group reuses entry points from KHR_debug */ +#endif + +#ifndef GL_ARB_debug_label +#define GL_ARB_debug_label 1 +/* ARB_debug_label reuses entry points from KHR_debug */ +#endif + +#ifndef GL_ARB_debug_output2 +#define GL_ARB_debug_output2 1 +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_ARB_ES3_compatibility 1 +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_ARB_explicit_uniform_location 1 +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#define GL_ARB_fragment_layer_viewport 1 +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_ARB_framebuffer_no_attachments 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); +GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_internalformat_query2 +#define GL_ARB_internalformat_query2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif + +#ifndef GL_ARB_invalidate_subdata +#define GL_ARB_invalidate_subdata 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); +GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); +GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); +GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_ARB_multi_draw_indirect +#define GL_ARB_multi_draw_indirect 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_ARB_program_interface_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#define GL_ARB_robust_buffer_access_behavior 1 +#endif + +#ifndef GL_ARB_shader_image_size +#define GL_ARB_shader_image_size 1 +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_ARB_shader_storage_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_ARB_stencil_texturing 1 +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_ARB_texture_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_texture_query_levels +#define GL_ARB_texture_query_levels 1 +#endif + +#ifndef GL_ARB_texture_storage_multisample +#define GL_ARB_texture_storage_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif + +#ifndef GL_ARB_texture_view +#define GL_ARB_texture_view 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_ARB_vertex_attrib_binding 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif + +#ifndef GL_ARB_robustness_isolation +#define GL_ARB_robustness_isolation 1 +#endif + #ifndef GL_EXT_abgr #define GL_EXT_abgr 1 #endif @@ -10054,10 +11031,10 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, c #ifndef GL_NV_pixel_data_range #define GL_NV_pixel_data_range 1 #ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, const GLvoid *pointer); GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target); #endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, const GLvoid *pointer); typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); #endif diff --git a/include/Nazara/Audio/Debug.hpp b/include/Nazara/Audio/Debug.hpp deleted file mode 100644 index 96ed6ccef..000000000 --- a/include/Nazara/Audio/Debug.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) - #include - - #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete - #define new new(__FILE__, __LINE__) -#endif diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp new file mode 100644 index 000000000..2fdf36497 --- /dev/null +++ b/include/Nazara/Core.hpp @@ -0,0 +1,60 @@ +// This file was automatically generated by Nazara + +/* + Nazara Engine + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Core/ByteArray.hpp b/include/Nazara/Core/ByteArray.hpp index aaef8e65a..94b64654e 100644 --- a/include/Nazara/Core/ByteArray.hpp +++ b/include/Nazara/Core/ByteArray.hpp @@ -8,10 +8,10 @@ #define NAZARA_BYTEARRAY_HPP #include -#include +#include #include -#if NAZARA_THREADSAFETY_BYTEARRAY +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_BYTEARRAY #include #else #include @@ -28,7 +28,7 @@ class NAZARA_API NzByteArray : public NzHashable NzByteArray(); NzByteArray(const nzUInt8* buffer, unsigned int bufferLength); NzByteArray(const NzByteArray& buffer); - NzByteArray(NzByteArray&& buffer); + NzByteArray(NzByteArray&& buffer) noexcept; NzByteArray(SharedArray* sharedArray); ~NzByteArray(); @@ -80,7 +80,7 @@ class NAZARA_API NzByteArray : public NzHashable nzUInt8 operator[](unsigned int pos) const; NzByteArray& operator=(const NzByteArray& byteArray); - NzByteArray& operator=(NzByteArray&& byteArray); + NzByteArray& operator=(NzByteArray&& byteArray) noexcept; NzByteArray operator+(const NzByteArray& byteArray) const; NzByteArray& operator+=(const NzByteArray& byteArray); @@ -89,10 +89,7 @@ class NAZARA_API NzByteArray : public NzHashable struct NAZARA_API SharedArray { - SharedArray() : - refCount(1) - { - } + SharedArray() = default; SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) : capacity(bufferSize), @@ -104,7 +101,7 @@ class NAZARA_API NzByteArray : public NzHashable unsigned int capacity; unsigned int size; - unsigned short refCount; + unsigned short refCount = 1; nzUInt8* buffer; NazaraMutex(mutex) diff --git a/include/Nazara/Core/Clock.hpp b/include/Nazara/Core/Clock.hpp index d6e221702..6ade015b7 100644 --- a/include/Nazara/Core/Clock.hpp +++ b/include/Nazara/Core/Clock.hpp @@ -9,7 +9,7 @@ #include -#if NAZARA_THREADSAFETY_CLOCK +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_CLOCK #include #else #include diff --git a/include/Nazara/Core/Color.inl b/include/Nazara/Core/Color.inl index 6c9cdd758..13fb3fe11 100644 --- a/include/Nazara/Core/Color.inl +++ b/include/Nazara/Core/Color.inl @@ -8,7 +8,7 @@ #include #include #include -#include +#include inline NzColor::NzColor() { @@ -198,26 +198,26 @@ inline NzColor NzColor::FromXYZ(float x, float y, float z) y /= 100; // Y from 0 to 100.000 z /= 100; // Z from 0 to 108.883 - double r = x * 3.2406 + y * -1.5372 + z * -0.4986; - double g = x * -0.9689 + y * 1.8758 + z * 0.0415; - double b = x * 0.0557 + y * -0.2040 + z * 1.0570; + float r = x * 3.2406f + y * -1.5372f + z * -0.4986f; + float g = x * -0.9689f + y * 1.8758f + z * 0.0415f; + float b = x * 0.0557f + y * -0.2040f + z * 1.0570f; if (r > 0.0031308f) - r = 1.055 * (std::pow(r, 1.0/2.4)) - 0.055; + r = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f; else - r *= 12.92; + r *= 12.92f; if (g > 0.0031308f) - g = 1.055 * (std::pow(g, 1.0/2.4)) - 0.055; + g = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f; else - g *= 12.92; + g *= 12.92f; if (b > 0.0031308f) - b = 1.055 * (std::pow(b, 1.0/2.4)) - 0.055; + b = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f; else - b *= 12.92; + b *= 12.92f; - return NzColor(r * 255.0, g * 255.0, b * 255.0); + return NzColor(r * 255.f, g * 255.f, b * 255.f); } inline void NzColor::ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow) @@ -409,4 +409,4 @@ inline std::ostream& operator<<(std::ostream& out, const NzColor& color) return out << color.ToString(); } -#include +#include diff --git a/include/Nazara/Core/ThreadCondition.hpp b/include/Nazara/Core/ConditionVariable.hpp similarity index 58% rename from include/Nazara/Core/ThreadCondition.hpp rename to include/Nazara/Core/ConditionVariable.hpp index 47a130847..f031a7e57 100644 --- a/include/Nazara/Core/ThreadCondition.hpp +++ b/include/Nazara/Core/ConditionVariable.hpp @@ -4,19 +4,19 @@ #pragma once -#ifndef NAZARA_THREADCONDITION_HPP -#define NAZARA_THREADCONDITION_HPP +#ifndef NAZARA_CONDITIONVARIABLE_HPP +#define NAZARA_CONDITIONVARIABLE_HPP #include +class NzConditionVariableImpl; class NzMutex; -class NzThreadConditionImpl; -class NAZARA_API NzThreadCondition +class NAZARA_API NzConditionVariable { public: - NzThreadCondition(); - ~NzThreadCondition(); + NzConditionVariable(); + ~NzConditionVariable(); void Signal(); void SignalAll(); @@ -25,7 +25,7 @@ class NAZARA_API NzThreadCondition bool Wait(NzMutex* mutex, nzUInt32 timeout); private: - NzThreadConditionImpl* m_impl; + NzConditionVariableImpl* m_impl; }; -#endif // NAZARA_THREADCONDITION_HPP +#endif // NAZARA_CONDITIONVARIABLE_HPP diff --git a/include/Nazara/Core/Config.hpp b/include/Nazara/Core/Config.hpp index ebc710456..7cfef54af 100644 --- a/include/Nazara/Core/Config.hpp +++ b/include/Nazara/Core/Config.hpp @@ -44,34 +44,36 @@ // Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_CORE_MEMORYLEAKTRACKER 0 -// Standardise les séparateurs des dossiers selon le système d'exploitation courant +// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution) #define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1 // Précision des réels lors de la transformation en texte (Max. chiffres après la virgule) #define NAZARA_CORE_REAL_PRECISION 6 -// Redirige la sortie du log sur le flux d'erreur standard (cerr) en cas d'erreur d'écriture (ou d'ouverture du fichier) -#define NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE 1 +// Duplique la sortie du log sur le flux de sortie standard (cout) +#define NAZARA_CORE_DUPLICATE_TO_COUT 0 // Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_CORE_SAFE 1 -// Protège le module des accès concurrentiels +// Protège les classes des accès concurrentiels #define NAZARA_CORE_THREADSAFE 1 -#if NAZARA_CORE_THREADSAFE - #define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW) - #define NAZARA_THREADSAFETY_CLOCK 0 // NzClock - #define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory - #define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib - #define NAZARA_THREADSAFETY_FILE 1 // NzFile - #define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest - #define NAZARA_THREADSAFETY_LOG 1 // NzLog - #define NAZARA_THREADSAFETY_STRING 1 // NzString (COW) - #define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream -#endif +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW) +#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock +#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory +#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib +#define NAZARA_THREADSAFETY_FILE 1 // NzFile +#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest +#define NAZARA_THREADSAFETY_LOG 1 // NzLog +#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW) +#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream -// Optimise certaines parties du code avec les avancées venues de Windows Vista (Nécessite Vista ou supérieur et compilateur compatible) +// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver) +#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096 + +// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS) #define NAZARA_CORE_WINDOWS_VISTA 0 /* diff --git a/include/Nazara/Core/Core.hpp b/include/Nazara/Core/Core.hpp new file mode 100644 index 000000000..9cf3bd232 --- /dev/null +++ b/include/Nazara/Core/Core.hpp @@ -0,0 +1,29 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CORE_HPP +#define NAZARA_CORE_HPP + +#include +#include + +class NAZARA_API NzCore +{ + public: + NzCore() = delete; + ~NzCore() = delete; + + static bool Initialize(); + + static bool IsInitialized(); + + static void Uninitialize(); + + private: + static unsigned int s_moduleReferenceCouter; +}; + +#endif // NAZARA_CORE_HPP diff --git a/include/Nazara/Core/Directory.hpp b/include/Nazara/Core/Directory.hpp index c4b0109dc..d39f8d00a 100644 --- a/include/Nazara/Core/Directory.hpp +++ b/include/Nazara/Core/Directory.hpp @@ -19,7 +19,7 @@ #define NAZARA_DIRECTORY_SEPARATOR '/' #endif -#if NAZARA_THREADSAFETY_DIRECTORY +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DIRECTORY #include #else #include @@ -36,10 +36,12 @@ class NAZARA_API NzDirectory void Close(); + NzString GetPattern() const; NzString GetResultName() const; NzString GetResultPath() const; nzUInt64 GetResultSize() const; + bool IsOpen() const; bool IsResultDirectory() const; bool NextResult(bool skipDots = true); @@ -47,6 +49,7 @@ class NAZARA_API NzDirectory bool Open(); void SetDirectory(const NzString& dirPath); + void SetPattern(const NzString& pattern); static bool Copy(const NzString& sourcePath, const NzString& destPath); static bool Create(const NzString& dirPath, bool recursive = false); @@ -59,7 +62,8 @@ class NAZARA_API NzDirectory NazaraMutexAttrib(m_mutex, mutable) NzString m_dirPath; - NzDirectoryImpl* m_impl; + NzString m_pattern; + NzDirectoryImpl* m_impl = nullptr; }; #endif // NAZARA_DIRECTORY_HPP diff --git a/include/Nazara/Core/DynLib.hpp b/include/Nazara/Core/DynLib.hpp index 3035e08a4..2c05a0eea 100644 --- a/include/Nazara/Core/DynLib.hpp +++ b/include/Nazara/Core/DynLib.hpp @@ -11,7 +11,7 @@ #include #include -#if NAZARA_THREADSAFETY_DYNLIB +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DYNLIB #include #else #include diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 9a43c84b6..dc28ff401 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -16,7 +16,7 @@ #include #include -#if NAZARA_THREADSAFETY_FILE +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE #include #else #include @@ -50,7 +50,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable NzFile(); NzFile(const NzString& filePath); NzFile(const NzString& filePath, unsigned long openMode); - NzFile(NzFile&& file); + NzFile(NzFile&& file) noexcept; ~NzFile(); bool Copy(const NzString& newFilePath); @@ -92,7 +92,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); NzFile& operator=(const NzString& filePath); - NzFile& operator=(NzFile&& file); + NzFile& operator=(NzFile&& file) noexcept; static NzString AbsolutePath(const NzString& filePath); static bool Copy(const NzString& sourcePath, const NzString& targetPath); diff --git a/include/Nazara/Core/HashDigest.hpp b/include/Nazara/Core/HashDigest.hpp index 18bc3a99a..0359318b1 100644 --- a/include/Nazara/Core/HashDigest.hpp +++ b/include/Nazara/Core/HashDigest.hpp @@ -17,7 +17,7 @@ class NAZARA_API NzHashDigest NzHashDigest(); NzHashDigest(const NzString& hashName, const nzUInt8* digest, unsigned int length); NzHashDigest(const NzHashDigest& rhs); - NzHashDigest(NzHashDigest&& rhs); + NzHashDigest(NzHashDigest&& rhs) noexcept; ~NzHashDigest(); bool IsValid() const; @@ -31,7 +31,7 @@ class NAZARA_API NzHashDigest nzUInt8 operator[](unsigned short pos) const; NzHashDigest& operator=(const NzHashDigest& rhs); - NzHashDigest& operator=(NzHashDigest&& rhs); + NzHashDigest& operator=(NzHashDigest&& rhs) noexcept; bool operator==(const NzHashDigest& rhs) const; bool operator!=(const NzHashDigest& rhs) const; diff --git a/include/Nazara/Core/Initializer.hpp b/include/Nazara/Core/Initializer.hpp new file mode 100644 index 000000000..592ffb506 --- /dev/null +++ b/include/Nazara/Core/Initializer.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_INITIALIZER_HPP +#define NAZARA_INITIALIZER_HPP + +#include + +template +class NzInitializer +{ + public: + template NzInitializer(Args... args); + ~NzInitializer(); + + bool IsInitialized() const; + + operator bool() const; +}; + +#include + +#endif // NAZARA_INITIALIZER_HPP diff --git a/include/Nazara/Core/Initializer.inl b/include/Nazara/Core/Initializer.inl new file mode 100644 index 000000000..83cc85612 --- /dev/null +++ b/include/Nazara/Core/Initializer.inl @@ -0,0 +1,35 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +// http://www.easyrgb.com/index.php?X=MATH + +#include +#include + +template +template +NzInitializer::NzInitializer(Args... args) +{ + T::Initialize(args...); +} + +template +NzInitializer::~NzInitializer() +{ + T::Uninitialize(); +} + +template +bool NzInitializer::IsInitialized() const +{ + return T::IsInitialized(); +} + +template +NzInitializer::operator bool() const +{ + return T::IsInitialized(); +} + +#include diff --git a/include/Nazara/Core/Log.hpp b/include/Nazara/Core/Log.hpp index b9696c96d..76d6b8776 100644 --- a/include/Nazara/Core/Log.hpp +++ b/include/Nazara/Core/Log.hpp @@ -12,7 +12,7 @@ #include #include -#if NAZARA_THREADSAFETY_LOG +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG #include #else #include diff --git a/include/Nazara/Core/Mutex.hpp b/include/Nazara/Core/Mutex.hpp index 01b410fcd..fe4821f00 100644 --- a/include/Nazara/Core/Mutex.hpp +++ b/include/Nazara/Core/Mutex.hpp @@ -11,11 +11,11 @@ #include class NzMutexImpl; -class NzThreadCondition; +class NzConditionVariable; class NAZARA_API NzMutex : NzNonCopyable { - friend class NzThreadCondition; + friend class NzConditionVariable; public: NzMutex(); diff --git a/include/Nazara/Utility/Resource.hpp b/include/Nazara/Core/Resource.hpp similarity index 100% rename from include/Nazara/Utility/Resource.hpp rename to include/Nazara/Core/Resource.hpp diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp index 7c3deae91..34bee2504 100644 --- a/include/Nazara/Core/String.hpp +++ b/include/Nazara/Core/String.hpp @@ -13,7 +13,7 @@ #include #include -#if NAZARA_THREADSAFETY_STRING +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING #include #else #include @@ -41,7 +41,7 @@ class NAZARA_API NzString : public NzHashable NzString(const char* string); NzString(const std::string& string); NzString(const NzString& string); - NzString(NzString&& string); + NzString(NzString&& string) noexcept; NzString(SharedString* sharedString); ~NzString(); @@ -112,8 +112,8 @@ class NAZARA_API NzString : public NzHashable unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None); unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None); unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None); - unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); - unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None); + //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); + //unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None); void Reserve(unsigned int bufferSize); @@ -184,7 +184,7 @@ class NAZARA_API NzString : public NzHashable NzString& operator=(const char* string); NzString& operator=(const std::string& string); NzString& operator=(const NzString& string); - NzString& operator=(NzString&& string); + NzString& operator=(NzString&& string) noexcept; NzString operator+(char character) const; NzString operator+(const char* string) const; @@ -282,10 +282,7 @@ class NAZARA_API NzString : public NzHashable struct NAZARA_API SharedString { - SharedString() : - refCount(1) - { - } + SharedString() = default; SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) : capacity(bufferSize), @@ -299,7 +296,7 @@ class NAZARA_API NzString : public NzHashable unsigned int size; char* string; - unsigned short refCount; + unsigned short refCount = 1; NazaraMutex(mutex) }; diff --git a/include/Nazara/Core/StringStream.hpp b/include/Nazara/Core/StringStream.hpp index 996c06eec..63b975772 100644 --- a/include/Nazara/Core/StringStream.hpp +++ b/include/Nazara/Core/StringStream.hpp @@ -12,7 +12,7 @@ #include #include -#if NAZARA_THREADSAFETY_STRINGSTREAM +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRINGSTREAM #include #else #include diff --git a/include/Nazara/Core/Thread.hpp b/include/Nazara/Core/Thread.hpp index d5bd416ab..5895040b8 100644 --- a/include/Nazara/Core/Thread.hpp +++ b/include/Nazara/Core/Thread.hpp @@ -26,7 +26,7 @@ class NAZARA_API NzThread : NzNonCopyable friend class NzThreadImpl; public: - Id() : m_handle(nullptr) {} + Id() = default; Id(Id&& rhs) = default; ~Id(); @@ -38,7 +38,7 @@ class NAZARA_API NzThread : NzNonCopyable Id(void* handle) : m_handle(handle) {} Id(const NzThreadImpl* thread); - void* m_handle; + void* m_handle = nullptr; }; template NzThread(F function); diff --git a/include/Nazara/Network/DebugOff.hpp b/include/Nazara/Debug.hpp similarity index 50% rename from include/Nazara/Network/DebugOff.hpp rename to include/Nazara/Debug.hpp index 08a1e8b1d..22ca244ef 100644 --- a/include/Nazara/Network/DebugOff.hpp +++ b/include/Nazara/Debug.hpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) - #undef delete - #undef new -#endif +#include + +#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete +#define new new(__FILE__, __LINE__) diff --git a/include/Nazara/Audio/DebugOff.hpp b/include/Nazara/DebugOff.hpp similarity index 63% rename from include/Nazara/Audio/DebugOff.hpp rename to include/Nazara/DebugOff.hpp index 7cb3c4ac2..e32f36866 100644 --- a/include/Nazara/Audio/DebugOff.hpp +++ b/include/Nazara/DebugOff.hpp @@ -2,7 +2,5 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) - #undef delete - #undef new -#endif +#undef delete +#undef new diff --git a/include/Nazara/Network/Config.hpp b/include/Nazara/Math.hpp similarity index 69% rename from include/Nazara/Network/Config.hpp rename to include/Nazara/Math.hpp index 1e99c1f0f..e26587f36 100644 --- a/include/Nazara/Network/Config.hpp +++ b/include/Nazara/Math.hpp @@ -1,7 +1,10 @@ +// This file was automatically generated by Nazara + /* Nazara Engine Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Rémi "overdrivr" Bèges (remi.beges@laposte.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -24,12 +27,14 @@ #pragma once -#ifndef NAZARA_CONFIG_NETWORK_HPP -#define NAZARA_CONFIG_NETWORK_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_NETWORK_MEMORYLEAKTRACKER 0 - -#endif // NAZARA_CONFIG_NETWORK_HPP +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Math/Basic.inl b/include/Nazara/Math/Basic.inl index 8655680f5..867002a92 100644 --- a/include/Nazara/Math/Basic.inl +++ b/include/Nazara/Math/Basic.inl @@ -10,6 +10,8 @@ #include #include +#define F(a) static_cast(a) + template T NzApproach(T value, T objective, T increment) { @@ -45,7 +47,7 @@ T NzDegrees(T degrees) template T NzDegreeToRadian(T degrees) { - return degrees * (M_PI/180.0); + return degrees * F(M_PI/180.0); } unsigned int NzGetNumberLength(signed char number) @@ -53,7 +55,15 @@ unsigned int NzGetNumberLength(signed char number) if (number == 0) return 1; - return static_cast(std::log10(std::abs(number)))+(number < 0 ? 2 : 1); + // Le standard définit le char comme étant codé sur un octet + static_assert(sizeof(number) == 1, "Signed char must be one byte-sized"); + + if (number >= 100) + return 3; + else if (number >= 10) + return 2; + else + return 1; } unsigned int NzGetNumberLength(unsigned char number) @@ -61,7 +71,15 @@ unsigned int NzGetNumberLength(unsigned char number) if (number == 0) return 1; - return static_cast(std::log10(number))+1; + // Le standard définit le char comme étant codé sur un octet + static_assert(sizeof(number) == 1, "Signed char must be one byte-sized"); + + if (number >= 100) + return 3; + else if (number >= 10) + return 2; + else + return 1; } unsigned int NzGetNumberLength(short number) @@ -152,20 +170,20 @@ T NzNormalizeAngle(T angle) #if NAZARA_MATH_ANGLE_RADIAN const T limit = M_PI; #else - const T limit = 180.0; + const T limit = F(180.0); #endif ///TODO: Trouver une solution sans duplication - if (angle > 0.0) + if (angle > F(0.0)) { angle += limit; - angle -= static_cast(angle/(2.0*limit))*(2.0*limit); + angle -= static_cast(angle/(F(2.0)*limit))*(F(2.0)*limit); angle -= limit; } else { angle -= limit; - angle -= static_cast(angle/(2.0*limit))*(2.0*limit); + angle -= static_cast(angle/(F(2.0)*limit))*(F(2.0)*limit); angle += limit; } @@ -175,11 +193,7 @@ T NzNormalizeAngle(T angle) template bool NzNumberEquals(T a, T b) { - if (a > b) - return (a-b) <= std::numeric_limits::epsilon(); - else - return (b-a) <= std::numeric_limits::epsilon(); - + return std::fabs(a-b) <= std::numeric_limits::epsilon(); } NzString NzNumberToString(long long number, nzUInt8 radix) @@ -235,7 +249,7 @@ T NzRadians(T radians) template T NzRadianToDegree(T radians) { - return radians * (180.0/M_PI); + return radians * F(180.0/M_PI); } long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok) @@ -288,4 +302,6 @@ long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok) return (negative) ? -static_cast(total) : total; } +#undef F + #include diff --git a/include/Nazara/Math/Config.hpp b/include/Nazara/Math/Config.hpp index e0f53a715..1325d5ad0 100644 --- a/include/Nazara/Math/Config.hpp +++ b/include/Nazara/Math/Config.hpp @@ -36,15 +36,17 @@ // Définit la disposition des matrices en colonnes (Façon OpenGL) #define NAZARA_MATH_MATRIX_COLUMN_MAJOR 1 +// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) +#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0 + // Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_MATH_SAFE 1 -// Protège le module des accès concurrentiels +// Protège les classes des accès concurrentiels #define NAZARA_MATH_THREADSAFE 1 -#if NAZARA_MATH_THREADSAFE - #define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) - #define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) -#endif +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) +#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) #endif // NAZARA_CONFIG_MATH_HPP diff --git a/include/Nazara/Math/Cube.hpp b/include/Nazara/Math/Cube.hpp index 57aacdf77..7230c1108 100644 --- a/include/Nazara/Math/Cube.hpp +++ b/include/Nazara/Math/Cube.hpp @@ -17,8 +17,9 @@ class NzCube public: NzCube(); NzCube(T X, T Y, T Z, T Width, T Height, T Depth); - NzCube(T cube[6]); + NzCube(const T cube[6]); NzCube(const NzRect& rect); + NzCube(const NzVector3& vec1, const NzVector3& vec2); template explicit NzCube(const NzCube& rect); NzCube(const NzCube& rect) = default; ~NzCube() = default; @@ -32,11 +33,16 @@ class NzCube NzVector3 GetCenter() const; - bool Intersect(const NzCube& rect) const; - bool Intersect(const NzCube& rect, NzCube& intersection) const; + bool Intersect(const NzCube& rect, NzCube* intersection = nullptr) const; bool IsValid() const; + void Set(T X, T Y, T Z, T Width, T Height, T Depth); + void Set(const T rect[6]); + void Set(const NzRect& rect); + void Set(const NzVector3& vec1, const NzVector3& vec2); + template void Set(const NzCube& rect); + NzString ToString() const; operator NzString() const; diff --git a/include/Nazara/Math/Cube.inl b/include/Nazara/Math/Cube.inl index 5fc3b0c2d..64d69bf66 100644 --- a/include/Nazara/Math/Cube.inl +++ b/include/Nazara/Math/Cube.inl @@ -6,54 +6,42 @@ #include #include +#define F(a) static_cast(a) + template NzCube::NzCube() { } template -NzCube::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) : -x(X), -y(Y), -z(Z), -width(Width), -height(Height), -depth(Depth) +NzCube::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) { + Set(X, Y, Z, Width, Height, Depth); } template -NzCube::NzCube(T vec[6]) : -x(vec[0]), -y(vec[1]), -z(vec[2]), -width(vec[3]), -height(vec[4]), -depth(vec[5]) +NzCube::NzCube(const T vec[6]) { + Set(vec); } template -NzCube::NzCube(const NzRect& rect) : -x(rect.x), -y(rect.y), -z(0), -width(rect.width), -height(rect.height), -depth(1) +NzCube::NzCube(const NzRect& rect) { + Set(rect); +} + +template +NzCube::NzCube(const NzVector3& vec1, const NzVector3& vec2) +{ + Set(vec1, vec2); } template template -NzCube::NzCube(const NzCube& rect) : -x(static_cast(rect.x)), -y(static_cast(rect.y)), -z(static_cast(rect.z)), -width(static_cast(rect.width)), -height(static_cast(rect.height)), -depth(static_cast(rect.depth)) +NzCube::NzCube(const NzCube& rect) { + Set(rect); } template @@ -102,18 +90,11 @@ void NzCube::ExtendTo(const NzCube& rect) template NzVector3 NzCube::GetCenter() const { - return NzVector3((x+width)/2, (y+height)/2, (z+depth)/2); + return NzVector3((x+width)/F(2.0), (y+height)/F(2.0), (z+depth)/F(2.0)); } template -bool NzCube::Intersect(const NzCube& rect) const -{ - NzCube intersection; // Optimisé par le compilateur - return Intersect(rect, intersection); -} - -template -bool NzCube::Intersect(const NzCube& rect, NzCube& intersection) const +bool NzCube::Intersect(const NzCube& rect, NzCube* intersection) const { T left = std::max(x, rect.x); T right = std::min(x+width, rect.x+rect.width); @@ -124,12 +105,15 @@ bool NzCube::Intersect(const NzCube& rect, NzCube& intersection) const if (left < right && top < bottom && up < down) { - intersection.x = left; - intersection.y = top; - intersection.z = up; - intersection.width = right-left; - intersection.height = bottom-top; - intersection.depth = down-up; + if (intersection) + { + intersection->x = left; + intersection->y = top; + intersection->z = up; + intersection->width = right-left; + intersection->height = bottom-top; + intersection->depth = down-up; + } return true; } @@ -140,7 +124,63 @@ bool NzCube::Intersect(const NzCube& rect, NzCube& intersection) const template bool NzCube::IsValid() const { - return width > 0 && height > 0 && depth > 0; + return width > F(0.0) && height > F(0.0) && depth > F(0.0); +} + +template +void NzCube::Set(T X, T Y, T Z, T Width, T Height, T Depth) +{ + x = X; + y = Y; + z = Z; + width = Width; + height = Height; + depth = Depth; +} + +template +void NzCube::Set(const T rect[6]) +{ + x = rect[0]; + y = rect[1]; + z = rect[2]; + width = rect[3]; + height = rect[4]; + depth = rect[5]; +} + +template +void NzCube::Set(const NzRect& rect) +{ + x = rect.x; + y = rect.y; + z = 0; + width = rect.width; + height = rect.height; + depth = 1; +} + +template +void NzCube::Set(const NzVector3& vec1, const NzVector3& vec2) +{ + x = std::min(vec1.x, vec2.x); + y = std::min(vec1.y, vec2.y); + z = std::min(vec1.z, vec2.z); + width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x; + height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y; + depth = (vec2.z > vec1.z) ? vec2.z-vec1.z : vec1.z-vec2.z; +} + +template +template +void NzCube::Set(const NzCube& cube) +{ + x = F(cube.x); + y = F(cube.y); + z = F(cube.z); + width = F(cube.width); + height = F(cube.height); + depth = F(cube.depth); } template @@ -160,13 +200,15 @@ NzCube::operator NzString() const template T& NzCube::operator[](unsigned int i) { + #if NAZARA_MATH_SAFE if (i >= 6) { NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 6)"; throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -174,13 +216,15 @@ T& NzCube::operator[](unsigned int i) template T NzCube::operator[](unsigned int i) const { + #if NAZARA_MATH_SAFE if (i >= 6) { NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 6)"; throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -191,4 +235,6 @@ std::ostream& operator<<(std::ostream& out, const NzCube& rect) return out << rect.ToString(); } +#undef F + #include diff --git a/include/Nazara/Math/EulerAngles.hpp b/include/Nazara/Math/EulerAngles.hpp index be39258fd..a9667186f 100644 --- a/include/Nazara/Math/EulerAngles.hpp +++ b/include/Nazara/Math/EulerAngles.hpp @@ -9,9 +9,8 @@ #define NAZARA_EULERANGLES_HPP #include - -template class NzQuaternion; -template class NzVector3; +#include +#include template class NzEulerAngles { @@ -25,9 +24,7 @@ template class NzEulerAngles NzEulerAngles(const NzEulerAngles& angles) = default; ~NzEulerAngles() = default; - NzVector3 GetForward() const; - NzVector3 GetRight() const; - NzVector3 GetUp() const; + void MakeZero(); void Normalize(); @@ -37,25 +34,28 @@ template class NzEulerAngles //void Set(const NzMatrix3& mat); void Set(const NzQuaternion& quat); template void Set(const NzEulerAngles& angles); - void SetZero(); //NzMatrix3 ToRotationMatrix() const; NzQuaternion ToQuaternion() const; NzString ToString() const; + operator NzString() const; + NzEulerAngles operator+(const NzEulerAngles& angles) const; NzEulerAngles operator-(const NzEulerAngles& angles) const; - NzEulerAngles operator*(const NzEulerAngles& angles) const; - NzEulerAngles operator/(const NzEulerAngles& angles) const; + /*NzEulerAngles operator*(const NzEulerAngles& angles) const; + NzEulerAngles operator/(const NzEulerAngles& angles) const;*/ NzEulerAngles operator+=(const NzEulerAngles& angles); NzEulerAngles operator-=(const NzEulerAngles& angles); - NzEulerAngles operator*=(const NzEulerAngles& angles); - NzEulerAngles operator/=(const NzEulerAngles& angles); + /*NzEulerAngles operator*=(const NzEulerAngles& angles); + NzEulerAngles operator/=(const NzEulerAngles& angles);*/ bool operator==(const NzEulerAngles& angles) const; bool operator!=(const NzEulerAngles& angles) const; + static NzEulerAngles Zero(); + T pitch, yaw, roll; }; diff --git a/include/Nazara/Math/EulerAngles.inl b/include/Nazara/Math/EulerAngles.inl index bf1e54c1a..0752f2948 100644 --- a/include/Nazara/Math/EulerAngles.inl +++ b/include/Nazara/Math/EulerAngles.inl @@ -7,9 +7,10 @@ #include #include #include -#include #include +#define F(a) static_cast(a) + template NzEulerAngles::NzEulerAngles() { @@ -41,33 +42,9 @@ NzEulerAngles::NzEulerAngles(const NzEulerAngles& angles) } template -NzVector3 NzEulerAngles::GetForward() const +void NzEulerAngles::MakeZero() { - #if NAZARA_MATH_ANGLE_RADIAN - return NzVector3(std::cos(yaw), std::sin(roll), std::sin(yaw)); - #else - return NzVector3(std::cos(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(roll)), std::sin(NzDegreeToRadian(yaw))); - #endif -} - -template -NzVector3 NzEulerAngles::GetRight() const -{ - #if NAZARA_MATH_ANGLE_RADIAN - return NzVector3(std::sin(yaw), std::sin(pitch), std::cos(pitch)); - #else - return NzVector3(std::sin(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(pitch)), std::cos(NzDegreeToRadian(pitch))); - #endif -} - -template -NzVector3 NzEulerAngles::GetUp() const -{ - #if NAZARA_MATH_ANGLE_RADIAN - return NzVector3(std::sin(roll), std::cos(pitch), -std::sin(pitch)); - #else - return NzVector3(std::sin(NzDegreeToRadian(roll)), std::cos(NzDegreeToRadian(pitch)), -std::sin(NzDegreeToRadian(pitch))); - #endif + Set(F(0.0), F(0.0), F(0.0)); } template @@ -117,20 +94,14 @@ void NzEulerAngles::Set(const NzEulerAngles& angles) roll = static_cast(angles.roll); } -template -void NzEulerAngles::SetZero() -{ - Set(0.0, 0.0, 0.0); -} - template NzQuaternion NzEulerAngles::ToQuaternion() const { - NzQuaternion Qx(pitch, NzVector3(1.0, 0.0, 0.0)); - NzQuaternion Qy(yaw, NzVector3(0.0, 1.0, 0.0)); - NzQuaternion Qz(roll, NzVector3(0.0, 0.0, 1.0)); + NzQuaternion rotX(pitch, NzVector3(F(1.0), F(0.0), F(0.0))); + NzQuaternion rotY(yaw, NzVector3(F(0.0), F(1.0), F(0.0))); + NzQuaternion rotZ(roll, NzVector3(F(0.0), F(0.0), F(1.0))); - return Qx * Qy * Qz; + return rotY * rotX * rotZ; } template @@ -141,6 +112,12 @@ NzString NzEulerAngles::ToString() const return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')'; } +template +NzEulerAngles::operator NzString() const +{ + return ToString(); +} + template NzEulerAngles NzEulerAngles::operator+(const NzEulerAngles& angles) const { @@ -191,10 +168,21 @@ bool NzEulerAngles::operator!=(const NzEulerAngles& angles) const return !operator==(angles); } +template +NzEulerAngles NzEulerAngles::Zero() +{ + NzEulerAngles angles; + angles.MakeZero(); + + return angles; +} + template std::ostream& operator<<(std::ostream& out, const NzEulerAngles& angles) { return out << angles.ToString(); } +#undef F + #include diff --git a/include/Nazara/Audio/Config.hpp b/include/Nazara/Math/Math.hpp similarity index 77% rename from include/Nazara/Audio/Config.hpp rename to include/Nazara/Math/Math.hpp index ac8b47f16..f0212dde6 100644 --- a/include/Nazara/Audio/Config.hpp +++ b/include/Nazara/Math/Math.hpp @@ -20,16 +20,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_AUDIO_HPP -#define NAZARA_CONFIG_AUDIO_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_AUDIO_MEMORYLEAKTRACKER 0 - -#endif // NAZARA_CONFIG_AUDIOs_HPP +*/ \ No newline at end of file diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 80d30b25f..f0c136207 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -8,8 +8,9 @@ #define NAZARA_MATRIX4_HPP #include +#include -#if NAZARA_THREADSAFETY_MATRIX4 +#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4 #include #else #include @@ -26,18 +27,21 @@ template class NzMatrix4 public: NzMatrix4(); NzMatrix4(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44); + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44); NzMatrix4(const T matrix[16]); //NzMatrix4(const NzMatrix3& matrix); template explicit NzMatrix4(const NzMatrix4& matrix); NzMatrix4(const NzMatrix4& matrix); - NzMatrix4(NzMatrix4&& matrix); + NzMatrix4(NzMatrix4&& matrix) noexcept; ~NzMatrix4(); + NzMatrix4 Concatenate(const NzMatrix4& matrix) const; + T GetDeterminant() const; NzMatrix4 GetInverse() const; + NzQuaternion GetRotation() const; //NzMatrix3 GetRotationMatrix() const; NzVector3 GetScale() const; NzVector3 GetTranslation() const; @@ -46,23 +50,30 @@ template class NzMatrix4 bool HasNegativeScale() const; bool HasScale() const; + bool IsAffine() const; + bool IsDefined() const; + + void MakeIdentity(); + void MakeLookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up); + void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); + void MakePerspective(T angle, T ratio, T zNear, T zFar); + void MakeRotation(const NzQuaternion& rotation); + void MakeScale(const NzVector3& scale); + void MakeTranslation(const NzVector3& translation); + void MakeZero(); + void Set(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44); + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44); void Set(const T matrix[16]); //NzMatrix4(const NzMatrix3& matrix); void Set(const NzMatrix4& matrix); void Set(NzMatrix4&& matrix); template void Set(const NzMatrix4& matrix); - void SetIdentity(); - void SetLookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up); - void SetOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); - void SetPerspective(T angle, T ratio, T zNear, T zFar); void SetRotation(const NzQuaternion& rotation); void SetScale(const NzVector3& scale); void SetTranslation(const NzVector3& translation); - void SetZero(); NzString ToString() const; @@ -72,6 +83,8 @@ template class NzMatrix4 NzMatrix4& Transpose(); + operator NzString() const; + operator T*(); operator const T*() const; @@ -79,7 +92,7 @@ template class NzMatrix4 const T& operator()(unsigned int x, unsigned int y) const; NzMatrix4& operator=(const NzMatrix4& matrix); - NzMatrix4& operator=(NzMatrix4&& matrix); + NzMatrix4& operator=(NzMatrix4&& matrix) noexcept; NzMatrix4 operator*(const NzMatrix4& matrix) const; NzVector2 operator*(const NzVector2& vector) const; @@ -90,12 +103,16 @@ template class NzMatrix4 NzMatrix4& operator*=(const NzMatrix4& matrix); NzMatrix4& operator*=(T scalar); + static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); + static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); + static NzMatrix4 Identity(); static NzMatrix4 LookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up); static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar); static NzMatrix4 Rotate(const NzQuaternion& rotation); static NzMatrix4 Scale(const NzVector3& scale); static NzMatrix4 Translate(const NzVector3& translation); + static NzMatrix4 Zero(); struct SharedMatrix { @@ -112,11 +129,13 @@ template class NzMatrix4 void EnsureOwnership(); void ReleaseMatrix(); - SharedMatrix* m_sharedMatrix; + SharedMatrix* m_sharedMatrix = nullptr; }; template std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix); +template NzMatrix4 operator*(T scale, const NzMatrix4& matrix); + typedef NzMatrix4 NzMatrix4d; typedef NzMatrix4 NzMatrix4f; diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 184648cbe..051b10697 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -15,52 +15,49 @@ #include #include #include -#include +//#include +///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) + +#define F(a) static_cast(a) template -NzMatrix4::NzMatrix4() : -m_sharedMatrix(nullptr) +NzMatrix4::NzMatrix4() { } template NzMatrix4::NzMatrix4(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44) : -m_sharedMatrix(nullptr) + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44) { Set(r11, r12, r13, r14, - r21, r22, r23, r24, - r31, r32, r33, r34, - r41, r42, r43, r44); + r21, r22, r23, r24, + r31, r32, r33, r34, + r41, r42, r43, r44); } template -NzMatrix4::NzMatrix4(const T matrix[16]) : -m_sharedMatrix(nullptr) +NzMatrix4::NzMatrix4(const T matrix[16]) { Set(matrix); } template template -NzMatrix4::NzMatrix4(const NzMatrix4& matrix) : -m_sharedMatrix(nullptr) +NzMatrix4::NzMatrix4(const NzMatrix4& matrix) { Set(matrix); } template -NzMatrix4::NzMatrix4(const NzMatrix4& matrix) : -m_sharedMatrix(nullptr) +NzMatrix4::NzMatrix4(const NzMatrix4& matrix) { Set(matrix); } template -NzMatrix4::NzMatrix4(NzMatrix4&& matrix) : -m_sharedMatrix(nullptr) +NzMatrix4::NzMatrix4(NzMatrix4&& matrix) noexcept { Set(matrix); } @@ -71,88 +68,96 @@ NzMatrix4::~NzMatrix4() ReleaseMatrix(); } +template +NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& matrix) const +{ + return Concatenate(*this, matrix); +} + template T NzMatrix4::GetDeterminant() const { #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) + if (!IsDefined()) { - NazaraError("Undefined matrix"); - return 0.0; + NazaraError("Matrix not defined"); + return F(0.0); } #endif - T A = m_sharedMatrix->m22 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m34) - m_sharedMatrix->m32 * (m_sharedMatrix->m23 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m24) + m_sharedMatrix->m42 * (m_sharedMatrix->m23 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m24); - T B = m_sharedMatrix->m12 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m34) - m_sharedMatrix->m32 * (m_sharedMatrix->m13 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m14) + m_sharedMatrix->m42 * (m_sharedMatrix->m13 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m14); - T C = m_sharedMatrix->m12 * (m_sharedMatrix->m23 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m24) - m_sharedMatrix->m22 * (m_sharedMatrix->m13 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m14) + m_sharedMatrix->m42 * (m_sharedMatrix->m13 * m_sharedMatrix->m24 - m_sharedMatrix->m23 * m_sharedMatrix->m14); - T D = m_sharedMatrix->m12 * (m_sharedMatrix->m23 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m24) - m_sharedMatrix->m22 * (m_sharedMatrix->m13 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m14) + m_sharedMatrix->m32 * (m_sharedMatrix->m13 * m_sharedMatrix->m24 - m_sharedMatrix->m23 * m_sharedMatrix->m14); + T A = m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24); + T B = m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14); + T C = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); + T D = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); - return m_sharedMatrix->m11 * A - m_sharedMatrix->m21 * B + m_sharedMatrix->m31 * C - m_sharedMatrix->m41 * D; + return m_sharedMatrix->m11*A - m_sharedMatrix->m21*B + m_sharedMatrix->m31*C - m_sharedMatrix->m41*D; } template NzMatrix4 NzMatrix4::GetInverse() const { #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) + if (!IsDefined()) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return NzMatrix4(); } #endif - NzMatrix4 matrix; T det = GetDeterminant(); - - if (!NzNumberEquals(det, static_cast(0.0))) + if (!NzNumberEquals(det, F(0.0))) { - matrix(0, 0) = (m_sharedMatrix->m22 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m43) - m_sharedMatrix->m32 * (m_sharedMatrix->m23 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m24) + m_sharedMatrix->m42 * (m_sharedMatrix->m23 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m24)) / det; - matrix(0, 1) = -(m_sharedMatrix->m12 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m34) - m_sharedMatrix->m32 * (m_sharedMatrix->m13 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m14) + m_sharedMatrix->m42 * (m_sharedMatrix->m13 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m14)) / det; - matrix(0, 2) = (m_sharedMatrix->m12 * (m_sharedMatrix->m23 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m24) - m_sharedMatrix->m22 * (m_sharedMatrix->m13 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m14) + m_sharedMatrix->m42 * (m_sharedMatrix->m13 * m_sharedMatrix->m24 - m_sharedMatrix->m23 * m_sharedMatrix->m14)) / det; - matrix(0, 3) = -(m_sharedMatrix->m12 * (m_sharedMatrix->m23 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m24) - m_sharedMatrix->m22 * (m_sharedMatrix->m13 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m14) + m_sharedMatrix->m32 * (m_sharedMatrix->m13 * m_sharedMatrix->m24 - m_sharedMatrix->m23 * m_sharedMatrix->m14)) / det; + return NzMatrix4((m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24)) / det, + -(m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14)) / det, + (m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, + -(m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, - matrix(1, 0) = -(m_sharedMatrix->m21 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m43) - m_sharedMatrix->m23 * (m_sharedMatrix->m31 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m41) + m_sharedMatrix->m24 * (m_sharedMatrix->m31 * m_sharedMatrix->m43 - m_sharedMatrix->m33 * m_sharedMatrix->m41)) / det; - matrix(1, 1) = (m_sharedMatrix->m11 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m43) - m_sharedMatrix->m13 * (m_sharedMatrix->m31 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m41) + m_sharedMatrix->m14 * (m_sharedMatrix->m31 * m_sharedMatrix->m43 - m_sharedMatrix->m33 * m_sharedMatrix->m41)) / det; - matrix(1, 2) = -(m_sharedMatrix->m11 * (m_sharedMatrix->m23 * m_sharedMatrix->m44 - m_sharedMatrix->m24 * m_sharedMatrix->m43) - m_sharedMatrix->m13 * (m_sharedMatrix->m21 * m_sharedMatrix->m44 - m_sharedMatrix->m24 * m_sharedMatrix->m41) + m_sharedMatrix->m14 * (m_sharedMatrix->m21 * m_sharedMatrix->m43 - m_sharedMatrix->m23 * m_sharedMatrix->m41)) / det; - matrix(1, 3) = (m_sharedMatrix->m11 * (m_sharedMatrix->m23 * m_sharedMatrix->m34 - m_sharedMatrix->m24 * m_sharedMatrix->m33) - m_sharedMatrix->m13 * (m_sharedMatrix->m21 * m_sharedMatrix->m34 - m_sharedMatrix->m24 * m_sharedMatrix->m31) + m_sharedMatrix->m14 * (m_sharedMatrix->m21 * m_sharedMatrix->m33 - m_sharedMatrix->m23 * m_sharedMatrix->m31)) / det; + -(m_sharedMatrix->m21*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m33) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31)) / det, - matrix(2, 0) = (m_sharedMatrix->m21 * (m_sharedMatrix->m32 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m42) - m_sharedMatrix->m22 * (m_sharedMatrix->m31 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m41) + m_sharedMatrix->m24 * (m_sharedMatrix->m31 * m_sharedMatrix->m42 - m_sharedMatrix->m32 * m_sharedMatrix->m41)) / det; - matrix(2, 1) = -(m_sharedMatrix->m11 * (m_sharedMatrix->m32 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m42) - m_sharedMatrix->m12 * (m_sharedMatrix->m31 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m41) + m_sharedMatrix->m14 * (m_sharedMatrix->m31 * m_sharedMatrix->m42 - m_sharedMatrix->m32 * m_sharedMatrix->m41)) / det; - matrix(2, 2) = (m_sharedMatrix->m11 * (m_sharedMatrix->m22 * m_sharedMatrix->m44 - m_sharedMatrix->m24 * m_sharedMatrix->m42) - m_sharedMatrix->m12 * (m_sharedMatrix->m21 * m_sharedMatrix->m44 - m_sharedMatrix->m24 * m_sharedMatrix->m41) + m_sharedMatrix->m14 * (m_sharedMatrix->m21 * m_sharedMatrix->m42 - m_sharedMatrix->m22 * m_sharedMatrix->m41)) / det; - matrix(2, 3) = -(m_sharedMatrix->m11 * (m_sharedMatrix->m22 * m_sharedMatrix->m34 - m_sharedMatrix->m24 * m_sharedMatrix->m32) - m_sharedMatrix->m12 * (m_sharedMatrix->m21 * m_sharedMatrix->m34 - m_sharedMatrix->m24 * m_sharedMatrix->m31) + m_sharedMatrix->m14 * (m_sharedMatrix->m21 * m_sharedMatrix->m32 - m_sharedMatrix->m22 * m_sharedMatrix->m31)) / det; + (m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det, - matrix(3, 0) = -(m_sharedMatrix->m21 * (m_sharedMatrix->m32 * m_sharedMatrix->m43 - m_sharedMatrix->m33 * m_sharedMatrix->m42) - m_sharedMatrix->m22 * (m_sharedMatrix->m31 * m_sharedMatrix->m43 - m_sharedMatrix->m33 * m_sharedMatrix->m41) + m_sharedMatrix->m23 * (m_sharedMatrix->m31 * m_sharedMatrix->m42 - m_sharedMatrix->m32 * m_sharedMatrix->m41)) / det; - matrix(3, 1) = (m_sharedMatrix->m11 * (m_sharedMatrix->m32 * m_sharedMatrix->m43 - m_sharedMatrix->m33 * m_sharedMatrix->m42) - m_sharedMatrix->m12 * (m_sharedMatrix->m31 * m_sharedMatrix->m43 - m_sharedMatrix->m33 * m_sharedMatrix->m41) + m_sharedMatrix->m13 * (m_sharedMatrix->m31 * m_sharedMatrix->m42 - m_sharedMatrix->m32 * m_sharedMatrix->m41)) / det; - matrix(3, 2) = -(m_sharedMatrix->m11 * (m_sharedMatrix->m22 * m_sharedMatrix->m43 - m_sharedMatrix->m23 * m_sharedMatrix->m42) - m_sharedMatrix->m12 * (m_sharedMatrix->m21 * m_sharedMatrix->m43 - m_sharedMatrix->m23 * m_sharedMatrix->m41) + m_sharedMatrix->m13 * (m_sharedMatrix->m21 * m_sharedMatrix->m42 - m_sharedMatrix->m22 * m_sharedMatrix->m41)) / det; - matrix(3, 3) = (m_sharedMatrix->m11 * (m_sharedMatrix->m22 * m_sharedMatrix->m33 - m_sharedMatrix->m23 * m_sharedMatrix->m32) - m_sharedMatrix->m12 * (m_sharedMatrix->m21 * m_sharedMatrix->m33 - m_sharedMatrix->m23 * m_sharedMatrix->m31) + m_sharedMatrix->m13 * (m_sharedMatrix->m21 * m_sharedMatrix->m32 - m_sharedMatrix->m22 * m_sharedMatrix->m31)) / det; + -(m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det); } + else + { + NazaraError("Matrix has no inverse"); - return matrix; + return Identity(); + } } template NzVector3 NzMatrix4::GetScale() const { #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) + if (!IsDefined()) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return NzVector3(); } #endif - return NzVector3(std::sqrt(m_sharedMatrix->m11 * m_sharedMatrix->m11 + m_sharedMatrix->m21 * m_sharedMatrix->m21 + m_sharedMatrix->m31 * m_sharedMatrix->m31), - std::sqrt(m_sharedMatrix->m12 * m_sharedMatrix->m12 + m_sharedMatrix->m22 * m_sharedMatrix->m22 + m_sharedMatrix->m32 * m_sharedMatrix->m32), - std::sqrt(m_sharedMatrix->m13 * m_sharedMatrix->m13 + m_sharedMatrix->m23 * m_sharedMatrix->m23 + m_sharedMatrix->m33 * m_sharedMatrix->m33)); + return NzVector3(std::sqrt(m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31), + std::sqrt(m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32), + std::sqrt(m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33)); } template NzVector3 NzMatrix4::GetTranslation() const { #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) + if (!IsDefined()) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return NzVector3(); } #endif @@ -168,51 +173,209 @@ template NzMatrix4 NzMatrix4::GetTransposed() const { #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) + if (!IsDefined()) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return NzMatrix4(); } #endif return NzMatrix4(m_sharedMatrix->m11, m_sharedMatrix->m21, m_sharedMatrix->m31, m_sharedMatrix->m41, - m_sharedMatrix->m12, m_sharedMatrix->m22, m_sharedMatrix->m32, m_sharedMatrix->m42, - m_sharedMatrix->m13, m_sharedMatrix->m23, m_sharedMatrix->m33, m_sharedMatrix->m43, - m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34, m_sharedMatrix->m44); + m_sharedMatrix->m12, m_sharedMatrix->m22, m_sharedMatrix->m32, m_sharedMatrix->m42, + m_sharedMatrix->m13, m_sharedMatrix->m23, m_sharedMatrix->m33, m_sharedMatrix->m43, + m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34, m_sharedMatrix->m44); } template bool NzMatrix4::HasNegativeScale() const { - return GetDeterminant() < 0.f; + return GetDeterminant() < F(0.0); } template bool NzMatrix4::HasScale() const { #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) + if (!IsDefined()) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return false; } #endif - T t = m_sharedMatrix->m11 * m_sharedMatrix->m11 + m_sharedMatrix->m21 * m_sharedMatrix->m21 + m_sharedMatrix->m31 * m_sharedMatrix->m31; - if (1.0 - t > std::numeric_limits::epsilon()) + T t = m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31; + if (!NzNumberEquals(t, F(1.0))) return true; - t = m_sharedMatrix->m12 * m_sharedMatrix->m12 + m_sharedMatrix->m22 * m_sharedMatrix->m22 + m_sharedMatrix->m32 * m_sharedMatrix->m32; - if (1.0 - t > std::numeric_limits::epsilon()) + t = m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32; + if (!NzNumberEquals(t, F(1.0))) return true; - t = m_sharedMatrix->m13 * m_sharedMatrix->m13 + m_sharedMatrix->m23 * m_sharedMatrix->m23 + m_sharedMatrix->m33 * m_sharedMatrix->m33; - if (1.0 - t > std::numeric_limits::epsilon()) + t = m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33; + if (!NzNumberEquals(t, F(1.0))) return true; return false; } +template +bool NzMatrix4::IsAffine() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return false; + } + #endif + + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + return NzNumberEquals(m_sharedMatrix->m14, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m24, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m34, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m44, F(1.0)); + #else + return NzNumberEquals(m_sharedMatrix->m41, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m42, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m43, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m44, F(1.0)); + #endif +} + +template +bool NzMatrix4::IsDefined() const +{ + return m_sharedMatrix != nullptr; +} + +template +void NzMatrix4::MakeIdentity() +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(1.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(1.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeOrtho(T left, T top, T width, T height, T zNear, T zFar) +{ + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + Set(F(2.0)/(width-left), F(0.0), F(0.0), -(width+left)/(width-left), + F(0.0), F(2.0)/(top-height), F(0.0), -(top+height)/(top-height), + F(0.0), F(0.0), F(-2.0)/(zFar-zNear), -(zFar+zNear)/(zFar-zNear), + F(0.0), F(0.0), F(0.0), F(1.0)); + #else + Set(F(2.0)/(width-left), F(0.0), F(0.0), F(0.0), + F(0.0), F(2.0)/(top-height), F(0.0), F(0.0), + F(0.0), F(0.0), F(-2.0)/(zFar-zNear), F(0.0), + -(width+left)/(width-left), -(top+height)/(top-height), -(zFar+zNear)/(zFar-zNear), F(1.0)); + #endif +} + +template +void NzMatrix4::MakeLookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up) +{ + // http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml + NzVector3 f = center - eye; + f.Normalize(); + + NzVector3 u = up; + u.Normalize(); + + NzVector3 s = f.CrossProduct(u); + u = s.CrossProduct(f); + + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + Set(s.x, s.y, s.z, F(0.0), + u.x, u.y, u.z, F(0.0), + -f.x, -f.y, -f.z, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); + #else + Set(s.x, u.x, -f.x, F(0.0), + s.y, u.y, -f.y, F(0.0), + s.z, u.z, -f.z, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); + #endif + + Concatenate(Translate(-eye)); +} + +template +void NzMatrix4::MakePerspective(T angle, T ratio, T zNear, T zFar) +{ + #if NAZARA_MATH_ANGLE_RADIAN + angle /= F(2.0); + #else + angle = NzDegreeToRadian(angle/2); + #endif + + T f = F(1.0) / std::tan(angle); + + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + Set(f / ratio, F(0.0), F(0.0), F(0.0), + F(0.0), f, F(0.0), F(0.0), + F(0.0), F(0.0), (zNear+zFar) / (zNear-zFar), F(-1.0), + F(0.0), F(0.0), (F(2.0)*zNear*zFar) / (zNear-zFar), F(1.0)); + #else + Set(f / ratio, F(0.0), F(0.0), F(0.0), + F(0.0), f, F(0.0), F(0.0), + F(0.0), F(0.0), (zNear+zFar) / (zNear-zFar), (F(2.0)*zNear*zFar) / (zNear-zFar), + F(0.0), F(0.0), F(-1.0), F(1.0)); + #endif +} + +template +void NzMatrix4::MakeRotation(const NzQuaternion& rotation) +{ + // http://stackoverflow.com/questions/1556260/convert-quaternion-rotation-to-rotation-matrix + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, F(0.0), + F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, F(0.0), + F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); + #else + Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, F(0.0), + F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, F(0.0), + F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); + #endif +} + +template +void NzMatrix4::MakeScale(const NzVector3& scale) +{ + Set(scale.x, F(0.0), F(0.0), F(0.0), + F(0.0), scale.y, F(0.0), F(0.0), + F(0.0), F(0.0), scale.z, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeTranslation(const NzVector3& translation) +{ + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + Set(F(1.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(1.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(1.0), F(0.0), + translation.x, translation.y, translation.z, F(1.0)); + #else + Set(F(1.0), F(0.0), F(0.0), translation.x, + F(0.0), F(1.0), F(0.0), translation.y, + F(0.0), F(0.0), F(1.0), translation.z, + F(0.0), F(0.0), F(0.0), F(1.0)); + #endif +} + +template +void NzMatrix4::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0)); +} + template void NzMatrix4::Set(T r11, T r12, T r13, T r14, T r21, T r22, T r23, T r24, @@ -272,143 +435,65 @@ template template void NzMatrix4::Set(const NzMatrix4& matrix) { - Set(static_cast(matrix.m11), static_cast(matrix.m12), static_cast(matrix.m13), static_cast(matrix.m14), - static_cast(matrix.m21), static_cast(matrix.m22), static_cast(matrix.m23), static_cast(matrix.m24), - static_cast(matrix.m31), static_cast(matrix.m32), static_cast(matrix.m33), static_cast(matrix.m34), - static_cast(matrix.m41), static_cast(matrix.m42), static_cast(matrix.m43), static_cast(matrix.m44)); -} - -template -void NzMatrix4::SetIdentity() -{ - Set(1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0); -} - -template -void NzMatrix4::SetOrtho(T left, T top, T width, T height, T zNear, T zFar) -{ - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(2.0/(width-left), 0.0, 0.0, -(width+left)/(width-left), - 0.0, 2.0/(top-height), 0.0, -(top+height)/(top-height), - 0.0, 0.0, -2.0/(zFar-zNear), -(zFar+zNear)/(zFar-zNear), - 0.0, 0.0, 0.0, 1.0); - #else - Set(2.0/(width-left), 0.0, 0.0, 0.0, - 0.0, 2.0/(top-height), 0.0, 0.0, - 0.0, 0.0, -2.0/(zFar-zNear), 0.0, - -(width+left)/(width-left), -(top+height)/(top-height), -(zFar+zNear)/(zFar-zNear), 1.0); - #endif -} - -template -void NzMatrix4::SetLookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up) -{ - // http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml - NzVector3 f = center - eye; - f.Normalize(); - - NzVector3 u = up; - u.Normalize(); - - NzVector3 s = f.CrossProduct(u); - u = s.CrossProduct(f); - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(s.x, s.y, s.z, 0.0, - u.x, u.y, u.z, 0.0, - -f.x, -f.y, -f.z, 0.0, - 0.0, 0.0, 0.0, 1.0); - #else - Set(s.x, u.x, -f.x, 0.0, - s.y, u.y, -f.y, 0.0, - s.z, u.z, -f.z, 0.0, - 0.0, 0.0, 0.0, 1.0); - #endif - - operator*=(Translate(-eye)); -} - -template -void NzMatrix4::SetPerspective(T angle, T ratio, T zNear, T zFar) -{ - #if NAZARA_MATH_ANGLE_RADIAN - angle /= 2; - #else - angle = NzDegreeToRadian(angle/2); - #endif - - auto f = 1 / std::tan(angle); - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(f / ratio, 0.0, 0.0, 0.0, - 0.0, f, 0.0, 0.0, - 0.0, 0.0, (zNear + zFar) / (zNear - zFar), -1.0, - 0.0, 0.0, (2 * zNear * zFar) / (zNear - zFar), 1.0); - #else - Set(f / ratio, 0.0, 0.0, 0.0, - 0.0, f, 0.0, 0.0, - 0.0, 0.0, (zNear + zFar) / (zNear - zFar), (2 * zNear * zFar) / (zNear - zFar), - 0.0, 0.0, -1.0, 1.0); - #endif + Set(F(matrix.m_sharedMatrix->m11), F(matrix.m_sharedMatrix->m12), F(matrix.m_sharedMatrix->m13), F(matrix.m_sharedMatrix->m14), + F(matrix.m_sharedMatrix->m21), F(matrix.m_sharedMatrix->m22), F(matrix.m_sharedMatrix->m23), F(matrix.m_sharedMatrix->m24), + F(matrix.m_sharedMatrix->m31), F(matrix.m_sharedMatrix->m32), F(matrix.m_sharedMatrix->m33), F(matrix.m_sharedMatrix->m34), + F(matrix.m_sharedMatrix->m41), F(matrix.m_sharedMatrix->m42), F(matrix.m_sharedMatrix->m43), F(matrix.m_sharedMatrix->m44)); } template void NzMatrix4::SetRotation(const NzQuaternion& rotation) { // http://www.flipcode.com/documents/matrfaq.html#Q54 - T xx = rotation.x * rotation.x; - T xy = rotation.x * rotation.y; - T xz = rotation.x * rotation.z; - T xw = rotation.x * rotation.w; + EnsureOwnership(); - T yy = rotation.y * rotation.y; - T yz = rotation.y * rotation.z; - T yw = rotation.y * rotation.w; + m_sharedMatrix->m11 = F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z; + m_sharedMatrix->m22 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z; + m_sharedMatrix->m33 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y; - T zz = rotation.z * rotation.z; - T zw = rotation.z * rotation.w; - - Set(1.0 - 2.0*(yy+zz), 2.0*(xy-zw), 2.0*(xz+yw), 0.0, - 2.0*(xz+zw), 1.0 - 2.0*(xx+zz), 2.0*(yz-xw), 0.0, - 2.0*(xz-yw), 2.0*(yz+xw), 1.0 - 2.0*(xx+yy), 0.0, - 0.0, 0.0, 0.0, 1.0); + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; + m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; + #else + m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; + m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; + #endif } template -void NzMatrix4::SetScale(const NzVector3& vector) +void NzMatrix4::SetScale(const NzVector3& scale) { - Set(vector.x, 0.0, 0.0, 0.0, - 0.0, vector.y, 0.0, 0.0, - 0.0, 0.0, vector.z, 0.0, - 0.0, 0.0, 0.0, 1.0); + EnsureOwnership(); + + m_sharedMatrix->m11 = scale.x; + m_sharedMatrix->m22 = scale.y; + m_sharedMatrix->m33 = scale.z; } template void NzMatrix4::SetTranslation(const NzVector3& translation) { - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - translation.x, translation.y, translation.z, 1.0); - #else - Set(1.0, 0.0, 0.0, translation.x, - 0.0, 1.0, 0.0, translation.y, - 0.0, 0.0, 1.0, translation.z, - 0.0, 0.0, 0.0, 1.0); - #endif -} + EnsureOwnership(); -template -void NzMatrix4::SetZero() -{ - Set(0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0); + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + m_sharedMatrix->m41 = translation.x; + m_sharedMatrix->m42 = translation.y; + m_sharedMatrix->m43 = translation.z; + m_sharedMatrix->m44 = F(1.0); + #else + m_sharedMatrix->m14 = translation.x; + m_sharedMatrix->m24 = translation.y; + m_sharedMatrix->m34 = translation.z; + m_sharedMatrix->m44 = F(1.0); + #endif } template @@ -419,9 +504,9 @@ NzString NzMatrix4::ToString() const NzStringStream ss; return ss << "Matrix4(" << m_sharedMatrix->m11 << ", " << m_sharedMatrix->m12 << ", " << m_sharedMatrix->m13 << ", " << m_sharedMatrix->m14 << ",\n" - << " " << m_sharedMatrix->m21 << ", " << m_sharedMatrix->m22 << ", " << m_sharedMatrix->m23 << ", " << m_sharedMatrix->m24 << ",\n" - << " " << m_sharedMatrix->m31 << ", " << m_sharedMatrix->m32 << ", " << m_sharedMatrix->m33 << ", " << m_sharedMatrix->m34 << ",\n" - << " " << m_sharedMatrix->m41 << ", " << m_sharedMatrix->m42 << ", " << m_sharedMatrix->m43 << ", " << m_sharedMatrix->m44 << ')'; + << " " << m_sharedMatrix->m21 << ", " << m_sharedMatrix->m22 << ", " << m_sharedMatrix->m23 << ", " << m_sharedMatrix->m24 << ",\n" + << " " << m_sharedMatrix->m31 << ", " << m_sharedMatrix->m32 << ", " << m_sharedMatrix->m33 << ", " << m_sharedMatrix->m34 << ",\n" + << " " << m_sharedMatrix->m41 << ", " << m_sharedMatrix->m42 << ", " << m_sharedMatrix->m43 << ", " << m_sharedMatrix->m44 << ')'; } template @@ -430,13 +515,13 @@ NzVector2 NzMatrix4::Transform(const NzVector2& vector, T z, T w) const #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return vector; } #endif - return NzVector2(m_sharedMatrix->m11 * vector.x + m_sharedMatrix->m12 * vector.y + m_sharedMatrix->m13 * z + m_sharedMatrix->m14 * w, - m_sharedMatrix->m21 * vector.x + m_sharedMatrix->m22 * vector.y + m_sharedMatrix->m23 * z + m_sharedMatrix->m24 * w); + return NzVector2(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*z + m_sharedMatrix->m14*w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*z + m_sharedMatrix->m24*w); } template @@ -445,14 +530,14 @@ NzVector3 NzMatrix4::Transform(const NzVector3& vector, T w) const #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return vector; } #endif - return NzVector3(m_sharedMatrix->m11 * vector.x + m_sharedMatrix->m12 * vector.y + m_sharedMatrix->m13 * vector.z + m_sharedMatrix->m14 * w, - m_sharedMatrix->m21 * vector.x + m_sharedMatrix->m22 * vector.y + m_sharedMatrix->m23 * vector.z + m_sharedMatrix->m24 * w, - m_sharedMatrix->m31 * vector.x + m_sharedMatrix->m32 * vector.y + m_sharedMatrix->m33 * vector.z + m_sharedMatrix->m34 * w); + return NzVector3(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*w, + m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*w); } template @@ -461,15 +546,15 @@ NzVector4 NzMatrix4::Transform(const NzVector4& vector) const #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return vector; } #endif - return NzVector4(m_sharedMatrix->m11 * vector.x + m_sharedMatrix->m12 * vector.y + m_sharedMatrix->m13 * vector.z + m_sharedMatrix->m14 * vector.w, - m_sharedMatrix->m21 * vector.x + m_sharedMatrix->m22 * vector.y + m_sharedMatrix->m23 * vector.z + m_sharedMatrix->m24 * vector.w, - m_sharedMatrix->m31 * vector.x + m_sharedMatrix->m32 * vector.y + m_sharedMatrix->m33 * vector.z + m_sharedMatrix->m34 * vector.w, - m_sharedMatrix->m41 * vector.x + m_sharedMatrix->m42 * vector.y + m_sharedMatrix->m43 * vector.z + m_sharedMatrix->m44 * vector.w); + return NzVector4(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*vector.w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*vector.w, + m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*vector.w, + m_sharedMatrix->m41*vector.x + m_sharedMatrix->m42*vector.y + m_sharedMatrix->m43*vector.z + m_sharedMatrix->m44*vector.w); } template @@ -478,7 +563,7 @@ NzMatrix4& NzMatrix4::Transpose() #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return *this; } #endif @@ -493,13 +578,19 @@ NzMatrix4& NzMatrix4::Transpose() return *this; } +template +NzMatrix4::operator NzString() const +{ + return ToString(); +} + template NzMatrix4::operator T*() { #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return nullptr; } #endif @@ -515,7 +606,7 @@ NzMatrix4::operator const T*() const #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return nullptr; } #endif @@ -538,7 +629,7 @@ T& NzMatrix4::operator()(unsigned int x, unsigned int y) EnsureOwnership(); - return (&m_sharedMatrix->m11)[x*4+y]; + return (&m_sharedMatrix->m11)[y*4+x]; } template @@ -547,8 +638,8 @@ const T& NzMatrix4::operator()(unsigned int x, unsigned int y) const #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); - throw std::runtime_error("Tried to access element of undefined matrix"); + NazaraError("Matrix not defined"); + throw std::runtime_error("Tried to access element of Matrix not defined"); } if (x > 3 || y > 3) @@ -560,7 +651,7 @@ const T& NzMatrix4::operator()(unsigned int x, unsigned int y) const } #endif - return (&m_sharedMatrix->m11)[x*4+y]; + return (&m_sharedMatrix->m11)[y*4+x]; } template @@ -572,7 +663,7 @@ NzMatrix4& NzMatrix4::operator=(const NzMatrix4& matrix) } template -NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) +NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) noexcept { Set(matrix); @@ -582,30 +673,7 @@ NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) template NzMatrix4 NzMatrix4::operator*(const NzMatrix4& matrix) const { - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Undefined matrix"); - return matrix; - } - #endif - - return NzMatrix4(m_sharedMatrix->m11 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m14, - m_sharedMatrix->m12 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m14, - m_sharedMatrix->m13 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m14, - m_sharedMatrix->m14 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m14, - m_sharedMatrix->m11 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m24, - m_sharedMatrix->m12 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m24, - m_sharedMatrix->m13 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m24, - m_sharedMatrix->m14 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m24, - m_sharedMatrix->m11 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m34, - m_sharedMatrix->m12 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m34, - m_sharedMatrix->m13 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m34, - m_sharedMatrix->m14 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m34, - m_sharedMatrix->m11 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m44, - m_sharedMatrix->m12 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m44, - m_sharedMatrix->m13 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m44, - m_sharedMatrix->m14 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m44); + return Concatenate(matrix); } template @@ -632,15 +700,15 @@ NzMatrix4 NzMatrix4::operator*(T scalar) const #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return *this; } #endif return NzMatrix4(m_sharedMatrix->m11 * scalar, m_sharedMatrix->m12 * scalar, m_sharedMatrix->m13 * scalar, m_sharedMatrix->m14 * scalar, - m_sharedMatrix->m21 * scalar, m_sharedMatrix->m22 * scalar, m_sharedMatrix->m23 * scalar, m_sharedMatrix->m24 * scalar, - m_sharedMatrix->m31 * scalar, m_sharedMatrix->m32 * scalar, m_sharedMatrix->m33 * scalar, m_sharedMatrix->m34 * scalar, - m_sharedMatrix->m41 * scalar, m_sharedMatrix->m42 * scalar, m_sharedMatrix->m43 * scalar, m_sharedMatrix->m44 * scalar); + m_sharedMatrix->m21 * scalar, m_sharedMatrix->m22 * scalar, m_sharedMatrix->m23 * scalar, m_sharedMatrix->m24 * scalar, + m_sharedMatrix->m31 * scalar, m_sharedMatrix->m32 * scalar, m_sharedMatrix->m33 * scalar, m_sharedMatrix->m34 * scalar, + m_sharedMatrix->m41 * scalar, m_sharedMatrix->m42 * scalar, m_sharedMatrix->m43 * scalar, m_sharedMatrix->m44 * scalar); } template @@ -649,34 +717,12 @@ NzMatrix4& NzMatrix4::operator*=(const NzMatrix4& matrix) #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return *this; } #endif - // On calcule dans des variables temporaires - T r11 = m_sharedMatrix->m11 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m14; - T r12 = m_sharedMatrix->m12 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m14; - T r13 = m_sharedMatrix->m13 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m14; - T r14 = m_sharedMatrix->m14 * matrix.m_sharedMatrix->m11 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m12 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m13 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m14; - T r21 = m_sharedMatrix->m11 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m24; - T r22 = m_sharedMatrix->m12 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m24; - T r23 = m_sharedMatrix->m13 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m24; - T r24 = m_sharedMatrix->m14 * matrix.m_sharedMatrix->m21 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m22 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m23 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m24; - T r31 = m_sharedMatrix->m11 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m34; - T r32 = m_sharedMatrix->m12 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m34; - T r33 = m_sharedMatrix->m13 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m34; - T r34 = m_sharedMatrix->m14 * matrix.m_sharedMatrix->m31 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m32 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m33 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m34; - T r41 = m_sharedMatrix->m11 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m21 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m31 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m41 * matrix.m_sharedMatrix->m44; - T r42 = m_sharedMatrix->m12 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m22 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m32 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m42 * matrix.m_sharedMatrix->m44; - T r43 = m_sharedMatrix->m13 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m23 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m33 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m43 * matrix.m_sharedMatrix->m44; - T r44 = m_sharedMatrix->m14 * matrix.m_sharedMatrix->m41 + m_sharedMatrix->m24 * matrix.m_sharedMatrix->m42 + m_sharedMatrix->m34 * matrix.m_sharedMatrix->m43 + m_sharedMatrix->m44 * matrix.m_sharedMatrix->m44; - - // Et puis on affecte - Set(r11, r12, r13, r14, - r21, r22, r23, r24, - r31, r32, r33, r34, - r41, r42, r43, r44); + Set(Concatenate(*this, matrix)); return *this; } @@ -687,7 +733,7 @@ NzMatrix4& NzMatrix4::operator*=(T scalar) #if NAZARA_MATH_SAFE if (!m_sharedMatrix) { - NazaraError("Undefined matrix"); + NazaraError("Matrix not defined"); return *this; } #endif @@ -712,11 +758,137 @@ NzMatrix4& NzMatrix4::operator*=(T scalar) return *this; } +template +NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) +{ + #if NAZARA_MATH_SAFE + if (!m1.IsDefined()) + { + NazaraError("First matrix not defined"); + return NzMatrix4(); + } + + if (!m2.IsDefined()) + { + NazaraError("Second matrix not defined"); + return NzMatrix4(); + } + #endif + + #if NAZARA_MATH_MATRIX4_CHECK_AFFINE + if (m1.IsAffine() && m2.IsAffine()) + return ConcatenateAffine(m1, m2); + #endif + + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m44); +} + +template +NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2) +{ + #if NAZARA_MATH_SAFE + if (!m1.IsDefined()) + { + NazaraError("First matrix not defined"); + return NzMatrix4(); + } + + if (!m2.IsDefined()) + { + NazaraError("Second matrix not defined"); + return NzMatrix4(); + } + #endif + + #ifdef NAZARA_DEBUG + if (!m1.IsAffine()) + { + NazaraError("First matrix not affine"); + return NzMatrix4(); + } + + if (!m2.IsAffine()) + { + NazaraError("Second matrix not affine"); + return NzMatrix4(); + } + #endif + + #if NAZARA_MATH_MATRIX_COLUMN_MAJOR + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m2.m_sharedMatrix->m43, + F(1.0)); + #else + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14, + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24, + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34, + + F(0.0), + F(0.0), + F(0.0), + F(1.0)); + #endif +} + +template +NzMatrix4 NzMatrix4::Identity() +{ + NzMatrix4 matrix; + matrix.MakeIdentity(); + + return matrix; +} + template NzMatrix4 NzMatrix4::LookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up) { NzMatrix4 matrix; - matrix.SetLookAt(eye, center, up); + matrix.MakeLookAt(eye, center, up); return matrix; } @@ -725,7 +897,7 @@ template NzMatrix4 NzMatrix4::Ortho(T left, T top, T width, T height, T zNear, T zFar) { NzMatrix4 matrix; - matrix.SetOrtho(left, top, width, height, zNear, zFar); + matrix.MakeOrtho(left, top, width, height, zNear, zFar); return matrix; } @@ -734,7 +906,7 @@ template NzMatrix4 NzMatrix4::Perspective(T angle, T ratio, T zNear, T zFar) { NzMatrix4 matrix; - matrix.SetPerspective(angle, ratio, zNear, zFar); + matrix.MakePerspective(angle, ratio, zNear, zFar); return matrix; } @@ -743,7 +915,7 @@ template NzMatrix4 NzMatrix4::Rotate(const NzQuaternion& rotation) { NzMatrix4 matrix; - matrix.SetRotation(rotation); + matrix.MakeRotation(rotation); return matrix; } @@ -752,7 +924,7 @@ template NzMatrix4 NzMatrix4::Scale(const NzVector3& scale) { NzMatrix4 matrix; - matrix.SetScale(scale); + matrix.MakeScale(scale); return matrix; } @@ -761,17 +933,32 @@ template NzMatrix4 NzMatrix4::Translate(const NzVector3& translation) { NzMatrix4 mat; - mat.SetTranslation(translation); + mat.MakeTranslation(translation); return mat; } +template +NzMatrix4 NzMatrix4::Zero() +{ + NzMatrix4 matrix; + matrix.MakeZero(); + + return matrix; +} + template std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix) { return out << matrix.ToString(); } +template +NzMatrix4 operator*(T scale, const NzMatrix4& matrix) +{ + return matrix * scale; +} + template void NzMatrix4::EnsureOwnership() { @@ -806,6 +993,6 @@ void NzMatrix4::ReleaseMatrix() m_sharedMatrix = nullptr; } -#undef NAZARA_MATRIX4_INL +#undef F #include diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index a5e892f2a..b09518b52 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -31,9 +31,12 @@ template class NzQuaternion NzQuaternion GetConjugate() const; NzQuaternion GetNormalized() const; + void MakeIdentity(); + void MakeZero(); + T Magnitude() const; + T Normalize(); - T SquaredMagnitude() const; void Set(T W, T X, T Y, T Z); void Set(T quat[4]); @@ -42,13 +45,17 @@ template class NzQuaternion //void Set(const NzMatrix3& mat); void Set(const NzQuaternion& quat); template void Set(const NzQuaternion& quat); - void SetIdentity(); - void SetZero(); + + T SquaredMagnitude() const; NzEulerAngles ToEulerAngles() const; //NzMatrix3 ToRotationMatrix() const; NzString ToString() const; + operator NzString() const; + + NzQuaternion& operator=(const NzQuaternion& quat); + NzQuaternion operator+(const NzQuaternion& quat) const; NzQuaternion operator*(const NzQuaternion& quat) const; NzVector3 operator*(const NzVector3& vec) const; @@ -67,7 +74,9 @@ template class NzQuaternion bool operator>(const NzQuaternion& quat) const; bool operator>=(const NzQuaternion& quat) const; + static NzQuaternion Identity(); static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp); + static NzQuaternion Zero(); T w, x, y, z; }; diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index b4a459d3d..b03c588f2 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -8,8 +8,11 @@ #include #include #include +#include #include +#define F(a) static_cast(a) + template NzQuaternion::NzQuaternion() { @@ -53,9 +56,9 @@ NzQuaternion::NzQuaternion(const NzQuaternion& quat) } template -T NzQuaternion::DotProduct(const NzQuaternion& vec) const +T NzQuaternion::DotProduct(const NzQuaternion& quat) const { - return w*vec.w + x*vec.x + y*vec.y + z.vec.z; + return w*quat.w + x*quat.x + y*quat.y + z*quat.z; } template @@ -73,6 +76,18 @@ NzQuaternion NzQuaternion::GetNormalized() const return quat; } +template +void NzQuaternion::MakeIdentity() +{ + Set(1.0, 0.0, 0.0, 0.0); +} + +template +void NzQuaternion::MakeZero() +{ + Set(0.0, 0.0, 0.0, 0.0); +} + template T NzQuaternion::Magnitude() const { @@ -82,27 +97,21 @@ T NzQuaternion::Magnitude() const template T NzQuaternion::Normalize() { - T squaredLength = SquaredMagnitude(); + T squaredMagnitude = SquaredMagnitude(); - if (std::fabs(squaredLength) > 0.00001 && std::fabs(squaredLength - 1.0) > 0.00001) + if (squaredMagnitude-F(1.0) > std::numeric_limits::epsilon()) { - T length = std::sqrt(squaredLength); + T magnitude = std::sqrt(squaredMagnitude); - w /= length; - x /= length; - y /= length; - z /= length; + w /= magnitude; + x /= magnitude; + y /= magnitude; + z /= magnitude; - return length; + return magnitude; } else - return 1.0; // Le quaternion est déjà normalisé -} - -template -T NzQuaternion::SquaredMagnitude() const -{ - return w * w + x * x + y * y + z * z; + return F(1.0); // Le quaternion est déjà normalisé } template @@ -166,81 +175,29 @@ void NzQuaternion::Set(const NzQuaternion& quat) } template -void NzQuaternion::SetIdentity() +T NzQuaternion::SquaredMagnitude() const { - Set(1.0, 0.0, 0.0, 0.0); -} - -template -void NzQuaternion::SetZero() -{ - Set(0.0, 0.0, 0.0, 0.0); -} - -template -NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp) -{ - if (interp <= 0.0) - return quatA; - - if (interp >= 1.0) - return quatB; - - NzQuaternion q; - - T cosOmega = quatA.DotProduct(quatB); - if (cosOmega < 0.0) - { - // On inverse tout - q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z); - cosOmega = -cosOmega; - } - else - q.Set(quatB); - - T k0, k1; - if (cosOmega > 0.9999) - { - // Interpolation linéaire pour éviter une division par zéro - k0 = 1.0 - interp; - k1 = interp; - } - else - { - T sinOmega = std::sqrt(1.0f - (cosOmega * cosOmega)); - T omega = std::atan2(sinOmega, cosOmega); - - // Pour éviter deux divisions - sinOmega = 1/sinOmega; - - k0 = std::sin((1.0 - interp) * omega) * sinOmega; - k1 = std::sin(interp * omega) * sinOmega; - } - - NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z); - return result += q; + return w*w + x*x + y*y + z*z; } template NzEulerAngles NzQuaternion::ToEulerAngles() const { - Normalize(); - T test = x*y + z*w; - if (test > 0.499) + if (test > F(0.499)) // singularity at north pole - return NzEulerAngles(NzDegrees(90.0), NzRadians(2.0 * std::atan2(x, w)), 0.0); + return NzEulerAngles(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0)); - if (test < -0.499) - return NzEulerAngles(NzDegrees(-90.0), NzRadians(-2.0 * std::atan2(x, w)), 0.0); + if (test < F(-0.499)) + return NzEulerAngles(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0)); T xx = x*x; T yy = y*y; T zz = z*z; - return NzEulerAngles(NzRadians(std::atan2(2.0*x*w - 2.0*y*z, 1.0 - 2.0*xx - 2.0*zz)), - NzRadians(std::atan2(2.0*y*w - 2.0*x*z, 1.f - 2.0*yy - 2.0*zz)), - NzRadians(std::asin(2.0*test))); + return NzEulerAngles(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*xx - F(2.0)*zz)), + NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*yy - F(2.0)*zz)), + NzRadians(std::asin(F(2.0)*test))); } template @@ -251,6 +208,20 @@ NzString NzQuaternion::ToString() const return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')'; } +template +NzQuaternion::operator NzString() const +{ + return ToString(); +} + +template +NzQuaternion& NzQuaternion::operator=(const NzQuaternion& quat) +{ + Set(quat); + + return *this; +} + template NzQuaternion NzQuaternion::operator+(const NzQuaternion& quat) const { @@ -263,10 +234,10 @@ NzQuaternion NzQuaternion::operator+(const NzQuaternion& quat) const template NzQuaternion NzQuaternion::operator*(const NzQuaternion& quat) const { - return NzQuaternion(w * quat.w - x * quat.x - y * quat.y - z * quat.z, - w * quat.x + x * quat.w + y * quat.z - z * quat.y, - w * quat.y + y * quat.w + z * quat.x - x * quat.z, - w * quat.z + z * quat.w + x * quat.y - y * quat.x); + return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z, + w*quat.x + x*quat.w + y*quat.z - z*quat.y, + w*quat.y + y*quat.w + z*quat.x - x*quat.z, + w*quat.z + z*quat.w + x*quat.y - y*quat.x); } template @@ -276,7 +247,7 @@ NzVector3 NzQuaternion::operator*(const NzVector3& vec) const normal.Normalize(); NzQuaternion qvec(0.0, normal.x, normal.y, normal.z); - NzQuaternion result = operator*(qvec * GetConjugate()); + NzQuaternion result(operator*(qvec * GetConjugate())); return NzVector3(result.x, result.y, result.z); @@ -360,10 +331,74 @@ bool NzQuaternion::operator>=(const NzQuaternion& quat) const return !operator<(quat); } +template +NzQuaternion NzQuaternion::Identity() +{ + NzQuaternion quaternion; + quaternion.MakeIdentity(); + + return quaternion; +} + +template +NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp) +{ + if (interp <= F(0.0)) + return quatA; + + if (interp >= F(1.0)) + return quatB; + + NzQuaternion q; + + T cosOmega = quatA.DotProduct(quatB); + if (cosOmega < F(0.0)) + { + // On inverse tout + q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z); + cosOmega = -cosOmega; + } + else + q.Set(quatB); + + T k0, k1; + if (cosOmega > F(0.9999)) + { + // Interpolation linéaire pour éviter une division par zéro + k0 = F(1.0) - interp; + k1 = interp; + } + else + { + T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); + T omega = std::atan2(sinOmega, cosOmega); + + // Pour éviter deux divisions + sinOmega = F(1.0)/sinOmega; + + k0 = std::sin((F(1.0) - interp) * omega) * sinOmega; + k1 = std::sin(interp*omega) * sinOmega; + } + + NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z); + return result += q*k1; +} + +template +NzQuaternion NzQuaternion::Zero() +{ + NzQuaternion quaternion; + quaternion.MakeZero(); + + return quaternion; +} + template std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat) { return out << quat.ToString(); } +#undef F + #include diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index 4669c801d..5c06e9140 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -16,7 +16,8 @@ class NzRect public: NzRect(); NzRect(T X, T Y, T Width, T Height); - NzRect(T rect[4]); + NzRect(const T rect[4]); + NzRect(const NzVector2& vec1, const NzVector2& vec2); template explicit NzRect(const NzRect& rect); NzRect(const NzRect& rect) = default; ~NzRect() = default; @@ -30,11 +31,15 @@ class NzRect NzVector2 GetCenter() const; - bool Intersect(const NzRect& rect) const; - bool Intersect(const NzRect& rect, NzRect& intersection) const; + bool Intersect(const NzRect& rect, NzRect* intersection = nullptr) const; bool IsValid() const; + void Set(T X, T Y, T Width, T Height); + void Set(const T rect[4]); + void Set(const NzVector2& vec1, const NzVector2& vec2); + template void Set(const NzRect& rect); + NzString ToString() const; operator NzString() const; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 97dab6292..97d1a6a69 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -6,37 +6,36 @@ #include #include +#define F(a) static_cast(a) + template NzRect::NzRect() { } template -NzRect::NzRect(T X, T Y, T Width, T Height) : -x(X), -y(Y), -width(Width), -height(Height) +NzRect::NzRect(T X, T Y, T Width, T Height) { + Set(X, Y, Width, Height); } template -NzRect::NzRect(T vec[4]) : -x(vec[0]), -y(vec[1]), -width(vec[2]), -height(vec[3]) +NzRect::NzRect(const T vec[4]) { + Set(vec); +} + +template +NzRect::NzRect(const NzVector2& vec1, const NzVector2& vec2) +{ + Set(vec1, vec2); } template template -NzRect::NzRect(const NzRect& rect) : -x(static_cast(rect.x)), -y(static_cast(rect.y)), -width(static_cast(rect.width)), -height(static_cast(rect.height)) +NzRect::NzRect(const NzRect& rect) { + Set(rect); } template @@ -80,18 +79,11 @@ void NzRect::ExtendTo(const NzRect& rect) template NzVector2 NzRect::GetCenter() const { - return NzVector2((x+width)/2, (y+height)/2); + return NzVector2((x+width)/F(2.0), (y+height)/F(2.0)); } template -bool NzRect::Intersect(const NzRect& rect) const -{ - NzRect intersection; // Optimisé par le compilateur - return Intersect(rect, intersection); -} - -template -bool NzRect::Intersect(const NzRect& rect, NzRect& intersection) const +bool NzRect::Intersect(const NzRect& rect, NzRect* intersection) const { T left = std::max(x, rect.x); T right = std::min(x+width, rect.x+rect.width); @@ -100,10 +92,13 @@ bool NzRect::Intersect(const NzRect& rect, NzRect& intersection) const if (left < right && top < bottom) { - intersection.x = left; - intersection.y = top; - intersection.width = right-left; - intersection.height = bottom-top; + if (intersection) + { + intersection->x = left; + intersection->y = top; + intersection->width = right-left; + intersection->height = bottom-top; + } return true; } @@ -114,7 +109,44 @@ bool NzRect::Intersect(const NzRect& rect, NzRect& intersection) const template bool NzRect::IsValid() const { - return width > 0 && height > 0; + return width > F(0.0) && height > F(0.0); +} + +template +void NzRect::Set(T X, T Y, T Width, T Height) +{ + x = X; + y = Y; + width = Width; + height = Height; +} + +template +void NzRect::Set(const T rect[4]) +{ + x = rect[0]; + y = rect[1]; + width = rect[2]; + height = rect[3]; +} + +template +void NzRect::Set(const NzVector2& vec1, const NzVector2& vec2) +{ + x = std::min(vec1.x, vec2.x); + y = std::min(vec1.y, vec2.y); + width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x; + height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y; +} + +template +template +void NzRect::Set(const NzRect& rect) +{ + x = F(rect.x); + y = F(rect.y); + width = F(rect.width); + height = F(rect.height); } template @@ -134,6 +166,7 @@ NzRect::operator NzString() const template T& NzRect::operator[](unsigned int i) { + #if NAZARA_MATH_SAFE if (i >= 4) { NzStringStream ss; @@ -141,6 +174,7 @@ T& NzRect::operator[](unsigned int i) throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -148,6 +182,7 @@ T& NzRect::operator[](unsigned int i) template T NzRect::operator[](unsigned int i) const { + #if NAZARA_MATH_SAFE if (i >= 4) { NzStringStream ss; @@ -155,6 +190,7 @@ T NzRect::operator[](unsigned int i) const throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -165,4 +201,6 @@ std::ostream& operator<<(std::ostream& out, const NzRect& rect) return out << rect.ToString(); } +#undef F + #include diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 6473d7206..b7fc3eff1 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -21,20 +21,37 @@ template class NzVector2 ~NzVector2() = default; T AbsDotProduct(const NzVector2& vec) const; + T Distance(const NzVector2& vec) const; float Distancef(const NzVector2& vec) const; + T DotProduct(const NzVector2& vec) const; + NzVector2 GetNormal() const; + void MakeCeil(const NzVector2& vec); void MakeFloor(const NzVector2& vec); + void MakeUnitX(); + void MakeUnitY(); + void MakeZero(); + T Length() const; float Lengthf() const; + void Normalize(); + + void Set(T X, T Y); + void Set(T scale); + void Set(T vec[2]); + template void Set(const NzVector2& vec); + T SquaredDistance(const NzVector2& vec) const; T SquaredLength() const; NzString ToString() const; + operator NzString() const; + operator T*(); operator const T*() const; @@ -65,8 +82,11 @@ template class NzVector2 bool operator>(const NzVector2& vec) const; bool operator>=(const NzVector2& vec) const; - T x; - T y; + static NzVector2 UnitX(); + static NzVector2 UnitY(); + static NzVector2 Zero(); + + T x, y; }; template std::ostream& operator<<(std::ostream& out, const NzVector2& vec); diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 3889aaa78..3ee71da3f 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -6,41 +6,40 @@ #include #include #include +#include #include #include +#define F(a) static_cast(a) + template NzVector2::NzVector2() { } template -NzVector2::NzVector2(T X, T Y) : -x(X), -y(Y) +NzVector2::NzVector2(T X, T Y) { + Set(X, Y); } template -NzVector2::NzVector2(T scale) : -x(scale), -y(scale) +NzVector2::NzVector2(T scale) { + Set(scale); } template -NzVector2::NzVector2(T vec[2]) : -x(vec[0]), -y(vec[1]) +NzVector2::NzVector2(T vec[2]) { + Set(vec); } template template -NzVector2::NzVector2(const NzVector2& vec) : -x(static_cast(vec.x)), -y(static_cast(vec.y)) +NzVector2::NzVector2(const NzVector2& vec) { + Set(vec); } template @@ -76,7 +75,7 @@ float NzVector2::Distancef(const NzVector2& vec) const template T NzVector2::DotProduct(const NzVector2& vec) const { - return x * vec.x + y * vec.y; + return x*vec.x + y*vec.y; } template @@ -88,6 +87,18 @@ NzVector2 NzVector2::GetNormal() const return vec; } +template +T NzVector2::Length() const +{ + return std::sqrt(SquaredLength()); +} + +template +float NzVector2::Lengthf() const +{ + return std::sqrt(static_cast(SquaredLength())); +} + template void NzVector2::MakeCeil(const NzVector2& vec) { @@ -109,29 +120,65 @@ void NzVector2::MakeFloor(const NzVector2& vec) } template -T NzVector2::Length() const +void NzVector2::MakeUnitX() { - return std::sqrt(SquaredLength()); + Set(F(1.0), F(0.0)); } template -float NzVector2::Lengthf() const +void NzVector2::MakeUnitY() { - return std::sqrt(static_cast(SquaredLength())); + Set(F(0.0), F(1.0)); +} + +template +void NzVector2::MakeZero() +{ + Set(F(0.0), F(0.0)); } template void NzVector2::Normalize() { - auto length = Length(); + T squaredLength = SquaredLength(); - if (!NzNumberEquals(length, static_cast(0.0))) + if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) { + T length = std::sqrt(squaredLength); + x /= length; y /= length; } } +template +void NzVector2::Set(T X, T Y) +{ + x = X; + y = Y; +} + +template +void NzVector2::Set(T scale) +{ + x = scale; + y = scale; +} + +template +void NzVector2::Set(T vec[2]) +{ + std::memcpy(&x, vec, 2*sizeof(T)); +} + +template +template +void NzVector2::Set(const NzVector2& vec) +{ + x = F(vec.x); + y = F(vec.y); +} + template T NzVector2::SquaredDistance(const NzVector2& vec) const { @@ -141,7 +188,7 @@ T NzVector2::SquaredDistance(const NzVector2& vec) const template T NzVector2::SquaredLength() const { - return x * x + y * y; + return x*x + y*y; } template @@ -152,6 +199,12 @@ NzString NzVector2::ToString() const return ss << "Vector2(" << x << ", " << y << ')'; } +template +NzVector2::operator NzString() const +{ + return ToString(); +} + template NzVector2::operator T*() { @@ -167,6 +220,7 @@ NzVector2::operator const T*() const template T& NzVector2::operator[](unsigned int i) { + #if NAZARA_MATH_SAFE if (i >= 2) { NzStringStream ss; @@ -174,6 +228,7 @@ T& NzVector2::operator[](unsigned int i) throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -181,6 +236,7 @@ T& NzVector2::operator[](unsigned int i) template T NzVector2::operator[](unsigned int i) const { + #if NAZARA_MATH_SAFE if (i >= 2) { NzStringStream ss; @@ -188,6 +244,7 @@ T NzVector2::operator[](unsigned int i) const throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -231,13 +288,15 @@ NzVector2 NzVector2::operator*(T scale) const template NzVector2 NzVector2::operator/(const NzVector2& vec) const { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector2(x / vec.x, y / vec.y); } @@ -245,13 +304,15 @@ NzVector2 NzVector2::operator/(const NzVector2& vec) const template NzVector2 NzVector2::operator/(T scale) const { - if (NzNumberEquals(scale, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector2(x / scale, y / scale); } @@ -295,13 +356,15 @@ NzVector2& NzVector2::operator*=(T scale) template NzVector2& NzVector2::operator/=(const NzVector2& vec) { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif x /= vec.x; y /= vec.y; @@ -312,13 +375,15 @@ NzVector2& NzVector2::operator/=(const NzVector2& vec) template NzVector2& NzVector2::operator/=(T scale) { - if (NzNumberEquals(scale, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif x /= scale; y /= scale; @@ -363,6 +428,33 @@ bool NzVector2::operator>=(const NzVector2& vec) const return !operator<(vec); } +template +NzVector2 NzVector2::UnitX() +{ + NzVector2 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector2 NzVector2::UnitY() +{ + NzVector2 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector2 NzVector2::Zero() +{ + NzVector2 vector; + vector.MakeZero(); + + return vector; +} + template std::ostream& operator<<(std::ostream& out, const NzVector2& vec) { @@ -378,15 +470,19 @@ NzVector2 operator*(T scale, const NzVector2& vec) template NzVector2 operator/(T scale, const NzVector2& vec) { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector2(scale/vec.x, scale/vec.y); } +#undef F + #include diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index af4a2b934..c8320b9f0 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -23,21 +23,41 @@ template class NzVector3 ~NzVector3() = default; T AbsDotProduct(const NzVector3& vec) const; + NzVector3 CrossProduct(const NzVector3& vec) const; + T Distance(const NzVector3& vec) const; float Distancef(const NzVector3& vec) const; + T DotProduct(const NzVector3& vec) const; + NzVector3 GetNormal() const; - void MakeCeil(const NzVector3& vec); - void MakeFloor(const NzVector3& vec); + T Length() const; float Lengthf() const; + + void MakeCeil(const NzVector3& vec); + void MakeFloor(const NzVector3& vec); + void MakeUnitX(); + void MakeUnitY(); + void MakeUnitZ(); + void MakeZero(); + void Normalize(); + + void Set(T X, T Y, T Z); + void Set(T scale); + void Set(T vec[3]); + void Set(const NzVector2& vec, T Z = 0.0); + template void Set(const NzVector3& vec); + T SquaredDistance(const NzVector3& vec) const; T SquaredLength() const; NzString ToString() const; + operator NzString() const; + operator T*(); operator const T*() const; @@ -68,9 +88,12 @@ template class NzVector3 bool operator>(const NzVector3& vec) const; bool operator>=(const NzVector3& vec) const; - T x; - T y; - T z; + static NzVector3 UnitX(); + static NzVector3 UnitY(); + static NzVector3 UnitZ(); + static NzVector3 Zero(); + + T x, y, z; }; template std::ostream& operator<<(std::ostream& out, const NzVector3& vec); diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index aec284b9b..136fce90b 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -6,53 +6,46 @@ #include #include #include +#include #include #include +#define F(a) static_cast(a) + template NzVector3::NzVector3() { } template -NzVector3::NzVector3(T X, T Y, T Z) : -x(X), -y(Y), -z(Z) +NzVector3::NzVector3(T X, T Y, T Z) { + Set(X, Y, Z); } template -NzVector3::NzVector3(T scale) : -x(scale), -y(scale), -z(scale) +NzVector3::NzVector3(T scale) { + Set(scale); } template -NzVector3::NzVector3(T vec[3]) : -x(vec[0]), -y(vec[1]), -z(vec[2]) +NzVector3::NzVector3(T vec[3]) { + Set(vec); } template -NzVector3::NzVector3(const NzVector2& vec, T Z) : -x(vec.x), -y(vec.y), -z(Z) +NzVector3::NzVector3(const NzVector2& vec, T Z) { + Set(vec, Z); } template template -NzVector3::NzVector3(const NzVector3& vec) : -x(static_cast(vec.x)), -y(static_cast(vec.y)), -z(static_cast(vec.z)) +NzVector3::NzVector3(const NzVector3& vec) { + Set(vec); } template @@ -94,7 +87,7 @@ float NzVector3::Distancef(const NzVector3& vec) const template T NzVector3::DotProduct(const NzVector3& vec) const { - return x * vec.x + y * vec.y + z * vec.z; + return x*vec.x + y*vec.y + z*vec.z; } template @@ -132,6 +125,30 @@ void NzVector3::MakeFloor(const NzVector3& vec) z = vec.z; } +template +void NzVector3::MakeUnitX() +{ + Set(F(1.0), F(0.0), F(0.0)); +} + +template +void NzVector3::MakeUnitY() +{ + Set(F(0.0), F(1.0), F(0.0)); +} + +template +void NzVector3::MakeUnitZ() +{ + Set(F(0.0), F(0.0), F(1.0)); +} + +template +void NzVector3::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0)); +} + template T NzVector3::Length() const { @@ -147,16 +164,57 @@ float NzVector3::Lengthf() const template void NzVector3::Normalize() { - T length = Length(); + T squaredLength = SquaredLength(); - if (!NzNumberEquals(length, static_cast(0.0))) + if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) { + T length = std::sqrt(squaredLength); + x /= length; y /= length; z /= length; } } +template +void NzVector3::Set(T X, T Y, T Z) +{ + x = X; + y = Y; + z = Z; +} + +template +void NzVector3::Set(T scale) +{ + x = scale; + y = scale; + z = scale; +} + +template +void NzVector3::Set(T vec[3]) +{ + std::memcpy(&x, vec, 3*sizeof(T)); +} + +template +void NzVector3::Set(const NzVector2& vec, T Z) +{ + x = vec.x; + y = vec.y; + z = Z; +} + +template +template +void NzVector3::Set(const NzVector3& vec) +{ + x = F(vec.x); + y = F(vec.y); + z = F(vec.z); +} + template T NzVector3::SquaredDistance(const NzVector3& vec) const { @@ -166,7 +224,7 @@ T NzVector3::SquaredDistance(const NzVector3& vec) const template T NzVector3::SquaredLength() const { - return x * x + y * y + z * z; + return x*x + y*y + z*z; } template @@ -177,6 +235,12 @@ NzString NzVector3::ToString() const return ss << "Vector3(" << x << ", " << y << ", " << z <<')'; } +template +NzVector3::operator NzString() const +{ + return ToString(); +} + template NzVector3::operator T*() { @@ -192,13 +256,15 @@ NzVector3::operator const T*() const template T& NzVector3::operator[](unsigned int i) { + #if NAZARA_MATH_SAFE if (i >= 3) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; - throw std::domain_error(ss.ToString()); + throw std::out_of_range(ss.ToString()); } + #endif return *(&x+i); } @@ -206,13 +272,15 @@ T& NzVector3::operator[](unsigned int i) template T NzVector3::operator[](unsigned int i) const { + #if NAZARA_MATH_SAFE if (i >= 3) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; - throw std::domain_error(ss.ToString()); + throw std::out_of_range(ss.ToString()); } + #endif return *(&x+i); } @@ -256,13 +324,15 @@ NzVector3 NzVector3::operator*(T scale) const template NzVector3 NzVector3::operator/(const NzVector3& vec) const { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector3(x / vec.x, y / vec.y, z / vec.z); } @@ -270,13 +340,15 @@ NzVector3 NzVector3::operator/(const NzVector3& vec) const template NzVector3 NzVector3::operator/(T scale) const { - if (NzNumberEquals(scale, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector3(x / scale, y / scale, z / scale); } @@ -324,7 +396,7 @@ NzVector3& NzVector3::operator*=(T scale) template NzVector3& NzVector3::operator/=(const NzVector3& vec) { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0))) + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; @@ -342,7 +414,7 @@ NzVector3& NzVector3::operator/=(const NzVector3& vec) template NzVector3& NzVector3::operator/=(T scale) { - if (NzNumberEquals(scale, static_cast(0.0))) + if (NzNumberEquals(scale, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; @@ -395,6 +467,42 @@ bool NzVector3::operator>=(const NzVector3& vec) const return !operator<(vec); } +template +NzVector3 NzVector3::UnitX() +{ + NzVector3 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector3 NzVector3::UnitY() +{ + NzVector3 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector3 NzVector3::UnitZ() +{ + NzVector3 vector; + vector.MakeUnitZ(); + + return vector; +} + +template +NzVector3 NzVector3::Zero() +{ + NzVector3 vector; + vector.MakeZero(); + + return vector; +} + template std::ostream& operator<<(std::ostream& out, const NzVector3& vec) { @@ -410,15 +518,19 @@ NzVector3 operator*(T scale, const NzVector3& vec) template NzVector3 operator/(T scale, const NzVector3& vec) { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector3(scale / vec.x, scale / vec.y, scale / vec.z); } +#undef F + #include diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 872ac16c0..8faa3b94c 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -17,19 +17,34 @@ template class NzVector4 NzVector4(T X, T Y, T Z, T W = 1.0); explicit NzVector4(T scale); NzVector4(T vec[4]); - template explicit NzVector4(const NzVector4& vec); NzVector4(const NzVector3& vec, T W = 1.0); + template explicit NzVector4(const NzVector4& vec); NzVector4(const NzVector4& vec) = default; ~NzVector4() = default; T AbsDotProduct(const NzVector4& vec) const; + T DotProduct(const NzVector4& vec) const; + void MakeCeil(const NzVector4& vec); void MakeFloor(const NzVector4& vec); + void MakeUnitX(); + void MakeUnitY(); + void MakeUnitZ(); + void MakeZero(); + void Normalize(); + void Set(T X, T Y, T Z, T W = 1.0); + void Set(T scale); + void Set(T vec[4]); + void Set(const NzVector3& vec, T W = 1.0); + template void Set(const NzVector4& vec); + NzString ToString() const; + operator NzString() const; + operator T*(); operator const T*() const; @@ -60,10 +75,12 @@ template class NzVector4 bool operator>(const NzVector4& vec) const; bool operator>=(const NzVector4& vec) const; - T x; - T y; - T z; - T w; + static NzVector4 UnitX(); + static NzVector4 UnitY(); + static NzVector4 UnitZ(); + static NzVector4 Zero(); + + T x, y, z, w; }; template std::ostream& operator<<(std::ostream& out, const NzVector4& vec); diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index e5ec906fd..99e868cf6 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -9,55 +9,44 @@ #include #include +///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D + +#define F(a) static_cast(a) + template NzVector4::NzVector4() { } template -NzVector4::NzVector4(T X, T Y, T Z, T W) : -x(X), -y(Y), -z(Z), -w(W) +NzVector4::NzVector4(T X, T Y, T Z, T W) { + Set(X, Y, Z, W); } template -NzVector4::NzVector4(T scale) : -x(scale), -y(scale), -z(scale), -w(scale) +NzVector4::NzVector4(T scale) { + Set(scale); } template -NzVector4::NzVector4(T vec[4]) : -x(vec[0]), -y(vec[1]), -z(vec[2]), -w(vec[3]) +NzVector4::NzVector4(T vec[4]) { + Set(vec); +} + +template +NzVector4::NzVector4(const NzVector3& vec, T W) +{ + Set(vec, W); } template template -NzVector4::NzVector4(const NzVector4& vec) : -x(static_cast(vec.x)), -y(static_cast(vec.y)), -z(static_cast(vec.z)), -w(static_cast(vec.w)) -{ -} - -template -NzVector4::NzVector4(const NzVector3& vec, T W) : -x(vec.x), -y(vec.y), -z(vec.z), -w(W) +NzVector4::NzVector4(const NzVector4& vec) { + Set(vec); } template @@ -81,7 +70,7 @@ inline unsigned int NzVector4::AbsDotProduct(const NzVector4 T NzVector4::DotProduct(const NzVector4& vec) const { - return x * vec.x + y * vec.y + z * vec.z + w * vec.w; + return x*vec.x + y*vec.y + z*vec.z + w*vec.w; } template @@ -116,10 +105,34 @@ void NzVector4::MakeFloor(const NzVector4& vec) w = vec.w; } +template +void NzVector4::MakeUnitX() +{ + Set(F(1.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzVector4::MakeUnitY() +{ + Set(F(0.0), F(1.0), F(0.0), F(1.0)); +} + +template +void NzVector4::MakeUnitZ() +{ + Set(F(0.0), F(0.0), F(1.0), F(1.0)); +} + +template +void NzVector4::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0)); +} + template void NzVector4::Normalize() { - if (!NzNumberEquals(w, static_cast(0.0))) + if (!NzNumberEquals(w, F(0.0))) { x /= w; y /= w; @@ -127,6 +140,49 @@ void NzVector4::Normalize() } } +template +void NzVector4::Set(T X, T Y, T Z, T W) +{ + w = W; + x = X; + y = Y; + z = Z; +} + +template +void NzVector4::Set(T scale) +{ + w = scale; + x = scale; + y = scale; + z = scale; +} + +template +void NzVector4::Set(T vec[4]) +{ + std::memcpy(&x, vec, 4*sizeof(T)); +} + +template +void NzVector4::Set(const NzVector3& vec, T W) +{ + w = W; + x = vec.x; + y = vec.y; + z = vec.z; +} + +template +template +void NzVector4::Set(const NzVector4& vec) +{ + w = F(vec.w); + x = F(vec.x); + y = F(vec.y); + z = F(vec.z); +} + template NzString NzVector4::ToString() const { @@ -135,6 +191,12 @@ NzString NzVector4::ToString() const return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')'; } +template +NzVector4::operator NzString() const +{ + return ToString(); +} + template NzVector4::operator T*() { @@ -150,6 +212,7 @@ NzVector4::operator const T*() const template T& NzVector4::operator[](unsigned int i) { + #if NAZARA_MATH_SAFE if (i >= 4) { NzStringStream ss; @@ -157,6 +220,7 @@ T& NzVector4::operator[](unsigned int i) throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -164,6 +228,7 @@ T& NzVector4::operator[](unsigned int i) template T NzVector4::operator[](unsigned int i) const { + #if NAZARA_MATH_SAFE if (i >= 4) { NzStringStream ss; @@ -171,6 +236,7 @@ T NzVector4::operator[](unsigned int i) const throw std::domain_error(ss.ToString()); } + #endif return *(&x+i); } @@ -214,13 +280,15 @@ NzVector4 NzVector4::operator*(T scale) const template NzVector4 NzVector4::operator/(const NzVector4& vec) const { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0)) || NzNumberEquals(vec.w, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w); } @@ -228,13 +296,15 @@ NzVector4 NzVector4::operator/(const NzVector4& vec) const template NzVector4 NzVector4::operator/(T scale) const { - if (NzNumberEquals(scale, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector4(x / scale, y / scale, z / scale, w / scale); } @@ -286,13 +356,15 @@ NzVector4& NzVector4::operator*=(T scale) template NzVector4& NzVector4::operator/=(const NzVector4& vec) { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0)) || NzNumberEquals(vec.w, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif x /= vec.x; y /= vec.y; @@ -305,13 +377,15 @@ NzVector4& NzVector4::operator/=(const NzVector4& vec) template NzVector4& NzVector4::operator/=(T scale) { - if (NzNumberEquals(scale, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif x /= scale; y /= scale; @@ -360,6 +434,42 @@ bool NzVector4::operator>=(const NzVector4& vec) const return !operator<(vec); } +template +NzVector4 NzVector4::UnitX() +{ + NzVector4 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector4 NzVector4::UnitY() +{ + NzVector4 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector4 NzVector4::UnitZ() +{ + NzVector4 vector; + vector.MakeUnitZ(); + + return vector; +} + +template +NzVector4 NzVector4::Zero() +{ + NzVector4 vector; + vector.MakeZero(); + + return vector; +} + template std::ostream& operator<<(std::ostream& out, const NzVector4& vec) { @@ -375,15 +485,19 @@ NzVector4 operator*(T scale, const NzVector4& vec) template NzVector4 operator/(T scale, const NzVector4& vec) { - if (NzNumberEquals(vec.x, static_cast(0.0)) || NzNumberEquals(vec.y, static_cast(0.0)) || NzNumberEquals(vec.z, static_cast(0.0)) || NzNumberEquals(vec.w, static_cast(0.0))) + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; throw std::domain_error(ss.ToString()); } + #endif return NzVector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); } +#undef F + #include diff --git a/include/Nazara/Network/Debug.hpp b/include/Nazara/Network/Debug.hpp deleted file mode 100644 index 21b4efd1c..000000000 --- a/include/Nazara/Network/Debug.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) - #include - - #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete - #define new new(__FILE__, __LINE__) -#endif diff --git a/include/Nazara/Noise.hpp b/include/Nazara/Noise.hpp new file mode 100644 index 000000000..6603cf442 --- /dev/null +++ b/include/Nazara/Noise.hpp @@ -0,0 +1,39 @@ +// This file was automatically generated by Nazara + +/* + Nazara Engine - NzNoise Module + + Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Noise/Config.hpp b/include/Nazara/Noise/Config.hpp index 77cb9d990..dff3349d1 100644 --- a/include/Nazara/Noise/Config.hpp +++ b/include/Nazara/Noise/Config.hpp @@ -1,8 +1,4 @@ /* - Nazara Engine - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - Nazara Engine - NzNoise Module Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp index a42cad927..1b6206c84 100644 --- a/include/Nazara/Noise/Noise.hpp +++ b/include/Nazara/Noise/Noise.hpp @@ -8,20 +8,22 @@ #define NAZARA_NOISE_HPP #include +#include class NAZARA_API NzNoise { public: - NzNoise(); - ~NzNoise(); + NzNoise() = delete; + ~NzNoise() = delete; - bool Initialize(); - void Uninitialize(); + static bool Initialize(); static bool IsInitialized(); + static void Uninitialize(); + private: - static bool s_initialized; + static unsigned int s_moduleReferenceCouter; }; -#endif // NOISE_HPP +#endif // NAZARA_NOISE_HPP diff --git a/include/Nazara/Prerequesites.hpp b/include/Nazara/Prerequesites.hpp index 0691fc975..4593dce62 100644 --- a/include/Nazara/Prerequesites.hpp +++ b/include/Nazara/Prerequesites.hpp @@ -6,7 +6,7 @@ #define NAZARA_PREREQUESITES_HPP #if __cplusplus < 201103L -#error Nazara requires a C++11 compliant compiler + #error Nazara requires a C++11 compliant compiler #endif // Version du moteur @@ -42,7 +42,7 @@ #define NazaraUnused(a) (void) a -#if defined(_WIN32) || defined(__WIN32__) || defined(NAZARA_PLATFORM_WINDOWSVISTA) +#if defined(_WIN32) || defined(__WIN32__) #if !defined(NAZARA_STATIC) #ifdef NAZARA_BUILD #define NAZARA_API __declspec(dllexport) @@ -71,6 +71,7 @@ #define NAZARA_WINNT 0x0501 #endif + // Pour ne pas casser le define déjà en place s'il est applicable #if defined(_WIN32_WINNT) #if _WIN32_WINNT < NAZARA_WINNT #undef _WIN32_WINNT @@ -110,6 +111,16 @@ #include +static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" ); +static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size"); +static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size"); +static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size"); + +static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" ); +static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size"); +static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size"); +static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size"); + typedef int8_t nzInt8; typedef uint8_t nzUInt8; diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp new file mode 100644 index 000000000..98d61077e --- /dev/null +++ b/include/Nazara/Renderer.hpp @@ -0,0 +1,40 @@ +// This file was automatically generated by Nazara + +/* + Nazara Engine + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Renderer/Config.hpp b/include/Nazara/Renderer/Config.hpp index 9d5cbe613..ae970da77 100644 --- a/include/Nazara/Renderer/Config.hpp +++ b/include/Nazara/Renderer/Config.hpp @@ -32,9 +32,6 @@ // Active une fenêtre de rendu (NzRenderWindow) lors de sa création #define NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION 1 -// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire) -#define NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0 - // Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 diff --git a/include/Nazara/Renderer/Enums.hpp b/include/Nazara/Renderer/Enums.hpp index 2497b0df8..47678946e 100644 --- a/include/Nazara/Renderer/Enums.hpp +++ b/include/Nazara/Renderer/Enums.hpp @@ -35,6 +35,15 @@ enum nzFaceFilling nzFaceFilling_Fill }; +enum nzMatrixType +{ + nzMatrixType_Projection, + nzMatrixType_View, + nzMatrixType_World, + + nzMatrixType_Max = nzMatrixType_World +}; + enum nzPixelBufferType { nzPixelBufferType_Pack, diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index adb36a520..ea844a904 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #ifdef NAZARA_RENDERER_COMMON -#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it + #error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it #endif #pragma once @@ -12,18 +12,16 @@ #define NAZARA_OPENGL_HPP // gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier -#include +#include #include #include -// Il semblerait qu'il ne soit pas conseillé d'inclure gl3.h t glext.h en même temps, mais je ne vois pas oomment gérer les extensions autrement... +// Inclusion des extensions #include #if defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_LINUX) #include -#else - #error OS not handled #endif typedef void (*NzOpenGLFunc)(); @@ -40,11 +38,12 @@ class NAZARA_API NzOpenGL PixelBufferObject, SeparateShaderObjects, Texture3D, + TextureArray, TextureCompression_s3tc, TextureStorage, VertexArrayObject, - Count + Max = VertexArrayObject }; static NzOpenGLFunc GetEntry(const NzString& entryPoint); diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index 8772a8c9e..391314c31 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -10,6 +10,7 @@ #define NAZARA_RENDERWINDOW_HPP #include +#include #include #include #include @@ -23,7 +24,7 @@ struct NzContextParameters; class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow { public: - NzRenderWindow(); + NzRenderWindow() = default; NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); virtual ~NzRenderWindow(); @@ -52,15 +53,19 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow bool IsValid() const; + void SetFramerateLimit(unsigned int limit); + protected: - bool Activate(); + virtual bool Activate() override; private: - void OnClose(); - bool OnCreate(); + virtual void OnWindowDestroying() override; + virtual bool OnWindowCreated() override; - NzContext* m_context; + NzClock m_clock; NzContextParameters m_parameters; + NzContext* m_context = nullptr; + unsigned int m_framerateLimit = 0; }; #endif // NAZARA_RENDERWINDOW_HPP diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index 74484ff36..b73fb07a5 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -8,99 +8,76 @@ #define NAZARA_RENDERER_HPP #include +#include +#include #include #include #include #include -#include - -#define NazaraRenderer NzRenderer::Instance() class NzColor; class NzContext; class NzIndexBuffer; class NzRenderTarget; class NzShader; -class NzUtility; class NzVertexBuffer; class NzVertexDeclaration; class NAZARA_API NzRenderer { public: - NzRenderer(); - ~NzRenderer(); + NzRenderer() = delete; + ~NzRenderer() = delete; - void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth); + static void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth); - void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount); - void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount); + static void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount); + static void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount); - void Enable(nzRendererParameter parameter, bool enable); + static void Enable(nzRendererParameter parameter, bool enable); - unsigned int GetMaxAnisotropyLevel() const; - unsigned int GetMaxRenderTargets() const; - unsigned int GetMaxTextureUnits() const; - NzShader* GetShader() const; - NzRenderTarget* GetTarget() const; - NzRectui GetViewport() const; + //static NzMatrix4f GetMatrix(nzMatrixCombination combination); + static NzMatrix4f GetMatrix(nzMatrixType type); + static unsigned int GetMaxAnisotropyLevel(); + static unsigned int GetMaxRenderTargets(); + static unsigned int GetMaxTextureUnits(); + static NzShader* GetShader(); + static NzRenderTarget* GetTarget(); + static NzRectui GetViewport(); - bool HasCapability(nzRendererCap capability) const; - bool Initialize(); + static bool HasCapability(nzRendererCap capability); - void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest); - void SetClearColor(const NzColor& color); - void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255); - void SetClearDepth(double depth); - void SetClearStencil(unsigned int value); - void SetFaceCulling(nzFaceCulling cullingMode); - void SetFaceFilling(nzFaceFilling fillingMode); - bool SetIndexBuffer(const NzIndexBuffer* indexBuffer); - bool SetShader(NzShader* shader); - void SetStencilCompareFunction(nzRendererComparison compareFunc); - void SetStencilFailOperation(nzStencilOperation failOperation); - void SetStencilMask(nzUInt32 mask); - void SetStencilPassOperation(nzStencilOperation passOperation); - void SetStencilReferenceValue(unsigned int refValue); - void SetStencilZFailOperation(nzStencilOperation zfailOperation); - bool SetTarget(NzRenderTarget* target); - bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer); - bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration); - void SetViewport(const NzRectui& viewport); + static bool Initialize(); - void Uninitialize(); - - static NzRenderer* Instance(); static bool IsInitialized(); + static void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest); + static void SetClearColor(const NzColor& color); + static void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255); + static void SetClearDepth(double depth); + static void SetClearStencil(unsigned int value); + static void SetFaceCulling(nzFaceCulling cullingMode); + static void SetFaceFilling(nzFaceFilling fillingMode); + static bool SetIndexBuffer(const NzIndexBuffer* indexBuffer); + static void SetMatrix(nzMatrixType type, const NzMatrix4f& matrix); + static bool SetShader(NzShader* shader); + static void SetStencilCompareFunction(nzRendererComparison compareFunc); + static void SetStencilFailOperation(nzStencilOperation failOperation); + static void SetStencilMask(nzUInt32 mask); + static void SetStencilPassOperation(nzStencilOperation passOperation); + static void SetStencilReferenceValue(unsigned int refValue); + static void SetStencilZFailOperation(nzStencilOperation zfailOperation); + static bool SetTarget(NzRenderTarget* target); + static bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer); + static bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration); + static void SetViewport(const NzRectui& viewport); + + static void Uninitialize(); + private: - bool EnsureStateUpdate(); + static bool EnsureStateUpdate(); - typedef std::tuple VAO_Key; - - std::map m_vaos; - nzRendererComparison m_stencilCompare; - nzStencilOperation m_stencilFail; - nzStencilOperation m_stencilPass; - nzStencilOperation m_stencilZFail; - nzUInt32 m_stencilMask; - const NzIndexBuffer* m_indexBuffer; - NzRenderTarget* m_target; - NzShader* m_shader; - NzUtility* m_utilityModule; - const NzVertexBuffer* m_vertexBuffer; - const NzVertexDeclaration* m_vertexDeclaration; - bool m_vaoUpdated; - bool m_capabilities[nzRendererCap_Max+1]; - bool m_stencilFuncUpdated; - bool m_stencilOpUpdated; - unsigned int m_maxAnisotropyLevel; - unsigned int m_maxRenderTarget; - unsigned int m_maxTextureUnit; - unsigned int m_stencilReference; - - static NzRenderer* s_instance; - static bool s_initialized; + static unsigned int s_moduleReferenceCouter; }; #endif // NAZARA_RENDERER_HPP diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index c100cef13..f1ebb9ed2 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -9,13 +9,13 @@ #include #include +#include #include #include #include #include #include #include -#include class NzRenderer; class NzShaderImpl; @@ -38,6 +38,9 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable NzString GetLog() const; nzShaderLanguage GetLanguage() const; NzString GetSourceCode(nzShaderType type) const; + int GetUniformLocation(const NzString& name) const; + + bool HasUniform(const NzString& name) const; bool IsCompiled() const; bool IsLoaded(nzShaderType type) const; @@ -47,19 +50,19 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable bool Lock(); - bool SendBoolean(const NzString& name, bool value); - bool SendDouble(const NzString& name, double value); - bool SendFloat(const NzString& name, float value); - bool SendInteger(const NzString& name, int value); - bool SendMatrix(const NzString& name, const NzMatrix4d& matrix); - bool SendMatrix(const NzString& name, const NzMatrix4f& matrix); - bool SendVector(const NzString& name, const NzVector2d& vector); - bool SendVector(const NzString& name, const NzVector2f& vector); - bool SendVector(const NzString& name, const NzVector3d& vector); - bool SendVector(const NzString& name, const NzVector3f& vector); - bool SendVector(const NzString& name, const NzVector4d& vector); - bool SendVector(const NzString& name, const NzVector4f& vector); - bool SendTexture(const NzString& name, NzTexture* texture); + bool SendBoolean(int location, bool value); + bool SendDouble(int location, double value); + bool SendFloat(int location, float value); + bool SendInteger(int location, int value); + bool SendMatrix(int location, const NzMatrix4d& matrix); + bool SendMatrix(int location, const NzMatrix4f& matrix); + bool SendTexture(int location, const NzTexture* texture); + bool SendVector(int location, const NzVector2d& vector); + bool SendVector(int location, const NzVector2f& vector); + bool SendVector(int location, const NzVector3d& vector); + bool SendVector(int location, const NzVector3f& vector); + bool SendVector(int location, const NzVector4d& vector); + bool SendVector(int location, const NzVector4f& vector); void Unlock(); diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp new file mode 100644 index 000000000..449b99967 --- /dev/null +++ b/include/Nazara/Utility.hpp @@ -0,0 +1,53 @@ +// This file was automatically generated by Nazara + +/* + Nazara Engine + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index b8b8d251e..11b2c08bb 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -8,9 +8,9 @@ #define NAZARA_ANIMATION_HPP #include +#include #include #include -#include #include #include #include diff --git a/include/Nazara/Utility/AxisAlignedBox.hpp b/include/Nazara/Utility/AxisAlignedBox.hpp new file mode 100644 index 000000000..a12658c30 --- /dev/null +++ b/include/Nazara/Utility/AxisAlignedBox.hpp @@ -0,0 +1,50 @@ +// Copyright (C) 2011 Jérôme Leclercq +// This file is part of the "Ungine". +// For conditions of distribution and use, see copyright notice in Core.h + +#ifndef NAZARA_AXISALIGNEDBOX_HPP +#define NAZARA_AXISALIGNEDBOX_HPP + +#include +#include +#include +#include +#include + +class NAZARA_API NzAxisAlignedBox +{ + public: + NzAxisAlignedBox(); + NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2); + NzAxisAlignedBox(nzExtend extend); + + bool Contains(const NzAxisAlignedBox& box); + + void ExtendTo(const NzAxisAlignedBox& box); + void ExtendTo(const NzVector3f& vector); + + nzExtend GetExtend() const; + NzVector3f GetMaximum() const; + NzVector3f GetMinimum() const; + + bool IsFinite() const; + bool IsInfinite() const; + bool IsNull() const; + + void SetInfinite(); + void SetExtends(const NzVector3f& vec1, const NzVector3f& vec2); + void SetNull(); + + NzString ToString() const; + + static const NzAxisAlignedBox Infinite; + static const NzAxisAlignedBox Null; + + private: + nzExtend m_extend; + NzCubef m_cube; +}; + +NAZARA_API std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb); + +#endif // NAZARA_AXISALIGNEDBOX_HPP diff --git a/include/Nazara/Utility/Buffer.hpp b/include/Nazara/Utility/Buffer.hpp index 7fcad2221..5c728473a 100644 --- a/include/Nazara/Utility/Buffer.hpp +++ b/include/Nazara/Utility/Buffer.hpp @@ -9,8 +9,8 @@ #include #include +#include #include -#include class NzBufferImpl; class NzRenderer; diff --git a/include/Nazara/Utility/Config.hpp b/include/Nazara/Utility/Config.hpp index a9f059da4..f18cea996 100644 --- a/include/Nazara/Utility/Config.hpp +++ b/include/Nazara/Utility/Config.hpp @@ -29,6 +29,9 @@ /// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci +// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire) +#define NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0 + // Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_UTILITY_MEMORYLEAKTRACKER 0 @@ -38,12 +41,11 @@ // Fait tourner chaque fenêtre dans un thread séparé si le système le supporte #define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7 -// Protège le module des accès concurrentiels +// Protège les classes des accès concurrentiels #define NAZARA_UTILITY_THREADSAFE 1 -#if NAZARA_UTILITY_THREADSAFE - #define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW) - #define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW) -#endif +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW) +#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW) #endif // NAZARA_CONFIG_UTILITY_HPP diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index b2da366e7..5758f14ea 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -24,6 +24,7 @@ enum nzBufferAccess enum nzBufferStorage { + //nzBufferStorage_Both, nzBufferStorage_Hardware, nzBufferStorage_Software, @@ -44,8 +45,8 @@ enum nzBufferUsage enum nzCubemapFace { - // L'ordre est X, -X, Y, -Y, Z, -Z // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap + // L'ordre est X, -X, Y, -Y, Z, -Z nzCubemapFace_PositiveX = 0, nzCubemapFace_PositiveY = 2, nzCubemapFace_PositiveZ = 4, @@ -86,10 +87,38 @@ enum nzElementUsage nzElementUsage_Max = nzElementUsage_TexCoord }; +enum nzEventType +{ + nzEventType_GainedFocus, + nzEventType_LostFocus, + nzEventType_KeyPressed, + nzEventType_KeyReleased, + nzEventType_MouseButtonDoubleClicked, + nzEventType_MouseButtonPressed, + nzEventType_MouseButtonReleased, + nzEventType_MouseEntered, + nzEventType_MouseLeft, + nzEventType_MouseMoved, + nzEventType_MouseWheelMoved, + nzEventType_Moved, + nzEventType_Quit, + nzEventType_Resized, + nzEventType_TextEntered +}; + +enum nzExtend +{ + nzExtend_Finite, + nzExtend_Infinite, + nzExtend_Null +}; + enum nzImageType { nzImageType_1D, + nzImageType_1D_Array, nzImageType_2D, + nzImageType_2D_Array, nzImageType_3D, nzImageType_Cubemap, diff --git a/include/Nazara/Utility/Event.hpp b/include/Nazara/Utility/Event.hpp index 5b2dbbd4c..6f8d28dee 100644 --- a/include/Nazara/Utility/Event.hpp +++ b/include/Nazara/Utility/Event.hpp @@ -14,15 +14,22 @@ struct NzEvent { + // Utilisé par: + // -nzEventType_KeyPressed + // -nzEventType_KeyReleased struct KeyEvent { NzKeyboard::Key code; bool alt; bool control; + bool repeated; bool shift; bool system; }; + // Utilisé par: + // -nzEventType_MouseButtonDoubleClicked + // -nzEventType_MouseButtonPressed struct MouseButtonEvent { NzMouse::Button button; @@ -30,63 +37,79 @@ struct NzEvent unsigned int y; }; + // Utilisé par: + // -nzEventType_MouseMoved struct MouseMoveEvent { - int x; - int y; + int deltaX; + int deltaY; + unsigned int x; + unsigned int y; }; + // Utilisé par: + // -nzEventType_MouseWheelMoved struct MouseWheelEvent { float delta; }; + // Utilisé par: + // -nzEventType_Moved struct PositionEvent { int x; int y; }; + // Utilisé par: + // -nzEventType_Resized struct SizeEvent { unsigned int height; unsigned int width; }; + // Utilisé par: + // -nzEventType_TextEntered struct TextEvent { + bool repeated; char32_t character; }; - enum Type - { - GainedFocus, - LostFocus, - KeyPressed, - KeyReleased, - MouseButtonDoubleClicked, - MouseButtonPressed, - MouseButtonReleased, - MouseEntered, - MouseLeft, - MouseMoved, - MouseWheelMoved, - Moved, - Quit, - Resized, - TextEntered - }; - - Type type; + nzEventType type; union { + // Utilisé par: + // -nzEventType_KeyPressed + // -nzEventType_KeyReleased KeyEvent key; + + // Utilisé par: + // -nzEventType_MouseButtonDoubleClicked + // -nzEventType_MouseButtonPressed MouseButtonEvent mouseButton; + + // Utilisé par: + // -nzEventType_MouseMoved MouseMoveEvent mouseMove; + + // Utilisé par: + // -nzEventType_MouseWheelMoved MouseWheelEvent mouseWheel; + + // Utilisé par: + // -nzEventType_Moved PositionEvent position; + + // Utilisé par: + // -nzEventType_Resized SizeEvent size; + + // Utilisé par: + // -nzEventType_TextEntered TextEvent text; }; }; diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 8882aa73f..3a98656e1 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -10,17 +10,17 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include -#if NAZARA_THREADSAFETY_IMAGE +#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE #include #else #include @@ -49,7 +49,7 @@ class NAZARA_API NzImage : public NzResource NzImage(); NzImage(const NzImage& image); - NzImage(NzImage&& image); + NzImage(NzImage&& image) noexcept; NzImage(SharedImage* sharedImage); ~NzImage(); @@ -68,14 +68,14 @@ class NAZARA_API NzImage : public NzResource bool FlipVertically(); nzUInt8 GetBPP() const; - const nzUInt8* GetConstPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0) const; + const nzUInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0) const; unsigned int GetDepth(nzUInt8 level = 0) const; nzPixelFormat GetFormat() const; unsigned int GetHeight(nzUInt8 level = 0) const; nzUInt8 GetLevelCount() const; nzUInt8 GetMaxLevel() const; NzColor GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const; - nzUInt8* GetPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0); + nzUInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0); unsigned int GetSize() const; unsigned int GetSize(nzUInt8 level) const; nzImageType GetType() const; @@ -97,7 +97,7 @@ class NAZARA_API NzImage : public NzResource bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0); NzImage& operator=(const NzImage& image); - NzImage& operator=(NzImage&& image); + NzImage& operator=(NzImage&& image) noexcept; static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1); diff --git a/include/Nazara/Utility/IndexBuffer.hpp b/include/Nazara/Utility/IndexBuffer.hpp index 22c22104b..dd6f99fd0 100644 --- a/include/Nazara/Utility/IndexBuffer.hpp +++ b/include/Nazara/Utility/IndexBuffer.hpp @@ -8,8 +8,8 @@ #define NAZARA_INDEXBUFFER_HPP #include +#include #include -#include class NAZARA_API NzIndexBuffer : public NzResource { diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index b7dbc71f1..7b4072035 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -9,21 +9,22 @@ #include #include +#include #include #include +#include #include -#include +#include #include #include -class NzSubMesh; class NzVertexDeclaration; struct NzMeshParams { NzAnimationParams animation; //const NzVertexDeclaration* declaration = nullptr; - bool forceSoftware = false; + nzBufferStorage storage = nzBufferStorage_Hardware; bool loadAnimations = true; bool IsValid() const; @@ -52,6 +53,7 @@ class NAZARA_API NzMesh : public NzResource bool Create(nzAnimationType type); void Destroy(); + const NzAxisAlignedBox& GetAABB() const; const NzAnimation* GetAnimation() const; nzAnimationType GetAnimationType() const; unsigned int GetFrameCount() const; @@ -69,6 +71,8 @@ class NAZARA_API NzMesh : public NzResource bool HasSubMesh(const NzString& identifier) const; bool HasSubMesh(nzUInt8 index = 0) const; + void InvalidateAABB() const; + bool IsAnimable() const; bool IsValid() const; diff --git a/include/Nazara/Utility/Mouse.hpp b/include/Nazara/Utility/Mouse.hpp index 4139efce3..37befe3ca 100644 --- a/include/Nazara/Utility/Mouse.hpp +++ b/include/Nazara/Utility/Mouse.hpp @@ -25,7 +25,7 @@ class NAZARA_API NzMouse XButton1, XButton2, - Count + Max = XButton2 }; static NzVector2i GetPosition(); diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index 917450700..bac3ff377 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -361,7 +361,7 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format) return "RGBA8"; case nzPixelFormat_Undefined: - break; + return "Undefined"; } NazaraError("Invalid pixel format"); diff --git a/include/Nazara/Utility/StaticMesh.hpp b/include/Nazara/Utility/StaticMesh.hpp index 2e1c5684a..dbdbf2cc1 100644 --- a/include/Nazara/Utility/StaticMesh.hpp +++ b/include/Nazara/Utility/StaticMesh.hpp @@ -14,12 +14,15 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh { public: NzStaticMesh(const NzMesh* parent); - NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr); + NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); virtual ~NzStaticMesh(); - bool Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr); + bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); void Destroy(); + bool GenerateAABB(); + + const NzAxisAlignedBox& GetAABB() const; nzAnimationType GetAnimationType() const; unsigned int GetFrameCount() const; const NzIndexBuffer* GetIndexBuffer() const; @@ -30,14 +33,16 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh bool IsAnimated() const; bool IsValid() const; + void SetAABB(const NzAxisAlignedBox& aabb); void SetPrimitiveType(nzPrimitiveType primitiveType); private: void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation); nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList; - const NzIndexBuffer* m_indexBuffer = nullptr; - const NzVertexBuffer* m_vertexBuffer = nullptr; + NzAxisAlignedBox m_aabb; + NzIndexBuffer* m_indexBuffer = nullptr; + NzVertexBuffer* m_vertexBuffer = nullptr; const NzVertexDeclaration* m_vertexDeclaration = nullptr; }; diff --git a/include/Nazara/Utility/SubMesh.hpp b/include/Nazara/Utility/SubMesh.hpp index 070563218..ee4c6bd5a 100644 --- a/include/Nazara/Utility/SubMesh.hpp +++ b/include/Nazara/Utility/SubMesh.hpp @@ -8,9 +8,10 @@ #define NAZARA_SUBMESH_HPP #include +#include +#include #include #include -#include #include #include @@ -26,6 +27,7 @@ class NAZARA_API NzSubMesh : public NzResource void Animate(unsigned int frameA, unsigned int frameB, float interpolation); + virtual const NzAxisAlignedBox& GetAABB() const = 0; virtual const NzIndexBuffer* GetIndexBuffer() const = 0; const NzMesh* GetParent() const; virtual nzPrimitiveType GetPrimitiveType() const = 0; diff --git a/include/Nazara/Utility/Utility.hpp b/include/Nazara/Utility/Utility.hpp index 5d70c6ba6..1133f0210 100644 --- a/include/Nazara/Utility/Utility.hpp +++ b/include/Nazara/Utility/Utility.hpp @@ -8,20 +8,22 @@ #define NAZARA_UTILITY_HPP #include +#include class NAZARA_API NzUtility { public: - NzUtility(); - ~NzUtility(); + NzUtility() = delete; + ~NzUtility() = delete; - bool Initialize(); - void Uninitialize(); + static bool Initialize(); static bool IsInitialized(); + static void Uninitialize(); + private: - static bool s_initialized; + static unsigned int s_moduleReferenceCouter; }; #endif // NAZARA_UTILITY_HPP diff --git a/include/Nazara/Utility/VertexBuffer.hpp b/include/Nazara/Utility/VertexBuffer.hpp index 49cee5012..51c5f154d 100644 --- a/include/Nazara/Utility/VertexBuffer.hpp +++ b/include/Nazara/Utility/VertexBuffer.hpp @@ -8,8 +8,8 @@ #define NAZARA_VERTEXBUFFER_HPP #include +#include #include -#include class NAZARA_API NzVertexBuffer : public NzResource { diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 78e284b97..049fb43f7 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -6,8 +6,8 @@ #define NAZARA_VERTEXDECLARATION_HPP #include +#include #include -#include struct NzVertexElement { @@ -26,7 +26,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource NzVertexDeclaration() = default; NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount); NzVertexDeclaration(const NzVertexDeclaration& declaration); - NzVertexDeclaration(NzVertexDeclaration&& declaration); + NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept; ~NzVertexDeclaration(); bool Create(const NzVertexElement* elements, unsigned int elementCount); @@ -44,7 +44,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource bool IsValid() const; NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); - NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration); + NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept; private: NzVertexDeclarationImpl* m_sharedImpl = nullptr; diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index be45ed6b9..ab803d30b 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -28,11 +28,13 @@ class NzCursor; class NzImage; class NzIcon; +class NzMouse; class NzUtility; class NzWindowImpl; class NAZARA_API NzWindow : NzNonCopyable { + friend class NzMouse; friend class NzUtility; friend class NzWindowImpl; @@ -42,11 +44,11 @@ class NAZARA_API NzWindow : NzNonCopyable NzWindow(NzWindowHandle handle); virtual ~NzWindow(); - void Close(); - bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); bool Create(NzWindowHandle handle); + void Destroy(); + void EnableKeyRepeat(bool enable); void EnableSmoothScrolling(bool enable); @@ -78,20 +80,20 @@ class NAZARA_API NzWindow : NzNonCopyable void SetPosition(int x, int y); void SetSize(const NzVector2i& size); void SetSize(unsigned int width, unsigned int height); + void SetStayOnTop(bool stayOnTop); void SetTitle(const NzString& title); void SetVisible(bool visible); - void StayOnTop(bool stayOnTop); - bool WaitEvent(NzEvent* event); protected: - virtual void OnClose(); - virtual bool OnCreate(); + virtual void OnWindowDestroying(); + virtual bool OnWindowCreated(); NzWindowImpl* m_impl; private: + void IgnoreNextMouseEvent(int mouseX, int mouseY) const; void PushEvent(const NzEvent& event); static bool Initialize(); @@ -99,9 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable std::queue m_events; #if NAZARA_UTILITY_THREADED_WINDOW + NzConditionVariable m_eventCondition; NzMutex m_eventMutex; NzMutex m_eventConditionMutex; - NzThreadCondition m_eventCondition; bool m_eventListener; bool m_waitForEvent; #endif diff --git a/src/Nazara/Audio/Debug/Leaks.cpp b/src/Nazara/Audio/Debug/Leaks.cpp deleted file mode 100644 index e28e0794e..000000000 --- a/src/Nazara/Audio/Debug/Leaks.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) -#include -#include - -void* operator new(std::size_t size) -{ - return NzMemoryManager::Allocate(size, false); -} - -void* operator new[](std::size_t size) -{ - return NzMemoryManager::Allocate(size, true); -} - -void operator delete(void* pointer) noexcept -{ - NzMemoryManager::Free(pointer, false); -} - -void operator delete[](void* pointer) noexcept -{ - NzMemoryManager::Free(pointer, true); -} -#endif diff --git a/src/Nazara/Core/Clock.cpp b/src/Nazara/Core/Clock.cpp index 0963cf4af..5f685b3dc 100644 --- a/src/Nazara/Core/Clock.cpp +++ b/src/Nazara/Core/Clock.cpp @@ -15,6 +15,24 @@ #include +namespace +{ + nzUInt64 NzGetMicrosecondsLowPrecision() + { + return NzClockImplGetMilliseconds()*1000ULL; + } + + nzUInt64 NzGetMicrosecondsFirstRun() + { + if (NzClockImplInitializeHighPrecision()) + NzGetMicroseconds = NzClockImplGetMicroseconds; + else + NzGetMicroseconds = NzGetMicrosecondsLowPrecision; + + return NzGetMicroseconds(); + } +} + NzClock::NzClock() : m_elapsedTime(0), m_refTime(NzGetMicroseconds()), @@ -81,20 +99,5 @@ void NzClock::Unpause() NazaraWarning("Clock is not paused, ignoring..."); } -nzUInt64 NzGetMicrosecondsLowPrecision() -{ - return NzClockImplGetMilliseconds()*1000ULL; -} - -nzUInt64 NzGetMicrosecondsFirstRun() -{ - if (NzClockImplInitializeHighPrecision()) - NzGetMicroseconds = NzClockImplGetMicroseconds; - else - NzGetMicroseconds = NzGetMicrosecondsLowPrecision; - - return NzGetMicroseconds(); -} - NzClockFunction NzGetMicroseconds = NzGetMicrosecondsFirstRun; NzClockFunction NzGetMilliseconds = NzClockImplGetMilliseconds; diff --git a/src/Nazara/Core/ThreadCondition.cpp b/src/Nazara/Core/ConditionVariable.cpp similarity index 52% rename from src/Nazara/Core/ThreadCondition.cpp rename to src/Nazara/Core/ConditionVariable.cpp index fb8c3b7e8..88337bb64 100644 --- a/src/Nazara/Core/ThreadCondition.cpp +++ b/src/Nazara/Core/ConditionVariable.cpp @@ -2,45 +2,45 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include #if defined(NAZARA_PLATFORM_WINDOWS) - #include + #include #elif defined(NAZARA_PLATFORM_POSIX) - #include + #include #else #error Thread condition has no implementation #endif #include -NzThreadCondition::NzThreadCondition() +NzConditionVariable::NzConditionVariable() { - m_impl = new NzThreadConditionImpl; + m_impl = new NzConditionVariableImpl; } -NzThreadCondition::~NzThreadCondition() +NzConditionVariable::~NzConditionVariable() { delete m_impl; } -void NzThreadCondition::Signal() +void NzConditionVariable::Signal() { m_impl->Signal(); } -void NzThreadCondition::SignalAll() +void NzConditionVariable::SignalAll() { m_impl->SignalAll(); } -void NzThreadCondition::Wait(NzMutex* mutex) +void NzConditionVariable::Wait(NzMutex* mutex) { m_impl->Wait(mutex->m_impl); } -bool NzThreadCondition::Wait(NzMutex* mutex, nzUInt32 timeout) +bool NzConditionVariable::Wait(NzMutex* mutex, nzUInt32 timeout) { return m_impl->Wait(mutex->m_impl, timeout); } diff --git a/src/Nazara/Core/Core.cpp b/src/Nazara/Core/Core.cpp new file mode 100644 index 000000000..0bd2ff041 --- /dev/null +++ b/src/Nazara/Core/Core.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include + +bool NzCore::Initialize() +{ + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation du module + // Le noyau de Nazara n'a pour l'instant aucun besoin d'initialisation, mais dans le futur il est très probable que ce soit le cas. + // Donc en prévision, tous les modules initialisent le noyau + + NazaraNotice("Initialized: Core"); + + return true; +} + +bool NzCore::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + +void NzCore::Uninitialize() +{ + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé + + // Libération du module + NazaraNotice("Uninitialized: Core"); +} + +unsigned int NzCore::s_moduleReferenceCouter = 0; diff --git a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp index 08fce3532..35e96a967 100644 --- a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp +++ b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp @@ -119,19 +119,16 @@ void NzMemoryManager::Free(void* pointer, bool multi) if (nextFreeFile) { if (multi) - std::fprintf(log, "%s Warning: delete[] on new at %s:%d\n", time, nextFreeFile, nextFreeLine); + std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine); else - std::fprintf(log, "%s Warning: delete on new[] at %s:%d\n", time, nextFreeFile, nextFreeLine); - - nextFreeFile = nullptr; - nextFreeLine = 0; + std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine); } else { if (multi) - std::fprintf(log, "%s Warning: delete[] on new at unknown position\n", time); + std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time); else - std::fprintf(log, "%s Warning: delete on new[] at unknown position\n", time); + std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time); } std::fclose(log); @@ -145,6 +142,9 @@ void NzMemoryManager::Free(void* pointer, bool multi) std::free(ptr); + nextFreeFile = nullptr; + nextFreeLine = 0; + #if defined(NAZARA_PLATFORM_WINDOWS) LeaveCriticalSection(&mutex); #elif defined(NAZARA_PLATFORM_POSIX) diff --git a/src/Nazara/Core/Directory.cpp b/src/Nazara/Core/Directory.cpp index c5aa37c51..a614ba695 100644 --- a/src/Nazara/Core/Directory.cpp +++ b/src/Nazara/Core/Directory.cpp @@ -25,14 +25,14 @@ namespace } NzDirectory::NzDirectory() : -m_impl(nullptr) +m_pattern('*') { } NzDirectory::NzDirectory(const NzString& dirPath) : -m_impl(nullptr) +m_dirPath(dirPath), +m_pattern('*') { - SetDirectory(dirPath); } NzDirectory::~NzDirectory() @@ -42,18 +42,27 @@ NzDirectory::~NzDirectory() void NzDirectory::Close() { + NazaraLock(m_mutex); + if (m_impl) { m_impl->Close(); delete m_impl; m_impl = nullptr; - - NazaraMutexUnlock(m_mutex); } } +NzString NzDirectory::GetPattern() const +{ + NazaraLock(m_mutex); + + return m_pattern; +} + NzString NzDirectory::GetResultName() const { + NazaraLock(m_mutex); + #if NAZARA_CORE_SAFE if (!m_impl) { @@ -67,6 +76,8 @@ NzString NzDirectory::GetResultName() const NzString NzDirectory::GetResultPath() const { + NazaraLock(m_mutex); + #if NAZARA_CORE_SAFE if (!m_impl) { @@ -80,6 +91,8 @@ NzString NzDirectory::GetResultPath() const nzUInt64 NzDirectory::GetResultSize() const { + NazaraLock(m_mutex); + #if NAZARA_CORE_SAFE if (!m_impl) { @@ -91,8 +104,17 @@ nzUInt64 NzDirectory::GetResultSize() const return m_impl->GetResultSize(); } +bool NzDirectory::IsOpen() const +{ + NazaraLock(m_mutex); + + return m_impl != nullptr; +} + bool NzDirectory::IsResultDirectory() const { + NazaraLock(m_mutex); + #if NAZARA_CORE_SAFE if (!m_impl) { @@ -106,6 +128,8 @@ bool NzDirectory::IsResultDirectory() const bool NzDirectory::NextResult(bool skipDots) { + NazaraLock(m_mutex); + #if NAZARA_CORE_SAFE if (!m_impl) { @@ -114,41 +138,40 @@ bool NzDirectory::NextResult(bool skipDots) } #endif - if (skipDots) + NzString name; + do { - NzString name; - do - { - if (!m_impl->NextResult()) - return false; + if (!m_impl->NextResult()) + return false; - name = m_impl->GetResultName(); - } - while (name == '.' || name == ".."); + name = m_impl->GetResultName(); - return true; + if (skipDots && (name == '.' || name == "..")) + continue; + + if (name.Match(m_pattern)) + break; } - else - return m_impl->NextResult(); + while (true); + + return true; } bool NzDirectory::Open() { + NazaraLock(m_mutex); + Close(); if (!Exists(m_dirPath)) return false; - NazaraMutexLock(m_mutex); - m_impl = new NzDirectoryImpl(this); if (!m_impl->Open(m_dirPath)) { delete m_impl; m_impl = nullptr; - NazaraMutexUnlock(m_mutex); - return false; } @@ -157,11 +180,20 @@ bool NzDirectory::Open() void NzDirectory::SetDirectory(const NzString& dirPath) { + NazaraLock(m_mutex); + Close(); m_dirPath = NzFile::AbsolutePath(dirPath); } +void NzDirectory::SetPattern(const NzString& pattern) +{ + NazaraLock(m_mutex); + + m_pattern = pattern; +} + bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath) { if (sourcePath.IsEmpty() || destPath.IsEmpty()) @@ -187,12 +219,12 @@ bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath) { if (dir.IsResultDirectory()) { - if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName())) + if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName())) return false; } else if (!NzFile::Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName())) { - NazaraError("Unable to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"'); + NazaraError("Failed to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"'); return false; } } diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index ad5c87091..a81012b2e 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -42,7 +42,7 @@ NzString NzGetLastSystemError(unsigned int code) wchar_t* buffer = nullptr; FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, - 0, + nullptr, code, 0, reinterpret_cast(&buffer), diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 4b88e957f..6a4d8ae20 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -45,7 +45,7 @@ m_openMode(0) Open(openMode); } -NzFile::NzFile(NzFile&& file) : +NzFile::NzFile(NzFile&& file) noexcept : m_endianness(file.m_endianness), m_filePath(std::move(file.m_filePath)), m_impl(file.m_impl), @@ -525,7 +525,7 @@ NzFile& NzFile::operator=(const NzString& filePath) return *this; } -NzFile& NzFile::operator=(NzFile&& file) +NzFile& NzFile::operator=(NzFile&& file) noexcept { NazaraLock(m_mutex) @@ -570,7 +570,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath) NazaraError("Path unrecognized"); return path; } - #elif NAZARA_PLATEFORM_LINUX + #elif defined(NAZARA_PLATEFORM_LINUX) base = '/'; start = 0; #else @@ -718,7 +718,7 @@ bool NzFile::IsAbsolute(const NzString& path) return true; else return false; - #elif NAZARA_PLATEFORM_LINUX + #elif defined(NAZARA_PLATEFORM_LINUX) return wpath.StartsWith('/'); #else #error OS case not implemented @@ -752,7 +752,7 @@ NzString NzFile::NormalizeSeparators(const NzString& filePath) #elif defined(NAZARA_PLATFORM_LINUX) path.Replace('\\', '/'); #else - #error OS not handled + #error OS case not implemented #endif return path; @@ -793,4 +793,4 @@ bool NzFile::FillHash(NzHashImpl* hash) const } return true; -} // Fermeture auttomatique du fichier +} // Fermeture automatique du fichier diff --git a/src/Nazara/Core/Hash/MD5.cpp b/src/Nazara/Core/Hash/MD5.cpp index 6570fc8cc..3095746e0 100644 --- a/src/Nazara/Core/Hash/MD5.cpp +++ b/src/Nazara/Core/Hash/MD5.cpp @@ -136,7 +136,7 @@ namespace * On little-endian machines, we can process properly aligned * data without copying it. */ - if (!((data - reinterpret_cast(0)) & 3)) + if (!(data - static_cast(nullptr)) & 3) { /* data are properly aligned */ X = reinterpret_cast(data); diff --git a/src/Nazara/Core/Hash/SHA/Internal.cpp b/src/Nazara/Core/Hash/SHA/Internal.cpp index 734de4ede..40f9fcd68 100644 --- a/src/Nazara/Core/Hash/SHA/Internal.cpp +++ b/src/Nazara/Core/Hash/SHA/Internal.cpp @@ -315,119 +315,122 @@ void SHA1_Init(SHA_CTX* context) (b) = ROTL32(30, b); \ j++; -void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data) +namespace { - nzUInt32 a, b, c, d, e; - nzUInt32 T1, *W1; - int j; + void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data) + { + nzUInt32 a, b, c, d, e; + nzUInt32 T1, *W1; + int j; - W1 = reinterpret_cast(context->s1.buffer); + W1 = reinterpret_cast(context->s1.buffer); - /* Initialize registers with the prev. intermediate value */ - a = context->s1.state[0]; - b = context->s1.state[1]; - c = context->s1.state[2]; - d = context->s1.state[3]; - e = context->s1.state[4]; + /* Initialize registers with the prev. intermediate value */ + a = context->s1.state[0]; + b = context->s1.state[1]; + c = context->s1.state[2]; + d = context->s1.state[3]; + e = context->s1.state[4]; - j = 0; + j = 0; - /* Rounds 0 to 15 unrolled: */ - ROUND1_0_TO_15(a,b,c,d,e); - ROUND1_0_TO_15(e,a,b,c,d); - ROUND1_0_TO_15(d,e,a,b,c); - ROUND1_0_TO_15(c,d,e,a,b); - ROUND1_0_TO_15(b,c,d,e,a); - ROUND1_0_TO_15(a,b,c,d,e); - ROUND1_0_TO_15(e,a,b,c,d); - ROUND1_0_TO_15(d,e,a,b,c); - ROUND1_0_TO_15(c,d,e,a,b); - ROUND1_0_TO_15(b,c,d,e,a); - ROUND1_0_TO_15(a,b,c,d,e); - ROUND1_0_TO_15(e,a,b,c,d); - ROUND1_0_TO_15(d,e,a,b,c); - ROUND1_0_TO_15(c,d,e,a,b); - ROUND1_0_TO_15(b,c,d,e,a); - ROUND1_0_TO_15(a,b,c,d,e); + /* Rounds 0 to 15 unrolled: */ + ROUND1_0_TO_15(a,b,c,d,e); + ROUND1_0_TO_15(e,a,b,c,d); + ROUND1_0_TO_15(d,e,a,b,c); + ROUND1_0_TO_15(c,d,e,a,b); + ROUND1_0_TO_15(b,c,d,e,a); + ROUND1_0_TO_15(a,b,c,d,e); + ROUND1_0_TO_15(e,a,b,c,d); + ROUND1_0_TO_15(d,e,a,b,c); + ROUND1_0_TO_15(c,d,e,a,b); + ROUND1_0_TO_15(b,c,d,e,a); + ROUND1_0_TO_15(a,b,c,d,e); + ROUND1_0_TO_15(e,a,b,c,d); + ROUND1_0_TO_15(d,e,a,b,c); + ROUND1_0_TO_15(c,d,e,a,b); + ROUND1_0_TO_15(b,c,d,e,a); + ROUND1_0_TO_15(a,b,c,d,e); - /* Rounds 16 to 19 unrolled: */ - ROUND1_16_TO_19(e,a,b,c,d); - ROUND1_16_TO_19(d,e,a,b,c); - ROUND1_16_TO_19(c,d,e,a,b); - ROUND1_16_TO_19(b,c,d,e,a); + /* Rounds 16 to 19 unrolled: */ + ROUND1_16_TO_19(e,a,b,c,d); + ROUND1_16_TO_19(d,e,a,b,c); + ROUND1_16_TO_19(c,d,e,a,b); + ROUND1_16_TO_19(b,c,d,e,a); - /* Rounds 20 to 39 unrolled: */ - ROUND1_20_TO_39(a,b,c,d,e); - ROUND1_20_TO_39(e,a,b,c,d); - ROUND1_20_TO_39(d,e,a,b,c); - ROUND1_20_TO_39(c,d,e,a,b); - ROUND1_20_TO_39(b,c,d,e,a); - ROUND1_20_TO_39(a,b,c,d,e); - ROUND1_20_TO_39(e,a,b,c,d); - ROUND1_20_TO_39(d,e,a,b,c); - ROUND1_20_TO_39(c,d,e,a,b); - ROUND1_20_TO_39(b,c,d,e,a); - ROUND1_20_TO_39(a,b,c,d,e); - ROUND1_20_TO_39(e,a,b,c,d); - ROUND1_20_TO_39(d,e,a,b,c); - ROUND1_20_TO_39(c,d,e,a,b); - ROUND1_20_TO_39(b,c,d,e,a); - ROUND1_20_TO_39(a,b,c,d,e); - ROUND1_20_TO_39(e,a,b,c,d); - ROUND1_20_TO_39(d,e,a,b,c); - ROUND1_20_TO_39(c,d,e,a,b); - ROUND1_20_TO_39(b,c,d,e,a); + /* Rounds 20 to 39 unrolled: */ + ROUND1_20_TO_39(a,b,c,d,e); + ROUND1_20_TO_39(e,a,b,c,d); + ROUND1_20_TO_39(d,e,a,b,c); + ROUND1_20_TO_39(c,d,e,a,b); + ROUND1_20_TO_39(b,c,d,e,a); + ROUND1_20_TO_39(a,b,c,d,e); + ROUND1_20_TO_39(e,a,b,c,d); + ROUND1_20_TO_39(d,e,a,b,c); + ROUND1_20_TO_39(c,d,e,a,b); + ROUND1_20_TO_39(b,c,d,e,a); + ROUND1_20_TO_39(a,b,c,d,e); + ROUND1_20_TO_39(e,a,b,c,d); + ROUND1_20_TO_39(d,e,a,b,c); + ROUND1_20_TO_39(c,d,e,a,b); + ROUND1_20_TO_39(b,c,d,e,a); + ROUND1_20_TO_39(a,b,c,d,e); + ROUND1_20_TO_39(e,a,b,c,d); + ROUND1_20_TO_39(d,e,a,b,c); + ROUND1_20_TO_39(c,d,e,a,b); + ROUND1_20_TO_39(b,c,d,e,a); - /* Rounds 40 to 59 unrolled: */ - ROUND1_40_TO_59(a,b,c,d,e); - ROUND1_40_TO_59(e,a,b,c,d); - ROUND1_40_TO_59(d,e,a,b,c); - ROUND1_40_TO_59(c,d,e,a,b); - ROUND1_40_TO_59(b,c,d,e,a); - ROUND1_40_TO_59(a,b,c,d,e); - ROUND1_40_TO_59(e,a,b,c,d); - ROUND1_40_TO_59(d,e,a,b,c); - ROUND1_40_TO_59(c,d,e,a,b); - ROUND1_40_TO_59(b,c,d,e,a); - ROUND1_40_TO_59(a,b,c,d,e); - ROUND1_40_TO_59(e,a,b,c,d); - ROUND1_40_TO_59(d,e,a,b,c); - ROUND1_40_TO_59(c,d,e,a,b); - ROUND1_40_TO_59(b,c,d,e,a); - ROUND1_40_TO_59(a,b,c,d,e); - ROUND1_40_TO_59(e,a,b,c,d); - ROUND1_40_TO_59(d,e,a,b,c); - ROUND1_40_TO_59(c,d,e,a,b); - ROUND1_40_TO_59(b,c,d,e,a); + /* Rounds 40 to 59 unrolled: */ + ROUND1_40_TO_59(a,b,c,d,e); + ROUND1_40_TO_59(e,a,b,c,d); + ROUND1_40_TO_59(d,e,a,b,c); + ROUND1_40_TO_59(c,d,e,a,b); + ROUND1_40_TO_59(b,c,d,e,a); + ROUND1_40_TO_59(a,b,c,d,e); + ROUND1_40_TO_59(e,a,b,c,d); + ROUND1_40_TO_59(d,e,a,b,c); + ROUND1_40_TO_59(c,d,e,a,b); + ROUND1_40_TO_59(b,c,d,e,a); + ROUND1_40_TO_59(a,b,c,d,e); + ROUND1_40_TO_59(e,a,b,c,d); + ROUND1_40_TO_59(d,e,a,b,c); + ROUND1_40_TO_59(c,d,e,a,b); + ROUND1_40_TO_59(b,c,d,e,a); + ROUND1_40_TO_59(a,b,c,d,e); + ROUND1_40_TO_59(e,a,b,c,d); + ROUND1_40_TO_59(d,e,a,b,c); + ROUND1_40_TO_59(c,d,e,a,b); + ROUND1_40_TO_59(b,c,d,e,a); - /* Rounds 60 to 79 unrolled: */ - ROUND1_60_TO_79(a,b,c,d,e); - ROUND1_60_TO_79(e,a,b,c,d); - ROUND1_60_TO_79(d,e,a,b,c); - ROUND1_60_TO_79(c,d,e,a,b); - ROUND1_60_TO_79(b,c,d,e,a); - ROUND1_60_TO_79(a,b,c,d,e); - ROUND1_60_TO_79(e,a,b,c,d); - ROUND1_60_TO_79(d,e,a,b,c); - ROUND1_60_TO_79(c,d,e,a,b); - ROUND1_60_TO_79(b,c,d,e,a); - ROUND1_60_TO_79(a,b,c,d,e); - ROUND1_60_TO_79(e,a,b,c,d); - ROUND1_60_TO_79(d,e,a,b,c); - ROUND1_60_TO_79(c,d,e,a,b); - ROUND1_60_TO_79(b,c,d,e,a); - ROUND1_60_TO_79(a,b,c,d,e); - ROUND1_60_TO_79(e,a,b,c,d); - ROUND1_60_TO_79(d,e,a,b,c); - ROUND1_60_TO_79(c,d,e,a,b); - ROUND1_60_TO_79(b,c,d,e,a); + /* Rounds 60 to 79 unrolled: */ + ROUND1_60_TO_79(a,b,c,d,e); + ROUND1_60_TO_79(e,a,b,c,d); + ROUND1_60_TO_79(d,e,a,b,c); + ROUND1_60_TO_79(c,d,e,a,b); + ROUND1_60_TO_79(b,c,d,e,a); + ROUND1_60_TO_79(a,b,c,d,e); + ROUND1_60_TO_79(e,a,b,c,d); + ROUND1_60_TO_79(d,e,a,b,c); + ROUND1_60_TO_79(c,d,e,a,b); + ROUND1_60_TO_79(b,c,d,e,a); + ROUND1_60_TO_79(a,b,c,d,e); + ROUND1_60_TO_79(e,a,b,c,d); + ROUND1_60_TO_79(d,e,a,b,c); + ROUND1_60_TO_79(c,d,e,a,b); + ROUND1_60_TO_79(b,c,d,e,a); + ROUND1_60_TO_79(a,b,c,d,e); + ROUND1_60_TO_79(e,a,b,c,d); + ROUND1_60_TO_79(d,e,a,b,c); + ROUND1_60_TO_79(c,d,e,a,b); + ROUND1_60_TO_79(b,c,d,e,a); - /* Compute the current intermediate hash value */ - context->s1.state[0] += a; - context->s1.state[1] += b; - context->s1.state[2] += c; - context->s1.state[3] += d; - context->s1.state[4] += e; + /* Compute the current intermediate hash value */ + context->s1.state[0] += a; + context->s1.state[1] += b; + context->s1.state[2] += c; + context->s1.state[3] += d; + context->s1.state[4] += e; + } } void SHA1_Update(SHA_CTX* context, const nzUInt8* data, std::size_t len) @@ -766,9 +769,12 @@ void SHA224_Init(SHA_CTX* context) SHA256_Internal_Init(context, sha224_initial_hash_value); } -void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data) +namespace { - SHA256_Internal_Transform(context, data); + void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data) + { + SHA256_Internal_Transform(context, data); + } } void SHA224_Update(SHA_CTX* context, const nzUInt8 *data, std::size_t len) diff --git a/src/Nazara/Core/HashDigest.cpp b/src/Nazara/Core/HashDigest.cpp index e41666b55..d86a0e53f 100644 --- a/src/Nazara/Core/HashDigest.cpp +++ b/src/Nazara/Core/HashDigest.cpp @@ -42,7 +42,7 @@ m_digestLength(rhs.m_digestLength) m_digest = nullptr; } -NzHashDigest::NzHashDigest(NzHashDigest&& rhs) : +NzHashDigest::NzHashDigest(NzHashDigest&& rhs) noexcept : m_hashName(std::move(rhs.m_hashName)), m_digest(rhs.m_digest), m_digestLength(rhs.m_digestLength) @@ -118,7 +118,7 @@ NzHashDigest& NzHashDigest::operator=(const NzHashDigest& rhs) return *this; } -NzHashDigest& NzHashDigest::operator=(NzHashDigest&& rhs) +NzHashDigest& NzHashDigest::operator=(NzHashDigest&& rhs) noexcept { std::swap(m_hashName, rhs.m_hashName); std::swap(m_digest, rhs.m_digest); diff --git a/src/Nazara/Core/Log.cpp b/src/Nazara/Core/Log.cpp index 6c7ea1cf8..946182d62 100644 --- a/src/Nazara/Core/Log.cpp +++ b/src/Nazara/Core/Log.cpp @@ -8,8 +8,9 @@ #include #include #include +#include -#if NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE +#if NAZARA_CORE_DUPLICATE_TO_COUT #include #endif @@ -17,7 +18,7 @@ namespace { - NzString errorType[] = { + const char* errorType[] = { "Assert failed: ", // nzErrorType_AssertFailed "Internal error: ", // nzErrorType_Internal "Error: ", // nzErrorType_Normal @@ -124,12 +125,11 @@ void NzLog::Write(const NzString& string) line += string; line += '\n'; - #if NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE - if (!m_file->IsOpen() || !m_file->Write(line)) - std::fputs(line.GetBuffer(), stderr); - #else if (m_file->IsOpen()) m_file->Write(line); + + #if NAZARA_CORE_DUPLICATE_TO_COUT + std::fputs(line.GetConstBuffer(), stderr); #endif } } @@ -137,7 +137,7 @@ void NzLog::Write(const NzString& string) void NzLog::WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func) { NzString stream; - stream.Reserve(errorType[type].GetSize() + error.GetSize() + 2 + file.GetSize() + 1 + NzGetNumberLength(line) +2 + func.GetSize() + 1); + stream.Reserve(std::strlen(errorType[type]) + error.GetSize() + 2 + file.GetSize() + 1 + NzGetNumberLength(line) +2 + func.GetSize() + 1); stream += errorType[type]; stream += error; stream += " ("; diff --git a/src/Nazara/Utility/Resource.cpp b/src/Nazara/Core/Resource.cpp similarity index 88% rename from src/Nazara/Utility/Resource.cpp rename to src/Nazara/Core/Resource.cpp index 7e7a06c1a..810d02e0a 100644 --- a/src/Nazara/Utility/Resource.cpp +++ b/src/Nazara/Core/Resource.cpp @@ -2,10 +2,10 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include +#include #include -#include -#include +#include NzResource::NzResource(bool persistent) : m_resourcePersistent(persistent), @@ -33,7 +33,7 @@ bool NzResource::IsPersistent() const void NzResource::RemoveResourceReference() const { - #if NAZARA_UTILITY_SAFE + #if NAZARA_CORE_SAFE if (m_resourceReferenceCount == 0) { NazaraError("Impossible to remove reference (Ref. counter is already 0)"); diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index b983ed9e7..40642cb4e 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -142,7 +142,7 @@ m_sharedString(string.m_sharedString) } } -NzString::NzString(NzString&& string) : +NzString::NzString(NzString&& string) noexcept : m_sharedString(string.m_sharedString) { string.m_sharedString = &emptyString; @@ -307,7 +307,6 @@ unsigned int NzString::Count(char character, int start, nzUInt32 flags) const { char character_lower = nzToLower(character); char character_upper = nzToUpper(character); - unsigned int count = 0; do { if (*str == character_lower || *str == character_upper) @@ -807,14 +806,14 @@ unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const { if (NzUnicode::GetLowercase(*it) == c) { - const char* pos = it.base(); + const char* ptrPos = it.base(); ++it; utf8::unchecked::iterator it2(t); while (true) { if (*it2 == '\0') - return static_cast(pos - m_sharedString->string); + return static_cast(ptrPos - m_sharedString->string); if (*it == '\0') return npos; @@ -836,14 +835,14 @@ unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const { if (nzToLower(*str) == c) { - char* pos = str; + char* ptrPos = str; str++; const char* ptr = &string[1]; while (true) { if (*ptr == '\0') - return static_cast(pos - m_sharedString->string); + return static_cast(ptrPos - m_sharedString->string); if (*str == '\0') return npos; @@ -897,14 +896,14 @@ unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) c { if (NzUnicode::GetLowercase(*it) == c) { - const char* pos = it.base(); + const char* ptrPos = it.base(); ++it; utf8::unchecked::iterator it2(t); while (true) { if (*it2 == '\0') - return static_cast(pos - m_sharedString->string); + return static_cast(ptrPos - m_sharedString->string); if (*it == '\0') return npos; @@ -926,14 +925,14 @@ unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) c { if (nzToLower(*str) == c) { - char* pos = str; + char* ptrPos = str; str++; const char* ptr = &string.m_sharedString->string[1]; while (true) { if (*ptr == '\0') - return static_cast(pos - m_sharedString->string); + return static_cast(ptrPos - m_sharedString->string); if (*str == '\0') return npos; @@ -2296,7 +2295,7 @@ char16_t* NzString::GetUtf16Buffer(unsigned int* size) const catch (const utf8::exception& exception) { NazaraError("UTF-8 error : " + NzString(exception.what())); - return 0; + return nullptr; } #endif @@ -2340,7 +2339,7 @@ char32_t* NzString::GetUtf32Buffer(unsigned int* size) const catch (const utf8::exception& exception) { NazaraError("UTF-8 error : " + NzString(exception.what())); - return 0; + return nullptr; } #endif } @@ -2387,7 +2386,7 @@ wchar_t* NzString::GetWideBuffer(unsigned int* size) const catch (const utf8::exception& exception) { NazaraError("UTF-8 error : " + NzString(exception.what())); - return 0; + return nullptr; } #endif } @@ -2621,7 +2620,7 @@ bool NzString::IsNull() const bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const { - #if !NAZARA_UNSAFE + #if NAZARA_CORE_SAFE if (base < 2 || base > 36) { NazaraError("Base must be between 2 and 36"); @@ -2770,11 +2769,11 @@ unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start, { if (!found) { - unsigned int pos = ptr-m_sharedString->string; + unsigned int offset = ptr-m_sharedString->string; EnsureOwnership(); - ptr = &m_sharedString->string[pos]; + ptr = &m_sharedString->string[offset]; found = true; } @@ -2790,11 +2789,11 @@ unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start, { if (!found) { - unsigned int pos = ptr-m_sharedString->string; + unsigned int offset = ptr-m_sharedString->string; EnsureOwnership(); - ptr = &m_sharedString->string[pos]; + ptr = &m_sharedString->string[offset]; found = true; } @@ -2954,6 +2953,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags) { + ///FIXME: Ne gère pas l'UTF-8 if (!oldCharacters || !oldCharacters[0]) return 0; @@ -2982,11 +2982,11 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact { if (!found) { - unsigned int pos = ptr-m_sharedString->string; + unsigned int offset = ptr-m_sharedString->string; EnsureOwnership(); - ptr = &m_sharedString->string[pos]; + ptr = &m_sharedString->string[offset]; found = true; } @@ -3006,11 +3006,11 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact { if (!found) { - unsigned int pos = ptr-m_sharedString->string; + unsigned int offset = ptr-m_sharedString->string; EnsureOwnership(); - ptr = &m_sharedString->string[pos]; + ptr = &m_sharedString->string[offset]; found = true; } @@ -3203,7 +3203,10 @@ void NzString::Reserve(unsigned int bufferSize) NzString& NzString::Resize(int size, char character) { if (size == 0) + { Clear(true); + return *this; + } if (size < 0) size = std::max(static_cast(m_sharedString->size + size), 0); @@ -3249,9 +3252,6 @@ NzString& NzString::Resize(int size, char character) NzString NzString::Resized(int size, char character) const { - if (size == 0) - return NzString(); - if (size < 0) size = m_sharedString->size + size; @@ -3692,12 +3692,12 @@ NzString NzString::Substr(int startPos, int endPos) const return NzString(); } - unsigned int end = std::min(static_cast(endPos), m_sharedString->size-1); + unsigned int minEnd = std::min(static_cast(endPos), m_sharedString->size-1); - if (start > end || start >= m_sharedString->size) + if (start > minEnd || start >= m_sharedString->size) return NzString(); - unsigned int size = end-start+1; + unsigned int size = minEnd-start+1; char* str = new char[size+1]; std::memcpy(str, &m_sharedString->string[start], size*sizeof(char)); str[size] = '\0'; @@ -4232,7 +4232,7 @@ NzString& NzString::operator=(const NzString& string) return *this; } -NzString& NzString::operator=(NzString&& string) +NzString& NzString::operator=(NzString&& string) noexcept { std::swap(m_sharedString, string.m_sharedString); @@ -5107,7 +5107,6 @@ void NzString::ReleaseString() if (freeSharedString) { - NazaraMutexUnlock(m_sharedString->mutex); delete[] m_sharedString->string; delete m_sharedString; } diff --git a/src/Nazara/Core/Win32/ThreadConditionImpl.cpp b/src/Nazara/Core/Win32/ConditionVariableImpl.cpp similarity index 80% rename from src/Nazara/Core/Win32/ThreadConditionImpl.cpp rename to src/Nazara/Core/Win32/ConditionVariableImpl.cpp index 53d8a07d2..76cdf8cd9 100644 --- a/src/Nazara/Core/Win32/ThreadConditionImpl.cpp +++ b/src/Nazara/Core/Win32/ConditionVariableImpl.cpp @@ -4,13 +4,13 @@ // Source: http://www.cs.wustl.edu/~schmidt/win32-cv-1.html -#include +#include #include #include -NzThreadConditionImpl::NzThreadConditionImpl() +NzConditionVariableImpl::NzConditionVariableImpl() { - #ifdef NAZARA_PLATFORM_WINDOWSVISTA + #if NAZARA_CORE_WINDOWS_VISTA InitializeConditionVariable(&m_cv); #else m_count = 0; @@ -20,16 +20,16 @@ NzThreadConditionImpl::NzThreadConditionImpl() #endif } -#ifndef NAZARA_PLATFORM_WINDOWSVISTA -NzThreadConditionImpl::~NzThreadConditionImpl() +#if !NAZARA_CORE_WINDOWS_VISTA +NzConditionVariableImpl::~NzConditionVariableImpl() { DeleteCriticalSection(&m_countLock); } #endif -void NzThreadConditionImpl::Signal() +void NzConditionVariableImpl::Signal() { - #ifdef NAZARA_PLATFORM_WINDOWSVISTA + #if NAZARA_CORE_WINDOWS_VISTA WakeConditionVariable(&m_cv); #else // Avoid race conditions. @@ -42,9 +42,9 @@ void NzThreadConditionImpl::Signal() #endif } -void NzThreadConditionImpl::SignalAll() +void NzConditionVariableImpl::SignalAll() { - #ifdef NAZARA_PLATFORM_WINDOWSVISTA + #if NAZARA_CORE_WINDOWS_VISTA WakeAllConditionVariable(&m_cv); #else // Avoid race conditions. @@ -57,14 +57,14 @@ void NzThreadConditionImpl::SignalAll() #endif } -void NzThreadConditionImpl::Wait(NzMutexImpl* mutex) +void NzConditionVariableImpl::Wait(NzMutexImpl* mutex) { Wait(mutex, INFINITE); } -bool NzThreadConditionImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout) +bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout) { - #ifdef NAZARA_PLATFORM_WINDOWSVISTA + #if NAZARA_CORE_WINDOWS_VISTA return SleepConditionVariableCS(&m_cv, mutex->m_criticalSection, timeout); #else // Avoid race conditions. diff --git a/src/Nazara/Core/Win32/ThreadConditionImpl.hpp b/src/Nazara/Core/Win32/ConditionVariableImpl.hpp similarity index 67% rename from src/Nazara/Core/Win32/ThreadConditionImpl.hpp rename to src/Nazara/Core/Win32/ConditionVariableImpl.hpp index cf2fb3b8f..f4afa4545 100644 --- a/src/Nazara/Core/Win32/ThreadConditionImpl.hpp +++ b/src/Nazara/Core/Win32/ConditionVariableImpl.hpp @@ -6,22 +6,22 @@ #pragma once -#ifndef NAZARA_THREADCONDITIONIMPL_HPP -#define NAZARA_THREADCONDITIONIMPL_HPP +#ifndef NAZARA_CONDITIONVARIABLEIMPL_HPP +#define NAZARA_CONDITIONVARIABLEIMPL_HPP #include #include class NzMutexImpl; -class NzThreadConditionImpl +class NzConditionVariableImpl { public: - NzThreadConditionImpl(); - #ifdef NAZARA_PLATFORM_WINDOWSVISTA - ~NzThreadConditionImpl() = default; + NzConditionVariableImpl(); + #if NAZARA_CORE_WINDOWS_VISTA + ~NzConditionVariableImpl() = default; #else - ~NzThreadConditionImpl(); + ~NzConditionVariableImpl(); #endif void Signal(); @@ -31,7 +31,7 @@ class NzThreadConditionImpl bool Wait(NzMutexImpl* mutex, nzUInt32 timeout); private: - #ifdef NAZARA_PLATFORM_WINDOWSVISTA + #if NAZARA_CORE_WINDOWS_VISTA CONDITION_VARIABLE m_cv; #else enum @@ -48,4 +48,4 @@ class NzThreadConditionImpl }; -#endif // NAZARA_THREADCONDITIONIMPL_HPP +#endif // NAZARA_CONDITIONVARIABLEIMPL_HPP diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index b93ca618e..6154b1b65 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -117,7 +117,7 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size) /// D'après les tests, ce n'est pas le cas, la taille lue est inférieure à la taille en argument, mais pas nulle /// Peut-être ais-je mal compris la documentation /// Le correctif (dans le cas où la doc serait vraie) est commenté en début de fonction et après ce commentaire - /// Il est cependant plus lourd, et ne fonctionne pas selon les tests... + /// Il est cependant plus lourd, et ne fonctionne pas avec le comportement observé de la fonction /* if (read == 0) { @@ -254,7 +254,7 @@ time_t NzFileImpl::GetCreationTime(const NzString& filePath) CloseHandle(handle); - return FileTimeToTime(&creationTime); + return NzFileTimeToTime(&creationTime); } time_t NzFileImpl::GetLastAccessTime(const NzString& filePath) @@ -277,7 +277,7 @@ time_t NzFileImpl::GetLastAccessTime(const NzString& filePath) CloseHandle(handle); - return FileTimeToTime(&accessTime); + return NzFileTimeToTime(&accessTime); } time_t NzFileImpl::GetLastWriteTime(const NzString& filePath) @@ -300,7 +300,7 @@ time_t NzFileImpl::GetLastWriteTime(const NzString& filePath) CloseHandle(handle); - return FileTimeToTime(&writeTime); + return NzFileTimeToTime(&writeTime); } nzUInt64 NzFileImpl::GetSize(const NzString& filePath) diff --git a/src/Nazara/Core/Win32/MutexImpl.cpp b/src/Nazara/Core/Win32/MutexImpl.cpp index d37568955..9bebb187c 100644 --- a/src/Nazara/Core/Win32/MutexImpl.cpp +++ b/src/Nazara/Core/Win32/MutexImpl.cpp @@ -7,7 +7,11 @@ NzMutexImpl::NzMutexImpl() { + #if NAZARA_CORE_WINDOWS_CS_SPINLOCKS > 0 + InitializeCriticalSectionAndSpinCount(&m_criticalSection, NAZARA_CORE_WINDOWS_CS_SPINLOCKS); + #else InitializeCriticalSection(&m_criticalSection); + #endif } NzMutexImpl::~NzMutexImpl() diff --git a/src/Nazara/Core/Win32/MutexImpl.hpp b/src/Nazara/Core/Win32/MutexImpl.hpp index 5b01e7864..6356f9e9e 100644 --- a/src/Nazara/Core/Win32/MutexImpl.hpp +++ b/src/Nazara/Core/Win32/MutexImpl.hpp @@ -9,11 +9,11 @@ #include -class NzThreadConditionImpl; +class NzConditionVariableImpl; class NzMutexImpl { - friend class NzThreadConditionImpl; + friend class NzConditionVariableImpl; public: NzMutexImpl(); diff --git a/src/Nazara/Core/Win32/Time.cpp b/src/Nazara/Core/Win32/Time.cpp new file mode 100644 index 000000000..23643d39e --- /dev/null +++ b/src/Nazara/Core/Win32/Time.cpp @@ -0,0 +1,24 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include + +time_t NzFileTimeToTime(FILETIME* time) +{ + SYSTEMTIME stUTC, stLocal; + + FileTimeToSystemTime(time, &stUTC); + SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal); + + std::tm timeinfo; + timeinfo.tm_sec = stLocal.wSecond; + timeinfo.tm_min = stLocal.wMinute; + timeinfo.tm_hour = stLocal.wHour; + timeinfo.tm_mday = stLocal.wDay; + timeinfo.tm_mon = stLocal.wMonth-1; + timeinfo.tm_year = stLocal.wYear-1900; + timeinfo.tm_isdst = -1; + + return std::mktime(&timeinfo); +} diff --git a/src/Nazara/Core/Win32/Time.hpp b/src/Nazara/Core/Win32/Time.hpp index 63d2aca26..952c2f240 100644 --- a/src/Nazara/Core/Win32/Time.hpp +++ b/src/Nazara/Core/Win32/Time.hpp @@ -10,23 +10,6 @@ #include #include -time_t FileTimeToTime(FILETIME* time) -{ - SYSTEMTIME stUTC, stLocal; - - FileTimeToSystemTime(time, &stUTC); - SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal); - - std::tm timeinfo; - timeinfo.tm_sec = stLocal.wSecond; - timeinfo.tm_min = stLocal.wMinute; - timeinfo.tm_hour = stLocal.wHour; - timeinfo.tm_mday = stLocal.wDay; - timeinfo.tm_mon = stLocal.wMonth-1; - timeinfo.tm_year = stLocal.wYear-1900; - timeinfo.tm_isdst = -1; - - return std::mktime(&timeinfo); -} +time_t NzFileTimeToTime(FILETIME* time); #endif // NAZARA_WINDOWS_TIME_HPP diff --git a/src/Nazara/Network/Debug/Leaks.cpp b/src/Nazara/Network/Debug/Leaks.cpp deleted file mode 100644 index 403a969d7..000000000 --- a/src/Nazara/Network/Debug/Leaks.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) -#include -#include - -void* operator new(std::size_t size) -{ - return NzMemoryManager::Allocate(size, false); -} - -void* operator new[](std::size_t size) -{ - return NzMemoryManager::Allocate(size, true); -} - -void operator delete(void* pointer) noexcept -{ - NzMemoryManager::Free(pointer, false); -} - -void operator delete[](void* pointer) noexcept -{ - NzMemoryManager::Free(pointer, true); -} -#endif diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index 8d5dd92f5..a5d1b00ed 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -3,57 +3,47 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include +#include #include #include -NzNoise::NzNoise() -{ -} - -NzNoise::~NzNoise() -{ - if (s_initialized) - Uninitialize(); -} - bool NzNoise::Initialize() { - #if NAZARA_NOISE_SAFE - if (s_initialized) + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation des dépendances + if (!NzCore::Initialize()) { - NazaraError("NzNoise already initialized"); - return true; + NazaraError("Failed to initialize core module"); + return false; } - #endif // Initialisation du module - s_initialized = true; + NazaraNotice("Initialized: Noise module"); return true; } +bool NzNoise::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + void NzNoise::Uninitialize() { - #if NAZARA_NOISE_SAFE - if (!s_initialized) - { - NazaraError("NzNoise not initialized"); - return; - } - #endif + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé // Libération du module - s_initialized = false; + // Libération des dépendances + NzCore::Uninitialize(); + + NazaraNotice("Uninitialized: Noise module"); } -bool NzNoise::IsInitialized() -{ - return s_initialized; -} - -bool NzNoise::s_initialized = false; - -//#include //A INCLURE ? +unsigned int NzNoise::s_moduleReferenceCouter = 0; diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLShader.cpp index b5d37d905..aa17c7ede 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLShader.cpp @@ -63,11 +63,22 @@ bool NzGLSLShader::Bind() glUseProgram(m_program); + return true; +} + +bool NzGLSLShader::BindTextures() +{ for (auto it = m_textures.begin(); it != m_textures.end(); ++it) { - glActiveTexture(GL_TEXTURE0 + it->second.unit); - if (!it->second.texture->Bind()) - NazaraWarning("Failed to bind texture"); + TextureSlot& slot = it->second; + if (!slot.updated) + { + glActiveTexture(GL_TEXTURE0 + slot.unit); + if (!slot.texture->Bind()) + NazaraWarning("Failed to bind texture"); + + slot.updated = true; + } } return true; @@ -78,6 +89,7 @@ bool NzGLSLShader::Compile() NzContext::EnsureContext(); m_idCache.clear(); + m_textures.clear(); glLinkProgram(m_program); @@ -86,8 +98,8 @@ bool NzGLSLShader::Compile() if (success == GL_TRUE) { - static NzString success("Linkage successful"); - m_log = success; + static NzString successStr("Linkage successful"); + m_log = successStr; return true; } @@ -131,7 +143,7 @@ bool NzGLSLShader::Create() glBindAttribLocation(m_program, attribIndex[nzElementUsage_Tangent], "Tangent"); NzString uniform = "TexCoord"; - unsigned int maxTexCoords = NazaraRenderer->GetMaxTextureUnits(); + unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits(); for (unsigned int i = 0; i < maxTexCoords; ++i) { NzString uniformName = uniform + NzString::Number(i); @@ -148,6 +160,9 @@ void NzGLSLShader::Destroy() { NzContext::EnsureContext(); + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + it->second.texture->RemoveResourceReference(); + for (GLuint shader : m_shaders) if (shader) glDeleteShader(shader); @@ -183,7 +198,7 @@ NzString NzGLSLShader::GetSourceCode(nzShaderType type) const return source; } -GLint NzGLSLShader::GetUniformLocation(const NzString& name) const +int NzGLSLShader::GetUniformLocation(const NzString& name) const { std::map::const_iterator it = m_idCache.find(name); GLint id; @@ -232,8 +247,8 @@ bool NzGLSLShader::Load(nzShaderType type, const NzString& source) glAttachShader(m_program, shader); m_shaders[type] = shader; - static NzString success("Compilation successful"); - m_log = success; + static NzString successStr("Compilation successful"); + m_log = successStr; return true; } @@ -280,226 +295,247 @@ bool NzGLSLShader::Lock() return true; } -bool NzGLSLShader::SendBoolean(const NzString& name, bool value) +bool NzGLSLShader::SendBoolean(int location, bool value) { if (glProgramUniform1i) - glProgramUniform1i(m_program, GetUniformLocation(name), value); + glProgramUniform1i(m_program, location, value); else { Lock(); - glUniform1i(GetUniformLocation(name), value); + glUniform1i(location, value); Unlock(); } return true; } -bool NzGLSLShader::SendDouble(const NzString& name, double value) +bool NzGLSLShader::SendDouble(int location, double value) { if (glProgramUniform1d) - glProgramUniform1d(m_program, GetUniformLocation(name), value); + glProgramUniform1d(m_program, location, value); else { Lock(); - glUniform1d(GetUniformLocation(name), value); + glUniform1d(location, value); Unlock(); } return true; } -bool NzGLSLShader::SendFloat(const NzString& name, float value) +bool NzGLSLShader::SendFloat(int location, float value) { if (glProgramUniform1f) - glProgramUniform1f(m_program, GetUniformLocation(name), value); + glProgramUniform1f(m_program, location, value); else { Lock(); - glUniform1f(GetUniformLocation(name), value); + glUniform1f(location, value); Unlock(); } return true; } -bool NzGLSLShader::SendInteger(const NzString& name, int value) +bool NzGLSLShader::SendInteger(int location, int value) { if (glProgramUniform1i) - glProgramUniform1i(m_program, GetUniformLocation(name), value); + glProgramUniform1i(m_program, location, value); else { Lock(); - glUniform1i(GetUniformLocation(name), value); + glUniform1i(location, value); Unlock(); } return true; } -bool NzGLSLShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix) +bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) { if (glProgramUniformMatrix4dv) - glProgramUniformMatrix4dv(m_program, GetUniformLocation(name), 1, GL_FALSE, matrix); + glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix); else { Lock(); - glUniformMatrix4dv(GetUniformLocation(name), 1, GL_FALSE, matrix); + glUniformMatrix4dv(location, 1, GL_FALSE, matrix); Unlock(); } return true; } -bool NzGLSLShader::SendMatrix(const NzString& name, const NzMatrix4f& matrix) +bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) { if (glProgramUniformMatrix4fv) - glProgramUniformMatrix4fv(m_program, GetUniformLocation(name), 1, GL_FALSE, matrix); + glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix); else { Lock(); - glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, matrix); + glUniformMatrix4fv(location, 1, GL_FALSE, matrix); Unlock(); } return true; } -bool NzGLSLShader::SendVector(const NzString& name, const NzVector2d& vector) +bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) { - if (glProgramUniform2dv) - glProgramUniform2dv(m_program, GetUniformLocation(name), 1, vector); - else + auto it = m_textures.find(location); + if (it != m_textures.end()) { - Lock(); - glUniform2dv(GetUniformLocation(name), 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(const NzString& name, const NzVector2f& vector) -{ - if (glProgramUniform2fv) - glProgramUniform2fv(m_program, GetUniformLocation(name), 1, vector); - else - { - Lock(); - glUniform2fv(GetUniformLocation(name), 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(const NzString& name, const NzVector3d& vector) -{ - if (glProgramUniform3dv) - glProgramUniform3dv(m_program, GetUniformLocation(name), 1, vector); - else - { - Lock(); - glUniform3dv(GetUniformLocation(name), 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(const NzString& name, const NzVector3f& vector) -{ - if (glProgramUniform3fv) - glProgramUniform3fv(m_program, GetUniformLocation(name), 1, vector); - else - { - Lock(); - glUniform3fv(GetUniformLocation(name), 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(const NzString& name, const NzVector4d& vector) -{ - if (glProgramUniform4dv) - glProgramUniform4dv(m_program, GetUniformLocation(name), 1, vector); - else - { - Lock(); - glUniform4dv(GetUniformLocation(name), 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(const NzString& name, const NzVector4f& vector) -{ - if (glProgramUniform4fv) - glProgramUniform4fv(m_program, GetUniformLocation(name), 1, vector); - else - { - Lock(); - glUniform4fv(GetUniformLocation(name), 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendTexture(const NzString& name, NzTexture* texture) -{ - static const unsigned int maxUnits = NazaraRenderer->GetMaxTextureUnits(); - - unsigned int unitUsed = m_textures.size(); - if (unitUsed >= maxUnits) - { - NazaraError("Unable to use texture \"" + name + "\" for shader: all available texture units are used"); - return false; - } - - // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre - GLint location = GetUniformLocation(name); - if (location == -1) - { - NazaraError("Parameter name \"" + name + "\" not found in shader"); - return false; - } - - nzUInt8 unit; - if (unitUsed == 0) - // Pas d'unité utilisée, la tâche est simple - unit = 0; - else - { - auto it = m_textures.rbegin(); // Itérateur vers la fin de la map - unit = it->second.unit; - if (unit == maxUnits-1) + // Slot déjà utilisé + TextureSlot& slot = it->second; + if (slot.texture != texture) { - // Il y a une place libre, mais pas à la fin - for (; it != m_textures.rend(); ++it) + slot.texture->RemoveResourceReference(); + + if (texture) { - if (unit - it->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre + slot.texture = texture; + slot.texture->AddResourceReference(); + + slot.updated = false; + } + else + m_textures.erase(it); // On supprime le slot + } + } + else + { + static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits(); + + unsigned int unitUsed = m_textures.size(); + if (unitUsed >= maxUnits) + { + NazaraError("Unable to use texture for shader: all available texture units are used"); + return false; + } + + // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre + nzUInt8 unit; + if (unitUsed == 0) + // Pas d'unité utilisée, la tâche est simple + unit = 0; + else + { + auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map + unit = it2->second.unit; + if (unit == maxUnits-1) + { + // Il y a une place libre, mais pas à la fin + for (; it2 != m_textures.rend(); ++it2) { - unit--; - break; + if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre + { + unit--; + break; + } } } + else + // Il y a une place libre à la fin + unit++; } + + TextureSlot slot; + slot.unit = unit; + slot.texture = texture; + texture->AddResourceReference(); + + m_textures[location] = slot; + + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, unit); else - // Il y a une place libre à la fin - unit++; + { + Lock(); + glUniform1i(location, unit); + Unlock(); + } } - m_textures[location] = TextureSlot{unit, texture}; + return true; +} - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, unit); +bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) +{ + if (glProgramUniform2dv) + glProgramUniform2dv(m_program, location, 1, vector); else { Lock(); - glUniform1i(location, unit); + glUniform2dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) +{ + if (glProgramUniform2fv) + glProgramUniform2fv(m_program, location, 1, vector); + else + { + Lock(); + glUniform2fv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) +{ + if (glProgramUniform3dv) + glProgramUniform3dv(m_program, location, 1, vector); + else + { + Lock(); + glUniform3dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) +{ + if (glProgramUniform3fv) + glProgramUniform3fv(m_program, location, 1, vector); + else + { + Lock(); + glUniform3fv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) +{ + if (glProgramUniform4dv) + glProgramUniform4dv(m_program, location, 1, vector); + else + { + Lock(); + glUniform4dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) +{ + if (glProgramUniform4fv) + glProgramUniform4fv(m_program, location, 1, vector); + else + { + Lock(); + glUniform4fv(location, 1, vector); Unlock(); } diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLShader.hpp index f32d783ec..b429daced 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLShader.hpp @@ -20,35 +20,36 @@ class NzGLSLShader : public NzShaderImpl ~NzGLSLShader(); bool Bind(); + bool BindTextures(); bool Compile(); - bool Create(); + bool Create(); void Destroy(); NzString GetLog() const; nzShaderLanguage GetLanguage() const; NzString GetSourceCode(nzShaderType type) const; - GLint GetUniformLocation(const NzString& name) const; + int GetUniformLocation(const NzString& name) const; bool IsLoaded(nzShaderType type) const; bool Load(nzShaderType type, const NzString& source); bool Lock(); - bool SendBoolean(const NzString& name, bool value); - bool SendDouble(const NzString& name, double value); - bool SendFloat(const NzString& name, float value); - bool SendInteger(const NzString& name, int value); - bool SendMatrix(const NzString& name, const NzMatrix4d& matrix); - bool SendMatrix(const NzString& name, const NzMatrix4f& matrix); - bool SendVector(const NzString& name, const NzVector2d& vector); - bool SendVector(const NzString& name, const NzVector2f& vector); - bool SendVector(const NzString& name, const NzVector3d& vector); - bool SendVector(const NzString& name, const NzVector3f& vector); - bool SendVector(const NzString& name, const NzVector4d& vector); - bool SendVector(const NzString& name, const NzVector4f& vector); - bool SendTexture(const NzString& name, NzTexture* texture); + bool SendBoolean(int location, bool value); + bool SendDouble(int location, double value); + bool SendFloat(int location, float value); + bool SendInteger(int location, int value); + bool SendMatrix(int location, const NzMatrix4d& matrix); + bool SendMatrix(int location, const NzMatrix4f& matrix); + bool SendTexture(int location, const NzTexture* texture); + bool SendVector(int location, const NzVector2d& vector); + bool SendVector(int location, const NzVector2f& vector); + bool SendVector(int location, const NzVector3d& vector); + bool SendVector(int location, const NzVector3f& vector); + bool SendVector(int location, const NzVector4d& vector); + bool SendVector(int location, const NzVector4f& vector); void Unbind(); void Unlock(); @@ -56,8 +57,9 @@ class NzGLSLShader : public NzShaderImpl private: struct TextureSlot { + bool updated = false; nzUInt8 unit; - NzTexture* texture; + const NzTexture* texture; }; mutable std::map m_idCache; diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index af6401074..a56223103 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -52,14 +52,14 @@ namespace if (access == nzBufferAccess_DiscardAndWrite) { - GLint bufferSize; - glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufferSize); + GLint bufSize; + glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize); - GLint bufferUsage; - glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufferUsage); + GLint bufUsage; + glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage); // On discard le buffer - glBufferData(bufferTargetBinding[type], bufferSize, nullptr, bufferUsage); + glBufferData(bufferTargetBinding[type], bufSize, nullptr, bufUsage); } void* ptr = glMapBuffer(bufferTarget[type], bufferLock[access]); diff --git a/src/Nazara/Renderer/OcclusionQuery.cpp b/src/Nazara/Renderer/OcclusionQuery.cpp index 50901e190..2b2d062cd 100644 --- a/src/Nazara/Renderer/OcclusionQuery.cpp +++ b/src/Nazara/Renderer/OcclusionQuery.cpp @@ -98,5 +98,5 @@ bool NzOcclusionQuery::IsResultAvailable() const bool NzOcclusionQuery::IsSupported() { - return NazaraRenderer->HasCapability(nzRendererCap_OcclusionQuery); + return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery); } diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 0c775fef5..89545800d 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1,3 +1,7 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + #include #include #include @@ -54,7 +58,7 @@ namespace } std::set openGLextensionSet; - bool openGLextensions[NzOpenGL::Count] = {false}; + bool openGLextensions[NzOpenGL::Max+1] = {false}; unsigned int openGLversion = 0; bool LoadExtensionsString(const NzString& extensionString) @@ -129,7 +133,7 @@ bool NzOpenGL::Initialize() /* Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant - de créer le second avec les bons paramètres.s + de créer le second avec les bons paramètres. Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise */ @@ -157,7 +161,7 @@ bool NzOpenGL::Initialize() // Récupération de la version d'OpenGL // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... - glGetString = reinterpret_cast(LoadEntry("glGetString")); + glGetString = reinterpret_cast(LoadEntry("glGetString", false)); if (!glGetString) { NazaraError("Unable to load OpenGL: failed to load glGetString"); @@ -191,10 +195,17 @@ bool NzOpenGL::Initialize() } openGLversion = major*100 + minor*10; + if (openGLversion < 200) + { + NazaraError("OpenGL version is too low, please upgrade your drivers or your graphics card"); + Uninitialize(); + + return false; + } parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output) - parameters.majorVersion = NzContextParameters::defaultMajorVersion = openGLversion/100; - parameters.minorVersion = NzContextParameters::defaultMinorVersion = (openGLversion%100)/10; + parameters.majorVersion = NzContextParameters::defaultMajorVersion = major; + parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor; // Destruction implicite du premier contexte if (!loadContext.Create(parameters)) @@ -331,7 +342,7 @@ bool NzOpenGL::Initialize() loaded = false; if (!loaded) - NazaraWarning("Failed to load windows' extension string"); + NazaraWarning("Failed to load wgl extension string"); } #endif @@ -403,7 +414,7 @@ bool NzOpenGL::Initialize() openGLextensions[NzOpenGL::PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object")); // SeparateShaderObjects - if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) + if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects")) { glProgramUniform1f = reinterpret_cast(LoadEntry("glProgramUniform1f")); glProgramUniform1i = reinterpret_cast(LoadEntry("glProgramUniform1i")); @@ -412,6 +423,7 @@ bool NzOpenGL::Initialize() glProgramUniform4fv = reinterpret_cast(LoadEntry("glProgramUniform4fv")); glProgramUniformMatrix4fv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4fv")); + // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double if (openGLextensions[NzOpenGL::FP64]) { glProgramUniform1d = reinterpret_cast(LoadEntry("glProgramUniform1d")); @@ -434,8 +446,7 @@ bool NzOpenGL::Initialize() } catch (const std::exception& e) { - if (openGLversion >= 120) - NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")"); + NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")"); if (IsSupported("GL_EXT_texture3D")) { @@ -449,13 +460,16 @@ bool NzOpenGL::Initialize() openGLextensions[NzOpenGL::Texture3D] = true; } - catch (const std::exception& e) + catch (const std::exception& e2) { - NazaraWarning("Failed to load EXT_texture3D: " + NzString(e.what())); + NazaraWarning("Failed to load EXT_texture3D: " + NzString(e2.what())); } } } + // TextureArray + openGLextensions[NzOpenGL::TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array")); + // TextureCompression_s3tc openGLextensions[NzOpenGL::TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc"); diff --git a/src/Nazara/Renderer/RenderTarget.cpp b/src/Nazara/Renderer/RenderTarget.cpp index 2954e61ca..9a9be298d 100644 --- a/src/Nazara/Renderer/RenderTarget.cpp +++ b/src/Nazara/Renderer/RenderTarget.cpp @@ -10,15 +10,15 @@ NzRenderTarget::~NzRenderTarget() = default; bool NzRenderTarget::IsActive() const { - return NazaraRenderer->GetTarget() == this; + return NzRenderer::GetTarget() == this; } bool NzRenderTarget::SetActive(bool active) { if (active) - return NazaraRenderer->SetTarget(this); - else if (NazaraRenderer->GetTarget() == this) - return NazaraRenderer->SetTarget(nullptr); + return NzRenderer::SetTarget(this); + else if (NzRenderer::GetTarget() == this) + return NzRenderer::SetTarget(nullptr); return true; } diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index 1af1c2174..46861f4eb 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -5,18 +5,13 @@ #include #include #include +#include #include #include #include #include -NzRenderWindow::NzRenderWindow() : -m_context(nullptr) -{ -} - -NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) : -m_context(nullptr) +NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) { Create(mode, title, style, parameters); @@ -29,8 +24,7 @@ m_context(nullptr) #endif } -NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) : -m_context(nullptr) +NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) { Create(handle, parameters); @@ -45,6 +39,8 @@ m_context(nullptr) NzRenderWindow::~NzRenderWindow() { + // Nécessaire si NzWindow::Destroy est appelé par son destructeur + OnWindowDestroying(); } bool NzRenderWindow::CopyToImage(NzImage* image) @@ -136,6 +132,15 @@ bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& pa void NzRenderWindow::Display() { + if (m_framerateLimit > 0) + { + int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds(); + if (remainingTime > 0) + NzThread::Sleep(remainingTime); + + m_clock.Restart(); + } + if (m_context && m_parameters.doubleBuffered) m_context->SwapBuffers(); } @@ -218,6 +223,11 @@ bool NzRenderWindow::IsValid() const return m_impl != nullptr && m_context != nullptr; } +void NzRenderWindow::SetFramerateLimit(unsigned int limit) +{ + m_framerateLimit = limit; +} + bool NzRenderWindow::Activate() { if (m_context->SetActive(true)) @@ -232,12 +242,16 @@ bool NzRenderWindow::Activate() } } -void NzRenderWindow::OnClose() +void NzRenderWindow::OnWindowDestroying() { - delete m_context; + if (m_context) + { + delete m_context; + m_context = nullptr; + } } -bool NzRenderWindow::OnCreate() +bool NzRenderWindow::OnWindowCreated() { m_parameters.doubleBuffered = true; m_parameters.window = GetHandle(); @@ -258,5 +272,7 @@ bool NzRenderWindow::OnCreate() NazaraWarning("Failed to activate window"); #endif + m_clock.Restart(); + return true; } diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index d5865277f..65e1aceee 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include namespace @@ -61,7 +63,6 @@ namespace GL_FILL // nzFaceFilling_Fill }; - const GLenum openglPrimitive[] = { GL_LINES, // nzPrimitiveType_LineList, @@ -131,28 +132,47 @@ namespace GL_ZERO // nzStencilOperation_Zero }; + ///FIXME: Solution temporaire pour plus de facilité + enum nzMatrixCombination + { + nzMatrixCombination_ViewProj = nzMatrixType_Max+1, + nzMatrixCombination_WorldView, + nzMatrixCombination_WorldViewProj, + + nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj + }; + NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type) { return new NzHardwareBuffer(parent, type); } -} -NzRenderer::NzRenderer() -{ - #if NAZARA_RENDERER_SAFE - if (s_instance) - throw std::runtime_error("Renderer already instanced"); - #endif + typedef std::tuple VAO_Key; - s_instance = this; -} + constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; -NzRenderer::~NzRenderer() -{ - if (s_initialized) - Uninitialize(); - - s_instance = nullptr; + std::map s_vaos; + NzMatrix4f s_matrix[totalMatrixCount]; + int s_matrixLocation[totalMatrixCount]; + bool s_matrixUpdated[totalMatrixCount]; + nzRendererComparison s_stencilCompare; + nzStencilOperation s_stencilFail; + nzStencilOperation s_stencilPass; + nzStencilOperation s_stencilZFail; + nzUInt32 s_stencilMask; + const NzIndexBuffer* s_indexBuffer; + NzRenderTarget* s_target; + NzShader* s_shader; + const NzVertexBuffer* s_vertexBuffer; + const NzVertexDeclaration* s_vertexDeclaration; + bool s_vaoUpdated; + bool s_capabilities[nzRendererCap_Max+1]; + bool s_stencilFuncUpdated; + bool s_stencilOpUpdated; + unsigned int s_maxAnisotropyLevel; + unsigned int s_maxRenderTarget; + unsigned int s_maxTextureUnit; + unsigned int s_stencilReference; } void NzRenderer::Clear(unsigned long flags) @@ -190,8 +210,10 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f NazaraError("No active context"); return; } + #endif - if (!m_indexBuffer) + #if NAZARA_RENDERER_SAFE + if (!s_indexBuffer) { NazaraError("No index buffer"); return; @@ -204,11 +226,11 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f return; } - if (m_indexBuffer->IsSequential()) - glDrawArrays(openglPrimitive[primitive], m_indexBuffer->GetStartIndex(), m_indexBuffer->GetIndexCount()); + if (s_indexBuffer->IsSequential()) + glDrawArrays(openglPrimitive[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount()); else { - nzUInt8 indexSize = m_indexBuffer->GetIndexSize(); + nzUInt8 indexSize = s_indexBuffer->GetIndexSize(); GLenum type; switch (indexSize) @@ -230,7 +252,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f return; } - glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast(m_indexBuffer->GetPointer()) + firstIndex*indexSize); + glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast(s_indexBuffer->GetPointer()) + firstIndex*indexSize); } } @@ -282,33 +304,70 @@ void NzRenderer::Enable(nzRendererParameter parameter, bool enable) break; } } - -unsigned int NzRenderer::GetMaxAnisotropyLevel() const +/* +NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination) { - return m_maxAnisotropyLevel; + switch (combination) + { + case nzMatrixCombination_ViewProj: + if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) + { + s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; + s_matrixUpdated[nzMatrixCombination_ViewProj] = true; + } + break; + + case nzMatrixCombination_WorldView: + if (!s_matrixUpdated[nzMatrixCombination_WorldView]) + { + s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); + s_matrixUpdated[nzMatrixCombination_WorldView] = true; + } + break; + + case nzMatrixCombination_WorldViewProj: + if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) + { + s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; + } + break; + } + + return m_matrix[combination]; +} +*/ +NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type) +{ + return s_matrix[type]; } -unsigned int NzRenderer::GetMaxRenderTargets() const +unsigned int NzRenderer::GetMaxAnisotropyLevel() { - return m_maxRenderTarget; + return s_maxAnisotropyLevel; } -unsigned int NzRenderer::GetMaxTextureUnits() const +unsigned int NzRenderer::GetMaxRenderTargets() { - return m_maxTextureUnit; + return s_maxRenderTarget; } -NzShader* NzRenderer::GetShader() const +unsigned int NzRenderer::GetMaxTextureUnits() { - return m_shader; + return s_maxTextureUnit; } -NzRenderTarget* NzRenderer::GetTarget() const +NzShader* NzRenderer::GetShader() { - return m_target; + return s_shader; } -NzRectui NzRenderer::GetViewport() const +NzRenderTarget* NzRenderer::GetTarget() +{ + return s_target; +} + +NzRectui NzRenderer::GetViewport() { #ifdef NAZARA_DEBUG if (NzContext::GetCurrent() == nullptr) @@ -324,103 +383,110 @@ NzRectui NzRenderer::GetViewport() const return NzRectui(params[0], params[1], params[2], params[3]); } -bool NzRenderer::HasCapability(nzRendererCap capability) const +bool NzRenderer::HasCapability(nzRendererCap capability) { - return m_capabilities[capability]; + return s_capabilities[capability]; } bool NzRenderer::Initialize() { - #if NAZARA_RENDERER_SAFE - if (s_initialized) + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation des dépendances + if (!NzUtility::Initialize()) { - NazaraError("Renderer already initialized"); - return true; - } - #endif - - // Initialisation du module Utility - if (!NzUtility::IsInitialized()) - { - m_utilityModule = new NzUtility; - m_utilityModule->Initialize(); - } - else - m_utilityModule = nullptr; - - if (NzOpenGL::Initialize()) - { - NzContext::EnsureContext(); - - m_indexBuffer = nullptr; - m_shader = nullptr; - m_stencilCompare = nzRendererComparison_Always; - m_stencilFail = nzStencilOperation_Keep; - m_stencilFuncUpdated = true; - m_stencilMask = 0xFFFFFFFF; - m_stencilOpUpdated = true; - m_stencilPass = nzStencilOperation_Keep; - m_stencilReference = 0; - m_stencilZFail = nzStencilOperation_Keep; - m_target = nullptr; - m_vaoUpdated = false; - m_vertexBuffer = nullptr; - m_vertexDeclaration = nullptr; - - // Récupération des capacités - m_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter); - m_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64); - m_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 - m_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0 - m_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 - m_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject); - m_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D); - m_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 - m_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 - m_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0 - - if (m_capabilities[nzRendererCap_AnisotropicFilter]) - { - GLint maxAnisotropy; - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); - - m_maxAnisotropyLevel = static_cast(maxAnisotropy); - } - else - m_maxAnisotropyLevel = 1; - - if (m_capabilities[nzRendererCap_MultipleRenderTargets]) - { - GLint maxDrawBuffers; - glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); - - m_maxRenderTarget = static_cast(maxDrawBuffers); - } - else - m_maxRenderTarget = 1; - - if (m_capabilities[nzRendererCap_TextureMulti]) - { - GLint maxTextureUnits; - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); - - GLint maxVertexAttribs; - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); - - // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) - m_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord])); - } - else - m_maxTextureUnit = 1; - - NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); - - s_initialized = true; - - return true; - } - else + NazaraError("Failed to initialize utility module"); return false; + } + + // Initialisation du module + if (!NzOpenGL::Initialize()) + { + NazaraError("Failed to initialize OpenGL"); + return false; + } + + NzContext::EnsureContext(); + + for (unsigned int i = 0; i < totalMatrixCount; ++i) + { + s_matrix[i].MakeIdentity(); + s_matrixLocation[i] = -1; + s_matrixUpdated[i] = false; + } + + s_indexBuffer = nullptr; + s_shader = nullptr; + s_stencilCompare = nzRendererComparison_Always; + s_stencilFail = nzStencilOperation_Keep; + s_stencilFuncUpdated = true; + s_stencilMask = 0xFFFFFFFF; + s_stencilOpUpdated = true; + s_stencilPass = nzStencilOperation_Keep; + s_stencilReference = 0; + s_stencilZFail = nzStencilOperation_Keep; + s_target = nullptr; + s_vaoUpdated = false; + s_vertexBuffer = nullptr; + s_vertexDeclaration = nullptr; + + // Récupération des capacités + s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter); + s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64); + s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 + s_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0 + s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 + s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject); + s_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D); + s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 + s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 + s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0 + + if (s_capabilities[nzRendererCap_AnisotropicFilter]) + { + GLint maxAnisotropy; + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); + + s_maxAnisotropyLevel = static_cast(maxAnisotropy); + } + else + s_maxAnisotropyLevel = 1; + + if (s_capabilities[nzRendererCap_MultipleRenderTargets]) + { + GLint maxDrawBuffers; + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); + + s_maxRenderTarget = static_cast(maxDrawBuffers); + } + else + s_maxRenderTarget = 1; + + if (s_capabilities[nzRendererCap_TextureMulti]) + { + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + + GLint maxVertexAttribs; + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); + + // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) + s_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord])); + } + else + s_maxTextureUnit = 1; + + NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); + + NazaraNotice("Initialized: Renderer module"); + + return true; +} + +bool NzRenderer::IsInitialized() +{ + return s_moduleReferenceCouter != 0; } void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest) @@ -524,22 +590,43 @@ bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer) } #endif - if (indexBuffer != m_indexBuffer) + if (s_indexBuffer != indexBuffer) { - m_indexBuffer = indexBuffer; - m_vaoUpdated = false; + s_indexBuffer = indexBuffer; + s_vaoUpdated = false; } return true; } +void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix) +{ + s_matrix[type] = matrix; + + // Cas particulier, la matrice projection doit être inversée sur l'axe Y à cause des conventions d'OpenGL + if (type == nzMatrixType_Projection) + s_matrix[type] *= NzMatrix4f::Scale(NzVector3f(1.f, -1.f, 1.f)); + + // Invalidation des combinaisons + switch (type) + { + case nzMatrixType_View: + case nzMatrixType_World: + s_matrixUpdated[nzMatrixCombination_WorldView] = false; + case nzMatrixType_Projection: + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false; + s_matrixUpdated[nzMatrixCombination_ViewProj] = false; + break; + } +} + bool NzRenderer::SetShader(NzShader* shader) { - if (shader == m_shader) + if (s_shader == shader) return true; - if (m_shader) - m_shader->m_impl->Unbind(); + if (s_shader) + s_shader->m_impl->Unbind(); if (shader) { @@ -547,7 +634,7 @@ bool NzRenderer::SetShader(NzShader* shader) if (!shader->IsCompiled()) { NazaraError("Shader is not compiled"); - m_shader = nullptr; + shader = nullptr; return false; } @@ -556,78 +643,87 @@ bool NzRenderer::SetShader(NzShader* shader) if (!shader->m_impl->Bind()) { NazaraError("Failed to bind shader"); - m_shader = nullptr; + shader = nullptr; return false; } + + // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) + s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix"); + s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix"); + s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix"); + + s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix"); + s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix"); + s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix"); } - m_shader = shader; + s_shader = shader; return true; } void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc) { - if (compareFunc != m_stencilCompare) + if (compareFunc != s_stencilCompare) { - m_stencilCompare = compareFunc; - m_stencilFuncUpdated = false; + s_stencilCompare = compareFunc; + s_stencilFuncUpdated = false; } } void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation) { - if (failOperation != m_stencilFail) + if (failOperation != s_stencilFail) { - m_stencilFail = failOperation; - m_stencilOpUpdated = false; + s_stencilFail = failOperation; + s_stencilOpUpdated = false; } } void NzRenderer::SetStencilMask(nzUInt32 mask) { - if (mask != m_stencilMask) + if (mask != s_stencilMask) { - m_stencilMask = mask; - m_stencilFuncUpdated = false; + s_stencilMask = mask; + s_stencilFuncUpdated = false; } } void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation) { - if (passOperation != m_stencilPass) + if (passOperation != s_stencilPass) { - m_stencilPass = passOperation; - m_stencilOpUpdated = false; + s_stencilPass = passOperation; + s_stencilOpUpdated = false; } } void NzRenderer::SetStencilReferenceValue(unsigned int refValue) { - if (refValue != m_stencilReference) + if (refValue != s_stencilReference) { - m_stencilReference = refValue; - m_stencilFuncUpdated = false; + s_stencilReference = refValue; + s_stencilFuncUpdated = false; } } void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation) { - if (zfailOperation != m_stencilZFail) + if (zfailOperation != s_stencilZFail) { - m_stencilZFail = zfailOperation; - m_stencilOpUpdated = false; + s_stencilZFail = zfailOperation; + s_stencilOpUpdated = false; } } bool NzRenderer::SetTarget(NzRenderTarget* target) { - if (target == m_target) + if (s_target == target) return true; - if (m_target && !m_target->HasContext()) - m_target->Desactivate(); + if (s_target && !target->HasContext()) + s_target->Desactivate(); if (target) { @@ -640,17 +736,17 @@ bool NzRenderer::SetTarget(NzRenderTarget* target) #endif if (target->Activate()) - m_target = target; + s_target = target; else { NazaraError("Failed to activate target"); - m_target = nullptr; + s_target = nullptr; return false; } } else - m_target = nullptr; + s_target = nullptr; return true; } @@ -665,10 +761,10 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) } #endif - if (m_vertexBuffer != vertexBuffer) + if (s_vertexBuffer != vertexBuffer) { - m_vertexBuffer = vertexBuffer; - m_vaoUpdated = false; + s_vertexBuffer = vertexBuffer; + s_vaoUpdated = false; } return true; @@ -676,10 +772,10 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration) { - if (m_vertexDeclaration != vertexDeclaration) + if (s_vertexDeclaration != vertexDeclaration) { - m_vertexDeclaration = vertexDeclaration; - m_vaoUpdated = false; + s_vertexDeclaration = vertexDeclaration; + s_vaoUpdated = false; } return true; @@ -695,16 +791,16 @@ void NzRenderer::SetViewport(const NzRectui& viewport) } #endif - unsigned int height = m_target->GetHeight(); + unsigned int height = s_target->GetHeight(); #if NAZARA_RENDERER_SAFE - if (!m_target) + if (!s_target) { NazaraError("Renderer has no target"); return; } - unsigned int width = m_target->GetWidth(); + unsigned int width = s_target->GetWidth(); if (viewport.x+viewport.width > width || viewport.y+viewport.height > height) { NazaraError("Rectangle dimensions are out of bounds"); @@ -718,20 +814,14 @@ void NzRenderer::SetViewport(const NzRectui& viewport) void NzRenderer::Uninitialize() { - #if NAZARA_RENDERER_SAFE - if (!s_initialized) - { - NazaraError("Renderer not initialized"); - return; - } - #endif + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé + // Libération du module NzContext::EnsureContext(); - s_initialized = false; - // Libération des VAOs - for (auto it = m_vaos.begin(); it != m_vaos.end(); ++it) + for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it) { GLuint vao = static_cast(it->second); glDeleteVertexArrays(1, &vao); @@ -739,26 +829,10 @@ void NzRenderer::Uninitialize() NzOpenGL::Uninitialize(); - if (m_utilityModule) - { - delete m_utilityModule; - m_utilityModule = nullptr; - } -} + NazaraNotice("Uninitialized: Renderer module"); -NzRenderer* NzRenderer::Instance() -{ - #if defined(NAZARA_DEBUG) - if (!s_instance) - NazaraError("Renderer not instanced"); - #endif - - return s_instance; -} - -bool NzRenderer::IsInitialized() -{ - return s_initialized; + // Libération des dépendances + NzUtility::Uninitialize(); } bool NzRenderer::EnsureStateUpdate() @@ -771,28 +845,76 @@ bool NzRenderer::EnsureStateUpdate() } #endif - if (!m_stencilFuncUpdated) + #if NAZARA_RENDERER_SAFE + if (!s_shader) { - glStencilFunc(rendererComparison[m_stencilCompare], m_stencilReference, m_stencilMask); - m_stencilFuncUpdated = true; + NazaraError("No shader"); + return false; + } + #endif + + // Il est plus rapide d'opérer sur l'implémentation du shader directement + NzShaderImpl* shaderImpl = s_shader->m_impl; + + if (!shaderImpl->BindTextures()) + NazaraWarning("Failed to bind textures"); + + for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) + { + if (!s_matrixUpdated[i]) + { + shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]); + s_matrixUpdated[i] = true; + } } - if (!m_stencilOpUpdated) + // Cas spéciaux car il faut recalculer la matrice + if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) { - glStencilOp(stencilOperation[m_stencilFail], stencilOperation[m_stencilZFail], stencilOperation[m_stencilPass]); - m_stencilOpUpdated = true; + s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]); + s_matrixUpdated[nzMatrixCombination_ViewProj] = true; } - if (!m_vaoUpdated) + if (!s_matrixUpdated[nzMatrixCombination_WorldView]) + { + s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]); + s_matrixUpdated[nzMatrixCombination_WorldView] = true; + } + + if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) + { + s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]); + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; + } + + if (!s_stencilFuncUpdated) + { + glStencilFunc(rendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask); + s_stencilFuncUpdated = true; + } + + if (!s_stencilOpUpdated) + { + glStencilOp(stencilOperation[s_stencilFail], stencilOperation[s_stencilZFail], stencilOperation[s_stencilPass]); + s_stencilOpUpdated = true; + } + + if (!s_vaoUpdated) { #if NAZARA_RENDERER_SAFE - if (!m_vertexBuffer) + if (!s_vertexBuffer) { NazaraError("No vertex buffer"); return false; } - if (!m_vertexDeclaration) + if (!s_vertexDeclaration) { NazaraError("No vertex declaration"); return false; @@ -809,16 +931,16 @@ bool NzRenderer::EnsureStateUpdate() // On recherche si un VAO existe déjà avec notre configuration // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration - auto key = std::make_tuple(NzContext::GetCurrent(), m_indexBuffer, m_vertexBuffer, m_vertexDeclaration); - auto it = m_vaos.find(key); - if (it == m_vaos.end()) + auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration); + auto it = s_vaos.find(key); + if (it == s_vaos.end()) { // On créé notre VAO glGenVertexArrays(1, &vao); glBindVertexArray(vao); // On l'ajoute à notre liste - m_vaos.insert(std::make_pair(key, static_cast(vao))); + s_vaos.insert(std::make_pair(key, static_cast(vao))); // Et on indique qu'on veut le programmer update = true; @@ -836,15 +958,15 @@ bool NzRenderer::EnsureStateUpdate() if (update) { - NzHardwareBuffer* vertexBuffer = static_cast(m_vertexBuffer->GetBuffer()->GetImpl()); - vertexBuffer->Bind(); + NzHardwareBuffer* vertexBufferImpl = static_cast(s_vertexBuffer->GetBuffer()->GetImpl()); + vertexBufferImpl->Bind(); - const nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->GetPointer()); + const nzUInt8* buffer = reinterpret_cast(s_vertexBuffer->GetPointer()); - unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData); + unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData); for (unsigned int i = 0; i <= nzElementUsage_Max; ++i) { - const NzVertexElement* element = m_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast(i)); + const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast(i)); if (element) { @@ -860,10 +982,10 @@ bool NzRenderer::EnsureStateUpdate() glDisableVertexAttribArray(attribIndex[i]); } - if (m_indexBuffer) + if (s_indexBuffer) { - NzHardwareBuffer* indexBuffer = static_cast(m_indexBuffer->GetBuffer()->GetImpl()); - indexBuffer->Bind(); + NzHardwareBuffer* indexBufferImpl = static_cast(s_indexBuffer->GetBuffer()->GetImpl()); + indexBufferImpl->Bind(); } } @@ -877,11 +999,10 @@ bool NzRenderer::EnsureStateUpdate() glBindVertexArray(vao); } - m_vaoUpdated = true; + s_vaoUpdated = true; } return true; } -NzRenderer* NzRenderer::s_instance = nullptr; -bool NzRenderer::s_initialized = false; +unsigned int NzRenderer::s_moduleReferenceCouter = 0; diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index f3e635089..ec12ee1d1 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -161,6 +161,32 @@ NzString NzShader::GetSourceCode(nzShaderType type) const return m_impl->GetSourceCode(type); } +int NzShader::GetUniformLocation(const NzString& name) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->GetUniformLocation(name); +} + +bool NzShader::HasUniform(const NzString& name) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->GetUniformLocation(name) != -1; +} + bool NzShader::IsCompiled() const { #if NAZARA_RENDERER_SAFE @@ -282,7 +308,7 @@ bool NzShader::Lock() return m_impl->Lock(); } -bool NzShader::SendBoolean(const NzString& name, bool value) +bool NzShader::SendBoolean(int location, bool value) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -290,57 +316,43 @@ bool NzShader::SendBoolean(const NzString& name, bool value) NazaraError("Shader not created"); return false; } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } #endif - return m_impl->SendBoolean(name, value); + return m_impl->SendBoolean(location, value); } -bool NzShader::SendDouble(const NzString& name, double value) +bool NzShader::SendDouble(int location, double value) { #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!NazaraRenderer->HasCapability(nzRendererCap_FP64)) + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) { NazaraError("FP64 is not supported"); return false; } - #endif - return m_impl->SendDouble(name, value); -} - -bool NzShader::SendFloat(const NzString& name, float value) -{ - #if NAZARA_RENDERER_SAFE if (!m_impl) { NazaraError("Shader not created"); return false; } - #endif - return m_impl->SendFloat(name, value); -} - -bool NzShader::SendInteger(const NzString& name, int value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) + if (location == -1) { - NazaraError("Shader not created"); + NazaraError("Invalid location"); return false; } #endif - return m_impl->SendInteger(name, value); + return m_impl->SendDouble(location, value); } -bool NzShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix) +bool NzShader::SendFloat(int location, float value) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -349,30 +361,61 @@ bool NzShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix) return false; } - if (!NazaraRenderer->HasCapability(nzRendererCap_FP64)) + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendFloat(location, value); +} + +bool NzShader::SendInteger(int location, int value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendInteger(location, value); +} + +bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) { NazaraError("FP64 is not supported"); return false; } - #endif - return m_impl->SendMatrix(name, matrix); -} - -bool NzShader::SendMatrix(const NzString& name, const NzMatrix4f& matrix) -{ - #if NAZARA_RENDERER_SAFE if (!m_impl) { NazaraError("Shader not created"); return false; } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } #endif - return m_impl->SendMatrix(name, matrix); + return m_impl->SendMatrix(location, matrix); } -bool NzShader::SendVector(const NzString& name, const NzVector2d& vector) +bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -381,30 +424,61 @@ bool NzShader::SendVector(const NzString& name, const NzVector2d& vector) return false; } - if (!NazaraRenderer->HasCapability(nzRendererCap_FP64)) + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendMatrix(location, matrix); +} + +bool NzShader::SendTexture(int location, const NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendTexture(location, texture); +} + +bool NzShader::SendVector(int location, const NzVector2d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) { NazaraError("FP64 is not supported"); return false; } - #endif - return m_impl->SendVector(name, vector); -} - -bool NzShader::SendVector(const NzString& name, const NzVector2f& vector) -{ - #if NAZARA_RENDERER_SAFE if (!m_impl) { NazaraError("Shader not created"); return false; } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } #endif - return m_impl->SendVector(name, vector); + return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(const NzString& name, const NzVector3d& vector) +bool NzShader::SendVector(int location, const NzVector2f& vector) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -413,30 +487,42 @@ bool NzShader::SendVector(const NzString& name, const NzVector3d& vector) return false; } - if (!NazaraRenderer->HasCapability(nzRendererCap_FP64)) + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector3d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) { NazaraError("FP64 is not supported"); return false; } - #endif - return m_impl->SendVector(name, vector); -} - -bool NzShader::SendVector(const NzString& name, const NzVector3f& vector) -{ - #if NAZARA_RENDERER_SAFE if (!m_impl) { NazaraError("Shader not created"); return false; } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } #endif - return m_impl->SendVector(name, vector); + return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(const NzString& name, const NzVector4d& vector) +bool NzShader::SendVector(int location, const NzVector3f& vector) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -445,17 +531,42 @@ bool NzShader::SendVector(const NzString& name, const NzVector4d& vector) return false; } - if (!NazaraRenderer->HasCapability(nzRendererCap_FP64)) + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector4d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) { NazaraError("FP64 is not supported"); return false; } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } #endif - return m_impl->SendVector(name, vector); + return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(const NzString& name, const NzVector4f& vector) +bool NzShader::SendVector(int location, const NzVector4f& vector) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -463,22 +574,15 @@ bool NzShader::SendVector(const NzString& name, const NzVector4f& vector) NazaraError("Shader not created"); return false; } - #endif - return m_impl->SendVector(name, vector); -} - -bool NzShader::SendTexture(const NzString& name, NzTexture* texture) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) + if (location == -1) { - NazaraError("Shader not created"); + NazaraError("Invalid location"); return false; } #endif - return m_impl->SendTexture(name, texture); + return m_impl->SendVector(location, vector); } void NzShader::Unlock() diff --git a/src/Nazara/Renderer/ShaderImpl.hpp b/src/Nazara/Renderer/ShaderImpl.hpp index 504f59853..94916904f 100644 --- a/src/Nazara/Renderer/ShaderImpl.hpp +++ b/src/Nazara/Renderer/ShaderImpl.hpp @@ -23,6 +23,7 @@ class NzShaderImpl virtual ~NzShaderImpl(); virtual bool Bind() = 0; + virtual bool BindTextures() = 0; virtual bool Compile() = 0; virtual bool Create() = 0; @@ -32,6 +33,7 @@ class NzShaderImpl virtual NzString GetLog() const = 0; virtual nzShaderLanguage GetLanguage() const = 0; virtual NzString GetSourceCode(nzShaderType type) const = 0; + virtual int GetUniformLocation(const NzString& name) const = 0; virtual bool IsLoaded(nzShaderType type) const = 0; @@ -39,19 +41,19 @@ class NzShaderImpl virtual bool Lock() = 0; - virtual bool SendBoolean(const NzString& name, bool value) = 0; - virtual bool SendDouble(const NzString& name, double value) = 0; - virtual bool SendFloat(const NzString& name, float value) = 0; - virtual bool SendInteger(const NzString& name, int value) = 0; - virtual bool SendMatrix(const NzString& name, const NzMatrix4d& matrix) = 0; - virtual bool SendMatrix(const NzString& name, const NzMatrix4f& matrix) = 0; - virtual bool SendVector(const NzString& name, const NzVector2d& vector) = 0; - virtual bool SendVector(const NzString& name, const NzVector2f& vector) = 0; - virtual bool SendVector(const NzString& name, const NzVector3d& vector) = 0; - virtual bool SendVector(const NzString& name, const NzVector3f& vector) = 0; - virtual bool SendVector(const NzString& name, const NzVector4d& vector) = 0; - virtual bool SendVector(const NzString& name, const NzVector4f& vector) = 0; - virtual bool SendTexture(const NzString& name, NzTexture* texture) = 0; + virtual bool SendBoolean(int location, bool value) = 0; + virtual bool SendDouble(int location, double value) = 0; + virtual bool SendFloat(int location, float value) = 0; + virtual bool SendInteger(int location, int value) = 0; + virtual bool SendMatrix(int location, const NzMatrix4d& matrix) = 0; + virtual bool SendMatrix(int location, const NzMatrix4f& matrix) = 0; + virtual bool SendTexture(int location, const NzTexture* texture) = 0; + virtual bool SendVector(int location, const NzVector2d& vector) = 0; + virtual bool SendVector(int location, const NzVector2f& vector) = 0; + virtual bool SendVector(int location, const NzVector3d& vector) = 0; + virtual bool SendVector(int location, const NzVector3f& vector) = 0; + virtual bool SendVector(int location, const NzVector4d& vector) = 0; + virtual bool SendVector(int location, const NzVector4f& vector) = 0; virtual void Unbind() = 0; virtual void Unlock() = 0; diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index abd54b992..cfe154a33 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -39,18 +39,31 @@ namespace GLenum openglTarget[] = { - GL_TEXTURE_1D, // nzImageType_1D - GL_TEXTURE_2D, // nzImageType_2D - GL_TEXTURE_3D, // nzImageType_3D - GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap + GL_TEXTURE_1D, // nzImageType_1D + GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array + GL_TEXTURE_2D, // nzImageType_2D + GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array + GL_TEXTURE_3D, // nzImageType_3D + GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap }; GLenum openglTargetBinding[] = { - GL_TEXTURE_BINDING_1D, // nzImageType_1D - GL_TEXTURE_BINDING_2D, // nzImageType_2D - GL_TEXTURE_BINDING_3D, // nzImageType_3D - GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap + GL_TEXTURE_BINDING_1D, // nzImageType_1D + GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D + GL_TEXTURE_BINDING_2D, // nzImageType_2D + GL_TEXTURE_BINDING_3D, // nzImageType_3D + GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap + }; + + GLenum openglTargetProxy[] = + { + GL_PROXY_TEXTURE_1D, // nzImageType_1D + GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array + GL_PROXY_TEXTURE_2D, // nzImageType_2D + GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array + GL_PROXY_TEXTURE_3D, // nzImageType_3D + GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap }; struct OpenGLFormat @@ -142,16 +155,16 @@ namespace return false; } - GLenum target; + GLenum target = (proxy) ? openglTargetProxy[impl->type] : openglTarget[impl->type]; + GLint previous; + glGetIntegerv(openglTargetBinding[impl->type], &previous); switch (impl->type) { case nzImageType_1D: { - target = (proxy) ? GL_TEXTURE_1D : GL_PROXY_TEXTURE_1D; - - /*if (glTexStorage1D) + if (glTexStorage1D) glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width); - else*/ + else { unsigned int w = impl->width; for (nzUInt8 level = 0; level < impl->levelCount; ++level) @@ -164,13 +177,12 @@ namespace break; } + case nzImageType_1D_Array: case nzImageType_2D: { - target = (proxy) ? GL_TEXTURE_2D : GL_PROXY_TEXTURE_2D; - - /*if (glTexStorage2D) + if (glTexStorage2D) glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); - else*/ + else { unsigned int w = impl->width; unsigned int h = impl->height; @@ -187,13 +199,12 @@ namespace break; } + case nzImageType_2D_Array: case nzImageType_3D: { - target = (proxy) ? GL_TEXTURE_3D : GL_PROXY_TEXTURE_3D; - - /*if (glTexStorage3D) + if (glTexStorage3D) glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth); - else*/ + else { unsigned int w = impl->width; unsigned int h = impl->height; @@ -216,11 +227,9 @@ namespace case nzImageType_Cubemap: { - target = (proxy) ? GL_TEXTURE_CUBE_MAP : GL_PROXY_TEXTURE_CUBE_MAP; - - /*if (glTexStorage2D) + if (glTexStorage2D) glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); - else*/ + else { unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique for (nzUInt8 level = 0; level < impl->levelCount; ++level) @@ -234,15 +243,11 @@ namespace } break; } - - default: - NazaraInternalError("Image type not handled"); - return false; } if (proxy) { - GLint internalFormat; + GLint internalFormat = 0; glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); if (internalFormat == 0) return false; @@ -400,6 +405,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt } break; + case nzImageType_1D_Array: case nzImageType_2D: if (depth > 1) { @@ -408,6 +414,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt } break; + case nzImageType_2D_Array: case nzImageType_3D: break; @@ -424,10 +431,6 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt return false; } break; - - default: - NazaraInternalError("Image type not handled"); - return false; } #endif @@ -454,7 +457,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt LockTexture(impl); // Vérification du support par la carte graphique - if (!CreateTexture(impl, true)) + /*if (!CreateTexture(impl, true)) { NazaraError("Texture's parameters not supported by driver"); UnlockTexture(impl); @@ -462,7 +465,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt delete impl; return false; - } + }*/ // Création de la texture if (!CreateTexture(impl, false)) @@ -603,16 +606,13 @@ unsigned int NzTexture::GetAnisotropyLevel() const if (!IsValid()) { NazaraError("Texture must be valid"); - return 1; - } - - if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter)) - { - NazaraError("Anisotropic filter not supported"); - return 1; + return 0; } #endif + if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter)) + return 1; + LockTexture(m_impl); GLint anisotropyLevel; @@ -937,7 +937,7 @@ bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) } #endif - if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter)) + if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter) && anistropyLevel > 1) { NazaraError("Anisotropic filter not supported"); return false; @@ -1070,9 +1070,11 @@ bool NzTexture::SetWrapMode(nzTextureWrap wrap) case nzImageType_3D: glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode); case nzImageType_2D: + case nzImageType_2D_Array: case nzImageType_Cubemap: glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode); case nzImageType_1D: + case nzImageType_1D_Array: glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode); break; @@ -1180,7 +1182,7 @@ bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) } #endif - if (m_impl->type == nzImageType_3D) + if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array) return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level); else return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level); @@ -1268,16 +1270,19 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels()); break; + case nzImageType_1D_Array: case nzImageType_2D: - glTexSubImage2D(GL_TEXTURE_2D, level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + glTexSubImage2D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels()); break; + case nzImageType_2D_Array: case nzImageType_3D: - glTexSubImage3D(GL_TEXTURE_3D, level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + glTexSubImage3D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels()); break; - default: - NazaraInternalError("Image type not handled (0x" + NzString::Number(m_impl->type, 16) + ')'); + case nzImageType_Cubemap: + NazaraError("Update used on a cubemap texture, please enable safe mode"); + break; } UnlockTexture(m_impl); @@ -1363,16 +1368,19 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 leve glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored); break; + case nzImageType_1D_Array: case nzImageType_2D: - glTexSubImage2D(GL_TEXTURE_2D, level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored); + glTexSubImage2D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored); break; + case nzImageType_2D_Array: case nzImageType_3D: - glTexSubImage3D(GL_TEXTURE_3D, level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored); + glTexSubImage3D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored); break; - default: - NazaraInternalError("Image type not handled (0x" + NzString::Number(m_impl->type, 16) + ')'); + case nzImageType_Cubemap: + NazaraError("Update used on a cubemap texture, please enable safe mode"); + break; } UnlockTexture(m_impl); @@ -1531,7 +1539,7 @@ void NzTexture::Unlock() unsigned int NzTexture::GetValidSize(unsigned int size) { - if (NazaraRenderer->HasCapability(nzRendererCap_TextureNPOT)) + if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT)) return size; else { @@ -1596,9 +1604,16 @@ bool NzTexture::IsTypeSupported(nzImageType type) case nzImageType_Cubemap: return true; // Tous supportés nativement dans OpenGL 2 - default: - return false; + case nzImageType_1D_Array: + case nzImageType_2D_Array: + { + static bool supported = NzOpenGL::IsSupported(NzOpenGL::TextureArray); + return supported; + } } + + NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); + return false; } void NzTexture::SetTarget(bool isTarget) diff --git a/src/Nazara/Utility/AxisAlignedBox.cpp b/src/Nazara/Utility/AxisAlignedBox.cpp new file mode 100644 index 000000000..81b76cbb6 --- /dev/null +++ b/src/Nazara/Utility/AxisAlignedBox.cpp @@ -0,0 +1,162 @@ +// Copyright (C) 2011 Jérôme Leclercq +// This file is part of the "Ungine". +// For conditions of distribution and use, see copyright notice in Core.h + +#include +#include +#include + +NzAxisAlignedBox::NzAxisAlignedBox() : +m_extend(nzExtend_Null) +{ +} + +NzAxisAlignedBox::NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2) : +m_extend(nzExtend_Finite), +m_cube(vec1, vec2) +{ +} + +NzAxisAlignedBox::NzAxisAlignedBox(nzExtend extend) : +m_extend(extend) +{ +} + +bool NzAxisAlignedBox::Contains(const NzAxisAlignedBox& box) +{ + if (m_extend == nzExtend_Null || box.m_extend == nzExtend_Null) + return false; + else if (m_extend == nzExtend_Infinite || box.m_extend == nzExtend_Infinite) + return true; + + return m_cube.Contains(box.m_cube); +} + +void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box) +{ + switch (m_extend) + { + case nzExtend_Finite: + { + switch (box.m_extend) + { + case nzExtend_Finite: + m_cube.ExtendTo(box.m_cube); + break; + + case nzExtend_Infinite: + SetInfinite(); + break; + + case nzExtend_Null: + break; + + break; + } + + case nzExtend_Infinite: + // Rien à faire + break; + + case nzExtend_Null: + operator=(box); + break; + } + } +} + +void NzAxisAlignedBox::ExtendTo(const NzVector3f& vector) +{ + switch (m_extend) + { + case nzExtend_Finite: + m_cube.ExtendTo(vector); + break; + + case nzExtend_Infinite: + // Rien à faire + break; + + case nzExtend_Null: + // Nous étendons l'AABB en la construisant de l'origine jusqu'au vecteur + m_cube.x = 0.f; + m_cube.y = 0.f; + m_cube.z = 0.f; + m_cube.width = std::fabs(vector.x); + m_cube.height = std::fabs(vector.y); + m_cube.depth = std::fabs(vector.z); + break; + } +} + +nzExtend NzAxisAlignedBox::GetExtend() const +{ + return m_extend; +} + +NzVector3f NzAxisAlignedBox::GetMaximum() const +{ + return NzVector3f(m_cube.x+m_cube.width, m_cube.y+m_cube.height, m_cube.z+m_cube.depth); +} + +NzVector3f NzAxisAlignedBox::GetMinimum() const +{ + return NzVector3f(m_cube.x, m_cube.y, m_cube.z); +} + +bool NzAxisAlignedBox::IsFinite() const +{ + return m_extend == nzExtend_Finite; +} + +bool NzAxisAlignedBox::IsInfinite() const +{ + return m_extend == nzExtend_Infinite; +} + +bool NzAxisAlignedBox::IsNull() const +{ + return m_extend == nzExtend_Null; +} + +void NzAxisAlignedBox::SetInfinite() +{ + m_extend = nzExtend_Infinite; +} + +void NzAxisAlignedBox::SetExtends(const NzVector3f& vec1, const NzVector3f& vec2) +{ + m_extend = nzExtend_Finite; + m_cube.Set(vec1, vec2); +} + +void NzAxisAlignedBox::SetNull() +{ + m_extend = nzExtend_Null; +} + +NzString NzAxisAlignedBox::ToString() const +{ + switch (m_extend) + { + case nzExtend_Finite: + return "NzAxisAlignedBox(min=" + GetMinimum().ToString() + ", max=" + GetMaximum().ToString() + ')'; + + case nzExtend_Infinite: + return "NzAxisAlignedBox(Infinite)"; + + case nzExtend_Null: + return "NzAxisAlignedBox(Null)"; + } + + return "NzAxisAlignedBox(ERROR)"; +} + +const NzAxisAlignedBox NzAxisAlignedBox::Infinite(nzExtend_Infinite); +const NzAxisAlignedBox NzAxisAlignedBox::Null(nzExtend_Null); + +std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb) +{ + out << aabb.ToString(); + return out; +} diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index 0f35946aa..c537aeb03 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -290,9 +290,10 @@ bool NzBuffer::SetStorage(nzBufferStorage storage) m_impl->Unmap(); m_impl->Destroy(); - delete m_impl; + delete m_impl; m_impl = impl; + m_storage = storage; return true; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 662d59238..79d4d16d9 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -17,7 +17,7 @@ namespace inline nzUInt8* GetPixelPtr(nzUInt8* base, nzUInt8 bpp, unsigned int x, unsigned int y, unsigned int z, unsigned int width, unsigned int height) { - return &base[(width*(height*z+y) + x) * bpp]; + return &base[(width*(height*z + y) + x)*bpp]; } } @@ -43,7 +43,7 @@ m_sharedImage(image.m_sharedImage) } } -NzImage::NzImage(NzImage&& image) : +NzImage::NzImage(NzImage&& image) noexcept : m_sharedImage(image.m_sharedImage) { image.m_sharedImage = &emptyImage; @@ -95,14 +95,15 @@ bool NzImage::Convert(nzPixelFormat format) unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format); unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format); - levels[i] = ptr; - for (unsigned int d = 0; d < depth; ++d) { if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr)) { NazaraError("Failed to convert image"); - for (unsigned int j = 0; j <= i; ++j) + + // Nettoyage de la mémoire + delete[] ptr; // Permet une optimisation de boucle (GCC) + for (unsigned int j = 0; j < i; ++j) delete[] levels[j]; delete[] levels; @@ -114,6 +115,8 @@ bool NzImage::Convert(nzPixelFormat format) ptr += dstStride; } + levels[i] = ptr; + if (width > 1) width >>= 1; @@ -223,6 +226,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, } break; + case nzImageType_1D_Array: case nzImageType_2D: if (depth > 1) { @@ -231,6 +235,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, } break; + case nzImageType_2D_Array: case nzImageType_3D: break; @@ -281,7 +286,10 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, catch (const std::exception& e) { NazaraError("Failed to allocate image's level " + NzString::Number(i) + " (" + NzString(e.what()) + ')'); - for (unsigned int j = 0; j <= i; ++j) + + // Nettoyage + delete[] levels[i]; // Permet une optimisation de boucle (GCC) + for (unsigned int j = 0; j < i; ++j) delete[] levels[j]; delete[] levels; @@ -302,7 +310,7 @@ void NzImage::Destroy() bool NzImage::Fill(const NzColor& color) { - #if NAZARA_RENDERER_SAFE + #if NAZARA_UTILITY_SAFE if (!IsValid()) { NazaraError("Image must be valid"); @@ -399,6 +407,7 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) return false; } + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, rect.x, rect.y, z, m_sharedImage->width, m_sharedImage->height); unsigned int srcStride = rect.width * bpp; unsigned int dstStride = m_sharedImage->width * bpp; @@ -415,6 +424,8 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) dstPixels += dstStride; } + delete[] pixels; + return true; } @@ -452,6 +463,7 @@ bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) return false; } + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height); unsigned int srcStride = cube.width * bpp; unsigned int dstStride = m_sharedImage->width * bpp; @@ -562,7 +574,7 @@ nzUInt8 NzImage::GetBPP() const return NzPixelFormat::GetBPP(m_sharedImage->format); } -const nzUInt8* NzImage::GetConstPixels(nzUInt8 level, unsigned int x, unsigned int y, unsigned int z) const +const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const { #if NAZARA_UTILITY_SAFE if (!IsValid()) @@ -571,12 +583,6 @@ const nzUInt8* NzImage::GetConstPixels(nzUInt8 level, unsigned int x, unsigned i return nullptr; } - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return nullptr; - } - if (x >= m_sharedImage->width) { NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); @@ -595,6 +601,12 @@ const nzUInt8* NzImage::GetConstPixels(nzUInt8 level, unsigned int x, unsigned i NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); return nullptr; } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return nullptr; + } #endif return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); @@ -685,7 +697,7 @@ NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) c return color; } -nzUInt8* NzImage::GetPixels(nzUInt8 level, unsigned int x, unsigned int y, unsigned int z) +nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) { #if NAZARA_UTILITY_SAFE if (!IsValid()) @@ -694,12 +706,6 @@ nzUInt8* NzImage::GetPixels(nzUInt8 level, unsigned int x, unsigned int y, unsig return nullptr; } - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return nullptr; - } - if (x >= m_sharedImage->width) { NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); @@ -718,6 +724,13 @@ nzUInt8* NzImage::GetPixels(nzUInt8 level, unsigned int x, unsigned int y, unsig NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); return nullptr; } + + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return nullptr; + } #endif EnsureOwnership(); @@ -1077,7 +1090,7 @@ NzImage& NzImage::operator=(const NzImage& image) return *this; } -NzImage& NzImage::operator=(NzImage&& image) +NzImage& NzImage::operator=(NzImage&& image) noexcept { std::swap(m_sharedImage, image.m_sharedImage); @@ -1086,11 +1099,11 @@ NzImage& NzImage::operator=(NzImage&& image) nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth) { - static const float l2 = std::log(2); + static const float l2 = std::log(2.f); - unsigned int widthLevel = std::log(width)/l2; - unsigned int heightLevel = std::log(height)/l2; - unsigned int depthLevel = std::log(depth)/l2; + unsigned int widthLevel = std::log(static_cast(width))/l2; + unsigned int heightLevel = std::log(static_cast(height))/l2; + unsigned int depthLevel = std::log(static_cast(depth))/l2; return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); } diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index b625ede27..cd9fc862b 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -48,7 +48,7 @@ namespace } // Les fichiers MD2 sont en little endian - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) NzByteSwap(&header.ident, sizeof(nzUInt32)); #endif @@ -58,7 +58,7 @@ namespace return false; } - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) NzByteSwap(&header.version, sizeof(nzUInt32)); #endif @@ -68,7 +68,7 @@ namespace return false; } - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) NzByteSwap(&header.skinwidth, sizeof(nzUInt32)); NzByteSwap(&header.skinheight, sizeof(nzUInt32)); NzByteSwap(&header.framesize, sizeof(nzUInt32)); @@ -129,6 +129,7 @@ namespace NzAnimation* animation = new NzAnimation; if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1)) { + // Décodage des séquences NzString frameName; NzSequence sequence; @@ -154,7 +155,7 @@ namespace stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name)); stream.Read(name, 16*sizeof(char)); - int pos = std::strlen(name)-1; + pos = std::strlen(name)-1; for (unsigned int j = 0; j < 2; ++j) { if (!std::isdigit(name[pos])) @@ -217,7 +218,7 @@ namespace const md2_header* header = reinterpret_cast(data); - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) nzUInt32 ident = header->ident; nzUInt32 version = header->version; @@ -238,7 +239,7 @@ namespace if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) return false; - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) NzByteSwap(&magic[0], sizeof(nzUInt32)); NzByteSwap(&magic[1], sizeof(nzUInt32)); #endif diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp index 184bb868f..1accab406 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp @@ -41,7 +41,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz stream.SetCursorPos(header.offset_st); stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord)); - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) for (unsigned int i = 0; i < header.num_st; ++i) { NzByteSwap(&texCoords[i].u, sizeof(nzInt16)); @@ -52,7 +52,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz stream.SetCursorPos(header.offset_tris); stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle)); - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) for (unsigned int i = 0; i < header.num_tris; ++i) { NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16)); @@ -72,9 +72,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz frame.vertices.resize(header.num_vertices); // Pour que le modèle soit correctement aligné, on génère une matrice de rotation que nous appliquerons à chacune des vertices - NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, 0.f, -90.f)); - //NzMatrix4f rotationMatrix; - //rotationMatrix.SetIdentity(); + NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(90.f, -90.f, 0.f)); unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); @@ -86,7 +84,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz stream.Read(&frame.name, 16*sizeof(char)); stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex)); - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) NzByteSwap(&frame.scale.x, sizeof(float)); NzByteSwap(&frame.scale.y, sizeof(float)); NzByteSwap(&frame.scale.z, sizeof(float)); @@ -98,6 +96,8 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice de la normale plutôt que la normale (gain d'espace) m_frames[i].vertices = new NzVector3f[m_vertexCount]; + + NzVector3f max, min; for (unsigned int t = 0; t < header.num_tris; ++t) { for (unsigned int v = 0; v < 3; ++v) @@ -105,17 +105,19 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]]; NzVector3f vertex = rotationMatrix * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z); + max.MakeCeil(vertex); + min.MakeFloor(vertex); m_frames[i].normal[t*3+v] = vert.n; m_frames[i].vertices[t*3+v] = vertex; } } + + m_frames[i].aabb.SetExtends(min, max); } - nzBufferStorage storage = (NzBuffer::IsSupported(nzBufferStorage_Hardware) && !parameters.forceSoftware) ? nzBufferStorage_Hardware : nzBufferStorage_Software; - m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant - m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), storage, nzBufferUsage_Dynamic); + m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic); nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); if (!ptr) @@ -185,6 +187,11 @@ void NzMD2Mesh::Destroy() } } +const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const +{ + return m_aabb; +} + nzAnimationType NzMD2Mesh::GetAnimationType() const { if (m_frameCount > 1) @@ -262,14 +269,19 @@ void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float inte NzVector3f* position = reinterpret_cast(ptr + positionOffset); NzVector3f* normal = reinterpret_cast(ptr + normalOffset); - *position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]); - *normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]); + *position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]); + *normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]); ptr += stride; } if (!m_vertexBuffer->Unmap()) NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption"); + + // Interpolation de l'AABB + NzVector3f max1 = fA->aabb.GetMaximum(); + NzVector3f min1 = fA->aabb.GetMinimum(); + m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1)); } NzVertexDeclaration NzMD2Mesh::s_declaration; diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.hpp b/src/Nazara/Utility/Loaders/MD2/Mesh.hpp index 5b0b47efd..baa5cc9a8 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.hpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.hpp @@ -27,6 +27,7 @@ class NAZARA_API NzMD2Mesh : public NzKeyframeMesh bool Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters); void Destroy(); + const NzAxisAlignedBox& GetAABB() const; nzAnimationType GetAnimationType() const; unsigned int GetFrameCount() const; const NzIndexBuffer* GetIndexBuffer() const; @@ -44,14 +45,14 @@ class NAZARA_API NzMD2Mesh : public NzKeyframeMesh struct Frame { - //AxisAlignedBox aabb; + NzAxisAlignedBox aabb; nzUInt8* normal; NzVector3f* tangents; NzVector3f* vertices; char name[16]; }; - //AxisAlignedBox m_aabb; + NzAxisAlignedBox m_aabb; Frame* m_frames; NzIndexBuffer* m_indexBuffer; NzVertexBuffer* m_vertexBuffer; diff --git a/src/Nazara/Utility/Loaders/PCX/Loader.cpp b/src/Nazara/Utility/Loaders/PCX/Loader.cpp index fd30498cd..abf21a8a7 100644 --- a/src/Nazara/Utility/Loaders/PCX/Loader.cpp +++ b/src/Nazara/Utility/Loaders/PCX/Loader.cpp @@ -74,7 +74,7 @@ namespace return false; } - #if NAZARA_BIG_ENDIAN + #if defined(NAZARA_BIG_ENDIAN) // Les fichiers PCX sont en little endian NzByteSwap(&header.xmin, sizeof(nzUInt16)); NzByteSwap(&header.ymin, sizeof(nzUInt16)); diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 7214e8bd3..db61476ce 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,12 @@ bool NzMeshParams::IsValid() const return false; } + if (!NzBuffer::IsSupported(storage)) + { + NazaraError("Storage not supported"); + return false; + } + return true; } @@ -27,6 +34,7 @@ struct NzMeshImpl std::deque skins; std::vector subMeshes; nzAnimationType animationType; + NzAxisAlignedBox aabb; const NzAnimation* animation = nullptr; }; @@ -76,6 +84,8 @@ nzUInt8 NzMesh::AddSubMesh(NzSubMesh* subMesh) #endif subMesh->AddResourceReference(); + + m_impl->aabb.SetNull(); // On invalide l'AABB m_impl->subMeshes.push_back(subMesh); return m_impl->subMeshes.size()-1; @@ -114,6 +124,7 @@ nzUInt8 NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh) subMesh->AddResourceReference(); + m_impl->aabb.SetNull(); // On invalide l'AABB m_impl->subMeshes.push_back(subMesh); m_impl->subMeshMap[identifier] = index; @@ -157,6 +168,8 @@ void NzMesh::Animate(unsigned int frameA, unsigned int frameB, float interpolati for (NzSubMesh* subMesh : m_impl->subMeshes) subMesh->AnimateImpl(frameA, frameB, interpolation); + + m_impl->aabb.SetNull(); // On invalide l'AABB } bool NzMesh::Create(nzAnimationType type) @@ -184,6 +197,25 @@ void NzMesh::Destroy() } } +const NzAxisAlignedBox& NzMesh::GetAABB() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return NzAxisAlignedBox::Null; + } + #endif + + if (m_impl->aabb.IsNull()) + { + for (NzSubMesh* subMesh : m_impl->subMeshes) + m_impl->aabb.ExtendTo(subMesh->GetAABB()); + } + + return m_impl->aabb; +} + const NzAnimation* NzMesh::GetAnimation() const { #if NAZARA_UTILITY_SAFE @@ -373,6 +405,19 @@ unsigned int NzMesh::GetVertexCount() const return vertexCount; } +void NzMesh::InvalidateAABB() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + #endif + + m_impl->aabb.SetNull(); +} + bool NzMesh::HasAnimation() const { #if NAZARA_UTILITY_SAFE @@ -505,6 +550,8 @@ void NzMesh::RemoveSubMesh(const NzString& identifier) std::advance(it2, index); m_impl->subMeshes.erase(it2); + + m_impl->aabb.SetNull(); // On invalide l'AABB } void NzMesh::RemoveSubMesh(nzUInt8 index) @@ -527,6 +574,8 @@ void NzMesh::RemoveSubMesh(nzUInt8 index) std::advance(it, index); m_impl->subMeshes.erase(it); + + m_impl->aabb.SetNull(); // On invalide l'AABB } bool NzMesh::SetAnimation(const NzAnimation* animation) diff --git a/src/Nazara/Utility/Mouse.cpp b/src/Nazara/Utility/Mouse.cpp index 0efd05663..206ea6c1d 100644 --- a/src/Nazara/Utility/Mouse.cpp +++ b/src/Nazara/Utility/Mouse.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #if defined(NAZARA_PLATFORM_WINDOWS) #include @@ -36,6 +37,9 @@ void NzMouse::SetPosition(const NzVector2i& position) void NzMouse::SetPosition(const NzVector2i& position, const NzWindow& relativeTo) { + if (position.x > 0 && position.y > 0) + relativeTo.IgnoreNextMouseEvent(position.x, position.y); + NzEventImpl::SetMousePosition(position.x, position.y, relativeTo); } @@ -46,5 +50,8 @@ void NzMouse::SetPosition(int x, int y) void NzMouse::SetPosition(int x, int y, const NzWindow& relativeTo) { + if (x > 0 && y > 0) + relativeTo.IgnoreNextMouseEvent(x, y); + NzEventImpl::SetMousePosition(x, y, relativeTo); } diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index c4178b4b4..ee440c489 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -1320,5 +1320,5 @@ void NzPixelFormat::Uninitialize() s_flipFunctions[i].clear(); } -NzPixelFormat::ConvertFunction NzPixelFormat::s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1] = {{0}}; ///FIXME: Fonctionne correctement ? +NzPixelFormat::ConvertFunction NzPixelFormat::s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1] = {{nullptr}}; ///FIXME: Fonctionne correctement ? std::map NzPixelFormat::s_flipFunctions[nzPixelFlipping_Max+1]; diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index 42171bb25..7d72e29c6 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -12,17 +12,17 @@ NzSubMesh(parent) { } -NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer) : +NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) : NzSubMesh(parent) { #ifdef NAZARA_DEBUG - if (!Create(vertexBuffer, vertexDeclaration, indexBuffer)) + if (!Create(vertexDeclaration, vertexBuffer, indexBuffer)) { NazaraError("Failed to create mesh"); throw std::runtime_error("Constructor failed"); } #else - Create(vertexBuffer, vertexDeclaration, indexBuffer); + Create(vertexDeclaration, vertexBuffer, indexBuffer); #endif } @@ -31,22 +31,22 @@ NzStaticMesh::~NzStaticMesh() Destroy(); } -bool NzStaticMesh::Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer) +bool NzStaticMesh::Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) { Destroy(); #if NAZARA_UTILITY_SAFE - if (!vertexBuffer) - { - NazaraError("Vertex buffer is null"); - return false; - } - if (!vertexDeclaration) { NazaraError("Vertex declaration is null"); return false; } + + if (!vertexBuffer) + { + NazaraError("Vertex buffer is null"); + return false; + } #endif if (indexBuffer) @@ -66,6 +66,8 @@ bool NzStaticMesh::Create(const NzVertexBuffer* vertexBuffer, const NzVertexDecl void NzStaticMesh::Destroy() { + m_aabb.SetNull(); + if (m_indexBuffer) { m_indexBuffer->RemoveResourceReference(); @@ -85,6 +87,44 @@ void NzStaticMesh::Destroy() } } +bool NzStaticMesh::GenerateAABB() +{ + if (!m_aabb.IsNull()) + return true; + + const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position); + if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3 + { + // On lock le buffer pour itérer sur toutes les positions et composer notre AABB + nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_ReadOnly)); + if (!buffer) + { + NazaraWarning("Failed to lock vertex buffer"); + return false; + } + + buffer += position->offset; + unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData); + unsigned int vertexCount = m_vertexBuffer->GetVertexCount(); + for (unsigned int i = 0; i < vertexCount; ++i) + { + m_aabb.ExtendTo(*reinterpret_cast(buffer)); + + buffer += stride; + } + + if (!m_vertexBuffer->Unmap()) + NazaraWarning("Failed to unmap vertex buffer"); + } + + return true; +} + +const NzAxisAlignedBox& NzStaticMesh::GetAABB() const +{ + return m_aabb; +} + nzAnimationType NzStaticMesh::GetAnimationType() const { return nzAnimationType_Static; @@ -125,6 +165,11 @@ bool NzStaticMesh::IsValid() const return m_vertexBuffer != nullptr && m_vertexDeclaration != nullptr; } +void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb) +{ + m_aabb = aabb; +} + void NzStaticMesh::SetPrimitiveType(nzPrimitiveType primitiveType) { m_primitiveType = primitiveType; diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index 40a6bd661..d4a7e6ce3 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -14,7 +14,7 @@ NzSubMesh::NzSubMesh(const NzMesh* parent) : NzResource(false), // Un SubMesh n'est pas persistant par défaut m_parent(parent) { - #if NAZARA_DEBUG + #ifdef NAZARA_DEBUG if (!m_parent) { NazaraError("Parent mesh is null"); @@ -55,6 +55,8 @@ void NzSubMesh::Animate(unsigned int frameA, unsigned int frameB, float interpol #endif AnimateImpl(frameA, frameB, interpolation); + + m_parent->InvalidateAABB(); } const NzMesh* NzSubMesh::GetParent() const diff --git a/src/Nazara/Utility/Utility.cpp b/src/Nazara/Utility/Utility.cpp index 0d5b541cb..755b05120 100644 --- a/src/Nazara/Utility/Utility.cpp +++ b/src/Nazara/Utility/Utility.cpp @@ -3,7 +3,9 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include +#include #include #include #include @@ -13,26 +15,19 @@ #include #include -NzUtility::NzUtility() -{ -} - -NzUtility::~NzUtility() -{ - if (s_initialized) - Uninitialize(); -} - bool NzUtility::Initialize() { - #if NAZARA_UTILITY_SAFE - if (s_initialized) - { - NazaraError("Renderer already initialized"); - return true; - } - #endif + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + // Initialisation des dépendances + if (!NzCore::Initialize()) + { + NazaraError("Failed to initialize core module"); + return false; + } + + // Initialisation du module if (!NzBuffer::Initialize()) { NazaraError("Failed to initialize buffers"); @@ -64,21 +59,22 @@ bool NzUtility::Initialize() // Image NzLoaders_STB_Register(); // Loader générique (STB) - s_initialized = true; + NazaraNotice("Initialized: Utility module"); return true; } +bool NzUtility::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + void NzUtility::Uninitialize() { - #if NAZARA_UTILITY_SAFE - if (!s_initialized) - { - NazaraError("Utility not initialized"); - return; - } - #endif + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé + // Libération du module NzLoaders_MD2_Unregister(); NzLoaders_PCX_Unregister(); NzLoaders_STB_Unregister(); @@ -87,12 +83,11 @@ void NzUtility::Uninitialize() NzPixelFormat::Uninitialize(); NzBuffer::Uninitialize(); - s_initialized = false; + NazaraNotice("Uninitialized: Utility module"); + + // Libération des dépendances + NzCore::Uninitialize(); } -bool NzUtility::IsInitialized() -{ - return s_initialized; -} +unsigned int NzUtility::s_moduleReferenceCouter = 0; -bool NzUtility::s_initialized = false; diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index 8db74ddd2..1d8f546f7 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -10,7 +10,7 @@ #include #include -#if NAZARA_THREADSAFETY_VERTEXDECLARATION +#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_VERTEXDECLARATION #include #else #include @@ -22,15 +22,15 @@ namespace { const unsigned int size[] = { - 4, // nzElementType_Color - 8, // nzElementType_Double1 - 16, // nzElementType_Double2 - 24, // nzElementType_Double3 - 32, // nzElementType_Double4 - 4, // nzElementType_Float1 - 8, // nzElementType_Float2 - 12, // nzElementType_Float3 - 16 // nzElementType_Float4 + sizeof(nzUInt32), // nzElementType_Color + 1*sizeof(double), // nzElementType_Double1 + 2*sizeof(double), // nzElementType_Double2 + 3*sizeof(double), // nzElementType_Double3 + 4*sizeof(double), // nzElementType_Double4 + 1*sizeof(float), // nzElementType_Float1 + 2*sizeof(float), // nzElementType_Float2 + 3*sizeof(float), // nzElementType_Float3 + 4*sizeof(float) // nzElementType_Float4 }; bool VertexElementCompare(const NzVertexElement& elementA, const NzVertexElement& elementB) @@ -57,7 +57,7 @@ struct NzVertexDeclarationImpl int streamPos[nzElementStream_Max+1]; unsigned int stride[nzElementStream_Max+1] = {0}; - unsigned short refCount; + unsigned short refCount = 1; NazaraMutex(mutex) }; @@ -86,7 +86,7 @@ m_sharedImpl(declaration.m_sharedImpl) } } -NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) : +NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept : m_sharedImpl(declaration.m_sharedImpl) { declaration.m_sharedImpl = nullptr; @@ -146,7 +146,7 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e impl->stride[current.stream] += size[current.type]; } - #if NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 + #if NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 for (unsigned int& stride : impl->stride) stride = ((static_cast(stride)-1)/32+1)*32; #endif @@ -335,7 +335,7 @@ NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& d return *this; } -NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) +NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) noexcept { Destroy(); diff --git a/src/Nazara/Utility/Win32/InputImpl.cpp b/src/Nazara/Utility/Win32/InputImpl.cpp index 4d44710db..a91c92cce 100644 --- a/src/Nazara/Utility/Win32/InputImpl.cpp +++ b/src/Nazara/Utility/Win32/InputImpl.cpp @@ -192,7 +192,7 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key) bool NzEventImpl::IsMouseButtonPressed(NzMouse::Button button) { - static int vButtons[NzMouse::Count] = { + static int vButtons[NzMouse::Max+1] = { VK_LBUTTON, // Button::Left VK_MBUTTON, // Button::Middle VK_RBUTTON, // Button::Right diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index 5b525c959..ec8dd7b96 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -7,10 +7,10 @@ #define OEMRESOURCE #include +#include #include #include #include -#include #include #include #include @@ -53,28 +53,6 @@ m_scrolling(0) { } -void NzWindowImpl::Close() -{ - if (m_ownsWindow) - { - #if NAZARA_UTILITY_THREADED_WINDOW - if (m_thread) - { - m_threadActive = false; - PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread - - m_thread->Join(); - delete m_thread; - } - #else - if (m_handle) - DestroyWindow(m_handle); - #endif - } - else - SetEventListener(false); -} - bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) { bool fullscreen = (style & nzWindowStyle_Fullscreen) != 0; @@ -99,6 +77,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl } } + // Testé une seconde fois car sa valeur peut changer if (fullscreen) { x = 0; @@ -143,7 +122,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl #if NAZARA_UTILITY_THREADED_WINDOW NzMutex mutex; - NzThreadCondition condition; + NzConditionVariable condition; m_thread = new NzThread(WindowThread, &m_handle, win32StyleEx, wtitle, win32Style, x, y, width, height, this, &mutex, &condition); m_threadActive = true; @@ -166,6 +145,9 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl m_eventListener = true; m_ownsWindow = true; + #if !NAZARA_UTILITY_THREADED_WINDOW + m_sizemove = false; + #endif return m_handle != nullptr; } @@ -181,10 +163,35 @@ bool NzWindowImpl::Create(NzWindowHandle handle) m_handle = reinterpret_cast(handle); m_eventListener = false; m_ownsWindow = false; + #if !NAZARA_UTILITY_THREADED_WINDOW + m_sizemove = false; + #endif return true; } +void NzWindowImpl::Destroy() +{ + if (m_ownsWindow) + { + #if NAZARA_UTILITY_THREADED_WINDOW + if (m_thread) + { + m_threadActive = false; + PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread + + m_thread->Join(); + delete m_thread; + } + #else + if (m_handle) + DestroyWindow(m_handle); + #endif + } + else + SetEventListener(false); +} + void NzWindowImpl::EnableKeyRepeat(bool enable) { m_keyRepeat = enable; @@ -267,6 +274,13 @@ void NzWindowImpl::ProcessEvents(bool block) } } +void NzWindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY) +{ + // Petite astuce ... + m_mousePos.x = mouseX; + m_mousePos.y = mouseY; +} + bool NzWindowImpl::IsMinimized() const { return IsIconic(m_handle); @@ -317,12 +331,12 @@ void NzWindowImpl::SetCursor(nzWindowCursor cursor) case nzWindowCursor_ResizeNW: case nzWindowCursor_ResizeSE: - m_cursor = reinterpret_cast(LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, 0, 0, LR_SHARED)); + m_cursor = reinterpret_cast(LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, 0, 0, LR_SHARED)); break; case nzWindowCursor_ResizeNE: case nzWindowCursor_ResizeSW: - m_cursor = reinterpret_cast(LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, 0, 0, LR_SHARED)); + m_cursor = reinterpret_cast(LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, 0, 0, LR_SHARED)); break; case nzWindowCursor_ResizeE: @@ -418,7 +432,7 @@ void NzWindowImpl::SetMinimumSize(int width, int height) void NzWindowImpl::SetPosition(int x, int y) { - SetWindowPos(m_handle, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + SetWindowPos(m_handle, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); } void NzWindowImpl::SetSize(unsigned int width, unsigned int height) @@ -427,7 +441,15 @@ void NzWindowImpl::SetSize(unsigned int width, unsigned int height) RECT rect = {0, 0, static_cast(width), static_cast(height)}; AdjustWindowRect(&rect, GetWindowLongPtr(m_handle, GWL_STYLE), false); - SetWindowPos(m_handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER); + SetWindowPos(m_handle, nullptr, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER); +} + +void NzWindowImpl::SetStayOnTop(bool stayOnTop) +{ + if (stayOnTop) + SetWindowPos(m_handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + else + SetWindowPos(m_handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } void NzWindowImpl::SetTitle(const NzString& title) @@ -442,11 +464,6 @@ void NzWindowImpl::SetVisible(bool visible) ShowWindow(m_handle, (visible) ? SW_SHOW : SW_HIDE); } -void NzWindowImpl::StayOnTop(bool stayOnTop) -{ - SetWindowPos(m_handle, (stayOnTop) ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); -} - bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam) { // Inutile de récupérer des évènements ne venant pas de notre fenêtre @@ -495,11 +512,13 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_CHAR: { // http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx - if (m_keyRepeat || (HIWORD(lParam) & KF_REPEAT) == 0) + bool repeated = ((HIWORD(lParam) & KF_REPEAT) != 0); + if (m_keyRepeat || !repeated) { NzEvent event; - event.type = NzEvent::TextEntered; - event.text.character = static_cast(wParam); + event.type = nzEventType_TextEntered; + event.text.character = static_cast(wParam); + event.text.repeated = repeated; m_parent->PushEvent(event); } @@ -509,65 +528,64 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_CLOSE: { NzEvent event; - event.type = NzEvent::Quit; + event.type = nzEventType_Quit; m_parent->PushEvent(event); return true; // Afin que Windows ne ferme pas la fenêtre automatiquement } - case WM_LBUTTONDBLCLK: + #if !NAZARA_UTILITY_THREADED_WINDOW + case WM_ENTERSIZEMOVE: { - // Cet évènement est généré à la place d'un WM_LBUTTONDOWN lors d'un double-clic. - // Comme nous désirons quand même notifier chaque clic, nous envoyons les deux évènements. - NzEvent event; - event.mouseButton.button = NzMouse::Left; - event.mouseButton.x = GET_X_LPARAM(lParam); - event.mouseButton.y = GET_Y_LPARAM(lParam); - - event.type = NzEvent::MouseButtonDoubleClicked; - m_parent->PushEvent(event); - - event.type = NzEvent::MouseButtonPressed; - m_parent->PushEvent(event); - + m_sizemove = true; break; } - case WM_LBUTTONDOWN: + case WM_EXITSIZEMOVE: { - NzEvent event; - event.type = NzEvent::MouseButtonPressed; - event.mouseButton.button = NzMouse::Left; - event.mouseButton.x = GET_X_LPARAM(lParam); - event.mouseButton.y = GET_Y_LPARAM(lParam); - m_parent->PushEvent(event); + m_sizemove = false; - break; + // On vérifie ce qui a changé + NzVector2i position = GetPosition(); + if (m_position != position) + { + m_position = position; + + NzEvent event; + event.type = nzEventType_Moved; + event.position.x = position.x; + event.position.y = position.y; + m_parent->PushEvent(event); + } + + NzVector2ui size = GetSize(); + if (m_size != size) + { + m_size = size; + + NzEvent event; + event.type = nzEventType_Resized; + event.size.width = size.x; + event.size.height = size.y; + m_parent->PushEvent(event); + } } - case WM_LBUTTONUP: - { - NzEvent event; - event.type = NzEvent::MouseButtonReleased; - event.mouseButton.button = NzMouse::Left; - event.mouseButton.x = GET_X_LPARAM(lParam); - event.mouseButton.y = GET_Y_LPARAM(lParam); - m_parent->PushEvent(event); - - break; - } + #endif case WM_KEYDOWN: case WM_SYSKEYDOWN: { // http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx - if (m_keyRepeat || (HIWORD(lParam) & KF_REPEAT) == 0) + bool repeated = ((HIWORD(lParam) & KF_REPEAT) != 0); + if (m_keyRepeat || !repeated) { NzEvent event; - event.type = NzEvent::KeyPressed; + event.type = nzEventType_KeyPressed; event.key.code = ConvertVirtualKey(wParam, lParam); event.key.alt = ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0); event.key.control = ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0); + event.key.repeated = repeated; event.key.shift = ((GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0); event.key.system = (((GetAsyncKeyState(VK_LWIN) & 0x8000) != 0) || ((GetAsyncKeyState(VK_RWIN) & 0x8000) != 0)); m_parent->PushEvent(event); @@ -581,7 +599,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA { // http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx NzEvent event; - event.type = NzEvent::KeyReleased; + event.type = nzEventType_KeyReleased; event.key.code = ConvertVirtualKey(wParam, lParam); event.key.alt = ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0); event.key.control = ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0); @@ -595,7 +613,49 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_KILLFOCUS: { NzEvent event; - event.type = NzEvent::LostFocus; + event.type = nzEventType_LostFocus; + m_parent->PushEvent(event); + + break; + } + + case WM_LBUTTONDBLCLK: + { + // Cet évènement est généré à la place d'un WM_LBUTTONDOWN lors d'un double-clic. + // Comme nous désirons quand même notifier chaque clic, nous envoyons les deux évènements. + NzEvent event; + event.mouseButton.button = NzMouse::Left; + event.mouseButton.x = GET_X_LPARAM(lParam); + event.mouseButton.y = GET_Y_LPARAM(lParam); + + event.type = nzEventType_MouseButtonDoubleClicked; + m_parent->PushEvent(event); + + event.type = nzEventType_MouseButtonPressed; + m_parent->PushEvent(event); + + break; + } + + case WM_LBUTTONDOWN: + { + NzEvent event; + event.type = nzEventType_MouseButtonPressed; + event.mouseButton.button = NzMouse::Left; + event.mouseButton.x = GET_X_LPARAM(lParam); + event.mouseButton.y = GET_Y_LPARAM(lParam); + m_parent->PushEvent(event); + + break; + } + + case WM_LBUTTONUP: + { + NzEvent event; + event.type = nzEventType_MouseButtonReleased; + event.mouseButton.button = NzMouse::Left; + event.mouseButton.x = GET_X_LPARAM(lParam); + event.mouseButton.y = GET_Y_LPARAM(lParam); m_parent->PushEvent(event); break; @@ -608,10 +668,10 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); - event.type = NzEvent::MouseButtonDoubleClicked; + event.type = nzEventType_MouseButtonDoubleClicked; m_parent->PushEvent(event); - event.type = NzEvent::MouseButtonPressed; + event.type = nzEventType_MouseButtonPressed; m_parent->PushEvent(event); break; @@ -620,7 +680,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_MBUTTONDOWN: { NzEvent event; - event.type = NzEvent::MouseButtonPressed; + event.type = nzEventType_MouseButtonPressed; event.mouseButton.button = NzMouse::Middle; event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); @@ -632,7 +692,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_MBUTTONUP: { NzEvent event; - event.type = NzEvent::MouseButtonReleased; + event.type = nzEventType_MouseButtonReleased; event.mouseButton.button = NzMouse::Middle; event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); @@ -648,13 +708,16 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA m_mouseInside = false; NzEvent event; - event.type = NzEvent::MouseLeft; + event.type = nzEventType_MouseLeft; m_parent->PushEvent(event); break; } case WM_MOUSEMOVE: { + int currentX = GET_X_LPARAM(lParam); + int currentY = GET_Y_LPARAM(lParam); + if (!m_mouseInside) { m_mouseInside = true; @@ -667,14 +730,37 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA TrackMouseEvent(&mouseEvent); NzEvent event; - event.type = NzEvent::MouseEntered; + event.type = nzEventType_MouseEntered; m_parent->PushEvent(event); + + event.type = nzEventType_MouseMoved; + + // Le delta sera 0 + event.mouseMove.deltaX = 0; + event.mouseMove.deltaY = 0; + + event.mouseMove.x = currentX; + event.mouseMove.y = currentY; + + m_mousePos.x = currentX; + m_mousePos.y = currentY; + + m_parent->PushEvent(event); + break; } + else if (m_mousePos.x == currentX && m_mousePos.y == currentY) + break; NzEvent event; - event.type = NzEvent::MouseMoved; - event.mouseMove.x = GET_X_LPARAM(lParam); - event.mouseMove.y = GET_Y_LPARAM(lParam); + event.type = nzEventType_MouseMoved; + event.mouseMove.deltaX = currentX - m_mousePos.x; + event.mouseMove.deltaY = currentY - m_mousePos.y; + event.mouseMove.x = currentX; + event.mouseMove.y = currentY; + + m_mousePos.x = currentX; + m_mousePos.y = currentY; + m_parent->PushEvent(event); break; } @@ -684,7 +770,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA if (m_smoothScrolling) { NzEvent event; - event.type = NzEvent::MouseWheelMoved; + event.type = nzEventType_MouseWheelMoved; event.mouseWheel.delta = static_cast(GET_WHEEL_DELTA_WPARAM(wParam))/WHEEL_DELTA; m_parent->PushEvent(event); } @@ -694,7 +780,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA if (std::abs(m_scrolling) >= WHEEL_DELTA) { NzEvent event; - event.type = NzEvent::MouseWheelMoved; + event.type = nzEventType_MouseWheelMoved; event.mouseWheel.delta = m_scrolling/WHEEL_DELTA; m_parent->PushEvent(event); @@ -709,7 +795,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA NzVector2i position = GetPosition(); NzEvent event; - event.type = NzEvent::Moved; + event.type = nzEventType_Moved; event.position.x = position.x; event.position.y = position.y; m_parent->PushEvent(event); @@ -724,10 +810,10 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); - event.type = NzEvent::MouseButtonDoubleClicked; + event.type = nzEventType_MouseButtonDoubleClicked; m_parent->PushEvent(event); - event.type = NzEvent::MouseButtonPressed; + event.type = nzEventType_MouseButtonPressed; m_parent->PushEvent(event); break; @@ -736,7 +822,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_RBUTTONDOWN: { NzEvent event; - event.type = NzEvent::MouseButtonPressed; + event.type = nzEventType_MouseButtonPressed; event.mouseButton.button = NzMouse::Right; event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); @@ -748,7 +834,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_RBUTTONUP: { NzEvent event; - event.type = NzEvent::MouseButtonReleased; + event.type = nzEventType_MouseButtonReleased; event.mouseButton.button = NzMouse::Right; event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); @@ -760,7 +846,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_SETFOCUS: { NzEvent event; - event.type = NzEvent::GainedFocus; + event.type = nzEventType_GainedFocus; m_parent->PushEvent(event); break; @@ -768,12 +854,22 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_SIZE: { + #if NAZARA_UTILITY_THREADED_WINDOW if (wParam != SIZE_MINIMIZED) + #else + if (!m_sizemove && wParam != SIZE_MINIMIZED) + #endif { NzVector2ui size = GetSize(); // On récupère uniquement la taille de la zone client + #if !NAZARA_UTILITY_THREADED_WINDOW + if (m_size == size) + break; + + m_size = size; + #endif NzEvent event; - event.type = NzEvent::Resized; + event.type = nzEventType_Resized; event.size.width = size.x; event.size.height = size.y; m_parent->PushEvent(event); @@ -792,10 +888,10 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA event.mouseButton.x = GET_X_LPARAM(lParam); event.mouseButton.y = GET_Y_LPARAM(lParam); - event.type = NzEvent::MouseButtonDoubleClicked; + event.type = nzEventType_MouseButtonDoubleClicked; m_parent->PushEvent(event); - event.type = NzEvent::MouseButtonPressed; + event.type = nzEventType_MouseButtonPressed; m_parent->PushEvent(event); break; @@ -804,6 +900,8 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_XBUTTONDOWN: { NzEvent event; + event.type = nzEventType_MouseButtonPressed; + if (HIWORD(wParam) == XBUTTON1) event.mouseButton.button = NzMouse::XButton1; else @@ -819,6 +917,8 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_XBUTTONUP: { NzEvent event; + event.type = nzEventType_MouseButtonReleased; + if (HIWORD(wParam) == XBUTTON1) event.mouseButton.button = NzMouse::XButton1; else @@ -1018,7 +1118,7 @@ NzKeyboard::Key NzWindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags) } #if NAZARA_UTILITY_THREADED_WINDOW -void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzThreadCondition* condition) +void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition) { *handle = CreateWindowExW(styleEx, className, title, style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window); diff --git a/src/Nazara/Utility/Win32/WindowImpl.hpp b/src/Nazara/Utility/Win32/WindowImpl.hpp index 16c28b70a..bb566ebda 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.hpp +++ b/src/Nazara/Utility/Win32/WindowImpl.hpp @@ -20,9 +20,9 @@ #include #if NAZARA_UTILITY_THREADED_WINDOW +class NzConditionVariable; class NzMutex; class NzThread; -class NzThreadCondition; #endif class NzWindow; @@ -34,11 +34,11 @@ class NzWindowImpl : NzNonCopyable NzWindowImpl(NzWindow* parent); ~NzWindowImpl() = default; - void Close(); - bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style); bool Create(NzWindowHandle handle); + void Destroy(); + void EnableKeyRepeat(bool enable); void EnableSmoothScrolling(bool enable); @@ -53,6 +53,8 @@ class NzWindowImpl : NzNonCopyable void ProcessEvents(bool block); + void IgnoreNextMouseEvent(int mouseX, int mouseY); + bool IsMinimized() const; bool IsVisible() const; @@ -65,11 +67,10 @@ class NzWindowImpl : NzNonCopyable void SetMinimumSize(int width, int height); void SetPosition(int x, int y); void SetSize(unsigned int width, unsigned int height); + void SetStayOnTop(bool stayOnTop); void SetTitle(const NzString& title); void SetVisible(bool visible); - void StayOnTop(bool stayOnTop); - static bool Initialize(); static void Uninitialize(); @@ -79,7 +80,7 @@ class NzWindowImpl : NzNonCopyable static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam); static NzKeyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags); #if NAZARA_UTILITY_THREADED_WINDOW - static void WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzThreadCondition* condition); + static void WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, NzWindowImpl* window, NzMutex* mutex, NzConditionVariable* condition); #endif HCURSOR m_cursor; @@ -87,7 +88,11 @@ class NzWindowImpl : NzNonCopyable LONG_PTR m_callback; NzVector2i m_maxSize; NzVector2i m_minSize; - #if NAZARA_UTILITY_THREADED_WINDOW + NzVector2i m_mousePos; + #if !NAZARA_UTILITY_THREADED_WINDOW + NzVector2i m_position; + NzVector2ui m_size; + #else NzThread* m_thread; #endif NzWindow* m_parent; @@ -95,6 +100,9 @@ class NzWindowImpl : NzNonCopyable bool m_keyRepeat; bool m_mouseInside; bool m_ownsWindow; + #if !NAZARA_UTILITY_THREADED_WINDOW + bool m_sizemove; + #endif bool m_smoothScrolling; #if NAZARA_UTILITY_THREADED_WINDOW bool m_threadActive; diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index 2c02557db..5e476dbaf 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -82,32 +82,18 @@ m_impl(nullptr) NzWindow::~NzWindow() { - Close(); -} - -void NzWindow::Close() -{ - if (m_impl) - { - OnClose(); - - m_impl->Close(); - delete m_impl; - m_impl = nullptr; - - if (fullscreenWindow == this) - fullscreenWindow = nullptr; - } + Destroy(); } bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) { + // Si la fenêtre est déjà ouverte, nous conservons sa position bool opened = IsOpen(); NzVector2i position; if (opened) position = m_impl->GetPosition(); - Close(); + Destroy(); // Inspiré du code de la SFML par Laurent Gomila if (style & nzWindowStyle_Fullscreen) @@ -143,7 +129,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) m_ownsWindow = true; - if (!OnCreate()) + if (!OnWindowCreated()) { NazaraError("Failed to initialize window extension"); delete m_impl; @@ -152,6 +138,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) return false; } + // Paramètres par défaut m_impl->EnableKeyRepeat(true); m_impl->EnableSmoothScrolling(false); m_impl->SetCursor(nzWindowCursor_Default); @@ -167,7 +154,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) bool NzWindow::Create(NzWindowHandle handle) { - Close(); + Destroy(); m_impl = new NzWindowImpl(this); if (!m_impl->Create(handle)) @@ -181,7 +168,7 @@ bool NzWindow::Create(NzWindowHandle handle) m_ownsWindow = false; - if (!OnCreate()) + if (!OnWindowCreated()) { NazaraError("Failed to initialize window's derivate"); delete m_impl; @@ -193,6 +180,21 @@ bool NzWindow::Create(NzWindowHandle handle) return true; } +void NzWindow::Destroy() +{ + if (m_impl) + { + OnWindowDestroying(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + + if (fullscreenWindow == this) + fullscreenWindow = nullptr; + } +} + void NzWindow::EnableKeyRepeat(bool enable) { if (m_impl) @@ -210,7 +212,7 @@ NzWindowHandle NzWindow::GetHandle() const if (m_impl) return m_impl->GetHandle(); else - return 0; + return reinterpret_cast(0); } unsigned int NzWindow::GetHeight() const @@ -420,6 +422,12 @@ void NzWindow::SetSize(unsigned int width, unsigned int height) m_impl->SetSize(width, height); } +void NzWindow::SetStayOnTop(bool stayOnTop) +{ + if (m_impl) + m_impl->SetStayOnTop(stayOnTop); +} + void NzWindow::SetTitle(const NzString& title) { if (m_impl) @@ -432,12 +440,6 @@ void NzWindow::SetVisible(bool visible) m_impl->SetVisible(visible); } -void NzWindow::StayOnTop(bool stayOnTop) -{ - if (m_impl) - m_impl->StayOnTop(stayOnTop); -} - bool NzWindow::WaitEvent(NzEvent* event) { if (!m_impl) @@ -481,15 +483,21 @@ bool NzWindow::WaitEvent(NzEvent* event) #endif } -void NzWindow::OnClose() +void NzWindow::OnWindowDestroying() { } -bool NzWindow::OnCreate() +bool NzWindow::OnWindowCreated() { return true; } +void NzWindow::IgnoreNextMouseEvent(int mouseX, int mouseY) const +{ + if (m_impl) + m_impl->IgnoreNextMouseEvent(mouseX, mouseY); +} + void NzWindow::PushEvent(const NzEvent& event) { #if NAZARA_UTILITY_THREADED_WINDOW From b559932d6311a50d2dfba2ef584bbc47393ac44b Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 10 Aug 2012 01:41:37 +0200 Subject: [PATCH 02/31] Changed readme and examples encoding to UTF-8 --- examples/AnimatedMesh/main.cpp | 258 +++++++++++++++----------------- examples/ListSequences/main.cpp | 14 +- readme.txt | 4 +- readme_fr.txt | 24 +-- 4 files changed, 145 insertions(+), 155 deletions(-) diff --git a/examples/AnimatedMesh/main.cpp b/examples/AnimatedMesh/main.cpp index 0617aaa5d..12ba84677 100644 --- a/examples/AnimatedMesh/main.cpp +++ b/examples/AnimatedMesh/main.cpp @@ -12,10 +12,10 @@ #include #include -// Une structure pour contenir nos informations (Cette structure est très simpliste) +// Une structure pour contenir nos informations (Cette structure est très simpliste) struct Model { - NzMatrix4f matrix; // Les transformations subies par le modèle + NzMatrix4f matrix; // Les transformations subies par le modèle NzMesh mesh; // Le mesh NzTexture texture; // Sa texture }; @@ -23,10 +23,10 @@ struct Model struct AnimatedModel : public Model { // Quelques variables pour l'animation - const NzSequence* currentSequence = nullptr; // La séquence en cours - float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) - unsigned int currentFrame = 0; // La première frame - unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là + const NzSequence* currentSequence = nullptr; // La séquence en cours + float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) + unsigned int currentFrame = 0; // La première frame + unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là }; void AnimateModel(AnimatedModel& moedel, float elapsed); @@ -42,15 +42,15 @@ int main() std::cout << "Dr. Freak controls: Up, down, left and right" << std::endl; std::cout << "Escape to quit" << std::endl; - // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) + // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) NzContextParameters::defaultCompatibilityProfile = true; - // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utlitaire) - // Cette étape est obligatoire pour beaucoup de classes + // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utilitaire) + // Cette étape est obligatoire pour beaucoup de fonctionnalités (Notamment le chargement de ressources et le rendu) NzInitializer renderer; if (!renderer) { - // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log + // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; std::getchar(); // On laise le temps de voir l'erreur return EXIT_FAILURE; @@ -58,35 +58,35 @@ int main() // 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 - // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] + // Charger une ressource se fait actuellement manuellement, mais un ResourceManager est à venir + // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] // Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters NzMeshParams parameters; // Le loader doit-il automatiquement charger les animations ? - // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. - // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné + // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. + // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné // qu'elles sont fourniees avec le mesh. - // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut - // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés - parameters.loadAnimations = true; // Vaut true par défaut + // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut + // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés + parameters.loadAnimations = true; // Vaut true par défaut - // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de - // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. - parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut + // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de + // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. + parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut AnimatedModel drfreak; - if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. + if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. { - // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. + // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. std::cout << "Failed to load mesh" << std::endl; std::getchar(); // On laise le temps de voir l'erreur return EXIT_FAILURE; } - if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? + if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? { - // Cette démo n'a aucun intérêt sans animations + // Cette démo n'a aucun intérêt sans animations std::cout << "Mesh has no animation" << std::endl; std::getchar(); return EXIT_FAILURE; @@ -94,17 +94,17 @@ int main() SetSequence(drfreak, "stand"); - // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture + // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture if (drfreak.mesh.HasSkin()) { // Contrairement aux autres ressources, la texture n'est pas critique if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin())) - drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire + drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire else std::cout << "Failed to load texture" << std::endl; } - if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée + if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée { std::cout << "Creating checker texture for mesh" << std::endl; @@ -116,7 +116,7 @@ int main() } } - // Nous créons maintenant notre sol + // Nous créons maintenant notre sol Model floor; if (!CreateFloorMesh(&floor.mesh)) { @@ -136,11 +136,11 @@ int main() floor.matrix.MakeIdentity(); // Pour effectuer un rendu, il faut que la carte graphique sache quoi faire. - // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors du pipeline. - // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! - // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. - // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL - // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. + // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors du pipeline. + // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! + // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. + // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL + // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. NzShader shader; if (!shader.Create(nzShaderLanguage_GLSL)) { @@ -149,13 +149,13 @@ int main() return EXIT_FAILURE; } - // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders - // Pour notre exemple nous prendrons un shader très simple - // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader + // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders + // Pour notre exemple nous prendrons un shader très simple + // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag")) { std::cout << "Failed to load fragment shader from file" << std::endl; - // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec + // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec std::cout << "Log: " << shader.GetLog() << std::endl; std::getchar(); return EXIT_FAILURE; @@ -170,7 +170,7 @@ int main() return EXIT_FAILURE; } - // Une fois le code source de nos shaders chargé, nous pouvons le compiler, afin de le rendre utilisable + // Une fois le code source de nos shaders chargé, nous pouvons le compiler, afin de le rendre utilisable if (!shader.Compile()) { std::cout << "Failed to compile shader" << std::endl; @@ -179,9 +179,9 @@ int main() return EXIT_FAILURE; } - // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça - // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow - // Tout d'abord, sa taille, disons celle du bureau divisé par deux + // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça + // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow + // Tout d'abord, sa taille, disons celle du bureau divisé par deux NzVideoMode mode = NzVideoMode::GetDesktopMode(); mode.width /= 2; mode.height /= 2; @@ -189,11 +189,11 @@ int main() NzString title = "Nazara Demo - AnimatedMesh"; NzRenderWindow window; - // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède des bordures elle sera légèrement plus grande) - // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle - // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. - // Attention que cela permet à la fenêtre d'envoyer des évènements, et de changer sa taille - // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) + // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède une bordure elle sera légèrement plus grande) + // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle + // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. + // Attention que cela permet à la fenêtre d'envoyer des évènements, et de changer sa taille + // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) if (!window.Create(mode, title, nzWindowStyle_Default)) { std::cout << "Failed to create window" << std::endl; @@ -204,40 +204,40 @@ int main() // On cache le curseur window.SetCursor(nzWindowCursor_None); - // Nous limitons les FPS à 100 + // Nous limitons les FPS à 100 window.SetFramerateLimit(100); - // La matrice de projection définit la transformation du vertice 3D à un point 2D + // La matrice de projection définit la transformation du vertice 3D à un point 2D NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(window.GetWidth())/window.GetHeight(), 1.f, 1000.f)); - // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements - NzClock secondClock, updateClock; // Des horloges pour gérer le temps + // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements + NzClock secondClock, updateClock; // Des horloges pour gérer le temps unsigned int fps = 0; // Compteur de FPS // Quelques variables pour notre improvisation de physique - float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Pas très exact + float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Pas très exact NzVector3f modelPos(0.f, groundPos, -50.f); NzVector3f modelVel(0.f, 0.f, 0.f); - NzQuaternionf modelRot(NzEulerAnglesf(0.f, 0.f, 0.f)); // Les angles d'eulers sont bien plus facile à se représenter + NzQuaternionf modelRot(NzEulerAnglesf(0.f, 0.f, 0.f)); // Les angles d'eulers sont bien plus facile à se représenter float speed = 60.f; // Nous initialisons la matrice drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); - // Notre caméra + // Notre caméra NzVector3f camPos(0.f, 25.f, -20.f); NzEulerAnglesf camRot(0.f, 0.f, 0.f); NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos); float camSpeed = 2.f; float sensitivity = 0.5; - // Dernière étape, nos touches + // Dernière étape, nos touches // Chaque touche fera bouger struct Movement { NzVector3f direction; // La direction - NzQuaternionf rotation; // La rotation du modèle + NzQuaternionf rotation; // La rotation du modèle }; std::map movements; @@ -247,39 +247,41 @@ int main() movements[NzKeyboard::Right] = Movement{NzVector3f(1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, -90.f, 0.f))}; NzKeyboard::Key currentKey = NzKeyboard::Undefined; - // Quelques booléens + // Quelques booléens bool camMode = true; bool windowOpen = true; + + // On peut commencer la boucle du programme while (windowOpen) { - // Ici nous gérons les évènements + // Ici nous gérons les évènements NzEvent event; - while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? + while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? { - // Nous avons un évènement - switch (event.type) // De quel type est cet évènement ? + // Nous avons un évènement + switch (event.type) // De quel type est cet évènement ? { - case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution - windowOpen = false; // Nous fermons alors la boucle + case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution + windowOpen = false; // Nous terminons alors la boucle break; case nzEventType_MouseMoved: { - // Si nous ne sommes pas en mode caméra, on ne traite pas l'évènement + // Si nous ne sommes pas en mode caméra, on ne traite pas l'évènement if (!camMode) break; - // On modifie l'angle de la caméra grâce au déplacement relatif de la souris + // On modifie l'angle de la caméra grâce au déplacement relatif de la souris camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity); - // Pour éviter les loopings, on restreint les angles + // Pour éviter les loopings, on restreint les angles camRot.pitch = NzClamp(camRot.pitch + event.mouseMove.deltaY*sensitivity, -90.f, 90.f); - // La matrice vue représente les transformations effectuées par la caméra - // On recalcule la matrice de la caméra et on l'envoie au renderer + // La matrice vue représente les transformations effectuées par la caméra + // On recalcule la matrice de la caméra et on l'envoie au renderer NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot)); - // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre + // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window); break; } @@ -288,7 +290,7 @@ int main() if (event.mouseButton.button == NzMouse::Left) { // L'utilisateur vient d'appuyer sur le bouton left de la souris - // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence + // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence if (camMode) { camMode = false; @@ -303,25 +305,25 @@ int main() } break; - case nzEventType_Resized: // L'utilisateur a changé notre taille, le coquin ! + case nzEventType_Resized: // L'utilisateur a changé notre taille, le coquin ! NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage - // Il nous faut aussi mettre à jour notre matrice de projection + // Il nous faut aussi mettre à jour notre matrice de projection NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(event.size.width)/event.size.height, 1.f, 1000.f)); break; case nzEventType_KeyPressed: - if (!event.key.repeated) // Si la touche n'est pas répétée + if (!event.key.repeated) // Si la touche n'est pas répétée { auto it = movements.find(event.key.code); if (it != movements.end()) { // Si la touche est une touche de mouvement - SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement + SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement - modelRot = it->second.rotation; // On change la rotation du modèle + modelRot = it->second.rotation; // On change la rotation du modèle drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); // On recalcule sa matrice - modelVel = it->second.direction * speed; // On change la vitesse de déplacement + modelVel = it->second.direction * speed; // On change la vitesse de déplacement currentKey = event.key.code; } } @@ -335,18 +337,18 @@ int main() if (event.key.code == currentKey) { SetSequence(drfreak, "stand"); - modelVel = NzVector3f(0.f); // On arrête le déplacement + modelVel = NzVector3f(0.f); // On arrête le déplacement break; } break; - default: // Les autres évènements, on s'en fiche + default: // Les autres évènements, on s'en fiche break; } } - // On active le shader et paramètrons le rendu + // On active le shader et paramètrons le rendu NzRenderer::SetShader(&shader); NzRenderer::Enable(nzRendererParameter_DepthTest, true); @@ -355,9 +357,9 @@ int main() if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde { - float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour + float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour - // Déplacement de la caméra + // Déplacement de la caméra static const NzVector3f forward(NzVector3f::UnitZ()); static const NzVector3f left(NzVector3f::UnitX()); static const NzVector3f up(NzVector3f::UnitY()); @@ -365,7 +367,7 @@ int main() // Notre rotation sous forme de quaternion nous permet de tourner un vecteur NzQuaternionf quaternion(camRot); - // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" + // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) camPos += quaternion * forward * camSpeed; @@ -378,15 +380,15 @@ int main() if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) camPos -= quaternion * left * camSpeed; - // En revanche, ici la hauteur est toujours la même, peu importe notre orientation + // En revanche, ici la hauteur est toujours la même, peu importe notre orientation if (NzKeyboard::IsKeyPressed(NzKeyboard::Space)) camPos += up * camSpeed; if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl)) camPos -= up * camSpeed; - // Oui le quaternion et la matrice sont calculés même si la caméra ne bouge pas - // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés + // Oui le quaternion et la matrice sont calculés même si la caméra ne bouge pas + // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot)); // Animation @@ -397,20 +399,8 @@ int main() if (modelVel != NzVector3f::Zero()) { modelPos += modelVel * elapsedTime; - /*if (jumping) - { - velocity.y -= 500.f * elapsedTime; // Un simulacre de gravité - if (modelPos.y <= groundPos) - { - // On stoppe net - modelPos.y = groundPos; - velocity.y = 0.f; - jumping = false; - SetSequence(drfreak, "stand"); - } - }*/ - // Mise à jour de la matrice + // Mise à jour de la matrice drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); } } @@ -418,14 +408,14 @@ int main() // Affichage des meshs DrawModel(floor); - // Notre Dr. Freak possède des normales, nous pouvons alors culler les faces qu'on ne voit pas + // Notre Dr. Freak possède des normales, nous pouvons alors culler les faces qu'on ne voit pas NzRenderer::Enable(nzRendererParameter_FaceCulling, true); DrawModel(drfreak); NzRenderer::Enable(nzRendererParameter_FaceCulling, false); - window.Display(); // Nous mettons à jour l'écran + window.Display(); // Nous mettons à jour l'écran fps++; @@ -459,16 +449,16 @@ void AnimateModel(AnimatedModel& model, float elapsed) bool CreateCheckerTexture(NzTexture* texture) { NzImage image; - // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) + // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16)) { - // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) + // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl; return false; } - // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel - // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. + // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel + // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. unsigned int blockCountX = image.GetWidth()/16; unsigned int blockCountY = image.GetHeight()/16; for (unsigned int x = 0; x < blockCountX; ++x) @@ -482,7 +472,7 @@ bool CreateCheckerTexture(NzTexture* texture) } } - if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image + if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image { // Nous n'avons vraiment pas beaucoup de chance.. std::cout << "Failed to load image" << std::endl; @@ -490,37 +480,37 @@ bool CreateCheckerTexture(NzTexture* texture) } texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture - texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée + texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée return true; } bool CreateFloorMesh(NzMesh* mesh) { - // Cette fonction créé un mesh statique simpliste pour servir de sol + // Cette fonction créé un mesh statique simpliste pour servir de sol - // Nous créons un mesh statique + // Nous créons un mesh statique if (!mesh->Create(nzAnimationType_Static)) { - // L'échec est techniquement impossible mais le moteur étant en constante évolution ... + // L'échec est techniquement impossible mais le moteur étant en constante évolution ... std::cout << "Failed to create mesh" << std::endl; return false; } - // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer - // Elles sont composées de VertexElement, chacun décrivant un élément du buffer + // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer + // Elles sont composées de VertexElement, chacun décrivant un élément du buffer NzVertexDeclaration* declaration = new NzVertexDeclaration; - // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) - // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) - // -Usage: Comment cette donnée doit-elle être envoyée au shader - // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) - // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) - // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. + // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) + // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) + // -Usage: Comment cette donnée doit-elle être envoyée au shader + // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) + // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) + // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. NzVertexElement elements[2]; - elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices - elements[0].offset = 0; // Celles-ci sont placées au début - elements[0].type = nzElementType_Float3; // Sont composées de trois flottants + elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices + elements[0].offset = 0; // Celles-ci sont placées au début + elements[0].type = nzElementType_Float3; // Sont composées de trois flottants elements[1].usage = nzElementUsage_TexCoord; elements[1].offset = 3*sizeof(float); @@ -528,12 +518,12 @@ bool CreateFloorMesh(NzMesh* mesh) if (!declaration->Create(elements, 2)) { - // Nos éléments sont invalides ! + // Nos éléments sont invalides ! std::cout << "Failed to create vertex declaration" << std::endl; return false; } - // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage + // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage // Et nous indiquons que nous n'y toucherons plus NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static); @@ -557,8 +547,8 @@ bool CreateFloorMesh(NzMesh* mesh) 10.f, 10.f // UV }; - // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) - if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices + // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) + if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices { std::cout << "Failed to fill buffer" << std::endl; return false; @@ -576,31 +566,31 @@ bool CreateFloorMesh(NzMesh* mesh) // On ajoute le submesh au mesh mesh->AddSubMesh(subMesh); - // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. - // Les ressources seront donc automatiquement libérées lorsque plus aucune classe n'en aura besoin + // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. + // Les ressources seront donc automatiquement libérées lorsque plus aucune classe n'en aura besoin buffer->SetPersistent(false); declaration->SetPersistent(false); - subMesh->SetPersistent(false); // Pour le submesh, c'est déjà à false à la base + subMesh->SetPersistent(false); // Pour le submesh, c'est déjà à false à la base return true; } void DrawModel(const Model& model) { - // La matrice world est celle qui représente les transformations du modèle + // La matrice world est celle qui représente les transformations du modèle NzRenderer::SetMatrix(nzMatrixType_World, model.matrix); - NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu + NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture); - // Un mesh est divisé en plusieurs submeshes + // Un mesh est divisé en plusieurs submeshes unsigned int subMeshCount = model.mesh.GetSubMeshCount(); for (unsigned int i = 0; i < subMeshCount; ++i) { - // On récupère le submesh + // On récupère le submesh const NzSubMesh* subMesh = model.mesh.GetSubMesh(i); - // On paramètre le Renderer avec ses données + // On paramètre le Renderer avec ses données NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer()); NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer()); NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration()); @@ -612,12 +602,12 @@ void DrawModel(const Model& model) void SetSequence(AnimatedModel& model, const NzString& sequenceName) { - // On récupère l'animation du mesh + // On récupère l'animation du mesh const NzAnimation* animation = model.mesh.GetAnimation(); - // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) + // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) model.currentSequence = animation->GetSequence(sequenceName); - // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame + // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame model.nextFrame = model.currentSequence->firstFrame; } diff --git a/examples/ListSequences/main.cpp b/examples/ListSequences/main.cpp index 5544e82eb..e58184466 100644 --- a/examples/ListSequences/main.cpp +++ b/examples/ListSequences/main.cpp @@ -4,17 +4,17 @@ int main() { - // Pour charger des ressources, il est impératif d'initialiser le module utilitaire + // Pour charger des ressources, il est impératif d'initialiser le module utilitaire NzInitializer utility; if (!utility) { - // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log + // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; std::getchar(); // On laise le temps de voir l'erreur return EXIT_FAILURE; } - // Le Renderer n'étant pas chargé, nous devons indiquer que nous désirons un stockage software de notre mesh + // Le Renderer n'étant pas chargé, nous devons indiquer que nous désirons un stockage software de notre mesh NzMeshParams parameters; parameters.storage = nzBufferStorage_Software; @@ -26,14 +26,14 @@ int main() return EXIT_FAILURE; } - if (drfreak.HasAnimation()) // Si le mesh possède des animations + if (drfreak.HasAnimation()) // Si le mesh possède des animations { std::cout << "Mesh has animation" << std::endl; - // Un objet NzAnimation représente un ensemble d'informations sur des animations + // Un objet NzAnimation représente un ensemble d'informations sur des animations const NzAnimation* animation = drfreak.GetAnimation(); - // Une séquence définit une "action", chaque séquence possède un nom, une frame de départ, une d'arrivée ainsi qu'un framerate + // Une séquence définit une "action", chaque séquence possède un nom, une frame de départ, une d'arrivée ainsi qu'un framerate unsigned int sequenceCount = animation->GetSequenceCount(); std::cout << sequenceCount << " sequences:" << std::endl; for (unsigned int i = 0; i < sequenceCount; ++i) @@ -44,6 +44,6 @@ int main() std::getchar(); // Une attente pour avoir le temps de lire :-) - // Le module utilitaire et le mesh sont déchargés automatiquement + // Le module utilitaire et le mesh sont déchargés automatiquement return EXIT_SUCCESS; } diff --git a/readme.txt b/readme.txt index baa55a86f..f4ec2aee4 100644 --- a/readme.txt +++ b/readme.txt @@ -11,8 +11,8 @@ You can use it in any kind of commercial/non-commercial applications. Authors ------- -Jérôme "Lynix" Leclercq - main developper (Lynix680@gmail.com) -Rémi "overdrivr" Bèges - developper & helper - NzNoise Module - (remi.beges@laposte.net) +Jérôme "Lynix" Leclercq - main developper (Lynix680@gmail.com) +Rémi "overdrivr" Bèges - developper & helper - NzNoise Module - (remi.beges@laposte.net) Install ------- diff --git a/readme_fr.txt b/readme_fr.txt index 7e2408b0e..75ebb87a5 100644 --- a/readme_fr.txt +++ b/readme_fr.txt @@ -1,38 +1,38 @@ Nazara Engine ============= -Nazara Engine est une API rapide, complète, portable et orientée-objet qui peut vous aider dans votre vie de développeur de tous les jours. -Son objectif est de fournir un ensemble de classes utiles : Son noyau dispose de chaînes de caractères unicode, de gestion du système de fichiers, hashs, threads, ... +Nazara Engine est une API rapide, complète, portable et orientée-objet qui peut vous aider dans votre vie de développeur de tous les jours. +Son objectif est de fournir un ensemble de classes utiles : Son noyau dispose de chaînes de caractères unicode, de gestion du système de fichiers, hashs, threads, ... -Il proposera aussi un ensemble de bibliothèques, comme audio, réseau, physique, moteur de rendu, moteur 2D et 3D. +Il proposera aussi un ensemble de bibliothèques, comme audio, réseau, physique, moteur de rendu, moteur 2D et 3D. Vous pouvez l'utiliser pour toute application commerciale ou non. Auteurs ------- -Jérôme "Lynix" Leclercq - développeur principal (Lynix680@gmail.com) -Rémi "overdrivr" Bèges - développeur & aide - module NzNoise - (remi.beges@laposte.net) +Jérôme "Lynix" Leclercq - développeur principal (Lynix680@gmail.com) +Rémi "overdrivr" Bèges - développeur & aide - module NzNoise - (remi.beges@laposte.net) Installation ------------ -Utilisez le système premake pour construire le projet du moteur, dans le dossier build, pour ensuite compiler le moteur pour votre plateforme. +Utilisez le système premake pour construire le projet du moteur, dans le dossier build, pour ensuite compiler le moteur pour votre plateforme. Utilisation ----------- -Vous pouvez lire des tutoriaux sur l'installation, la compilation et l'utilisation à http://wiki.digitalpulsesoftware.com/index.php?title=Nazara:Tutorials +Vous pouvez lire des tutoriaux sur l'installation, la compilation et l'utilisation à http://wiki.digitalpulsesoftware.com/index.php?title=Nazara:Tutorials Contribution ---------- -N'hésitez pas à contribuer à Nazara Engine en : --Contribuant au wiki à http://wiki.digitalpulsesoftware.com/index.php?title=Nazara --Soumettant un patch à GitHub +N'hésitez pas à contribuer à Nazara Engine en : +-Contribuant au wiki à http://wiki.digitalpulsesoftware.com/index.php?title=Nazara +-Soumettant un patch à GitHub -Postant des suggestions/bugs sur le forum ou sur le tracker GitHub (https://github.com/DigitalPulseSoftware/NazaraEngine/issues) -Faisant un fork du projet sur GitHub et en proposant vos changements (https://github.com/DigitalPulseSoftware/NazaraEngine/pulls) --Parlant du Nazara Engine à d'autres personnes +-Parlant du Nazara Engine à d'autres personnes -Faisant n'importe quoi d'autre qui pourrait nous aider. Liens @@ -42,5 +42,5 @@ Site web : http://www.digitalpulsesoftware.com Wiki : http://wiki.digitalpulsesoftware.com/index.php?title=Nazara Forum : http://forum.digitalpulsesoftware.com -Merci à +Merci à -RafBill: Recherche de bugs From f8a0cdad395084af76d44041b30e1d034b4344ae Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 10 Aug 2012 02:03:25 +0200 Subject: [PATCH 03/31] Added Windows shortcut to generate CodeLite project Changed two submesh's error message Fixed OpenGL.hpp/.cpp spaces for some displayers OpenGL loads GL_kdr_debug if possible instead of GL_ARB_debug_output Refactored external includes --- .gitignore | 3 + build/Build CodeLite + examples.bat | 1 + build/Build CodeLite.bat | 1 + build/scripts/common.lua | 7 +- build/scripts/common_examples.lua | 2 +- examples/ListSequences/build.lua | 4 - include/GL3/glcorearb.h | 4598 --------- include/GL3/glext.h | 12800 -------------------------- include/GL3/glxext.h | 1001 -- include/GL3/wglext.h | 943 -- include/Nazara/Renderer/OpenGL.hpp | 262 +- include/Utfcpp/utf8.h | 34 - include/Utfcpp/utf8/checked.h | 327 - include/Utfcpp/utf8/core.h | 351 - include/Utfcpp/utf8/unchecked.h | 228 - src/Nazara/Renderer/OpenGL.cpp | 279 +- src/Nazara/Utility/SubMesh.cpp | 4 +- 17 files changed, 291 insertions(+), 20554 deletions(-) create mode 100644 build/Build CodeLite + examples.bat create mode 100644 build/Build CodeLite.bat delete mode 100644 include/GL3/glcorearb.h delete mode 100644 include/GL3/glext.h delete mode 100644 include/GL3/glxext.h delete mode 100644 include/GL3/wglext.h delete mode 100644 include/Utfcpp/utf8.h delete mode 100644 include/Utfcpp/utf8/checked.h delete mode 100644 include/Utfcpp/utf8/core.h delete mode 100644 include/Utfcpp/utf8/unchecked.h diff --git a/.gitignore b/.gitignore index a4daea85f..c8a3d8d30 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ *.layout *.workspace +# CodeLite +*.project + # Compiled Object files *.slo *.lo diff --git a/build/Build CodeLite + examples.bat b/build/Build CodeLite + examples.bat new file mode 100644 index 000000000..e7ccf26d6 --- /dev/null +++ b/build/Build CodeLite + examples.bat @@ -0,0 +1 @@ +premake4 --with-examples codelite \ No newline at end of file diff --git a/build/Build CodeLite.bat b/build/Build CodeLite.bat new file mode 100644 index 000000000..6243e91aa --- /dev/null +++ b/build/Build CodeLite.bat @@ -0,0 +1 @@ +premake4 codelite \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index 75b85d056..c531d7c52 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -13,8 +13,9 @@ location(_ACTION) includedirs { - "../include", - "../src/" + "../include", + "../src/", + "../extlibs/include" } libdirs "../lib" @@ -35,7 +36,7 @@ configuration "*Static" configuration "*DLL" kind "SharedLib" -configuration "gmake" +configuration "codeblocks or codelite or gmake or xcode3*" buildoptions "-std=c++11" configuration { "linux or bsd or macosx", "gmake" } diff --git a/build/scripts/common_examples.lua b/build/scripts/common_examples.lua index 0fcc880f7..0ef097298 100644 --- a/build/scripts/common_examples.lua +++ b/build/scripts/common_examples.lua @@ -29,5 +29,5 @@ configuration "Release*" configuration "*Static" defines "NAZARA_STATIC" -configuration "gmake" +configuration "codeblocks or codelite or gmake or xcode3*" buildoptions "-std=c++11" diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua index 4d93b53c9..022a86bc8 100644 --- a/examples/ListSequences/build.lua +++ b/examples/ListSequences/build.lua @@ -4,20 +4,16 @@ files "main.cpp" configuration "DebugStatic" links "NazaraCored-s" - links "NazaraRendererd-s" links "NazaraUtilityd-s" configuration "ReleaseStatic" links "NazaraCore-s" - links "NazaraRenderer-s" links "NazaraUtility-s" configuration "DebugDLL" links "NazaraCored" - links "NazaraRendererd" links "NazaraUtilityd" configuration "ReleaseDLL" links "NazaraCore" - links "NazaraRenderer" links "NazaraUtility" \ No newline at end of file diff --git a/include/GL3/glcorearb.h b/include/GL3/glcorearb.h deleted file mode 100644 index df7ca48bc..000000000 --- a/include/GL3/glcorearb.h +++ /dev/null @@ -1,4598 +0,0 @@ -#ifndef __glcorearb_h_ -#define __glcorearb_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* -** Copyright (c) 2007-2012 The Khronos Group Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and/or associated documentation files (the -** "Materials"), to deal in the Materials without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Materials, and to -** permit persons to whom the Materials are furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be included -** in all copies or substantial portions of the Materials. -** -** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -*/ - -/* glcorearb.h replaces gl3.h. It is for use with OpenGL core - * profile implementations. - * - * glcorearb.h last updated on $Date: 2012-08-06 01:59:22 -0700 (Mon, 06 Aug 2012) $ - * - * RELEASE NOTES - 2012/08/06 - * - * glcorearb.h should be placed in the same directory as gl.h and - * included as - * ''. - * - * gl3.h includes only APIs in the latest OpenGL core profile - * implementation together with APIs in newer ARB extensions which can be - * can be supported by the core profile. It does not, and never will - * include functionality removed from the core profile, such as - * fixed-function vertex and fragment processing. - * - * It is not possible to #include both and either of - * or in the same source file. - * - * Feedback can be given by register for the Khronos Bugzilla - * (www.khronos.org/bugzilla) and filing issues there under product - * "OpenGL", category "Registry". - */ - -/* Function declaration macros - to move into glplatform.h */ - -#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) -#define WIN32_LEAN_AND_MEAN 1 -#include -#endif - -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef APIENTRYP -#define APIENTRYP APIENTRY * -#endif -#ifndef GLAPI -#define GLAPI extern -#endif - -/* Base GL types */ - -typedef unsigned int GLenum; -typedef unsigned char GLboolean; -typedef unsigned int GLbitfield; -typedef signed char GLbyte; -typedef short GLshort; -typedef int GLint; -typedef int GLsizei; -typedef unsigned char GLubyte; -typedef unsigned short GLushort; -typedef unsigned int GLuint; -typedef unsigned short GLhalf; -typedef float GLfloat; -typedef float GLclampf; -typedef double GLdouble; -typedef double GLclampd; -typedef void GLvoid; - -/*************************************************************/ - -#ifndef GL_VERSION_1_1 -/* AttribMask */ -#define GL_DEPTH_BUFFER_BIT 0x00000100 -#define GL_STENCIL_BUFFER_BIT 0x00000400 -#define GL_COLOR_BUFFER_BIT 0x00004000 -/* Boolean */ -#define GL_FALSE 0 -#define GL_TRUE 1 -/* BeginMode */ -#define GL_POINTS 0x0000 -#define GL_LINES 0x0001 -#define GL_LINE_LOOP 0x0002 -#define GL_LINE_STRIP 0x0003 -#define GL_TRIANGLES 0x0004 -#define GL_TRIANGLE_STRIP 0x0005 -#define GL_TRIANGLE_FAN 0x0006 -/* AlphaFunction */ -#define GL_NEVER 0x0200 -#define GL_LESS 0x0201 -#define GL_EQUAL 0x0202 -#define GL_LEQUAL 0x0203 -#define GL_GREATER 0x0204 -#define GL_NOTEQUAL 0x0205 -#define GL_GEQUAL 0x0206 -#define GL_ALWAYS 0x0207 -/* BlendingFactorDest */ -#define GL_ZERO 0 -#define GL_ONE 1 -#define GL_SRC_COLOR 0x0300 -#define GL_ONE_MINUS_SRC_COLOR 0x0301 -#define GL_SRC_ALPHA 0x0302 -#define GL_ONE_MINUS_SRC_ALPHA 0x0303 -#define GL_DST_ALPHA 0x0304 -#define GL_ONE_MINUS_DST_ALPHA 0x0305 -/* BlendingFactorSrc */ -#define GL_DST_COLOR 0x0306 -#define GL_ONE_MINUS_DST_COLOR 0x0307 -#define GL_SRC_ALPHA_SATURATE 0x0308 -/* DrawBufferMode */ -#define GL_NONE 0 -#define GL_FRONT_LEFT 0x0400 -#define GL_FRONT_RIGHT 0x0401 -#define GL_BACK_LEFT 0x0402 -#define GL_BACK_RIGHT 0x0403 -#define GL_FRONT 0x0404 -#define GL_BACK 0x0405 -#define GL_LEFT 0x0406 -#define GL_RIGHT 0x0407 -#define GL_FRONT_AND_BACK 0x0408 -/* ErrorCode */ -#define GL_NO_ERROR 0 -#define GL_INVALID_ENUM 0x0500 -#define GL_INVALID_VALUE 0x0501 -#define GL_INVALID_OPERATION 0x0502 -#define GL_OUT_OF_MEMORY 0x0505 -/* FrontFaceDirection */ -#define GL_CW 0x0900 -#define GL_CCW 0x0901 -/* GetPName */ -#define GL_POINT_SIZE 0x0B11 -#define GL_POINT_SIZE_RANGE 0x0B12 -#define GL_POINT_SIZE_GRANULARITY 0x0B13 -#define GL_LINE_SMOOTH 0x0B20 -#define GL_LINE_WIDTH 0x0B21 -#define GL_LINE_WIDTH_RANGE 0x0B22 -#define GL_LINE_WIDTH_GRANULARITY 0x0B23 -#define GL_POLYGON_SMOOTH 0x0B41 -#define GL_CULL_FACE 0x0B44 -#define GL_CULL_FACE_MODE 0x0B45 -#define GL_FRONT_FACE 0x0B46 -#define GL_DEPTH_RANGE 0x0B70 -#define GL_DEPTH_TEST 0x0B71 -#define GL_DEPTH_WRITEMASK 0x0B72 -#define GL_DEPTH_CLEAR_VALUE 0x0B73 -#define GL_DEPTH_FUNC 0x0B74 -#define GL_STENCIL_TEST 0x0B90 -#define GL_STENCIL_CLEAR_VALUE 0x0B91 -#define GL_STENCIL_FUNC 0x0B92 -#define GL_STENCIL_VALUE_MASK 0x0B93 -#define GL_STENCIL_FAIL 0x0B94 -#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 -#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 -#define GL_STENCIL_REF 0x0B97 -#define GL_STENCIL_WRITEMASK 0x0B98 -#define GL_VIEWPORT 0x0BA2 -#define GL_DITHER 0x0BD0 -#define GL_BLEND_DST 0x0BE0 -#define GL_BLEND_SRC 0x0BE1 -#define GL_BLEND 0x0BE2 -#define GL_LOGIC_OP_MODE 0x0BF0 -#define GL_COLOR_LOGIC_OP 0x0BF2 -#define GL_DRAW_BUFFER 0x0C01 -#define GL_READ_BUFFER 0x0C02 -#define GL_SCISSOR_BOX 0x0C10 -#define GL_SCISSOR_TEST 0x0C11 -#define GL_COLOR_CLEAR_VALUE 0x0C22 -#define GL_COLOR_WRITEMASK 0x0C23 -#define GL_DOUBLEBUFFER 0x0C32 -#define GL_STEREO 0x0C33 -#define GL_LINE_SMOOTH_HINT 0x0C52 -#define GL_POLYGON_SMOOTH_HINT 0x0C53 -#define GL_UNPACK_SWAP_BYTES 0x0CF0 -#define GL_UNPACK_LSB_FIRST 0x0CF1 -#define GL_UNPACK_ROW_LENGTH 0x0CF2 -#define GL_UNPACK_SKIP_ROWS 0x0CF3 -#define GL_UNPACK_SKIP_PIXELS 0x0CF4 -#define GL_UNPACK_ALIGNMENT 0x0CF5 -#define GL_PACK_SWAP_BYTES 0x0D00 -#define GL_PACK_LSB_FIRST 0x0D01 -#define GL_PACK_ROW_LENGTH 0x0D02 -#define GL_PACK_SKIP_ROWS 0x0D03 -#define GL_PACK_SKIP_PIXELS 0x0D04 -#define GL_PACK_ALIGNMENT 0x0D05 -#define GL_MAX_TEXTURE_SIZE 0x0D33 -#define GL_MAX_VIEWPORT_DIMS 0x0D3A -#define GL_SUBPIXEL_BITS 0x0D50 -#define GL_TEXTURE_1D 0x0DE0 -#define GL_TEXTURE_2D 0x0DE1 -#define GL_POLYGON_OFFSET_UNITS 0x2A00 -#define GL_POLYGON_OFFSET_POINT 0x2A01 -#define GL_POLYGON_OFFSET_LINE 0x2A02 -#define GL_POLYGON_OFFSET_FILL 0x8037 -#define GL_POLYGON_OFFSET_FACTOR 0x8038 -#define GL_TEXTURE_BINDING_1D 0x8068 -#define GL_TEXTURE_BINDING_2D 0x8069 -/* GetTextureParameter */ -#define GL_TEXTURE_WIDTH 0x1000 -#define GL_TEXTURE_HEIGHT 0x1001 -#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 -#define GL_TEXTURE_BORDER_COLOR 0x1004 -#define GL_TEXTURE_RED_SIZE 0x805C -#define GL_TEXTURE_GREEN_SIZE 0x805D -#define GL_TEXTURE_BLUE_SIZE 0x805E -#define GL_TEXTURE_ALPHA_SIZE 0x805F -/* HintMode */ -#define GL_DONT_CARE 0x1100 -#define GL_FASTEST 0x1101 -#define GL_NICEST 0x1102 -/* DataType */ -#define GL_BYTE 0x1400 -#define GL_UNSIGNED_BYTE 0x1401 -#define GL_SHORT 0x1402 -#define GL_UNSIGNED_SHORT 0x1403 -#define GL_INT 0x1404 -#define GL_UNSIGNED_INT 0x1405 -#define GL_FLOAT 0x1406 -#define GL_DOUBLE 0x140A -/* ErrorCode */ -#define GL_STACK_OVERFLOW 0x0503 -#define GL_STACK_UNDERFLOW 0x0504 -/* LogicOp */ -#define GL_CLEAR 0x1500 -#define GL_AND 0x1501 -#define GL_AND_REVERSE 0x1502 -#define GL_COPY 0x1503 -#define GL_AND_INVERTED 0x1504 -#define GL_NOOP 0x1505 -#define GL_XOR 0x1506 -#define GL_OR 0x1507 -#define GL_NOR 0x1508 -#define GL_EQUIV 0x1509 -#define GL_INVERT 0x150A -#define GL_OR_REVERSE 0x150B -#define GL_COPY_INVERTED 0x150C -#define GL_OR_INVERTED 0x150D -#define GL_NAND 0x150E -#define GL_SET 0x150F -/* MatrixMode (for gl3.h, FBO attachment type) */ -#define GL_TEXTURE 0x1702 -/* PixelCopyType */ -#define GL_COLOR 0x1800 -#define GL_DEPTH 0x1801 -#define GL_STENCIL 0x1802 -/* PixelFormat */ -#define GL_STENCIL_INDEX 0x1901 -#define GL_DEPTH_COMPONENT 0x1902 -#define GL_RED 0x1903 -#define GL_GREEN 0x1904 -#define GL_BLUE 0x1905 -#define GL_ALPHA 0x1906 -#define GL_RGB 0x1907 -#define GL_RGBA 0x1908 -/* PolygonMode */ -#define GL_POINT 0x1B00 -#define GL_LINE 0x1B01 -#define GL_FILL 0x1B02 -/* StencilOp */ -#define GL_KEEP 0x1E00 -#define GL_REPLACE 0x1E01 -#define GL_INCR 0x1E02 -#define GL_DECR 0x1E03 -/* StringName */ -#define GL_VENDOR 0x1F00 -#define GL_RENDERER 0x1F01 -#define GL_VERSION 0x1F02 -#define GL_EXTENSIONS 0x1F03 -/* TextureMagFilter */ -#define GL_NEAREST 0x2600 -#define GL_LINEAR 0x2601 -/* TextureMinFilter */ -#define GL_NEAREST_MIPMAP_NEAREST 0x2700 -#define GL_LINEAR_MIPMAP_NEAREST 0x2701 -#define GL_NEAREST_MIPMAP_LINEAR 0x2702 -#define GL_LINEAR_MIPMAP_LINEAR 0x2703 -/* TextureParameterName */ -#define GL_TEXTURE_MAG_FILTER 0x2800 -#define GL_TEXTURE_MIN_FILTER 0x2801 -#define GL_TEXTURE_WRAP_S 0x2802 -#define GL_TEXTURE_WRAP_T 0x2803 -/* TextureTarget */ -#define GL_PROXY_TEXTURE_1D 0x8063 -#define GL_PROXY_TEXTURE_2D 0x8064 -/* TextureWrapMode */ -#define GL_REPEAT 0x2901 -/* PixelInternalFormat */ -#define GL_R3_G3_B2 0x2A10 -#define GL_RGB4 0x804F -#define GL_RGB5 0x8050 -#define GL_RGB8 0x8051 -#define GL_RGB10 0x8052 -#define GL_RGB12 0x8053 -#define GL_RGB16 0x8054 -#define GL_RGBA2 0x8055 -#define GL_RGBA4 0x8056 -#define GL_RGB5_A1 0x8057 -#define GL_RGBA8 0x8058 -#define GL_RGB10_A2 0x8059 -#define GL_RGBA12 0x805A -#define GL_RGBA16 0x805B -#endif - -#ifndef GL_VERSION_1_2 -#define GL_UNSIGNED_BYTE_3_3_2 0x8032 -#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 -#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#define GL_UNSIGNED_INT_10_10_10_2 0x8036 -#define GL_TEXTURE_BINDING_3D 0x806A -#define GL_PACK_SKIP_IMAGES 0x806B -#define GL_PACK_IMAGE_HEIGHT 0x806C -#define GL_UNPACK_SKIP_IMAGES 0x806D -#define GL_UNPACK_IMAGE_HEIGHT 0x806E -#define GL_TEXTURE_3D 0x806F -#define GL_PROXY_TEXTURE_3D 0x8070 -#define GL_TEXTURE_DEPTH 0x8071 -#define GL_TEXTURE_WRAP_R 0x8072 -#define GL_MAX_3D_TEXTURE_SIZE 0x8073 -#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 -#define GL_UNSIGNED_SHORT_5_6_5 0x8363 -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_BGR 0x80E0 -#define GL_BGRA 0x80E1 -#define GL_MAX_ELEMENTS_VERTICES 0x80E8 -#define GL_MAX_ELEMENTS_INDICES 0x80E9 -#define GL_CLAMP_TO_EDGE 0x812F -#define GL_TEXTURE_MIN_LOD 0x813A -#define GL_TEXTURE_MAX_LOD 0x813B -#define GL_TEXTURE_BASE_LEVEL 0x813C -#define GL_TEXTURE_MAX_LEVEL 0x813D -#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 -#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 -#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 -#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 -#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E -#endif - -#ifndef GL_ARB_imaging -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 -#define GL_BLEND_COLOR 0x8005 -#define GL_FUNC_ADD 0x8006 -#define GL_MIN 0x8007 -#define GL_MAX 0x8008 -#define GL_BLEND_EQUATION 0x8009 -#define GL_FUNC_SUBTRACT 0x800A -#define GL_FUNC_REVERSE_SUBTRACT 0x800B -#endif - -#ifndef GL_VERSION_1_3 -#define GL_TEXTURE0 0x84C0 -#define GL_TEXTURE1 0x84C1 -#define GL_TEXTURE2 0x84C2 -#define GL_TEXTURE3 0x84C3 -#define GL_TEXTURE4 0x84C4 -#define GL_TEXTURE5 0x84C5 -#define GL_TEXTURE6 0x84C6 -#define GL_TEXTURE7 0x84C7 -#define GL_TEXTURE8 0x84C8 -#define GL_TEXTURE9 0x84C9 -#define GL_TEXTURE10 0x84CA -#define GL_TEXTURE11 0x84CB -#define GL_TEXTURE12 0x84CC -#define GL_TEXTURE13 0x84CD -#define GL_TEXTURE14 0x84CE -#define GL_TEXTURE15 0x84CF -#define GL_TEXTURE16 0x84D0 -#define GL_TEXTURE17 0x84D1 -#define GL_TEXTURE18 0x84D2 -#define GL_TEXTURE19 0x84D3 -#define GL_TEXTURE20 0x84D4 -#define GL_TEXTURE21 0x84D5 -#define GL_TEXTURE22 0x84D6 -#define GL_TEXTURE23 0x84D7 -#define GL_TEXTURE24 0x84D8 -#define GL_TEXTURE25 0x84D9 -#define GL_TEXTURE26 0x84DA -#define GL_TEXTURE27 0x84DB -#define GL_TEXTURE28 0x84DC -#define GL_TEXTURE29 0x84DD -#define GL_TEXTURE30 0x84DE -#define GL_TEXTURE31 0x84DF -#define GL_ACTIVE_TEXTURE 0x84E0 -#define GL_MULTISAMPLE 0x809D -#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE 0x809F -#define GL_SAMPLE_COVERAGE 0x80A0 -#define GL_SAMPLE_BUFFERS 0x80A8 -#define GL_SAMPLES 0x80A9 -#define GL_SAMPLE_COVERAGE_VALUE 0x80AA -#define GL_SAMPLE_COVERAGE_INVERT 0x80AB -#define GL_TEXTURE_CUBE_MAP 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A -#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C -#define GL_COMPRESSED_RGB 0x84ED -#define GL_COMPRESSED_RGBA 0x84EE -#define GL_TEXTURE_COMPRESSION_HINT 0x84EF -#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 -#define GL_TEXTURE_COMPRESSED 0x86A1 -#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 -#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 -#define GL_CLAMP_TO_BORDER 0x812D -#endif - -#ifndef GL_VERSION_1_4 -#define GL_BLEND_DST_RGB 0x80C8 -#define GL_BLEND_SRC_RGB 0x80C9 -#define GL_BLEND_DST_ALPHA 0x80CA -#define GL_BLEND_SRC_ALPHA 0x80CB -#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 -#define GL_DEPTH_COMPONENT16 0x81A5 -#define GL_DEPTH_COMPONENT24 0x81A6 -#define GL_DEPTH_COMPONENT32 0x81A7 -#define GL_MIRRORED_REPEAT 0x8370 -#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD -#define GL_TEXTURE_LOD_BIAS 0x8501 -#define GL_INCR_WRAP 0x8507 -#define GL_DECR_WRAP 0x8508 -#define GL_TEXTURE_DEPTH_SIZE 0x884A -#define GL_TEXTURE_COMPARE_MODE 0x884C -#define GL_TEXTURE_COMPARE_FUNC 0x884D -#endif - -#ifndef GL_VERSION_1_5 -#define GL_BUFFER_SIZE 0x8764 -#define GL_BUFFER_USAGE 0x8765 -#define GL_QUERY_COUNTER_BITS 0x8864 -#define GL_CURRENT_QUERY 0x8865 -#define GL_QUERY_RESULT 0x8866 -#define GL_QUERY_RESULT_AVAILABLE 0x8867 -#define GL_ARRAY_BUFFER 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 -#define GL_ARRAY_BUFFER_BINDING 0x8894 -#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 -#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F -#define GL_READ_ONLY 0x88B8 -#define GL_WRITE_ONLY 0x88B9 -#define GL_READ_WRITE 0x88BA -#define GL_BUFFER_ACCESS 0x88BB -#define GL_BUFFER_MAPPED 0x88BC -#define GL_BUFFER_MAP_POINTER 0x88BD -#define GL_STREAM_DRAW 0x88E0 -#define GL_STREAM_READ 0x88E1 -#define GL_STREAM_COPY 0x88E2 -#define GL_STATIC_DRAW 0x88E4 -#define GL_STATIC_READ 0x88E5 -#define GL_STATIC_COPY 0x88E6 -#define GL_DYNAMIC_DRAW 0x88E8 -#define GL_DYNAMIC_READ 0x88E9 -#define GL_DYNAMIC_COPY 0x88EA -#define GL_SAMPLES_PASSED 0x8914 -#endif - -#ifndef GL_VERSION_2_0 -#define GL_BLEND_EQUATION_RGB 0x8009 -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 -#define GL_CURRENT_VERTEX_ATTRIB 0x8626 -#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 -#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 -#define GL_STENCIL_BACK_FUNC 0x8800 -#define GL_STENCIL_BACK_FAIL 0x8801 -#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 -#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 -#define GL_MAX_DRAW_BUFFERS 0x8824 -#define GL_DRAW_BUFFER0 0x8825 -#define GL_DRAW_BUFFER1 0x8826 -#define GL_DRAW_BUFFER2 0x8827 -#define GL_DRAW_BUFFER3 0x8828 -#define GL_DRAW_BUFFER4 0x8829 -#define GL_DRAW_BUFFER5 0x882A -#define GL_DRAW_BUFFER6 0x882B -#define GL_DRAW_BUFFER7 0x882C -#define GL_DRAW_BUFFER8 0x882D -#define GL_DRAW_BUFFER9 0x882E -#define GL_DRAW_BUFFER10 0x882F -#define GL_DRAW_BUFFER11 0x8830 -#define GL_DRAW_BUFFER12 0x8831 -#define GL_DRAW_BUFFER13 0x8832 -#define GL_DRAW_BUFFER14 0x8833 -#define GL_DRAW_BUFFER15 0x8834 -#define GL_BLEND_EQUATION_ALPHA 0x883D -#define GL_MAX_VERTEX_ATTRIBS 0x8869 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A -#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 -#define GL_FRAGMENT_SHADER 0x8B30 -#define GL_VERTEX_SHADER 0x8B31 -#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 -#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A -#define GL_MAX_VARYING_FLOATS 0x8B4B -#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C -#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D -#define GL_SHADER_TYPE 0x8B4F -#define GL_FLOAT_VEC2 0x8B50 -#define GL_FLOAT_VEC3 0x8B51 -#define GL_FLOAT_VEC4 0x8B52 -#define GL_INT_VEC2 0x8B53 -#define GL_INT_VEC3 0x8B54 -#define GL_INT_VEC4 0x8B55 -#define GL_BOOL 0x8B56 -#define GL_BOOL_VEC2 0x8B57 -#define GL_BOOL_VEC3 0x8B58 -#define GL_BOOL_VEC4 0x8B59 -#define GL_FLOAT_MAT2 0x8B5A -#define GL_FLOAT_MAT3 0x8B5B -#define GL_FLOAT_MAT4 0x8B5C -#define GL_SAMPLER_1D 0x8B5D -#define GL_SAMPLER_2D 0x8B5E -#define GL_SAMPLER_3D 0x8B5F -#define GL_SAMPLER_CUBE 0x8B60 -#define GL_SAMPLER_1D_SHADOW 0x8B61 -#define GL_SAMPLER_2D_SHADOW 0x8B62 -#define GL_DELETE_STATUS 0x8B80 -#define GL_COMPILE_STATUS 0x8B81 -#define GL_LINK_STATUS 0x8B82 -#define GL_VALIDATE_STATUS 0x8B83 -#define GL_INFO_LOG_LENGTH 0x8B84 -#define GL_ATTACHED_SHADERS 0x8B85 -#define GL_ACTIVE_UNIFORMS 0x8B86 -#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 -#define GL_SHADER_SOURCE_LENGTH 0x8B88 -#define GL_ACTIVE_ATTRIBUTES 0x8B89 -#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A -#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B -#define GL_SHADING_LANGUAGE_VERSION 0x8B8C -#define GL_CURRENT_PROGRAM 0x8B8D -#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 -#define GL_LOWER_LEFT 0x8CA1 -#define GL_UPPER_LEFT 0x8CA2 -#define GL_STENCIL_BACK_REF 0x8CA3 -#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 -#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 -#endif - -#ifndef GL_VERSION_2_1 -#define GL_PIXEL_PACK_BUFFER 0x88EB -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED -#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF -#define GL_FLOAT_MAT2x3 0x8B65 -#define GL_FLOAT_MAT2x4 0x8B66 -#define GL_FLOAT_MAT3x2 0x8B67 -#define GL_FLOAT_MAT3x4 0x8B68 -#define GL_FLOAT_MAT4x2 0x8B69 -#define GL_FLOAT_MAT4x3 0x8B6A -#define GL_SRGB 0x8C40 -#define GL_SRGB8 0x8C41 -#define GL_SRGB_ALPHA 0x8C42 -#define GL_SRGB8_ALPHA8 0x8C43 -#define GL_COMPRESSED_SRGB 0x8C48 -#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 -#endif - -#ifndef GL_VERSION_3_0 -#define GL_COMPARE_REF_TO_TEXTURE 0x884E -#define GL_CLIP_DISTANCE0 0x3000 -#define GL_CLIP_DISTANCE1 0x3001 -#define GL_CLIP_DISTANCE2 0x3002 -#define GL_CLIP_DISTANCE3 0x3003 -#define GL_CLIP_DISTANCE4 0x3004 -#define GL_CLIP_DISTANCE5 0x3005 -#define GL_CLIP_DISTANCE6 0x3006 -#define GL_CLIP_DISTANCE7 0x3007 -#define GL_MAX_CLIP_DISTANCES 0x0D32 -#define GL_MAJOR_VERSION 0x821B -#define GL_MINOR_VERSION 0x821C -#define GL_NUM_EXTENSIONS 0x821D -#define GL_CONTEXT_FLAGS 0x821E -#define GL_COMPRESSED_RED 0x8225 -#define GL_COMPRESSED_RG 0x8226 -#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 -#define GL_RGBA32F 0x8814 -#define GL_RGB32F 0x8815 -#define GL_RGBA16F 0x881A -#define GL_RGB16F 0x881B -#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD -#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF -#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 -#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 -#define GL_CLAMP_READ_COLOR 0x891C -#define GL_FIXED_ONLY 0x891D -#define GL_MAX_VARYING_COMPONENTS 0x8B4B -#define GL_TEXTURE_1D_ARRAY 0x8C18 -#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 -#define GL_TEXTURE_2D_ARRAY 0x8C1A -#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B -#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C -#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D -#define GL_R11F_G11F_B10F 0x8C3A -#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B -#define GL_RGB9_E5 0x8C3D -#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E -#define GL_TEXTURE_SHARED_SIZE 0x8C3F -#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 -#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 -#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 -#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 -#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 -#define GL_PRIMITIVES_GENERATED 0x8C87 -#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 -#define GL_RASTERIZER_DISCARD 0x8C89 -#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B -#define GL_INTERLEAVED_ATTRIBS 0x8C8C -#define GL_SEPARATE_ATTRIBS 0x8C8D -#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E -#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F -#define GL_RGBA32UI 0x8D70 -#define GL_RGB32UI 0x8D71 -#define GL_RGBA16UI 0x8D76 -#define GL_RGB16UI 0x8D77 -#define GL_RGBA8UI 0x8D7C -#define GL_RGB8UI 0x8D7D -#define GL_RGBA32I 0x8D82 -#define GL_RGB32I 0x8D83 -#define GL_RGBA16I 0x8D88 -#define GL_RGB16I 0x8D89 -#define GL_RGBA8I 0x8D8E -#define GL_RGB8I 0x8D8F -#define GL_RED_INTEGER 0x8D94 -#define GL_GREEN_INTEGER 0x8D95 -#define GL_BLUE_INTEGER 0x8D96 -#define GL_RGB_INTEGER 0x8D98 -#define GL_RGBA_INTEGER 0x8D99 -#define GL_BGR_INTEGER 0x8D9A -#define GL_BGRA_INTEGER 0x8D9B -#define GL_SAMPLER_1D_ARRAY 0x8DC0 -#define GL_SAMPLER_2D_ARRAY 0x8DC1 -#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 -#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 -#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 -#define GL_UNSIGNED_INT_VEC2 0x8DC6 -#define GL_UNSIGNED_INT_VEC3 0x8DC7 -#define GL_UNSIGNED_INT_VEC4 0x8DC8 -#define GL_INT_SAMPLER_1D 0x8DC9 -#define GL_INT_SAMPLER_2D 0x8DCA -#define GL_INT_SAMPLER_3D 0x8DCB -#define GL_INT_SAMPLER_CUBE 0x8DCC -#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE -#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF -#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 -#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 -#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 -#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 -#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 -#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 -#define GL_QUERY_WAIT 0x8E13 -#define GL_QUERY_NO_WAIT 0x8E14 -#define GL_QUERY_BY_REGION_WAIT 0x8E15 -#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 -#define GL_BUFFER_ACCESS_FLAGS 0x911F -#define GL_BUFFER_MAP_LENGTH 0x9120 -#define GL_BUFFER_MAP_OFFSET 0x9121 -/* Reuse tokens from ARB_depth_buffer_float */ -/* reuse GL_DEPTH_COMPONENT32F */ -/* reuse GL_DEPTH32F_STENCIL8 */ -/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ -/* Reuse tokens from ARB_framebuffer_object */ -/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ -/* reuse GL_FRAMEBUFFER_DEFAULT */ -/* reuse GL_FRAMEBUFFER_UNDEFINED */ -/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ -/* reuse GL_INDEX */ -/* reuse GL_MAX_RENDERBUFFER_SIZE */ -/* reuse GL_DEPTH_STENCIL */ -/* reuse GL_UNSIGNED_INT_24_8 */ -/* reuse GL_DEPTH24_STENCIL8 */ -/* reuse GL_TEXTURE_STENCIL_SIZE */ -/* reuse GL_TEXTURE_RED_TYPE */ -/* reuse GL_TEXTURE_GREEN_TYPE */ -/* reuse GL_TEXTURE_BLUE_TYPE */ -/* reuse GL_TEXTURE_ALPHA_TYPE */ -/* reuse GL_TEXTURE_DEPTH_TYPE */ -/* reuse GL_UNSIGNED_NORMALIZED */ -/* reuse GL_FRAMEBUFFER_BINDING */ -/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ -/* reuse GL_RENDERBUFFER_BINDING */ -/* reuse GL_READ_FRAMEBUFFER */ -/* reuse GL_DRAW_FRAMEBUFFER */ -/* reuse GL_READ_FRAMEBUFFER_BINDING */ -/* reuse GL_RENDERBUFFER_SAMPLES */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ -/* reuse GL_FRAMEBUFFER_COMPLETE */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ -/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ -/* reuse GL_MAX_COLOR_ATTACHMENTS */ -/* reuse GL_COLOR_ATTACHMENT0 */ -/* reuse GL_COLOR_ATTACHMENT1 */ -/* reuse GL_COLOR_ATTACHMENT2 */ -/* reuse GL_COLOR_ATTACHMENT3 */ -/* reuse GL_COLOR_ATTACHMENT4 */ -/* reuse GL_COLOR_ATTACHMENT5 */ -/* reuse GL_COLOR_ATTACHMENT6 */ -/* reuse GL_COLOR_ATTACHMENT7 */ -/* reuse GL_COLOR_ATTACHMENT8 */ -/* reuse GL_COLOR_ATTACHMENT9 */ -/* reuse GL_COLOR_ATTACHMENT10 */ -/* reuse GL_COLOR_ATTACHMENT11 */ -/* reuse GL_COLOR_ATTACHMENT12 */ -/* reuse GL_COLOR_ATTACHMENT13 */ -/* reuse GL_COLOR_ATTACHMENT14 */ -/* reuse GL_COLOR_ATTACHMENT15 */ -/* reuse GL_DEPTH_ATTACHMENT */ -/* reuse GL_STENCIL_ATTACHMENT */ -/* reuse GL_FRAMEBUFFER */ -/* reuse GL_RENDERBUFFER */ -/* reuse GL_RENDERBUFFER_WIDTH */ -/* reuse GL_RENDERBUFFER_HEIGHT */ -/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ -/* reuse GL_STENCIL_INDEX1 */ -/* reuse GL_STENCIL_INDEX4 */ -/* reuse GL_STENCIL_INDEX8 */ -/* reuse GL_STENCIL_INDEX16 */ -/* reuse GL_RENDERBUFFER_RED_SIZE */ -/* reuse GL_RENDERBUFFER_GREEN_SIZE */ -/* reuse GL_RENDERBUFFER_BLUE_SIZE */ -/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ -/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ -/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ -/* reuse GL_MAX_SAMPLES */ -/* Reuse tokens from ARB_framebuffer_sRGB */ -/* reuse GL_FRAMEBUFFER_SRGB */ -/* Reuse tokens from ARB_half_float_vertex */ -/* reuse GL_HALF_FLOAT */ -/* Reuse tokens from ARB_map_buffer_range */ -/* reuse GL_MAP_READ_BIT */ -/* reuse GL_MAP_WRITE_BIT */ -/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ -/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ -/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ -/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ -/* Reuse tokens from ARB_texture_compression_rgtc */ -/* reuse GL_COMPRESSED_RED_RGTC1 */ -/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ -/* reuse GL_COMPRESSED_RG_RGTC2 */ -/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ -/* Reuse tokens from ARB_texture_rg */ -/* reuse GL_RG */ -/* reuse GL_RG_INTEGER */ -/* reuse GL_R8 */ -/* reuse GL_R16 */ -/* reuse GL_RG8 */ -/* reuse GL_RG16 */ -/* reuse GL_R16F */ -/* reuse GL_R32F */ -/* reuse GL_RG16F */ -/* reuse GL_RG32F */ -/* reuse GL_R8I */ -/* reuse GL_R8UI */ -/* reuse GL_R16I */ -/* reuse GL_R16UI */ -/* reuse GL_R32I */ -/* reuse GL_R32UI */ -/* reuse GL_RG8I */ -/* reuse GL_RG8UI */ -/* reuse GL_RG16I */ -/* reuse GL_RG16UI */ -/* reuse GL_RG32I */ -/* reuse GL_RG32UI */ -/* Reuse tokens from ARB_vertex_array_object */ -/* reuse GL_VERTEX_ARRAY_BINDING */ -#endif - -#ifndef GL_VERSION_3_1 -#define GL_SAMPLER_2D_RECT 0x8B63 -#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 -#define GL_SAMPLER_BUFFER 0x8DC2 -#define GL_INT_SAMPLER_2D_RECT 0x8DCD -#define GL_INT_SAMPLER_BUFFER 0x8DD0 -#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 -#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 -#define GL_TEXTURE_BUFFER 0x8C2A -#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B -#define GL_TEXTURE_BINDING_BUFFER 0x8C2C -#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D -#define GL_TEXTURE_BUFFER_FORMAT 0x8C2E -#define GL_TEXTURE_RECTANGLE 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 -#define GL_RED_SNORM 0x8F90 -#define GL_RG_SNORM 0x8F91 -#define GL_RGB_SNORM 0x8F92 -#define GL_RGBA_SNORM 0x8F93 -#define GL_R8_SNORM 0x8F94 -#define GL_RG8_SNORM 0x8F95 -#define GL_RGB8_SNORM 0x8F96 -#define GL_RGBA8_SNORM 0x8F97 -#define GL_R16_SNORM 0x8F98 -#define GL_RG16_SNORM 0x8F99 -#define GL_RGB16_SNORM 0x8F9A -#define GL_RGBA16_SNORM 0x8F9B -#define GL_SIGNED_NORMALIZED 0x8F9C -#define GL_PRIMITIVE_RESTART 0x8F9D -#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E -/* Reuse tokens from ARB_copy_buffer */ -/* reuse GL_COPY_READ_BUFFER */ -/* reuse GL_COPY_WRITE_BUFFER */ -/* Reuse tokens from ARB_draw_instanced (none) */ -/* Reuse tokens from ARB_uniform_buffer_object */ -/* reuse GL_UNIFORM_BUFFER */ -/* reuse GL_UNIFORM_BUFFER_BINDING */ -/* reuse GL_UNIFORM_BUFFER_START */ -/* reuse GL_UNIFORM_BUFFER_SIZE */ -/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ -/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ -/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ -/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ -/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ -/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ -/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ -/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ -/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ -/* reuse GL_UNIFORM_TYPE */ -/* reuse GL_UNIFORM_SIZE */ -/* reuse GL_UNIFORM_NAME_LENGTH */ -/* reuse GL_UNIFORM_BLOCK_INDEX */ -/* reuse GL_UNIFORM_OFFSET */ -/* reuse GL_UNIFORM_ARRAY_STRIDE */ -/* reuse GL_UNIFORM_MATRIX_STRIDE */ -/* reuse GL_UNIFORM_IS_ROW_MAJOR */ -/* reuse GL_UNIFORM_BLOCK_BINDING */ -/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ -/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ -/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ -/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ -/* reuse GL_INVALID_INDEX */ -#endif - -#ifndef GL_VERSION_3_2 -#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 -#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 -#define GL_LINES_ADJACENCY 0x000A -#define GL_LINE_STRIP_ADJACENCY 0x000B -#define GL_TRIANGLES_ADJACENCY 0x000C -#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D -#define GL_PROGRAM_POINT_SIZE 0x8642 -#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 -#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 -#define GL_GEOMETRY_SHADER 0x8DD9 -#define GL_GEOMETRY_VERTICES_OUT 0x8916 -#define GL_GEOMETRY_INPUT_TYPE 0x8917 -#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 -#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF -#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 -#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 -#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 -#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 -#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 -#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 -#define GL_CONTEXT_PROFILE_MASK 0x9126 -/* reuse GL_MAX_VARYING_COMPONENTS */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ -/* Reuse tokens from ARB_depth_clamp */ -/* reuse GL_DEPTH_CLAMP */ -/* Reuse tokens from ARB_draw_elements_base_vertex (none) */ -/* Reuse tokens from ARB_fragment_coord_conventions (none) */ -/* Reuse tokens from ARB_provoking_vertex */ -/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ -/* reuse GL_FIRST_VERTEX_CONVENTION */ -/* reuse GL_LAST_VERTEX_CONVENTION */ -/* reuse GL_PROVOKING_VERTEX */ -/* Reuse tokens from ARB_seamless_cube_map */ -/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ -/* Reuse tokens from ARB_sync */ -/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ -/* reuse GL_OBJECT_TYPE */ -/* reuse GL_SYNC_CONDITION */ -/* reuse GL_SYNC_STATUS */ -/* reuse GL_SYNC_FLAGS */ -/* reuse GL_SYNC_FENCE */ -/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ -/* reuse GL_UNSIGNALED */ -/* reuse GL_SIGNALED */ -/* reuse GL_ALREADY_SIGNALED */ -/* reuse GL_TIMEOUT_EXPIRED */ -/* reuse GL_CONDITION_SATISFIED */ -/* reuse GL_WAIT_FAILED */ -/* reuse GL_TIMEOUT_IGNORED */ -/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ -/* reuse GL_TIMEOUT_IGNORED */ -/* Reuse tokens from ARB_texture_multisample */ -/* reuse GL_SAMPLE_POSITION */ -/* reuse GL_SAMPLE_MASK */ -/* reuse GL_SAMPLE_MASK_VALUE */ -/* reuse GL_MAX_SAMPLE_MASK_WORDS */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE */ -/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ -/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_TEXTURE_SAMPLES */ -/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ -/* reuse GL_SAMPLER_2D_MULTISAMPLE */ -/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ -/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ -/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ -/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ -/* reuse GL_MAX_INTEGER_SAMPLES */ -/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ -#endif - -#ifndef GL_VERSION_3_3 -#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE -/* Reuse tokens from ARB_blend_func_extended */ -/* reuse GL_SRC1_COLOR */ -/* reuse GL_ONE_MINUS_SRC1_COLOR */ -/* reuse GL_ONE_MINUS_SRC1_ALPHA */ -/* reuse GL_MAX_DUAL_SOURCE_DRAW_BUFFERS */ -/* Reuse tokens from ARB_explicit_attrib_location (none) */ -/* Reuse tokens from ARB_occlusion_query2 */ -/* reuse GL_ANY_SAMPLES_PASSED */ -/* Reuse tokens from ARB_sampler_objects */ -/* reuse GL_SAMPLER_BINDING */ -/* Reuse tokens from ARB_shader_bit_encoding (none) */ -/* Reuse tokens from ARB_texture_rgb10_a2ui */ -/* reuse GL_RGB10_A2UI */ -/* Reuse tokens from ARB_texture_swizzle */ -/* reuse GL_TEXTURE_SWIZZLE_R */ -/* reuse GL_TEXTURE_SWIZZLE_G */ -/* reuse GL_TEXTURE_SWIZZLE_B */ -/* reuse GL_TEXTURE_SWIZZLE_A */ -/* reuse GL_TEXTURE_SWIZZLE_RGBA */ -/* Reuse tokens from ARB_timer_query */ -/* reuse GL_TIME_ELAPSED */ -/* reuse GL_TIMESTAMP */ -/* Reuse tokens from ARB_vertex_type_2_10_10_10_rev */ -/* reuse GL_INT_2_10_10_10_REV */ -#endif - -#ifndef GL_VERSION_4_0 -#define GL_SAMPLE_SHADING 0x8C36 -#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 -#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E -#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F -#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B -#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C -#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D -#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E -#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F -/* Reuse tokens from ARB_texture_query_lod (none) */ -/* Reuse tokens from ARB_draw_buffers_blend (none) */ -/* Reuse tokens from ARB_draw_indirect */ -/* reuse GL_DRAW_INDIRECT_BUFFER */ -/* reuse GL_DRAW_INDIRECT_BUFFER_BINDING */ -/* Reuse tokens from ARB_gpu_shader5 */ -/* reuse GL_GEOMETRY_SHADER_INVOCATIONS */ -/* reuse GL_MAX_GEOMETRY_SHADER_INVOCATIONS */ -/* reuse GL_MIN_FRAGMENT_INTERPOLATION_OFFSET */ -/* reuse GL_MAX_FRAGMENT_INTERPOLATION_OFFSET */ -/* reuse GL_FRAGMENT_INTERPOLATION_OFFSET_BITS */ -/* reuse GL_MAX_VERTEX_STREAMS */ -/* Reuse tokens from ARB_gpu_shader_fp64 */ -/* reuse GL_DOUBLE_VEC2 */ -/* reuse GL_DOUBLE_VEC3 */ -/* reuse GL_DOUBLE_VEC4 */ -/* reuse GL_DOUBLE_MAT2 */ -/* reuse GL_DOUBLE_MAT3 */ -/* reuse GL_DOUBLE_MAT4 */ -/* reuse GL_DOUBLE_MAT2x3 */ -/* reuse GL_DOUBLE_MAT2x4 */ -/* reuse GL_DOUBLE_MAT3x2 */ -/* reuse GL_DOUBLE_MAT3x4 */ -/* reuse GL_DOUBLE_MAT4x2 */ -/* reuse GL_DOUBLE_MAT4x3 */ -/* Reuse tokens from ARB_shader_subroutine */ -/* reuse GL_ACTIVE_SUBROUTINES */ -/* reuse GL_ACTIVE_SUBROUTINE_UNIFORMS */ -/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS */ -/* reuse GL_ACTIVE_SUBROUTINE_MAX_LENGTH */ -/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH */ -/* reuse GL_MAX_SUBROUTINES */ -/* reuse GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS */ -/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ -/* reuse GL_COMPATIBLE_SUBROUTINES */ -/* Reuse tokens from ARB_tessellation_shader */ -/* reuse GL_PATCHES */ -/* reuse GL_PATCH_VERTICES */ -/* reuse GL_PATCH_DEFAULT_INNER_LEVEL */ -/* reuse GL_PATCH_DEFAULT_OUTER_LEVEL */ -/* reuse GL_TESS_CONTROL_OUTPUT_VERTICES */ -/* reuse GL_TESS_GEN_MODE */ -/* reuse GL_TESS_GEN_SPACING */ -/* reuse GL_TESS_GEN_VERTEX_ORDER */ -/* reuse GL_TESS_GEN_POINT_MODE */ -/* reuse GL_ISOLINES */ -/* reuse GL_FRACTIONAL_ODD */ -/* reuse GL_FRACTIONAL_EVEN */ -/* reuse GL_MAX_PATCH_VERTICES */ -/* reuse GL_MAX_TESS_GEN_LEVEL */ -/* reuse GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS */ -/* reuse GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS */ -/* reuse GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_PATCH_COMPONENTS */ -/* reuse GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS */ -/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS */ -/* reuse GL_MAX_TESS_CONTROL_INPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS */ -/* reuse GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER */ -/* reuse GL_TESS_EVALUATION_SHADER */ -/* reuse GL_TESS_CONTROL_SHADER */ -/* Reuse tokens from ARB_texture_buffer_object_rgb32 (none) */ -/* Reuse tokens from ARB_transform_feedback2 */ -/* reuse GL_TRANSFORM_FEEDBACK */ -/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED */ -/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE */ -/* reuse GL_TRANSFORM_FEEDBACK_BINDING */ -/* Reuse tokens from ARB_transform_feedback3 */ -/* reuse GL_MAX_TRANSFORM_FEEDBACK_BUFFERS */ -/* reuse GL_MAX_VERTEX_STREAMS */ -#endif - -#ifndef GL_VERSION_4_1 -/* Reuse tokens from ARB_ES2_compatibility */ -/* reuse GL_FIXED */ -/* reuse GL_IMPLEMENTATION_COLOR_READ_TYPE */ -/* reuse GL_IMPLEMENTATION_COLOR_READ_FORMAT */ -/* reuse GL_LOW_FLOAT */ -/* reuse GL_MEDIUM_FLOAT */ -/* reuse GL_HIGH_FLOAT */ -/* reuse GL_LOW_INT */ -/* reuse GL_MEDIUM_INT */ -/* reuse GL_HIGH_INT */ -/* reuse GL_SHADER_COMPILER */ -/* reuse GL_NUM_SHADER_BINARY_FORMATS */ -/* reuse GL_MAX_VERTEX_UNIFORM_VECTORS */ -/* reuse GL_MAX_VARYING_VECTORS */ -/* reuse GL_MAX_FRAGMENT_UNIFORM_VECTORS */ -/* reuse GL_RGB565 */ -/* Reuse tokens from ARB_get_program_binary */ -/* reuse GL_PROGRAM_BINARY_RETRIEVABLE_HINT */ -/* reuse GL_PROGRAM_BINARY_LENGTH */ -/* reuse GL_NUM_PROGRAM_BINARY_FORMATS */ -/* reuse GL_PROGRAM_BINARY_FORMATS */ -/* Reuse tokens from ARB_separate_shader_objects */ -/* reuse GL_VERTEX_SHADER_BIT */ -/* reuse GL_FRAGMENT_SHADER_BIT */ -/* reuse GL_GEOMETRY_SHADER_BIT */ -/* reuse GL_TESS_CONTROL_SHADER_BIT */ -/* reuse GL_TESS_EVALUATION_SHADER_BIT */ -/* reuse GL_ALL_SHADER_BITS */ -/* reuse GL_PROGRAM_SEPARABLE */ -/* reuse GL_ACTIVE_PROGRAM */ -/* reuse GL_PROGRAM_PIPELINE_BINDING */ -/* Reuse tokens from ARB_shader_precision (none) */ -/* Reuse tokens from ARB_vertex_attrib_64bit - all are in GL 3.0 and 4.0 already */ -/* Reuse tokens from ARB_viewport_array - some are in GL 1.1 and ARB_provoking_vertex already */ -/* reuse GL_MAX_VIEWPORTS */ -/* reuse GL_VIEWPORT_SUBPIXEL_BITS */ -/* reuse GL_VIEWPORT_BOUNDS_RANGE */ -/* reuse GL_LAYER_PROVOKING_VERTEX */ -/* reuse GL_VIEWPORT_INDEX_PROVOKING_VERTEX */ -/* reuse GL_UNDEFINED_VERTEX */ -#endif - -#ifndef GL_VERSION_4_2 -/* Reuse tokens from ARB_base_instance (none) */ -/* Reuse tokens from ARB_shading_language_420pack (none) */ -/* Reuse tokens from ARB_transform_feedback_instanced (none) */ -/* Reuse tokens from ARB_compressed_texture_pixel_storage */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_WIDTH */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_HEIGHT */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_DEPTH */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_SIZE */ -/* reuse GL_PACK_COMPRESSED_BLOCK_WIDTH */ -/* reuse GL_PACK_COMPRESSED_BLOCK_HEIGHT */ -/* reuse GL_PACK_COMPRESSED_BLOCK_DEPTH */ -/* reuse GL_PACK_COMPRESSED_BLOCK_SIZE */ -/* Reuse tokens from ARB_conservative_depth (none) */ -/* Reuse tokens from ARB_internalformat_query */ -/* reuse GL_NUM_SAMPLE_COUNTS */ -/* Reuse tokens from ARB_map_buffer_alignment */ -/* reuse GL_MIN_MAP_BUFFER_ALIGNMENT */ -/* Reuse tokens from ARB_shader_atomic_counters */ -/* reuse GL_ATOMIC_COUNTER_BUFFER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_BINDING */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_START */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_SIZE */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER */ -/* reuse GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_VERTEX_ATOMIC_COUNTERS */ -/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS */ -/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS */ -/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTERS */ -/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTERS */ -/* reuse GL_MAX_COMBINED_ATOMIC_COUNTERS */ -/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE */ -/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS */ -/* reuse GL_ACTIVE_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX */ -/* reuse GL_UNSIGNED_INT_ATOMIC_COUNTER */ -/* Reuse tokens from ARB_shader_image_load_store */ -/* reuse GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT */ -/* reuse GL_ELEMENT_ARRAY_BARRIER_BIT */ -/* reuse GL_UNIFORM_BARRIER_BIT */ -/* reuse GL_TEXTURE_FETCH_BARRIER_BIT */ -/* reuse GL_SHADER_IMAGE_ACCESS_BARRIER_BIT */ -/* reuse GL_COMMAND_BARRIER_BIT */ -/* reuse GL_PIXEL_BUFFER_BARRIER_BIT */ -/* reuse GL_TEXTURE_UPDATE_BARRIER_BIT */ -/* reuse GL_BUFFER_UPDATE_BARRIER_BIT */ -/* reuse GL_FRAMEBUFFER_BARRIER_BIT */ -/* reuse GL_TRANSFORM_FEEDBACK_BARRIER_BIT */ -/* reuse GL_ATOMIC_COUNTER_BARRIER_BIT */ -/* reuse GL_ALL_BARRIER_BITS */ -/* reuse GL_MAX_IMAGE_UNITS */ -/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ -/* reuse GL_IMAGE_BINDING_NAME */ -/* reuse GL_IMAGE_BINDING_LEVEL */ -/* reuse GL_IMAGE_BINDING_LAYERED */ -/* reuse GL_IMAGE_BINDING_LAYER */ -/* reuse GL_IMAGE_BINDING_ACCESS */ -/* reuse GL_IMAGE_1D */ -/* reuse GL_IMAGE_2D */ -/* reuse GL_IMAGE_3D */ -/* reuse GL_IMAGE_2D_RECT */ -/* reuse GL_IMAGE_CUBE */ -/* reuse GL_IMAGE_BUFFER */ -/* reuse GL_IMAGE_1D_ARRAY */ -/* reuse GL_IMAGE_2D_ARRAY */ -/* reuse GL_IMAGE_CUBE_MAP_ARRAY */ -/* reuse GL_IMAGE_2D_MULTISAMPLE */ -/* reuse GL_IMAGE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_INT_IMAGE_1D */ -/* reuse GL_INT_IMAGE_2D */ -/* reuse GL_INT_IMAGE_3D */ -/* reuse GL_INT_IMAGE_2D_RECT */ -/* reuse GL_INT_IMAGE_CUBE */ -/* reuse GL_INT_IMAGE_BUFFER */ -/* reuse GL_INT_IMAGE_1D_ARRAY */ -/* reuse GL_INT_IMAGE_2D_ARRAY */ -/* reuse GL_INT_IMAGE_CUBE_MAP_ARRAY */ -/* reuse GL_INT_IMAGE_2D_MULTISAMPLE */ -/* reuse GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_1D */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D */ -/* reuse GL_UNSIGNED_INT_IMAGE_3D */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_RECT */ -/* reuse GL_UNSIGNED_INT_IMAGE_CUBE */ -/* reuse GL_UNSIGNED_INT_IMAGE_BUFFER */ -/* reuse GL_UNSIGNED_INT_IMAGE_1D_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_MAX_IMAGE_SAMPLES */ -/* reuse GL_IMAGE_BINDING_FORMAT */ -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE */ -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS */ -/* reuse GL_MAX_VERTEX_IMAGE_UNIFORMS */ -/* reuse GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS */ -/* reuse GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS */ -/* reuse GL_MAX_GEOMETRY_IMAGE_UNIFORMS */ -/* reuse GL_MAX_FRAGMENT_IMAGE_UNIFORMS */ -/* reuse GL_MAX_COMBINED_IMAGE_UNIFORMS */ -/* Reuse tokens from ARB_shading_language_packing (none) */ -/* Reuse tokens from ARB_texture_storage */ -/* reuse GL_TEXTURE_IMMUTABLE_FORMAT */ -#endif - -#ifndef GL_VERSION_4_3 -#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 -#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E -/* Reuse tokens from ARB_arrays_of_arrays (none, GLSL only) */ -/* Reuse tokens from ARB_fragment_layer_viewport (none, GLSL only) */ -/* Reuse tokens from ARB_shader_image_size (none, GLSL only) */ -/* Reuse tokens from ARB_ES3_compatibility */ -/* reuse GL_COMPRESSED_RGB8_ETC2 */ -/* reuse GL_COMPRESSED_SRGB8_ETC2 */ -/* reuse GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ -/* reuse GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ -/* reuse GL_COMPRESSED_RGBA8_ETC2_EAC */ -/* reuse GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ -/* reuse GL_COMPRESSED_R11_EAC */ -/* reuse GL_COMPRESSED_SIGNED_R11_EAC */ -/* reuse GL_COMPRESSED_RG11_EAC */ -/* reuse GL_COMPRESSED_SIGNED_RG11_EAC */ -/* reuse GL_PRIMITIVE_RESTART_FIXED_INDEX */ -/* reuse GL_ANY_SAMPLES_PASSED_CONSERVATIVE */ -/* reuse GL_MAX_ELEMENT_INDEX */ -/* Reuse tokens from ARB_clear_buffer_object (none) */ -/* Reuse tokens from ARB_compute_shader */ -/* reuse GL_COMPUTE_SHADER */ -/* reuse GL_MAX_COMPUTE_UNIFORM_BLOCKS */ -/* reuse GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS */ -/* reuse GL_MAX_COMPUTE_IMAGE_UNIFORMS */ -/* reuse GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */ -/* reuse GL_MAX_COMPUTE_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTERS */ -/* reuse GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMPUTE_LOCAL_INVOCATIONS */ -/* reuse GL_MAX_COMPUTE_WORK_GROUP_COUNT */ -/* reuse GL_MAX_COMPUTE_WORK_GROUP_SIZE */ -/* reuse GL_COMPUTE_LOCAL_WORK_SIZE */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER */ -/* reuse GL_DISPATCH_INDIRECT_BUFFER */ -/* reuse GL_DISPATCH_INDIRECT_BUFFER_BINDING */ -/* Reuse tokens from ARB_copy_image (none) */ -/* Reuse tokens from KHR_debug */ -/* reuse GL_DEBUG_OUTPUT_SYNCHRONOUS */ -/* reuse GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH */ -/* reuse GL_DEBUG_CALLBACK_FUNCTION */ -/* reuse GL_DEBUG_CALLBACK_USER_PARAM */ -/* reuse GL_DEBUG_SOURCE_API */ -/* reuse GL_DEBUG_SOURCE_WINDOW_SYSTEM */ -/* reuse GL_DEBUG_SOURCE_SHADER_COMPILER */ -/* reuse GL_DEBUG_SOURCE_THIRD_PARTY */ -/* reuse GL_DEBUG_SOURCE_APPLICATION */ -/* reuse GL_DEBUG_SOURCE_OTHER */ -/* reuse GL_DEBUG_TYPE_ERROR */ -/* reuse GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR */ -/* reuse GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR */ -/* reuse GL_DEBUG_TYPE_PORTABILITY */ -/* reuse GL_DEBUG_TYPE_PERFORMANCE */ -/* reuse GL_DEBUG_TYPE_OTHER */ -/* reuse GL_MAX_DEBUG_MESSAGE_LENGTH */ -/* reuse GL_MAX_DEBUG_LOGGED_MESSAGES */ -/* reuse GL_DEBUG_LOGGED_MESSAGES */ -/* reuse GL_DEBUG_SEVERITY_HIGH */ -/* reuse GL_DEBUG_SEVERITY_MEDIUM */ -/* reuse GL_DEBUG_SEVERITY_LOW */ -/* reuse GL_DEBUG_TYPE_MARKER */ -/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ -/* reuse GL_DEBUG_TYPE_POP_GROUP */ -/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ -/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_BUFFER */ -/* reuse GL_SHADER */ -/* reuse GL_PROGRAM */ -/* reuse GL_QUERY */ -/* reuse GL_PROGRAM_PIPELINE */ -/* reuse GL_SAMPLER */ -/* reuse GL_DISPLAY_LIST */ -/* reuse GL_MAX_LABEL_LENGTH */ -/* reuse GL_DEBUG_OUTPUT */ -/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ -/* reuse GL_STACK_UNDERFLOW */ -/* reuse GL_STACK_OVERFLOW */ -/* Reuse tokens from ARB_explicit_uniform_location */ -/* reuse GL_MAX_UNIFORM_LOCATIONS */ -/* Reuse tokens from ARB_framebuffer_no_attachments */ -/* reuse GL_FRAMEBUFFER_DEFAULT_WIDTH */ -/* reuse GL_FRAMEBUFFER_DEFAULT_HEIGHT */ -/* reuse GL_FRAMEBUFFER_DEFAULT_LAYERS */ -/* reuse GL_FRAMEBUFFER_DEFAULT_SAMPLES */ -/* reuse GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS */ -/* reuse GL_MAX_FRAMEBUFFER_WIDTH */ -/* reuse GL_MAX_FRAMEBUFFER_HEIGHT */ -/* reuse GL_MAX_FRAMEBUFFER_LAYERS */ -/* reuse GL_MAX_FRAMEBUFFER_SAMPLES */ -/* Reuse tokens from ARB_internalformat_query2 */ -/* reuse GL_INTERNALFORMAT_SUPPORTED */ -/* reuse GL_INTERNALFORMAT_PREFERRED */ -/* reuse GL_INTERNALFORMAT_RED_SIZE */ -/* reuse GL_INTERNALFORMAT_GREEN_SIZE */ -/* reuse GL_INTERNALFORMAT_BLUE_SIZE */ -/* reuse GL_INTERNALFORMAT_ALPHA_SIZE */ -/* reuse GL_INTERNALFORMAT_DEPTH_SIZE */ -/* reuse GL_INTERNALFORMAT_STENCIL_SIZE */ -/* reuse GL_INTERNALFORMAT_SHARED_SIZE */ -/* reuse GL_INTERNALFORMAT_RED_TYPE */ -/* reuse GL_INTERNALFORMAT_GREEN_TYPE */ -/* reuse GL_INTERNALFORMAT_BLUE_TYPE */ -/* reuse GL_INTERNALFORMAT_ALPHA_TYPE */ -/* reuse GL_INTERNALFORMAT_DEPTH_TYPE */ -/* reuse GL_INTERNALFORMAT_STENCIL_TYPE */ -/* reuse GL_MAX_WIDTH */ -/* reuse GL_MAX_HEIGHT */ -/* reuse GL_MAX_DEPTH */ -/* reuse GL_MAX_LAYERS */ -/* reuse GL_MAX_COMBINED_DIMENSIONS */ -/* reuse GL_COLOR_COMPONENTS */ -/* reuse GL_DEPTH_COMPONENTS */ -/* reuse GL_STENCIL_COMPONENTS */ -/* reuse GL_COLOR_RENDERABLE */ -/* reuse GL_DEPTH_RENDERABLE */ -/* reuse GL_STENCIL_RENDERABLE */ -/* reuse GL_FRAMEBUFFER_RENDERABLE */ -/* reuse GL_FRAMEBUFFER_RENDERABLE_LAYERED */ -/* reuse GL_FRAMEBUFFER_BLEND */ -/* reuse GL_READ_PIXELS */ -/* reuse GL_READ_PIXELS_FORMAT */ -/* reuse GL_READ_PIXELS_TYPE */ -/* reuse GL_TEXTURE_IMAGE_FORMAT */ -/* reuse GL_TEXTURE_IMAGE_TYPE */ -/* reuse GL_GET_TEXTURE_IMAGE_FORMAT */ -/* reuse GL_GET_TEXTURE_IMAGE_TYPE */ -/* reuse GL_MIPMAP */ -/* reuse GL_MANUAL_GENERATE_MIPMAP */ -/* reuse GL_AUTO_GENERATE_MIPMAP */ -/* reuse GL_COLOR_ENCODING */ -/* reuse GL_SRGB_READ */ -/* reuse GL_SRGB_WRITE */ -/* reuse GL_FILTER */ -/* reuse GL_VERTEX_TEXTURE */ -/* reuse GL_TESS_CONTROL_TEXTURE */ -/* reuse GL_TESS_EVALUATION_TEXTURE */ -/* reuse GL_GEOMETRY_TEXTURE */ -/* reuse GL_FRAGMENT_TEXTURE */ -/* reuse GL_COMPUTE_TEXTURE */ -/* reuse GL_TEXTURE_SHADOW */ -/* reuse GL_TEXTURE_GATHER */ -/* reuse GL_TEXTURE_GATHER_SHADOW */ -/* reuse GL_SHADER_IMAGE_LOAD */ -/* reuse GL_SHADER_IMAGE_STORE */ -/* reuse GL_SHADER_IMAGE_ATOMIC */ -/* reuse GL_IMAGE_TEXEL_SIZE */ -/* reuse GL_IMAGE_COMPATIBILITY_CLASS */ -/* reuse GL_IMAGE_PIXEL_FORMAT */ -/* reuse GL_IMAGE_PIXEL_TYPE */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE */ -/* reuse GL_TEXTURE_COMPRESSED_BLOCK_WIDTH */ -/* reuse GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT */ -/* reuse GL_TEXTURE_COMPRESSED_BLOCK_SIZE */ -/* reuse GL_CLEAR_BUFFER */ -/* reuse GL_TEXTURE_VIEW */ -/* reuse GL_VIEW_COMPATIBILITY_CLASS */ -/* reuse GL_FULL_SUPPORT */ -/* reuse GL_CAVEAT_SUPPORT */ -/* reuse GL_IMAGE_CLASS_4_X_32 */ -/* reuse GL_IMAGE_CLASS_2_X_32 */ -/* reuse GL_IMAGE_CLASS_1_X_32 */ -/* reuse GL_IMAGE_CLASS_4_X_16 */ -/* reuse GL_IMAGE_CLASS_2_X_16 */ -/* reuse GL_IMAGE_CLASS_1_X_16 */ -/* reuse GL_IMAGE_CLASS_4_X_8 */ -/* reuse GL_IMAGE_CLASS_2_X_8 */ -/* reuse GL_IMAGE_CLASS_1_X_8 */ -/* reuse GL_IMAGE_CLASS_11_11_10 */ -/* reuse GL_IMAGE_CLASS_10_10_10_2 */ -/* reuse GL_VIEW_CLASS_128_BITS */ -/* reuse GL_VIEW_CLASS_96_BITS */ -/* reuse GL_VIEW_CLASS_64_BITS */ -/* reuse GL_VIEW_CLASS_48_BITS */ -/* reuse GL_VIEW_CLASS_32_BITS */ -/* reuse GL_VIEW_CLASS_24_BITS */ -/* reuse GL_VIEW_CLASS_16_BITS */ -/* reuse GL_VIEW_CLASS_8_BITS */ -/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGB */ -/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGBA */ -/* reuse GL_VIEW_CLASS_S3TC_DXT3_RGBA */ -/* reuse GL_VIEW_CLASS_S3TC_DXT5_RGBA */ -/* reuse GL_VIEW_CLASS_RGTC1_RED */ -/* reuse GL_VIEW_CLASS_RGTC2_RG */ -/* reuse GL_VIEW_CLASS_BPTC_UNORM */ -/* reuse GL_VIEW_CLASS_BPTC_FLOAT */ -/* Reuse tokens from ARB_invalidate_subdata (none) */ -/* Reuse tokens from ARB_multi_draw_indirect (none) */ -/* Reuse tokens from ARB_program_interface_query */ -/* reuse GL_UNIFORM */ -/* reuse GL_UNIFORM_BLOCK */ -/* reuse GL_PROGRAM_INPUT */ -/* reuse GL_PROGRAM_OUTPUT */ -/* reuse GL_BUFFER_VARIABLE */ -/* reuse GL_SHADER_STORAGE_BLOCK */ -/* reuse GL_VERTEX_SUBROUTINE */ -/* reuse GL_TESS_CONTROL_SUBROUTINE */ -/* reuse GL_TESS_EVALUATION_SUBROUTINE */ -/* reuse GL_GEOMETRY_SUBROUTINE */ -/* reuse GL_FRAGMENT_SUBROUTINE */ -/* reuse GL_COMPUTE_SUBROUTINE */ -/* reuse GL_VERTEX_SUBROUTINE_UNIFORM */ -/* reuse GL_TESS_CONTROL_SUBROUTINE_UNIFORM */ -/* reuse GL_TESS_EVALUATION_SUBROUTINE_UNIFORM */ -/* reuse GL_GEOMETRY_SUBROUTINE_UNIFORM */ -/* reuse GL_FRAGMENT_SUBROUTINE_UNIFORM */ -/* reuse GL_COMPUTE_SUBROUTINE_UNIFORM */ -/* reuse GL_TRANSFORM_FEEDBACK_VARYING */ -/* reuse GL_ACTIVE_RESOURCES */ -/* reuse GL_MAX_NAME_LENGTH */ -/* reuse GL_MAX_NUM_ACTIVE_VARIABLES */ -/* reuse GL_MAX_NUM_COMPATIBLE_SUBROUTINES */ -/* reuse GL_NAME_LENGTH */ -/* reuse GL_TYPE */ -/* reuse GL_ARRAY_SIZE */ -/* reuse GL_OFFSET */ -/* reuse GL_BLOCK_INDEX */ -/* reuse GL_ARRAY_STRIDE */ -/* reuse GL_MATRIX_STRIDE */ -/* reuse GL_IS_ROW_MAJOR */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_INDEX */ -/* reuse GL_BUFFER_BINDING */ -/* reuse GL_BUFFER_DATA_SIZE */ -/* reuse GL_NUM_ACTIVE_VARIABLES */ -/* reuse GL_ACTIVE_VARIABLES */ -/* reuse GL_REFERENCED_BY_VERTEX_SHADER */ -/* reuse GL_REFERENCED_BY_TESS_CONTROL_SHADER */ -/* reuse GL_REFERENCED_BY_TESS_EVALUATION_SHADER */ -/* reuse GL_REFERENCED_BY_GEOMETRY_SHADER */ -/* reuse GL_REFERENCED_BY_FRAGMENT_SHADER */ -/* reuse GL_REFERENCED_BY_COMPUTE_SHADER */ -/* reuse GL_TOP_LEVEL_ARRAY_SIZE */ -/* reuse GL_TOP_LEVEL_ARRAY_STRIDE */ -/* reuse GL_LOCATION */ -/* reuse GL_LOCATION_INDEX */ -/* reuse GL_IS_PER_PATCH */ -/* Reuse tokens from ARB_robust_buffer_access_behavior (none) */ -/* Reuse tokens from ARB_shader_storage_buffer_object */ -/* reuse GL_SHADER_STORAGE_BUFFER */ -/* reuse GL_SHADER_STORAGE_BUFFER_BINDING */ -/* reuse GL_SHADER_STORAGE_BUFFER_START */ -/* reuse GL_SHADER_STORAGE_BUFFER_SIZE */ -/* reuse GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS */ -/* reuse GL_MAX_SHADER_STORAGE_BLOCK_SIZE */ -/* reuse GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT */ -/* reuse GL_SHADER_STORAGE_BARRIER_BIT */ -/* reuse GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES */ -/* Reuse tokens from ARB_stencil_texturing */ -/* reuse GL_DEPTH_STENCIL_TEXTURE_MODE */ -/* Reuse tokens from ARB_texture_buffer_range */ -/* reuse GL_TEXTURE_BUFFER_OFFSET */ -/* reuse GL_TEXTURE_BUFFER_SIZE */ -/* reuse GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT */ -/* Reuse tokens from ARB_texture_query_levels (none) */ -/* Reuse tokens from ARB_texture_storage_multisample (none) */ -/* Reuse tokens from ARB_texture_view */ -/* reuse GL_TEXTURE_VIEW_MIN_LEVEL */ -/* reuse GL_TEXTURE_VIEW_NUM_LEVELS */ -/* reuse GL_TEXTURE_VIEW_MIN_LAYER */ -/* reuse GL_TEXTURE_VIEW_NUM_LAYERS */ -/* reuse GL_TEXTURE_IMMUTABLE_LEVELS */ -/* Reuse tokens from ARB_vertex_attrib_binding */ -/* reuse GL_VERTEX_ATTRIB_BINDING */ -/* reuse GL_VERTEX_ATTRIB_RELATIVE_OFFSET */ -/* reuse GL_VERTEX_BINDING_DIVISOR */ -/* reuse GL_VERTEX_BINDING_OFFSET */ -/* reuse GL_VERTEX_BINDING_STRIDE */ -/* reuse GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET */ -/* reuse GL_MAX_VERTEX_ATTRIB_BINDINGS */ -#endif - -#ifndef GL_ARB_depth_buffer_float -#define GL_DEPTH_COMPONENT32F 0x8CAC -#define GL_DEPTH32F_STENCIL8 0x8CAD -#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD -#endif - -#ifndef GL_ARB_framebuffer_object -#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 -#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 -#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 -#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 -#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 -#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 -#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 -#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 -#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 -#define GL_FRAMEBUFFER_DEFAULT 0x8218 -#define GL_FRAMEBUFFER_UNDEFINED 0x8219 -#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A -#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 -#define GL_DEPTH_STENCIL 0x84F9 -#define GL_UNSIGNED_INT_24_8 0x84FA -#define GL_DEPTH24_STENCIL8 0x88F0 -#define GL_TEXTURE_STENCIL_SIZE 0x88F1 -#define GL_TEXTURE_RED_TYPE 0x8C10 -#define GL_TEXTURE_GREEN_TYPE 0x8C11 -#define GL_TEXTURE_BLUE_TYPE 0x8C12 -#define GL_TEXTURE_ALPHA_TYPE 0x8C13 -#define GL_TEXTURE_DEPTH_TYPE 0x8C16 -#define GL_UNSIGNED_NORMALIZED 0x8C17 -#define GL_FRAMEBUFFER_BINDING 0x8CA6 -#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING -#define GL_RENDERBUFFER_BINDING 0x8CA7 -#define GL_READ_FRAMEBUFFER 0x8CA8 -#define GL_DRAW_FRAMEBUFFER 0x8CA9 -#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA -#define GL_RENDERBUFFER_SAMPLES 0x8CAB -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 -#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC -#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD -#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_COLOR_ATTACHMENT1 0x8CE1 -#define GL_COLOR_ATTACHMENT2 0x8CE2 -#define GL_COLOR_ATTACHMENT3 0x8CE3 -#define GL_COLOR_ATTACHMENT4 0x8CE4 -#define GL_COLOR_ATTACHMENT5 0x8CE5 -#define GL_COLOR_ATTACHMENT6 0x8CE6 -#define GL_COLOR_ATTACHMENT7 0x8CE7 -#define GL_COLOR_ATTACHMENT8 0x8CE8 -#define GL_COLOR_ATTACHMENT9 0x8CE9 -#define GL_COLOR_ATTACHMENT10 0x8CEA -#define GL_COLOR_ATTACHMENT11 0x8CEB -#define GL_COLOR_ATTACHMENT12 0x8CEC -#define GL_COLOR_ATTACHMENT13 0x8CED -#define GL_COLOR_ATTACHMENT14 0x8CEE -#define GL_COLOR_ATTACHMENT15 0x8CEF -#define GL_DEPTH_ATTACHMENT 0x8D00 -#define GL_STENCIL_ATTACHMENT 0x8D20 -#define GL_FRAMEBUFFER 0x8D40 -#define GL_RENDERBUFFER 0x8D41 -#define GL_RENDERBUFFER_WIDTH 0x8D42 -#define GL_RENDERBUFFER_HEIGHT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 -#define GL_STENCIL_INDEX1 0x8D46 -#define GL_STENCIL_INDEX4 0x8D47 -#define GL_STENCIL_INDEX8 0x8D48 -#define GL_STENCIL_INDEX16 0x8D49 -#define GL_RENDERBUFFER_RED_SIZE 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 -#define GL_MAX_SAMPLES 0x8D57 -#endif - -#ifndef GL_ARB_framebuffer_sRGB -#define GL_FRAMEBUFFER_SRGB 0x8DB9 -#endif - -#ifndef GL_ARB_half_float_vertex -#define GL_HALF_FLOAT 0x140B -#endif - -#ifndef GL_ARB_map_buffer_range -#define GL_MAP_READ_BIT 0x0001 -#define GL_MAP_WRITE_BIT 0x0002 -#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 -#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 -#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 -#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 -#endif - -#ifndef GL_ARB_texture_compression_rgtc -#define GL_COMPRESSED_RED_RGTC1 0x8DBB -#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC -#define GL_COMPRESSED_RG_RGTC2 0x8DBD -#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE -#endif - -#ifndef GL_ARB_texture_rg -#define GL_RG 0x8227 -#define GL_RG_INTEGER 0x8228 -#define GL_R8 0x8229 -#define GL_R16 0x822A -#define GL_RG8 0x822B -#define GL_RG16 0x822C -#define GL_R16F 0x822D -#define GL_R32F 0x822E -#define GL_RG16F 0x822F -#define GL_RG32F 0x8230 -#define GL_R8I 0x8231 -#define GL_R8UI 0x8232 -#define GL_R16I 0x8233 -#define GL_R16UI 0x8234 -#define GL_R32I 0x8235 -#define GL_R32UI 0x8236 -#define GL_RG8I 0x8237 -#define GL_RG8UI 0x8238 -#define GL_RG16I 0x8239 -#define GL_RG16UI 0x823A -#define GL_RG32I 0x823B -#define GL_RG32UI 0x823C -#endif - -#ifndef GL_ARB_vertex_array_object -#define GL_VERTEX_ARRAY_BINDING 0x85B5 -#endif - -#ifndef GL_ARB_uniform_buffer_object -#define GL_UNIFORM_BUFFER 0x8A11 -#define GL_UNIFORM_BUFFER_BINDING 0x8A28 -#define GL_UNIFORM_BUFFER_START 0x8A29 -#define GL_UNIFORM_BUFFER_SIZE 0x8A2A -#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B -#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C -#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D -#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E -#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F -#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 -#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 -#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 -#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 -#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 -#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 -#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 -#define GL_UNIFORM_TYPE 0x8A37 -#define GL_UNIFORM_SIZE 0x8A38 -#define GL_UNIFORM_NAME_LENGTH 0x8A39 -#define GL_UNIFORM_BLOCK_INDEX 0x8A3A -#define GL_UNIFORM_OFFSET 0x8A3B -#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C -#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D -#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E -#define GL_UNIFORM_BLOCK_BINDING 0x8A3F -#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 -#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 -#define GL_INVALID_INDEX 0xFFFFFFFFu -#endif - -#ifndef GL_ARB_copy_buffer -#define GL_COPY_READ_BUFFER_BINDING 0x8F36 -#define GL_COPY_READ_BUFFER GL_COPY_READ_BUFFER_BINDING -#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37 -#define GL_COPY_WRITE_BUFFER GL_COPY_WRITE_BUFFER_BINDING -#endif - -#ifndef GL_ARB_depth_clamp -#define GL_DEPTH_CLAMP 0x864F -#endif - -#ifndef GL_ARB_draw_elements_base_vertex -#endif - -#ifndef GL_ARB_fragment_coord_conventions -#endif - -#ifndef GL_ARB_provoking_vertex -#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C -#define GL_FIRST_VERTEX_CONVENTION 0x8E4D -#define GL_LAST_VERTEX_CONVENTION 0x8E4E -#define GL_PROVOKING_VERTEX 0x8E4F -#endif - -#ifndef GL_ARB_seamless_cube_map -#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F -#endif - -#ifndef GL_ARB_sync -#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 -#define GL_OBJECT_TYPE 0x9112 -#define GL_SYNC_CONDITION 0x9113 -#define GL_SYNC_STATUS 0x9114 -#define GL_SYNC_FLAGS 0x9115 -#define GL_SYNC_FENCE 0x9116 -#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 -#define GL_UNSIGNALED 0x9118 -#define GL_SIGNALED 0x9119 -#define GL_ALREADY_SIGNALED 0x911A -#define GL_TIMEOUT_EXPIRED 0x911B -#define GL_CONDITION_SATISFIED 0x911C -#define GL_WAIT_FAILED 0x911D -#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 -#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull -#endif - -#ifndef GL_ARB_texture_multisample -#define GL_SAMPLE_POSITION 0x8E50 -#define GL_SAMPLE_MASK 0x8E51 -#define GL_SAMPLE_MASK_VALUE 0x8E52 -#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 -#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 -#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 -#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 -#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 -#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 -#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 -#define GL_TEXTURE_SAMPLES 0x9106 -#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 -#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 -#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 -#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A -#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B -#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C -#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D -#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E -#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F -#define GL_MAX_INTEGER_SAMPLES 0x9110 -#endif - -#ifndef GL_ARB_vertex_array_bgra -/* reuse GL_BGRA */ -#endif - -#ifndef GL_ARB_draw_buffers_blend -#endif - -#ifndef GL_ARB_sample_shading -#define GL_SAMPLE_SHADING_ARB 0x8C36 -#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 -#endif - -#ifndef GL_ARB_texture_cube_map_array -#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B -#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C -#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D -#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E -#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F -#endif - -#ifndef GL_ARB_texture_gather -#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E -#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F -#endif - -#ifndef GL_ARB_texture_query_lod -#endif - -#ifndef GL_ARB_shading_language_include -#define GL_SHADER_INCLUDE_ARB 0x8DAE -#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 -#define GL_NAMED_STRING_TYPE_ARB 0x8DEA -#endif - -#ifndef GL_ARB_texture_compression_bptc -#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C -#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D -#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E -#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F -#endif - -#ifndef GL_ARB_blend_func_extended -#define GL_SRC1_COLOR 0x88F9 -/* reuse GL_SRC1_ALPHA */ -#define GL_ONE_MINUS_SRC1_COLOR 0x88FA -#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB -#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC -#endif - -#ifndef GL_ARB_explicit_attrib_location -#endif - -#ifndef GL_ARB_occlusion_query2 -#define GL_ANY_SAMPLES_PASSED 0x8C2F -#endif - -#ifndef GL_ARB_sampler_objects -#define GL_SAMPLER_BINDING 0x8919 -#endif - -#ifndef GL_ARB_shader_bit_encoding -#endif - -#ifndef GL_ARB_texture_rgb10_a2ui -#define GL_RGB10_A2UI 0x906F -#endif - -#ifndef GL_ARB_texture_swizzle -#define GL_TEXTURE_SWIZZLE_R 0x8E42 -#define GL_TEXTURE_SWIZZLE_G 0x8E43 -#define GL_TEXTURE_SWIZZLE_B 0x8E44 -#define GL_TEXTURE_SWIZZLE_A 0x8E45 -#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 -#endif - -#ifndef GL_ARB_timer_query -#define GL_TIME_ELAPSED 0x88BF -#define GL_TIMESTAMP 0x8E28 -#endif - -#ifndef GL_ARB_vertex_type_2_10_10_10_rev -/* reuse GL_UNSIGNED_INT_2_10_10_10_REV */ -#define GL_INT_2_10_10_10_REV 0x8D9F -#endif - -#ifndef GL_ARB_draw_indirect -#define GL_DRAW_INDIRECT_BUFFER 0x8F3F -#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 -#endif - -#ifndef GL_ARB_gpu_shader5 -#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F -#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A -#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B -#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C -#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D -/* reuse GL_MAX_VERTEX_STREAMS */ -#endif - -#ifndef GL_ARB_gpu_shader_fp64 -/* reuse GL_DOUBLE */ -#define GL_DOUBLE_VEC2 0x8FFC -#define GL_DOUBLE_VEC3 0x8FFD -#define GL_DOUBLE_VEC4 0x8FFE -#define GL_DOUBLE_MAT2 0x8F46 -#define GL_DOUBLE_MAT3 0x8F47 -#define GL_DOUBLE_MAT4 0x8F48 -#define GL_DOUBLE_MAT2x3 0x8F49 -#define GL_DOUBLE_MAT2x4 0x8F4A -#define GL_DOUBLE_MAT3x2 0x8F4B -#define GL_DOUBLE_MAT3x4 0x8F4C -#define GL_DOUBLE_MAT4x2 0x8F4D -#define GL_DOUBLE_MAT4x3 0x8F4E -#endif - -#ifndef GL_ARB_shader_subroutine -#define GL_ACTIVE_SUBROUTINES 0x8DE5 -#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 -#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 -#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 -#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 -#define GL_MAX_SUBROUTINES 0x8DE7 -#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 -#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A -#define GL_COMPATIBLE_SUBROUTINES 0x8E4B -/* reuse GL_UNIFORM_SIZE */ -/* reuse GL_UNIFORM_NAME_LENGTH */ -#endif - -#ifndef GL_ARB_tessellation_shader -#define GL_PATCHES 0x000E -#define GL_PATCH_VERTICES 0x8E72 -#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 -#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 -#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 -#define GL_TESS_GEN_MODE 0x8E76 -#define GL_TESS_GEN_SPACING 0x8E77 -#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 -#define GL_TESS_GEN_POINT_MODE 0x8E79 -/* reuse GL_TRIANGLES */ -/* reuse GL_QUADS */ -#define GL_ISOLINES 0x8E7A -/* reuse GL_EQUAL */ -#define GL_FRACTIONAL_ODD 0x8E7B -#define GL_FRACTIONAL_EVEN 0x8E7C -/* reuse GL_CCW */ -/* reuse GL_CW */ -#define GL_MAX_PATCH_VERTICES 0x8E7D -#define GL_MAX_TESS_GEN_LEVEL 0x8E7E -#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F -#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 -#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 -#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 -#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 -#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 -#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 -#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 -#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 -#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A -#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C -#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D -#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E -#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F -#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 -#define GL_TESS_EVALUATION_SHADER 0x8E87 -#define GL_TESS_CONTROL_SHADER 0x8E88 -#endif - -#ifndef GL_ARB_texture_buffer_object_rgb32 -/* reuse GL_RGB32F */ -/* reuse GL_RGB32UI */ -/* reuse GL_RGB32I */ -#endif - -#ifndef GL_ARB_transform_feedback2 -#define GL_TRANSFORM_FEEDBACK 0x8E22 -#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 -#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED GL_TRANSFORM_FEEDBACK_PAUSED -#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 -#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE GL_TRANSFORM_FEEDBACK_ACTIVE -#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 -#endif - -#ifndef GL_ARB_transform_feedback3 -#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 -#define GL_MAX_VERTEX_STREAMS 0x8E71 -#endif - -#ifndef GL_ARB_ES2_compatibility -#define GL_FIXED 0x140C -#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A -#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B -#define GL_LOW_FLOAT 0x8DF0 -#define GL_MEDIUM_FLOAT 0x8DF1 -#define GL_HIGH_FLOAT 0x8DF2 -#define GL_LOW_INT 0x8DF3 -#define GL_MEDIUM_INT 0x8DF4 -#define GL_HIGH_INT 0x8DF5 -#define GL_SHADER_COMPILER 0x8DFA -#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 -#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB -#define GL_MAX_VARYING_VECTORS 0x8DFC -#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD -#define GL_RGB565 0x8D62 -#endif - -#ifndef GL_ARB_get_program_binary -#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 -#define GL_PROGRAM_BINARY_LENGTH 0x8741 -#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE -#define GL_PROGRAM_BINARY_FORMATS 0x87FF -#endif - -#ifndef GL_ARB_separate_shader_objects -#define GL_VERTEX_SHADER_BIT 0x00000001 -#define GL_FRAGMENT_SHADER_BIT 0x00000002 -#define GL_GEOMETRY_SHADER_BIT 0x00000004 -#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 -#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 -#define GL_ALL_SHADER_BITS 0xFFFFFFFF -#define GL_PROGRAM_SEPARABLE 0x8258 -#define GL_ACTIVE_PROGRAM 0x8259 -#define GL_PROGRAM_PIPELINE_BINDING 0x825A -#endif - -#ifndef GL_ARB_shader_precision -#endif - -#ifndef GL_ARB_vertex_attrib_64bit -/* reuse GL_RGB32I */ -/* reuse GL_DOUBLE_VEC2 */ -/* reuse GL_DOUBLE_VEC3 */ -/* reuse GL_DOUBLE_VEC4 */ -/* reuse GL_DOUBLE_MAT2 */ -/* reuse GL_DOUBLE_MAT3 */ -/* reuse GL_DOUBLE_MAT4 */ -/* reuse GL_DOUBLE_MAT2x3 */ -/* reuse GL_DOUBLE_MAT2x4 */ -/* reuse GL_DOUBLE_MAT3x2 */ -/* reuse GL_DOUBLE_MAT3x4 */ -/* reuse GL_DOUBLE_MAT4x2 */ -/* reuse GL_DOUBLE_MAT4x3 */ -#endif - -#ifndef GL_ARB_viewport_array -/* reuse GL_SCISSOR_BOX */ -/* reuse GL_VIEWPORT */ -/* reuse GL_DEPTH_RANGE */ -/* reuse GL_SCISSOR_TEST */ -#define GL_MAX_VIEWPORTS 0x825B -#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C -#define GL_VIEWPORT_BOUNDS_RANGE 0x825D -#define GL_LAYER_PROVOKING_VERTEX 0x825E -#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F -#define GL_UNDEFINED_VERTEX 0x8260 -/* reuse GL_FIRST_VERTEX_CONVENTION */ -/* reuse GL_LAST_VERTEX_CONVENTION */ -/* reuse GL_PROVOKING_VERTEX */ -#endif - -#ifndef GL_ARB_cl_event -#define GL_SYNC_CL_EVENT_ARB 0x8240 -#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 -#endif - -#ifndef GL_ARB_debug_output -#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 -#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 -#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 -#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 -#define GL_DEBUG_SOURCE_API_ARB 0x8246 -#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 -#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 -#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 -#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A -#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B -#define GL_DEBUG_TYPE_ERROR_ARB 0x824C -#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D -#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E -#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F -#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 -#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 -#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 -#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 -#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 -#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 -#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 -#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 -#endif - -#ifndef GL_ARB_robustness -/* reuse GL_NO_ERROR */ -#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 -#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 -#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 -#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 -#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 -#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 -#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 -#endif - -#ifndef GL_ARB_shader_stencil_export -#endif - -#ifndef GL_ARB_base_instance -#endif - -#ifndef GL_ARB_shading_language_420pack -#endif - -#ifndef GL_ARB_transform_feedback_instanced -#endif - -#ifndef GL_ARB_compressed_texture_pixel_storage -#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127 -#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128 -#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129 -#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A -#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B -#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C -#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D -#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E -#endif - -#ifndef GL_ARB_conservative_depth -#endif - -#ifndef GL_ARB_internalformat_query -#define GL_NUM_SAMPLE_COUNTS 0x9380 -#endif - -#ifndef GL_ARB_map_buffer_alignment -#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC -#endif - -#ifndef GL_ARB_shader_atomic_counters -#define GL_ATOMIC_COUNTER_BUFFER 0x92C0 -#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1 -#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2 -#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3 -#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4 -#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5 -#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB -#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC -#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD -#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE -#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF -#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0 -#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1 -#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2 -#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3 -#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4 -#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5 -#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6 -#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7 -#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8 -#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC -#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9 -#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA -#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB -#endif - -#ifndef GL_ARB_shader_image_load_store -#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001 -#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002 -#define GL_UNIFORM_BARRIER_BIT 0x00000004 -#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008 -#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020 -#define GL_COMMAND_BARRIER_BIT 0x00000040 -#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080 -#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100 -#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200 -#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400 -#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800 -#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000 -#define GL_ALL_BARRIER_BITS 0xFFFFFFFF -#define GL_MAX_IMAGE_UNITS 0x8F38 -#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39 -#define GL_IMAGE_BINDING_NAME 0x8F3A -#define GL_IMAGE_BINDING_LEVEL 0x8F3B -#define GL_IMAGE_BINDING_LAYERED 0x8F3C -#define GL_IMAGE_BINDING_LAYER 0x8F3D -#define GL_IMAGE_BINDING_ACCESS 0x8F3E -#define GL_IMAGE_1D 0x904C -#define GL_IMAGE_2D 0x904D -#define GL_IMAGE_3D 0x904E -#define GL_IMAGE_2D_RECT 0x904F -#define GL_IMAGE_CUBE 0x9050 -#define GL_IMAGE_BUFFER 0x9051 -#define GL_IMAGE_1D_ARRAY 0x9052 -#define GL_IMAGE_2D_ARRAY 0x9053 -#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 -#define GL_IMAGE_2D_MULTISAMPLE 0x9055 -#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056 -#define GL_INT_IMAGE_1D 0x9057 -#define GL_INT_IMAGE_2D 0x9058 -#define GL_INT_IMAGE_3D 0x9059 -#define GL_INT_IMAGE_2D_RECT 0x905A -#define GL_INT_IMAGE_CUBE 0x905B -#define GL_INT_IMAGE_BUFFER 0x905C -#define GL_INT_IMAGE_1D_ARRAY 0x905D -#define GL_INT_IMAGE_2D_ARRAY 0x905E -#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F -#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060 -#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061 -#define GL_UNSIGNED_INT_IMAGE_1D 0x9062 -#define GL_UNSIGNED_INT_IMAGE_2D 0x9063 -#define GL_UNSIGNED_INT_IMAGE_3D 0x9064 -#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065 -#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066 -#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 -#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068 -#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069 -#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A -#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B -#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C -#define GL_MAX_IMAGE_SAMPLES 0x906D -#define GL_IMAGE_BINDING_FORMAT 0x906E -#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7 -#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8 -#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9 -#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA -#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB -#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC -#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD -#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE -#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF -#endif - -#ifndef GL_ARB_shading_language_packing -#endif - -#ifndef GL_ARB_texture_storage -#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F -#endif - -#ifndef GL_KHR_texture_compression_astc_ldr -#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 -#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 -#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 -#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 -#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 -#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 -#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 -#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 -#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 -#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 -#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA -#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB -#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC -#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD -#endif - -#ifndef GL_KHR_debug -#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 -#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 -#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 -#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 -#define GL_DEBUG_SOURCE_API 0x8246 -#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 -#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 -#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 -#define GL_DEBUG_SOURCE_APPLICATION 0x824A -#define GL_DEBUG_SOURCE_OTHER 0x824B -#define GL_DEBUG_TYPE_ERROR 0x824C -#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D -#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E -#define GL_DEBUG_TYPE_PORTABILITY 0x824F -#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 -#define GL_DEBUG_TYPE_OTHER 0x8251 -#define GL_DEBUG_TYPE_MARKER 0x8268 -#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 -#define GL_DEBUG_TYPE_POP_GROUP 0x826A -#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B -#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C -#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D -#define GL_BUFFER 0x82E0 -#define GL_SHADER 0x82E1 -#define GL_PROGRAM 0x82E2 -#define GL_QUERY 0x82E3 -#define GL_PROGRAM_PIPELINE 0x82E4 -#define GL_SAMPLER 0x82E6 -#define GL_DISPLAY_LIST 0x82E7 -#define GL_MAX_LABEL_LENGTH 0x82E8 -#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 -#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 -#define GL_DEBUG_LOGGED_MESSAGES 0x9145 -#define GL_DEBUG_SEVERITY_HIGH 0x9146 -#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 -#define GL_DEBUG_SEVERITY_LOW 0x9148 -#define GL_DEBUG_OUTPUT 0x92E0 -#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 -/* reuse GL_STACK_UNDERFLOW */ -/* reuse GL_STACK_OVERFLOW */ -#endif - -#ifndef GL_ARB_arrays_of_arrays -#endif - -#ifndef GL_ARB_clear_buffer_object -#endif - -#ifndef GL_ARB_compute_shader -#define GL_COMPUTE_SHADER 0x91B9 -#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB -#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC -#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD -#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 -#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 -#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 -#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 -#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 -#define GL_MAX_COMPUTE_LOCAL_INVOCATIONS 0x90EB -#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE -#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF -#define GL_COMPUTE_LOCAL_WORK_SIZE 0x8267 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED -#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE -#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF -#define GL_COMPUTE_SHADER_BIT 0x00000020 -#endif - -#ifndef GL_ARB_copy_image -#endif - -#ifndef GL_ARB_debug_group -/* reuse GL_DEBUG_TYPE_MARKER */ -/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ -/* reuse GL_DEBUG_TYPE_POP_GROUP */ -/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ -/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_STACK_UNDERFLOW */ -/* reuse GL_STACK_OVERFLOW */ -#endif - -#ifndef GL_ARB_debug_label -/* reuse GL_BUFFER */ -/* reuse GL_SHADER */ -/* reuse GL_PROGRAM */ -/* reuse GL_QUERY */ -/* reuse GL_PROGRAM_PIPELINE */ -/* reuse GL_SAMPLER */ -/* DISPLAY_LIST used in compatibility profile only */ -/* reuse GL_DISPLAY_LIST */ -/* reuse GL_MAX_LABEL_LENGTH */ -/* reuse GL_VERTEX_ARRAY */ -#endif - -#ifndef GL_ARB_debug_output2 -/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ -/* reuse GL_DEBUG_OUTPUT */ -#endif - -#ifndef GL_ARB_ES3_compatibility -#define GL_COMPRESSED_RGB8_ETC2 0x9274 -#define GL_COMPRESSED_SRGB8_ETC2 0x9275 -#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 -#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 -#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 -#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 -#define GL_COMPRESSED_R11_EAC 0x9270 -#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 -#define GL_COMPRESSED_RG11_EAC 0x9272 -#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 -#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 -#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A -#define GL_MAX_ELEMENT_INDEX 0x8D6B -#endif - -#ifndef GL_ARB_explicit_uniform_location -#define GL_MAX_UNIFORM_LOCATIONS 0x826E -#endif - -#ifndef GL_ARB_fragment_layer_viewport -#endif - -#ifndef GL_ARB_framebuffer_no_attachments -#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 -#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 -#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 -#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 -#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 -#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 -#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 -#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 -#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 -#endif - -#ifndef GL_ARB_internalformat_query2 -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ -/* reuse GL_NUM_SAMPLE_COUNTS */ -/* reuse GL_RENDERBUFFER */ -/* reuse GL_SAMPLES */ -/* reuse GL_TEXTURE_1D */ -/* reuse GL_TEXTURE_1D_ARRAY */ -/* reuse GL_TEXTURE_2D */ -/* reuse GL_TEXTURE_2D_ARRAY */ -/* reuse GL_TEXTURE_3D */ -/* reuse GL_TEXTURE_CUBE_MAP */ -/* reuse GL_TEXTURE_CUBE_MAP_ARRAY */ -/* reuse GL_TEXTURE_RECTANGLE */ -/* reuse GL_TEXTURE_BUFFER */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_TEXTURE_COMPRESSED */ -#define GL_INTERNALFORMAT_SUPPORTED 0x826F -#define GL_INTERNALFORMAT_PREFERRED 0x8270 -#define GL_INTERNALFORMAT_RED_SIZE 0x8271 -#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 -#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 -#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 -#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 -#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 -#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 -#define GL_INTERNALFORMAT_RED_TYPE 0x8278 -#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 -#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A -#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B -#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C -#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D -#define GL_MAX_WIDTH 0x827E -#define GL_MAX_HEIGHT 0x827F -#define GL_MAX_DEPTH 0x8280 -#define GL_MAX_LAYERS 0x8281 -#define GL_MAX_COMBINED_DIMENSIONS 0x8282 -#define GL_COLOR_COMPONENTS 0x8283 -#define GL_DEPTH_COMPONENTS 0x8284 -#define GL_STENCIL_COMPONENTS 0x8285 -#define GL_COLOR_RENDERABLE 0x8286 -#define GL_DEPTH_RENDERABLE 0x8287 -#define GL_STENCIL_RENDERABLE 0x8288 -#define GL_FRAMEBUFFER_RENDERABLE 0x8289 -#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A -#define GL_FRAMEBUFFER_BLEND 0x828B -#define GL_READ_PIXELS 0x828C -#define GL_READ_PIXELS_FORMAT 0x828D -#define GL_READ_PIXELS_TYPE 0x828E -#define GL_TEXTURE_IMAGE_FORMAT 0x828F -#define GL_TEXTURE_IMAGE_TYPE 0x8290 -#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 -#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 -#define GL_MIPMAP 0x8293 -#define GL_MANUAL_GENERATE_MIPMAP 0x8294 -#define GL_AUTO_GENERATE_MIPMAP 0x8295 -#define GL_COLOR_ENCODING 0x8296 -#define GL_SRGB_READ 0x8297 -#define GL_SRGB_WRITE 0x8298 -#define GL_SRGB_DECODE_ARB 0x8299 -#define GL_FILTER 0x829A -#define GL_VERTEX_TEXTURE 0x829B -#define GL_TESS_CONTROL_TEXTURE 0x829C -#define GL_TESS_EVALUATION_TEXTURE 0x829D -#define GL_GEOMETRY_TEXTURE 0x829E -#define GL_FRAGMENT_TEXTURE 0x829F -#define GL_COMPUTE_TEXTURE 0x82A0 -#define GL_TEXTURE_SHADOW 0x82A1 -#define GL_TEXTURE_GATHER 0x82A2 -#define GL_TEXTURE_GATHER_SHADOW 0x82A3 -#define GL_SHADER_IMAGE_LOAD 0x82A4 -#define GL_SHADER_IMAGE_STORE 0x82A5 -#define GL_SHADER_IMAGE_ATOMIC 0x82A6 -#define GL_IMAGE_TEXEL_SIZE 0x82A7 -#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 -#define GL_IMAGE_PIXEL_FORMAT 0x82A9 -#define GL_IMAGE_PIXEL_TYPE 0x82AA -#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC -#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD -#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE -#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF -#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 -#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 -#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 -#define GL_CLEAR_BUFFER 0x82B4 -#define GL_TEXTURE_VIEW 0x82B5 -#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 -#define GL_FULL_SUPPORT 0x82B7 -#define GL_CAVEAT_SUPPORT 0x82B8 -#define GL_IMAGE_CLASS_4_X_32 0x82B9 -#define GL_IMAGE_CLASS_2_X_32 0x82BA -#define GL_IMAGE_CLASS_1_X_32 0x82BB -#define GL_IMAGE_CLASS_4_X_16 0x82BC -#define GL_IMAGE_CLASS_2_X_16 0x82BD -#define GL_IMAGE_CLASS_1_X_16 0x82BE -#define GL_IMAGE_CLASS_4_X_8 0x82BF -#define GL_IMAGE_CLASS_2_X_8 0x82C0 -#define GL_IMAGE_CLASS_1_X_8 0x82C1 -#define GL_IMAGE_CLASS_11_11_10 0x82C2 -#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 -#define GL_VIEW_CLASS_128_BITS 0x82C4 -#define GL_VIEW_CLASS_96_BITS 0x82C5 -#define GL_VIEW_CLASS_64_BITS 0x82C6 -#define GL_VIEW_CLASS_48_BITS 0x82C7 -#define GL_VIEW_CLASS_32_BITS 0x82C8 -#define GL_VIEW_CLASS_24_BITS 0x82C9 -#define GL_VIEW_CLASS_16_BITS 0x82CA -#define GL_VIEW_CLASS_8_BITS 0x82CB -#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC -#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD -#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE -#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF -#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 -#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 -#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 -#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 -#endif - -#ifndef GL_ARB_invalidate_subdata -#endif - -#ifndef GL_ARB_multi_draw_indirect -#endif - -#ifndef GL_ARB_program_interface_query -#define GL_UNIFORM 0x92E1 -#define GL_UNIFORM_BLOCK 0x92E2 -#define GL_PROGRAM_INPUT 0x92E3 -#define GL_PROGRAM_OUTPUT 0x92E4 -#define GL_BUFFER_VARIABLE 0x92E5 -#define GL_SHADER_STORAGE_BLOCK 0x92E6 -/* reuse GL_ATOMIC_COUNTER_BUFFER */ -#define GL_VERTEX_SUBROUTINE 0x92E8 -#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 -#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA -#define GL_GEOMETRY_SUBROUTINE 0x92EB -#define GL_FRAGMENT_SUBROUTINE 0x92EC -#define GL_COMPUTE_SUBROUTINE 0x92ED -#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE -#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF -#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 -#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 -#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 -#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 -#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 -#define GL_ACTIVE_RESOURCES 0x92F5 -#define GL_MAX_NAME_LENGTH 0x92F6 -#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 -#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 -#define GL_NAME_LENGTH 0x92F9 -#define GL_TYPE 0x92FA -#define GL_ARRAY_SIZE 0x92FB -#define GL_OFFSET 0x92FC -#define GL_BLOCK_INDEX 0x92FD -#define GL_ARRAY_STRIDE 0x92FE -#define GL_MATRIX_STRIDE 0x92FF -#define GL_IS_ROW_MAJOR 0x9300 -#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 -#define GL_BUFFER_BINDING 0x9302 -#define GL_BUFFER_DATA_SIZE 0x9303 -#define GL_NUM_ACTIVE_VARIABLES 0x9304 -#define GL_ACTIVE_VARIABLES 0x9305 -#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 -#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 -#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 -#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 -#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A -#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B -#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C -#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D -#define GL_LOCATION 0x930E -#define GL_LOCATION_INDEX 0x930F -#define GL_IS_PER_PATCH 0x92E7 -/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ -/* reuse GL_COMPATIBLE_SUBROUTINES */ -#endif - -#ifndef GL_ARB_robust_buffer_access_behavior -#endif - -#ifndef GL_ARB_shader_image_size -#endif - -#ifndef GL_ARB_shader_storage_buffer_object -#define GL_SHADER_STORAGE_BUFFER 0x90D2 -#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 -#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 -#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 -#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 -#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 -#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 -#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 -#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA -#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB -#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC -#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD -#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE -#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF -#define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 -#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS -/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ -#endif - -#ifndef GL_ARB_stencil_texturing -#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA -#endif - -#ifndef GL_ARB_texture_buffer_range -#define GL_TEXTURE_BUFFER_OFFSET 0x919D -#define GL_TEXTURE_BUFFER_SIZE 0x919E -#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F -#endif - -#ifndef GL_ARB_texture_query_levels -#endif - -#ifndef GL_ARB_texture_storage_multisample -#endif - -#ifndef GL_ARB_texture_view -#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB -#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC -#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD -#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE -#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF -#endif - -#ifndef GL_ARB_vertex_attrib_binding -#define GL_VERTEX_ATTRIB_BINDING 0x82D4 -#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 -#define GL_VERTEX_BINDING_DIVISOR 0x82D6 -#define GL_VERTEX_BINDING_OFFSET 0x82D7 -#define GL_VERTEX_BINDING_STRIDE 0x82D8 -#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 -#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA -#endif - -#ifndef GL_ARB_robustness_isolation -#endif - - -/*************************************************************/ - -#include -#ifndef GL_VERSION_2_0 -/* GL type for program/shader text */ -typedef char GLchar; -#endif - -#ifndef GL_VERSION_1_5 -/* GL types for handling large vertex buffer objects */ -typedef ptrdiff_t GLintptr; -typedef ptrdiff_t GLsizeiptr; -#endif - -#ifndef GL_ARB_vertex_buffer_object -/* GL types for handling large vertex buffer objects */ -typedef ptrdiff_t GLintptrARB; -typedef ptrdiff_t GLsizeiptrARB; -#endif - -#ifndef GL_ARB_shader_objects -/* GL types for program/shader text and shader object handles */ -typedef char GLcharARB; -typedef unsigned int GLhandleARB; -#endif - -/* GL type for "half" precision (s10e5) float data in host memory */ -#ifndef GL_ARB_half_float_pixel -typedef unsigned short GLhalfARB; -#endif - -#ifndef GL_NV_half_float -typedef unsigned short GLhalfNV; -#endif - -#ifndef GLEXT_64_TYPES_DEFINED -/* This code block is duplicated in glxext.h, so must be protected */ -#define GLEXT_64_TYPES_DEFINED -/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ -/* (as used in the GL_EXT_timer_query extension). */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#include -#elif defined(__sun__) || defined(__digital__) -#include -#if defined(__STDC__) -#if defined(__arch64__) || defined(_LP64) -typedef long int int64_t; -typedef unsigned long int uint64_t; -#else -typedef long long int int64_t; -typedef unsigned long long int uint64_t; -#endif /* __arch64__ */ -#endif /* __STDC__ */ -#elif defined( __VMS ) || defined(__sgi) -#include -#elif defined(__SCO__) || defined(__USLC__) -#include -#elif defined(__UNIXOS2__) || defined(__SOL64__) -typedef long int int32_t; -typedef long long int int64_t; -typedef unsigned long long int uint64_t; -#elif defined(_WIN32) && defined(__GNUC__) -#include -#elif defined(_WIN32) -typedef __int32 int32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else -/* Fallback if nothing above works */ -#include -#endif -#endif - -#ifndef GL_EXT_timer_query -typedef int64_t GLint64EXT; -typedef uint64_t GLuint64EXT; -#endif - -#ifndef GL_ARB_sync -typedef int64_t GLint64; -typedef uint64_t GLuint64; -typedef struct __GLsync *GLsync; -#endif - -#ifndef GL_ARB_cl_event -/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */ -struct _cl_context; -struct _cl_event; -#endif - -#ifndef GL_ARB_debug_output -typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); -#endif - -#ifndef GL_AMD_debug_output -typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); -#endif - -#ifndef GL_KHR_debug -typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); -#endif - -#ifndef GL_NV_vdpau_interop -typedef GLintptr GLvdpauSurfaceNV; -#endif - -#ifndef GL_VERSION_1_0 -#define GL_VERSION_1_0 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glCullFace (GLenum mode); -GLAPI void APIENTRY glFrontFace (GLenum mode); -GLAPI void APIENTRY glHint (GLenum target, GLenum mode); -GLAPI void APIENTRY glLineWidth (GLfloat width); -GLAPI void APIENTRY glPointSize (GLfloat size); -GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode); -GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); -GLAPI void APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glDrawBuffer (GLenum mode); -GLAPI void APIENTRY glClear (GLbitfield mask); -GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI void APIENTRY glClearStencil (GLint s); -GLAPI void APIENTRY glClearDepth (GLdouble depth); -GLAPI void APIENTRY glStencilMask (GLuint mask); -GLAPI void APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); -GLAPI void APIENTRY glDepthMask (GLboolean flag); -GLAPI void APIENTRY glDisable (GLenum cap); -GLAPI void APIENTRY glEnable (GLenum cap); -GLAPI void APIENTRY glFinish (void); -GLAPI void APIENTRY glFlush (void); -GLAPI void APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); -GLAPI void APIENTRY glLogicOp (GLenum opcode); -GLAPI void APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); -GLAPI void APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); -GLAPI void APIENTRY glDepthFunc (GLenum func); -GLAPI void APIENTRY glPixelStoref (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); -GLAPI void APIENTRY glReadBuffer (GLenum mode); -GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); -GLAPI void APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); -GLAPI void APIENTRY glGetDoublev (GLenum pname, GLdouble *params); -GLAPI GLenum APIENTRY glGetError (void); -GLAPI void APIENTRY glGetFloatv (GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *params); -GLAPI const GLubyte * APIENTRY glGetString (GLenum name); -GLAPI void APIENTRY glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); -GLAPI void APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params); -GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); -GLAPI void APIENTRY glDepthRange (GLdouble near, GLdouble far); -GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLFRONTFACEPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLHINTPROC) (GLenum target, GLenum mode); -typedef void (APIENTRYP PFNGLLINEWIDTHPROC) (GLfloat width); -typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size); -typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode); -typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLTEXPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLTEXIMAGE1DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLDRAWBUFFERPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); -typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s); -typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth); -typedef void (APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask); -typedef void (APIENTRYP PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); -typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag); -typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); -typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); -typedef void (APIENTRYP PFNGLFINISHPROC) (void); -typedef void (APIENTRYP PFNGLFLUSHPROC) (void); -typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor); -typedef void (APIENTRYP PFNGLLOGICOPPROC) (GLenum opcode); -typedef void (APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask); -typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass); -typedef void (APIENTRYP PFNGLDEPTHFUNCPROC) (GLenum func); -typedef void (APIENTRYP PFNGLPIXELSTOREFPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLREADBUFFERPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); -typedef void (APIENTRYP PFNGLGETBOOLEANVPROC) (GLenum pname, GLboolean *params); -typedef void (APIENTRYP PFNGLGETDOUBLEVPROC) (GLenum pname, GLdouble *params); -typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); -typedef void (APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); -typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); -typedef void (APIENTRYP PFNGLGETTEXIMAGEPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERFVPROC) (GLenum target, GLint level, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERIVPROC) (GLenum target, GLint level, GLenum pname, GLint *params); -typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap); -typedef void (APIENTRYP PFNGLDEPTHRANGEPROC) (GLdouble near, GLdouble far); -typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); -#endif - -#ifndef GL_VERSION_1_1 -#define GL_VERSION_1_1 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); -GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); -GLAPI void APIENTRY glGetPointerv (GLenum pname, GLvoid* *params); -GLAPI void APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); -GLAPI void APIENTRY glCopyTexImage1D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -GLAPI void APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -GLAPI void APIENTRY glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); -GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); -GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); -GLAPI GLboolean APIENTRY glIsTexture (GLuint texture); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); -typedef void (APIENTRYP PFNGLGETPOINTERVPROC) (GLenum pname, GLvoid* *params); -typedef void (APIENTRYP PFNGLPOLYGONOFFSETPROC) (GLfloat factor, GLfloat units); -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); -typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); -typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); -typedef GLboolean (APIENTRYP PFNGLISTEXTUREPROC) (GLuint texture); -#endif - -#ifndef GL_VERSION_1_2 -#define GL_VERSION_1_2 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI void APIENTRY glBlendEquation (GLenum mode); -GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif - -#ifndef GL_VERSION_1_3 -#define GL_VERSION_1_3 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glActiveTexture (GLenum texture); -GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); -GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); -#endif - -#ifndef GL_VERSION_1_4 -#define GL_VERSION_1_4 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); -GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); -GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); -GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); -#endif - -#ifndef GL_VERSION_1_5 -#define GL_VERSION_1_5 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); -GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); -GLAPI GLboolean APIENTRY glIsQuery (GLuint id); -GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); -GLAPI void APIENTRY glEndQuery (GLenum target); -GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); -GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); -GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); -GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); -GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); -GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); -GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); -GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); -GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); -GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); -GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); -typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); -typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); -typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); -typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); -#endif - -#ifndef GL_VERSION_2_0 -#define GL_VERSION_2_0 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); -GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); -GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); -GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); -GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); -GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); -GLAPI void APIENTRY glCompileShader (GLuint shader); -GLAPI GLuint APIENTRY glCreateProgram (void); -GLAPI GLuint APIENTRY glCreateShader (GLenum type); -GLAPI void APIENTRY glDeleteProgram (GLuint program); -GLAPI void APIENTRY glDeleteShader (GLuint shader); -GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); -GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); -GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); -GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); -GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); -GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); -GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); -GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); -GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid* *pointer); -GLAPI GLboolean APIENTRY glIsProgram (GLuint program); -GLAPI GLboolean APIENTRY glIsShader (GLuint shader); -GLAPI void APIENTRY glLinkProgram (GLuint program); -GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); -GLAPI void APIENTRY glUseProgram (GLuint program); -GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); -GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); -GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); -GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); -GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); -GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glValidateProgram (GLuint program); -GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); -GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); -GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); -GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); -GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); -typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); -typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); -typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); -typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); -typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); -typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); -typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); -typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); -typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); -typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); -typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); -typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); -typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); -typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_VERSION_2_1 -#define GL_VERSION_2_1 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -#endif - -#ifndef GL_VERSION_3_0 -#define GL_VERSION_3_0 1 -/* OpenGL 3.0 also reuses entry points from these extensions: */ -/* ARB_framebuffer_object */ -/* ARB_map_buffer_range */ -/* ARB_vertex_array_object */ -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); -GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); -GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); -GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); -GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); -GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); -GLAPI void APIENTRY glEndTransformFeedback (void); -GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); -GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); -GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); -GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); -GLAPI void APIENTRY glEndConditionalRender (void); -GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); -GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); -GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); -GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); -GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); -GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); -GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); -GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); -GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); -GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); -GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); -GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); -GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); -GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); -GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); -GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); -GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); -GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); -GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); -GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); -typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); -typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); -typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); -typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); -typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); -typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); -typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); -typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); -typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); -typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); -typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); -typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); -typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); -typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); -typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); -typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); -#endif - -#ifndef GL_VERSION_3_1 -#define GL_VERSION_3_1 1 -/* OpenGL 3.1 also reuses entry points from these extensions: */ -/* ARB_copy_buffer */ -/* ARB_uniform_buffer_object */ -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); -GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); -GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); -GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); -typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); -#endif - -#ifndef GL_VERSION_3_2 -#define GL_VERSION_3_2 1 -/* OpenGL 3.2 also reuses entry points from these extensions: */ -/* ARB_draw_elements_base_vertex */ -/* ARB_provoking_vertex */ -/* ARB_sync */ -/* ARB_texture_multisample */ -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); -GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); -GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); -#endif - -#ifndef GL_VERSION_3_3 -#define GL_VERSION_3_3 1 -/* OpenGL 3.3 also reuses entry points from these extensions: */ -/* ARB_blend_func_extended */ -/* ARB_sampler_objects */ -/* ARB_explicit_attrib_location, but it has none */ -/* ARB_occlusion_query2 (no entry points) */ -/* ARB_shader_bit_encoding (no entry points) */ -/* ARB_texture_rgb10_a2ui (no entry points) */ -/* ARB_texture_swizzle (no entry points) */ -/* ARB_timer_query */ -/* ARB_vertex_type_2_10_10_10_rev */ -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); -#endif - -#ifndef GL_VERSION_4_0 -#define GL_VERSION_4_0 1 -/* OpenGL 4.0 also reuses entry points from these extensions: */ -/* ARB_texture_query_lod (no entry points) */ -/* ARB_draw_indirect */ -/* ARB_gpu_shader5 (no entry points) */ -/* ARB_gpu_shader_fp64 */ -/* ARB_shader_subroutine */ -/* ARB_tessellation_shader */ -/* ARB_texture_buffer_object_rgb32 (no entry points) */ -/* ARB_texture_cube_map_array (no entry points) */ -/* ARB_texture_gather (no entry points) */ -/* ARB_transform_feedback2 */ -/* ARB_transform_feedback3 */ -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glMinSampleShading (GLfloat value); -GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); -GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); -GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value); -typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif - -#ifndef GL_VERSION_4_1 -#define GL_VERSION_4_1 1 -/* OpenGL 4.1 reuses entry points from these extensions: */ -/* ARB_ES2_compatibility */ -/* ARB_get_program_binary */ -/* ARB_separate_shader_objects */ -/* ARB_shader_precision (no entry points) */ -/* ARB_vertex_attrib_64bit */ -/* ARB_viewport_array */ -#endif - -#ifndef GL_VERSION_4_2 -#define GL_VERSION_4_2 1 -/* OpenGL 4.2 reuses entry points from these extensions: */ -/* ARB_base_instance */ -/* ARB_shading_language_420pack (no entry points) */ -/* ARB_transform_feedback_instanced */ -/* ARB_compressed_texture_pixel_storage (no entry points) */ -/* ARB_conservative_depth (no entry points) */ -/* ARB_internalformat_query */ -/* ARB_map_buffer_alignment (no entry points) */ -/* ARB_shader_atomic_counters */ -/* ARB_shader_image_load_store */ -/* ARB_shading_language_packing (no entry points) */ -/* ARB_texture_storage */ -#endif - -#ifndef GL_VERSION_4_3 -#define GL_VERSION_4_3 1 -/* OpenGL 4.3 reuses entry points from these extensions: */ -/* ARB_arrays_of_arrays (no entry points, GLSL only) */ -/* ARB_fragment_layer_viewport (no entry points, GLSL only) */ -/* ARB_shader_image_size (no entry points, GLSL only) */ -/* ARB_ES3_compatibility (no entry points) */ -/* ARB_clear_buffer_object */ -/* ARB_compute_shader */ -/* ARB_copy_image */ -/* ARB_debug_group */ -/* ARB_debug_label */ -/* KHR_debug (ARB_debug_output promoted to KHR without suffixes) */ -/* ARB_debug_output2 (no entry points) */ -/* ARB_explicit_uniform_location (no entry points) */ -/* ARB_framebuffer_no_attachments */ -/* ARB_internalformat_query2 */ -/* ARB_invalidate_subdata */ -/* ARB_multi_draw_indirect */ -/* ARB_program_interface_query */ -/* ARB_robust_buffer_access_behavior (no entry points) */ -/* ARB_shader_storage_buffer_object */ -/* ARB_stencil_texturing (no entry points) */ -/* ARB_texture_buffer_range */ -/* ARB_texture_query_levels (no entry points) */ -/* ARB_texture_storage_multisample */ -/* ARB_texture_view */ -/* ARB_vertex_attrib_binding */ -#endif - -#ifndef GL_ARB_depth_buffer_float -#define GL_ARB_depth_buffer_float 1 -#endif - -#ifndef GL_ARB_framebuffer_object -#define GL_ARB_framebuffer_object 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); -GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); -GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); -GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); -GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); -GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); -GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); -GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); -GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); -GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); -GLAPI void APIENTRY glGenerateMipmap (GLenum target); -GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -#endif /* GLCOREARB_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); -typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); -typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); -typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); -typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); -typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); -typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -#endif - -#ifndef GL_ARB_framebuffer_sRGB -#define GL_ARB_framebuffer_sRGB 1 -#endif - -#ifndef GL_ARB_half_float_vertex -#define GL_ARB_half_float_vertex 1 -#endif - -#ifndef GL_ARB_map_buffer_range -#define GL_ARB_map_buffer_range 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); -GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); -#endif /* GLCOREARB_PROTOTYPES */ -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); -typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); -#endif - -#ifndef GL_ARB_texture_compression_rgtc -#define GL_ARB_texture_compression_rgtc 1 -#endif - -#ifndef GL_ARB_texture_rg -#define GL_ARB_texture_rg 1 -#endif - -#ifndef GL_ARB_vertex_array_object -#define GL_ARB_vertex_array_object 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBindVertexArray (GLuint array); -GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); -GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); -GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); -typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); -typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); -typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); -#endif - -#ifndef GL_ARB_uniform_buffer_object -#define GL_ARB_uniform_buffer_object 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); -GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); -GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); -GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); -GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); -typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); -typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -#endif - -#ifndef GL_ARB_copy_buffer -#define GL_ARB_copy_buffer 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -#endif - -#ifndef GL_ARB_depth_clamp -#define GL_ARB_depth_clamp 1 -#endif - -#ifndef GL_ARB_draw_elements_base_vertex -#define GL_ARB_draw_elements_base_vertex 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); -GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); -#endif - -#ifndef GL_ARB_fragment_coord_conventions -#define GL_ARB_fragment_coord_conventions 1 -#endif - -#ifndef GL_ARB_provoking_vertex -#define GL_ARB_provoking_vertex 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glProvokingVertex (GLenum mode); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); -#endif - -#ifndef GL_ARB_seamless_cube_map -#define GL_ARB_seamless_cube_map 1 -#endif - -#ifndef GL_ARB_sync -#define GL_ARB_sync 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); -GLAPI GLboolean APIENTRY glIsSync (GLsync sync); -GLAPI void APIENTRY glDeleteSync (GLsync sync); -GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); -GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); -GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); -GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -#endif /* GLCOREARB_PROTOTYPES */ -typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); -typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); -typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); -typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); -typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); -typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); -typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -#endif - -#ifndef GL_ARB_texture_multisample -#define GL_ARB_texture_multisample 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); -GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); -typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); -#endif - -#ifndef GL_ARB_vertex_array_bgra -#define GL_ARB_vertex_array_bgra 1 -#endif - -#ifndef GL_ARB_draw_buffers_blend -#define GL_ARB_draw_buffers_blend 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); -GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); -GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif - -#ifndef GL_ARB_sample_shading -#define GL_ARB_sample_shading 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); -#endif - -#ifndef GL_ARB_texture_cube_map_array -#define GL_ARB_texture_cube_map_array 1 -#endif - -#ifndef GL_ARB_texture_gather -#define GL_ARB_texture_gather 1 -#endif - -#ifndef GL_ARB_texture_query_lod -#define GL_ARB_texture_query_lod 1 -#endif - -#ifndef GL_ARB_shading_language_include -#define GL_ARB_shading_language_include 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); -GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); -GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); -GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); -GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); -GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); -typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); -typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); -typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); -typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); -typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_texture_compression_bptc -#define GL_ARB_texture_compression_bptc 1 -#endif - -#ifndef GL_ARB_blend_func_extended -#define GL_ARB_blend_func_extended 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); -GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); -#endif - -#ifndef GL_ARB_explicit_attrib_location -#define GL_ARB_explicit_attrib_location 1 -#endif - -#ifndef GL_ARB_occlusion_query2 -#define GL_ARB_occlusion_query2 1 -#endif - -#ifndef GL_ARB_sampler_objects -#define GL_ARB_sampler_objects 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); -GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); -GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); -GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); -GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); -GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); -GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); -GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); -GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); -GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); -GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); -typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); -typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); -typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); -#endif - -#ifndef GL_ARB_shader_bit_encoding -#define GL_ARB_shader_bit_encoding 1 -#endif - -#ifndef GL_ARB_texture_rgb10_a2ui -#define GL_ARB_texture_rgb10_a2ui 1 -#endif - -#ifndef GL_ARB_texture_swizzle -#define GL_ARB_texture_swizzle 1 -#endif - -#ifndef GL_ARB_timer_query -#define GL_ARB_timer_query 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); -GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); -GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); -#endif - -#ifndef GL_ARB_vertex_type_2_10_10_10_rev -#define GL_ARB_vertex_type_2_10_10_10_rev 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); -GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); -GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); -GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); -GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); -GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); -GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); -GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); -GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); -GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); -GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); -GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); -GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); -typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); -typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); -typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); -typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); -typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); -typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -#endif - -#ifndef GL_ARB_draw_indirect -#define GL_ARB_draw_indirect 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); -GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); -#endif - -#ifndef GL_ARB_gpu_shader5 -#define GL_ARB_gpu_shader5 1 -#endif - -#ifndef GL_ARB_gpu_shader_fp64 -#define GL_ARB_gpu_shader_fp64 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); -GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); -GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); -typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); -#endif - -#ifndef GL_ARB_shader_subroutine -#define GL_ARB_shader_subroutine 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); -GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); -GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); -GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); -GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); -GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); -#endif /* GLCOREARB_PROTOTYPES */ -typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); -typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); -typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); -#endif - -#ifndef GL_ARB_tessellation_shader -#define GL_ARB_tessellation_shader 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); -GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); -typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); -#endif - -#ifndef GL_ARB_texture_buffer_object_rgb32 -#define GL_ARB_texture_buffer_object_rgb32 1 -#endif - -#ifndef GL_ARB_transform_feedback2 -#define GL_ARB_transform_feedback2 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); -GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); -GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); -GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); -GLAPI void APIENTRY glPauseTransformFeedback (void); -GLAPI void APIENTRY glResumeTransformFeedback (void); -GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); -typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); -typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); -typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); -#endif - -#ifndef GL_ARB_transform_feedback3 -#define GL_ARB_transform_feedback3 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); -GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); -GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); -GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); -typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_ES2_compatibility -#define GL_ARB_ES2_compatibility 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glReleaseShaderCompiler (void); -GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); -GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); -GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f); -GLAPI void APIENTRY glClearDepthf (GLfloat d); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); -typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); -typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); -typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f); -typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d); -#endif - -#ifndef GL_ARB_get_program_binary -#define GL_ARB_get_program_binary 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); -GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); -GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); -typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); -#endif - -#ifndef GL_ARB_separate_shader_objects -#define GL_ARB_separate_shader_objects 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); -GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); -GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* const *strings); -GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); -GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); -GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); -GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); -GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); -GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); -GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); -GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); -GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); -GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); -GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); -GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); -GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); -GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); -GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); -GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); -GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); -typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* const *strings); -typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); -typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); -typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); -typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); -typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -#endif - -#ifndef GL_ARB_vertex_attrib_64bit -#define GL_ARB_vertex_attrib_64bit 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); -#endif - -#ifndef GL_ARB_viewport_array -#define GL_ARB_viewport_array 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); -GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); -GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); -GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); -GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f); -GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); -GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); -typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); -typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f); -typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); -typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); -#endif - -#ifndef GL_ARB_cl_event -#define GL_ARB_cl_event 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); -#endif /* GLCOREARB_PROTOTYPES */ -typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); -#endif - -#ifndef GL_ARB_debug_output -#define GL_ARB_debug_output 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); -GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); -typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -#endif - -#ifndef GL_ARB_robustness -#define GL_ARB_robustness 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); -GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); -GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); -GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v); -GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values); -GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values); -GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values); -GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern); -GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); -GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); -GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); -GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); -GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); -GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); -GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); -GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); -GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); -GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); -typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); -typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); -typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); -typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values); -typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values); -typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values); -typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern); -typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); -typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); -typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); -typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); -typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); -typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); -typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); -typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); -typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); -typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); -#endif - -#ifndef GL_ARB_shader_stencil_export -#define GL_ARB_shader_stencil_export 1 -#endif - -#ifndef GL_ARB_base_instance -#define GL_ARB_base_instance 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); -#endif - -#ifndef GL_ARB_shading_language_420pack -#define GL_ARB_shading_language_420pack 1 -#endif - -#ifndef GL_ARB_transform_feedback_instanced -#define GL_ARB_transform_feedback_instanced 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); -GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); -#endif - -#ifndef GL_ARB_compressed_texture_pixel_storage -#define GL_ARB_compressed_texture_pixel_storage 1 -#endif - -#ifndef GL_ARB_conservative_depth -#define GL_ARB_conservative_depth 1 -#endif - -#ifndef GL_ARB_internalformat_query -#define GL_ARB_internalformat_query 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); -#endif - -#ifndef GL_ARB_map_buffer_alignment -#define GL_ARB_map_buffer_alignment 1 -#endif - -#ifndef GL_ARB_shader_atomic_counters -#define GL_ARB_shader_atomic_counters 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_shader_image_load_store -#define GL_ARB_shader_image_load_store 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); -GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); -typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); -#endif - -#ifndef GL_ARB_shading_language_packing -#define GL_ARB_shading_language_packing 1 -#endif - -#ifndef GL_ARB_texture_storage -#define GL_ARB_texture_storage 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -#endif - -#ifndef GL_KHR_texture_compression_astc_ldr -#define GL_KHR_texture_compression_astc_ldr 1 -#endif - -#ifndef GL_KHR_debug -#define GL_KHR_debug 1 -/* KHR_debug also reuses entry points from ARB_debug_group and ARB_debug_label */ -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); -GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); -GLAPI void APIENTRY glPopDebugGroup (void); -GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); -GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); -GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); -GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); -typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); -typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); -typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); -typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); -typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); -typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); -#endif - -#ifndef GL_ARB_arrays_of_arrays -#define GL_ARB_arrays_of_arrays 1 -#endif - -#ifndef GL_ARB_clear_buffer_object -#define GL_ARB_clear_buffer_object 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); -GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); -GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); -GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); -typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); -typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); -typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); -#endif - -#ifndef GL_ARB_compute_shader -#define GL_ARB_compute_shader 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); -GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); -typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); -#endif - -#ifndef GL_ARB_copy_image -#define GL_ARB_copy_image 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); -#endif - -#ifndef GL_ARB_debug_group -#define GL_ARB_debug_group 1 -/* ARB_debug_group reuses entry points from KHR_debug */ -#endif - -#ifndef GL_ARB_debug_label -#define GL_ARB_debug_label 1 -/* ARB_debug_label reuses entry points from KHR_debug */ -#endif - -#ifndef GL_ARB_debug_output2 -#define GL_ARB_debug_output2 1 -#endif - -#ifndef GL_ARB_ES3_compatibility -#define GL_ARB_ES3_compatibility 1 -#endif - -#ifndef GL_ARB_explicit_uniform_location -#define GL_ARB_explicit_uniform_location 1 -#endif - -#ifndef GL_ARB_fragment_layer_viewport -#define GL_ARB_fragment_layer_viewport 1 -#endif - -#ifndef GL_ARB_framebuffer_no_attachments -#define GL_ARB_framebuffer_no_attachments 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); -GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_internalformat_query2 -#define GL_ARB_internalformat_query2 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); -#endif - -#ifndef GL_ARB_invalidate_subdata -#define GL_ARB_invalidate_subdata 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); -GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); -GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); -GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); -GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); -GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); -typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); -typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); -typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); -#endif - -#ifndef GL_ARB_multi_draw_indirect -#define GL_ARB_multi_draw_indirect 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); -GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); -#endif - -#ifndef GL_ARB_program_interface_query -#define GL_ARB_program_interface_query 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); -GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); -GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); -GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); -GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); -GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); -typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); -typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); -#endif - -#ifndef GL_ARB_robust_buffer_access_behavior -#define GL_ARB_robust_buffer_access_behavior 1 -#endif - -#ifndef GL_ARB_shader_image_size -#define GL_ARB_shader_image_size 1 -#endif - -#ifndef GL_ARB_shader_storage_buffer_object -#define GL_ARB_shader_storage_buffer_object 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); -#endif - -#ifndef GL_ARB_stencil_texturing -#define GL_ARB_stencil_texturing 1 -#endif - -#ifndef GL_ARB_texture_buffer_range -#define GL_ARB_texture_buffer_range 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -#endif - -#ifndef GL_ARB_texture_query_levels -#define GL_ARB_texture_query_levels 1 -#endif - -#ifndef GL_ARB_texture_storage_multisample -#define GL_ARB_texture_storage_multisample 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -#endif - -#ifndef GL_ARB_texture_view -#define GL_ARB_texture_view 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); -#endif - -#ifndef GL_ARB_vertex_attrib_binding -#define GL_ARB_vertex_attrib_binding 1 -#ifdef GLCOREARB_PROTOTYPES -GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); -GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); -GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); -GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); -#endif /* GLCOREARB_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); -typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); -typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); -#endif - -#ifndef GL_ARB_robustness_isolation -#define GL_ARB_robustness_isolation 1 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/GL3/glext.h b/include/GL3/glext.h deleted file mode 100644 index 6175ad450..000000000 --- a/include/GL3/glext.h +++ /dev/null @@ -1,12800 +0,0 @@ -#ifndef __glext_h_ -#define __glext_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* -** Copyright (c) 2007-2012 The Khronos Group Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and/or associated documentation files (the -** "Materials"), to deal in the Materials without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Materials, and to -** permit persons to whom the Materials are furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be included -** in all copies or substantial portions of the Materials. -** -** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -*/ - -/* Header file version number, required by OpenGL ABI for Linux */ -/* glext.h last updated $Date: 2012-08-06 02:01:01 -0700 (Mon, 06 Aug 2012) $ */ -/* Current version at http://www.opengl.org/registry/ */ -#define GL_GLEXT_VERSION 83 -/* Function declaration macros - to move into glplatform.h */ - -#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) -#define WIN32_LEAN_AND_MEAN 1 -#include -#endif - -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef APIENTRYP -#define APIENTRYP APIENTRY * -#endif -#ifndef GLAPI -#define GLAPI extern -#endif - -/*************************************************************/ - -#ifndef GL_VERSION_1_2 -#define GL_UNSIGNED_BYTE_3_3_2 0x8032 -#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 -#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#define GL_UNSIGNED_INT_10_10_10_2 0x8036 -#define GL_TEXTURE_BINDING_3D 0x806A -#define GL_PACK_SKIP_IMAGES 0x806B -#define GL_PACK_IMAGE_HEIGHT 0x806C -#define GL_UNPACK_SKIP_IMAGES 0x806D -#define GL_UNPACK_IMAGE_HEIGHT 0x806E -#define GL_TEXTURE_3D 0x806F -#define GL_PROXY_TEXTURE_3D 0x8070 -#define GL_TEXTURE_DEPTH 0x8071 -#define GL_TEXTURE_WRAP_R 0x8072 -#define GL_MAX_3D_TEXTURE_SIZE 0x8073 -#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 -#define GL_UNSIGNED_SHORT_5_6_5 0x8363 -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_BGR 0x80E0 -#define GL_BGRA 0x80E1 -#define GL_MAX_ELEMENTS_VERTICES 0x80E8 -#define GL_MAX_ELEMENTS_INDICES 0x80E9 -#define GL_CLAMP_TO_EDGE 0x812F -#define GL_TEXTURE_MIN_LOD 0x813A -#define GL_TEXTURE_MAX_LOD 0x813B -#define GL_TEXTURE_BASE_LEVEL 0x813C -#define GL_TEXTURE_MAX_LEVEL 0x813D -#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 -#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 -#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 -#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 -#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E -#endif - -#ifndef GL_VERSION_1_2_DEPRECATED -#define GL_RESCALE_NORMAL 0x803A -#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 -#define GL_SINGLE_COLOR 0x81F9 -#define GL_SEPARATE_SPECULAR_COLOR 0x81FA -#define GL_ALIASED_POINT_SIZE_RANGE 0x846D -#endif - -#ifndef GL_ARB_imaging -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 -#define GL_BLEND_COLOR 0x8005 -#define GL_FUNC_ADD 0x8006 -#define GL_MIN 0x8007 -#define GL_MAX 0x8008 -#define GL_BLEND_EQUATION 0x8009 -#define GL_FUNC_SUBTRACT 0x800A -#define GL_FUNC_REVERSE_SUBTRACT 0x800B -#endif - -#ifndef GL_ARB_imaging_DEPRECATED -#define GL_CONVOLUTION_1D 0x8010 -#define GL_CONVOLUTION_2D 0x8011 -#define GL_SEPARABLE_2D 0x8012 -#define GL_CONVOLUTION_BORDER_MODE 0x8013 -#define GL_CONVOLUTION_FILTER_SCALE 0x8014 -#define GL_CONVOLUTION_FILTER_BIAS 0x8015 -#define GL_REDUCE 0x8016 -#define GL_CONVOLUTION_FORMAT 0x8017 -#define GL_CONVOLUTION_WIDTH 0x8018 -#define GL_CONVOLUTION_HEIGHT 0x8019 -#define GL_MAX_CONVOLUTION_WIDTH 0x801A -#define GL_MAX_CONVOLUTION_HEIGHT 0x801B -#define GL_POST_CONVOLUTION_RED_SCALE 0x801C -#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D -#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E -#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F -#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 -#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 -#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 -#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 -#define GL_HISTOGRAM 0x8024 -#define GL_PROXY_HISTOGRAM 0x8025 -#define GL_HISTOGRAM_WIDTH 0x8026 -#define GL_HISTOGRAM_FORMAT 0x8027 -#define GL_HISTOGRAM_RED_SIZE 0x8028 -#define GL_HISTOGRAM_GREEN_SIZE 0x8029 -#define GL_HISTOGRAM_BLUE_SIZE 0x802A -#define GL_HISTOGRAM_ALPHA_SIZE 0x802B -#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C -#define GL_HISTOGRAM_SINK 0x802D -#define GL_MINMAX 0x802E -#define GL_MINMAX_FORMAT 0x802F -#define GL_MINMAX_SINK 0x8030 -#define GL_TABLE_TOO_LARGE 0x8031 -#define GL_COLOR_MATRIX 0x80B1 -#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 -#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 -#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 -#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 -#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 -#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 -#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 -#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 -#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA -#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB -#define GL_COLOR_TABLE 0x80D0 -#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 -#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 -#define GL_PROXY_COLOR_TABLE 0x80D3 -#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 -#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 -#define GL_COLOR_TABLE_SCALE 0x80D6 -#define GL_COLOR_TABLE_BIAS 0x80D7 -#define GL_COLOR_TABLE_FORMAT 0x80D8 -#define GL_COLOR_TABLE_WIDTH 0x80D9 -#define GL_COLOR_TABLE_RED_SIZE 0x80DA -#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB -#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC -#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD -#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE -#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF -#define GL_CONSTANT_BORDER 0x8151 -#define GL_REPLICATE_BORDER 0x8153 -#define GL_CONVOLUTION_BORDER_COLOR 0x8154 -#endif - -#ifndef GL_VERSION_1_3 -#define GL_TEXTURE0 0x84C0 -#define GL_TEXTURE1 0x84C1 -#define GL_TEXTURE2 0x84C2 -#define GL_TEXTURE3 0x84C3 -#define GL_TEXTURE4 0x84C4 -#define GL_TEXTURE5 0x84C5 -#define GL_TEXTURE6 0x84C6 -#define GL_TEXTURE7 0x84C7 -#define GL_TEXTURE8 0x84C8 -#define GL_TEXTURE9 0x84C9 -#define GL_TEXTURE10 0x84CA -#define GL_TEXTURE11 0x84CB -#define GL_TEXTURE12 0x84CC -#define GL_TEXTURE13 0x84CD -#define GL_TEXTURE14 0x84CE -#define GL_TEXTURE15 0x84CF -#define GL_TEXTURE16 0x84D0 -#define GL_TEXTURE17 0x84D1 -#define GL_TEXTURE18 0x84D2 -#define GL_TEXTURE19 0x84D3 -#define GL_TEXTURE20 0x84D4 -#define GL_TEXTURE21 0x84D5 -#define GL_TEXTURE22 0x84D6 -#define GL_TEXTURE23 0x84D7 -#define GL_TEXTURE24 0x84D8 -#define GL_TEXTURE25 0x84D9 -#define GL_TEXTURE26 0x84DA -#define GL_TEXTURE27 0x84DB -#define GL_TEXTURE28 0x84DC -#define GL_TEXTURE29 0x84DD -#define GL_TEXTURE30 0x84DE -#define GL_TEXTURE31 0x84DF -#define GL_ACTIVE_TEXTURE 0x84E0 -#define GL_MULTISAMPLE 0x809D -#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE 0x809F -#define GL_SAMPLE_COVERAGE 0x80A0 -#define GL_SAMPLE_BUFFERS 0x80A8 -#define GL_SAMPLES 0x80A9 -#define GL_SAMPLE_COVERAGE_VALUE 0x80AA -#define GL_SAMPLE_COVERAGE_INVERT 0x80AB -#define GL_TEXTURE_CUBE_MAP 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A -#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C -#define GL_COMPRESSED_RGB 0x84ED -#define GL_COMPRESSED_RGBA 0x84EE -#define GL_TEXTURE_COMPRESSION_HINT 0x84EF -#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 -#define GL_TEXTURE_COMPRESSED 0x86A1 -#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 -#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 -#define GL_CLAMP_TO_BORDER 0x812D -#endif - -#ifndef GL_VERSION_1_3_DEPRECATED -#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 -#define GL_MAX_TEXTURE_UNITS 0x84E2 -#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 -#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 -#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 -#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 -#define GL_MULTISAMPLE_BIT 0x20000000 -#define GL_NORMAL_MAP 0x8511 -#define GL_REFLECTION_MAP 0x8512 -#define GL_COMPRESSED_ALPHA 0x84E9 -#define GL_COMPRESSED_LUMINANCE 0x84EA -#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB -#define GL_COMPRESSED_INTENSITY 0x84EC -#define GL_COMBINE 0x8570 -#define GL_COMBINE_RGB 0x8571 -#define GL_COMBINE_ALPHA 0x8572 -#define GL_SOURCE0_RGB 0x8580 -#define GL_SOURCE1_RGB 0x8581 -#define GL_SOURCE2_RGB 0x8582 -#define GL_SOURCE0_ALPHA 0x8588 -#define GL_SOURCE1_ALPHA 0x8589 -#define GL_SOURCE2_ALPHA 0x858A -#define GL_OPERAND0_RGB 0x8590 -#define GL_OPERAND1_RGB 0x8591 -#define GL_OPERAND2_RGB 0x8592 -#define GL_OPERAND0_ALPHA 0x8598 -#define GL_OPERAND1_ALPHA 0x8599 -#define GL_OPERAND2_ALPHA 0x859A -#define GL_RGB_SCALE 0x8573 -#define GL_ADD_SIGNED 0x8574 -#define GL_INTERPOLATE 0x8575 -#define GL_SUBTRACT 0x84E7 -#define GL_CONSTANT 0x8576 -#define GL_PRIMARY_COLOR 0x8577 -#define GL_PREVIOUS 0x8578 -#define GL_DOT3_RGB 0x86AE -#define GL_DOT3_RGBA 0x86AF -#endif - -#ifndef GL_VERSION_1_4 -#define GL_BLEND_DST_RGB 0x80C8 -#define GL_BLEND_SRC_RGB 0x80C9 -#define GL_BLEND_DST_ALPHA 0x80CA -#define GL_BLEND_SRC_ALPHA 0x80CB -#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 -#define GL_DEPTH_COMPONENT16 0x81A5 -#define GL_DEPTH_COMPONENT24 0x81A6 -#define GL_DEPTH_COMPONENT32 0x81A7 -#define GL_MIRRORED_REPEAT 0x8370 -#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD -#define GL_TEXTURE_LOD_BIAS 0x8501 -#define GL_INCR_WRAP 0x8507 -#define GL_DECR_WRAP 0x8508 -#define GL_TEXTURE_DEPTH_SIZE 0x884A -#define GL_TEXTURE_COMPARE_MODE 0x884C -#define GL_TEXTURE_COMPARE_FUNC 0x884D -#endif - -#ifndef GL_VERSION_1_4_DEPRECATED -#define GL_POINT_SIZE_MIN 0x8126 -#define GL_POINT_SIZE_MAX 0x8127 -#define GL_POINT_DISTANCE_ATTENUATION 0x8129 -#define GL_GENERATE_MIPMAP 0x8191 -#define GL_GENERATE_MIPMAP_HINT 0x8192 -#define GL_FOG_COORDINATE_SOURCE 0x8450 -#define GL_FOG_COORDINATE 0x8451 -#define GL_FRAGMENT_DEPTH 0x8452 -#define GL_CURRENT_FOG_COORDINATE 0x8453 -#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 -#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 -#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 -#define GL_FOG_COORDINATE_ARRAY 0x8457 -#define GL_COLOR_SUM 0x8458 -#define GL_CURRENT_SECONDARY_COLOR 0x8459 -#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A -#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B -#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C -#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D -#define GL_SECONDARY_COLOR_ARRAY 0x845E -#define GL_TEXTURE_FILTER_CONTROL 0x8500 -#define GL_DEPTH_TEXTURE_MODE 0x884B -#define GL_COMPARE_R_TO_TEXTURE 0x884E -#endif - -#ifndef GL_VERSION_1_5 -#define GL_BUFFER_SIZE 0x8764 -#define GL_BUFFER_USAGE 0x8765 -#define GL_QUERY_COUNTER_BITS 0x8864 -#define GL_CURRENT_QUERY 0x8865 -#define GL_QUERY_RESULT 0x8866 -#define GL_QUERY_RESULT_AVAILABLE 0x8867 -#define GL_ARRAY_BUFFER 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 -#define GL_ARRAY_BUFFER_BINDING 0x8894 -#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 -#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F -#define GL_READ_ONLY 0x88B8 -#define GL_WRITE_ONLY 0x88B9 -#define GL_READ_WRITE 0x88BA -#define GL_BUFFER_ACCESS 0x88BB -#define GL_BUFFER_MAPPED 0x88BC -#define GL_BUFFER_MAP_POINTER 0x88BD -#define GL_STREAM_DRAW 0x88E0 -#define GL_STREAM_READ 0x88E1 -#define GL_STREAM_COPY 0x88E2 -#define GL_STATIC_DRAW 0x88E4 -#define GL_STATIC_READ 0x88E5 -#define GL_STATIC_COPY 0x88E6 -#define GL_DYNAMIC_DRAW 0x88E8 -#define GL_DYNAMIC_READ 0x88E9 -#define GL_DYNAMIC_COPY 0x88EA -#define GL_SAMPLES_PASSED 0x8914 -#endif - -#ifndef GL_VERSION_1_5_DEPRECATED -#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 -#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 -#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 -#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 -#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A -#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B -#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C -#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D -#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E -#define GL_FOG_COORD_SRC 0x8450 -#define GL_FOG_COORD 0x8451 -#define GL_CURRENT_FOG_COORD 0x8453 -#define GL_FOG_COORD_ARRAY_TYPE 0x8454 -#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 -#define GL_FOG_COORD_ARRAY_POINTER 0x8456 -#define GL_FOG_COORD_ARRAY 0x8457 -#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D -#define GL_SRC0_RGB 0x8580 -#define GL_SRC1_RGB 0x8581 -#define GL_SRC2_RGB 0x8582 -#define GL_SRC0_ALPHA 0x8588 -#define GL_SRC1_ALPHA 0x8589 -#define GL_SRC2_ALPHA 0x858A -#endif - -#ifndef GL_VERSION_2_0 -#define GL_BLEND_EQUATION_RGB 0x8009 -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 -#define GL_CURRENT_VERTEX_ATTRIB 0x8626 -#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 -#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 -#define GL_STENCIL_BACK_FUNC 0x8800 -#define GL_STENCIL_BACK_FAIL 0x8801 -#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 -#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 -#define GL_MAX_DRAW_BUFFERS 0x8824 -#define GL_DRAW_BUFFER0 0x8825 -#define GL_DRAW_BUFFER1 0x8826 -#define GL_DRAW_BUFFER2 0x8827 -#define GL_DRAW_BUFFER3 0x8828 -#define GL_DRAW_BUFFER4 0x8829 -#define GL_DRAW_BUFFER5 0x882A -#define GL_DRAW_BUFFER6 0x882B -#define GL_DRAW_BUFFER7 0x882C -#define GL_DRAW_BUFFER8 0x882D -#define GL_DRAW_BUFFER9 0x882E -#define GL_DRAW_BUFFER10 0x882F -#define GL_DRAW_BUFFER11 0x8830 -#define GL_DRAW_BUFFER12 0x8831 -#define GL_DRAW_BUFFER13 0x8832 -#define GL_DRAW_BUFFER14 0x8833 -#define GL_DRAW_BUFFER15 0x8834 -#define GL_BLEND_EQUATION_ALPHA 0x883D -#define GL_MAX_VERTEX_ATTRIBS 0x8869 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A -#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 -#define GL_FRAGMENT_SHADER 0x8B30 -#define GL_VERTEX_SHADER 0x8B31 -#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 -#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A -#define GL_MAX_VARYING_FLOATS 0x8B4B -#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C -#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D -#define GL_SHADER_TYPE 0x8B4F -#define GL_FLOAT_VEC2 0x8B50 -#define GL_FLOAT_VEC3 0x8B51 -#define GL_FLOAT_VEC4 0x8B52 -#define GL_INT_VEC2 0x8B53 -#define GL_INT_VEC3 0x8B54 -#define GL_INT_VEC4 0x8B55 -#define GL_BOOL 0x8B56 -#define GL_BOOL_VEC2 0x8B57 -#define GL_BOOL_VEC3 0x8B58 -#define GL_BOOL_VEC4 0x8B59 -#define GL_FLOAT_MAT2 0x8B5A -#define GL_FLOAT_MAT3 0x8B5B -#define GL_FLOAT_MAT4 0x8B5C -#define GL_SAMPLER_1D 0x8B5D -#define GL_SAMPLER_2D 0x8B5E -#define GL_SAMPLER_3D 0x8B5F -#define GL_SAMPLER_CUBE 0x8B60 -#define GL_SAMPLER_1D_SHADOW 0x8B61 -#define GL_SAMPLER_2D_SHADOW 0x8B62 -#define GL_DELETE_STATUS 0x8B80 -#define GL_COMPILE_STATUS 0x8B81 -#define GL_LINK_STATUS 0x8B82 -#define GL_VALIDATE_STATUS 0x8B83 -#define GL_INFO_LOG_LENGTH 0x8B84 -#define GL_ATTACHED_SHADERS 0x8B85 -#define GL_ACTIVE_UNIFORMS 0x8B86 -#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 -#define GL_SHADER_SOURCE_LENGTH 0x8B88 -#define GL_ACTIVE_ATTRIBUTES 0x8B89 -#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A -#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B -#define GL_SHADING_LANGUAGE_VERSION 0x8B8C -#define GL_CURRENT_PROGRAM 0x8B8D -#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 -#define GL_LOWER_LEFT 0x8CA1 -#define GL_UPPER_LEFT 0x8CA2 -#define GL_STENCIL_BACK_REF 0x8CA3 -#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 -#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 -#endif - -#ifndef GL_VERSION_2_0_DEPRECATED -#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 -#define GL_POINT_SPRITE 0x8861 -#define GL_COORD_REPLACE 0x8862 -#define GL_MAX_TEXTURE_COORDS 0x8871 -#endif - -#ifndef GL_VERSION_2_1 -#define GL_PIXEL_PACK_BUFFER 0x88EB -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED -#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF -#define GL_FLOAT_MAT2x3 0x8B65 -#define GL_FLOAT_MAT2x4 0x8B66 -#define GL_FLOAT_MAT3x2 0x8B67 -#define GL_FLOAT_MAT3x4 0x8B68 -#define GL_FLOAT_MAT4x2 0x8B69 -#define GL_FLOAT_MAT4x3 0x8B6A -#define GL_SRGB 0x8C40 -#define GL_SRGB8 0x8C41 -#define GL_SRGB_ALPHA 0x8C42 -#define GL_SRGB8_ALPHA8 0x8C43 -#define GL_COMPRESSED_SRGB 0x8C48 -#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 -#endif - -#ifndef GL_VERSION_2_1_DEPRECATED -#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F -#define GL_SLUMINANCE_ALPHA 0x8C44 -#define GL_SLUMINANCE8_ALPHA8 0x8C45 -#define GL_SLUMINANCE 0x8C46 -#define GL_SLUMINANCE8 0x8C47 -#define GL_COMPRESSED_SLUMINANCE 0x8C4A -#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B -#endif - -#ifndef GL_VERSION_3_0 -#define GL_COMPARE_REF_TO_TEXTURE 0x884E -#define GL_CLIP_DISTANCE0 0x3000 -#define GL_CLIP_DISTANCE1 0x3001 -#define GL_CLIP_DISTANCE2 0x3002 -#define GL_CLIP_DISTANCE3 0x3003 -#define GL_CLIP_DISTANCE4 0x3004 -#define GL_CLIP_DISTANCE5 0x3005 -#define GL_CLIP_DISTANCE6 0x3006 -#define GL_CLIP_DISTANCE7 0x3007 -#define GL_MAX_CLIP_DISTANCES 0x0D32 -#define GL_MAJOR_VERSION 0x821B -#define GL_MINOR_VERSION 0x821C -#define GL_NUM_EXTENSIONS 0x821D -#define GL_CONTEXT_FLAGS 0x821E -#define GL_COMPRESSED_RED 0x8225 -#define GL_COMPRESSED_RG 0x8226 -#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 -#define GL_RGBA32F 0x8814 -#define GL_RGB32F 0x8815 -#define GL_RGBA16F 0x881A -#define GL_RGB16F 0x881B -#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD -#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF -#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 -#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 -#define GL_CLAMP_READ_COLOR 0x891C -#define GL_FIXED_ONLY 0x891D -#define GL_MAX_VARYING_COMPONENTS 0x8B4B -#define GL_TEXTURE_1D_ARRAY 0x8C18 -#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 -#define GL_TEXTURE_2D_ARRAY 0x8C1A -#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B -#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C -#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D -#define GL_R11F_G11F_B10F 0x8C3A -#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B -#define GL_RGB9_E5 0x8C3D -#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E -#define GL_TEXTURE_SHARED_SIZE 0x8C3F -#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 -#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 -#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 -#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 -#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 -#define GL_PRIMITIVES_GENERATED 0x8C87 -#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 -#define GL_RASTERIZER_DISCARD 0x8C89 -#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B -#define GL_INTERLEAVED_ATTRIBS 0x8C8C -#define GL_SEPARATE_ATTRIBS 0x8C8D -#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E -#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F -#define GL_RGBA32UI 0x8D70 -#define GL_RGB32UI 0x8D71 -#define GL_RGBA16UI 0x8D76 -#define GL_RGB16UI 0x8D77 -#define GL_RGBA8UI 0x8D7C -#define GL_RGB8UI 0x8D7D -#define GL_RGBA32I 0x8D82 -#define GL_RGB32I 0x8D83 -#define GL_RGBA16I 0x8D88 -#define GL_RGB16I 0x8D89 -#define GL_RGBA8I 0x8D8E -#define GL_RGB8I 0x8D8F -#define GL_RED_INTEGER 0x8D94 -#define GL_GREEN_INTEGER 0x8D95 -#define GL_BLUE_INTEGER 0x8D96 -#define GL_RGB_INTEGER 0x8D98 -#define GL_RGBA_INTEGER 0x8D99 -#define GL_BGR_INTEGER 0x8D9A -#define GL_BGRA_INTEGER 0x8D9B -#define GL_SAMPLER_1D_ARRAY 0x8DC0 -#define GL_SAMPLER_2D_ARRAY 0x8DC1 -#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 -#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 -#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 -#define GL_UNSIGNED_INT_VEC2 0x8DC6 -#define GL_UNSIGNED_INT_VEC3 0x8DC7 -#define GL_UNSIGNED_INT_VEC4 0x8DC8 -#define GL_INT_SAMPLER_1D 0x8DC9 -#define GL_INT_SAMPLER_2D 0x8DCA -#define GL_INT_SAMPLER_3D 0x8DCB -#define GL_INT_SAMPLER_CUBE 0x8DCC -#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE -#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF -#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 -#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 -#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 -#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 -#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 -#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 -#define GL_QUERY_WAIT 0x8E13 -#define GL_QUERY_NO_WAIT 0x8E14 -#define GL_QUERY_BY_REGION_WAIT 0x8E15 -#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 -#define GL_BUFFER_ACCESS_FLAGS 0x911F -#define GL_BUFFER_MAP_LENGTH 0x9120 -#define GL_BUFFER_MAP_OFFSET 0x9121 -/* Reuse tokens from ARB_depth_buffer_float */ -/* reuse GL_DEPTH_COMPONENT32F */ -/* reuse GL_DEPTH32F_STENCIL8 */ -/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ -/* Reuse tokens from ARB_framebuffer_object */ -/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ -/* reuse GL_FRAMEBUFFER_DEFAULT */ -/* reuse GL_FRAMEBUFFER_UNDEFINED */ -/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ -/* reuse GL_INDEX */ -/* reuse GL_MAX_RENDERBUFFER_SIZE */ -/* reuse GL_DEPTH_STENCIL */ -/* reuse GL_UNSIGNED_INT_24_8 */ -/* reuse GL_DEPTH24_STENCIL8 */ -/* reuse GL_TEXTURE_STENCIL_SIZE */ -/* reuse GL_TEXTURE_RED_TYPE */ -/* reuse GL_TEXTURE_GREEN_TYPE */ -/* reuse GL_TEXTURE_BLUE_TYPE */ -/* reuse GL_TEXTURE_ALPHA_TYPE */ -/* reuse GL_TEXTURE_DEPTH_TYPE */ -/* reuse GL_UNSIGNED_NORMALIZED */ -/* reuse GL_FRAMEBUFFER_BINDING */ -/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ -/* reuse GL_RENDERBUFFER_BINDING */ -/* reuse GL_READ_FRAMEBUFFER */ -/* reuse GL_DRAW_FRAMEBUFFER */ -/* reuse GL_READ_FRAMEBUFFER_BINDING */ -/* reuse GL_RENDERBUFFER_SAMPLES */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ -/* reuse GL_FRAMEBUFFER_COMPLETE */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ -/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ -/* reuse GL_MAX_COLOR_ATTACHMENTS */ -/* reuse GL_COLOR_ATTACHMENT0 */ -/* reuse GL_COLOR_ATTACHMENT1 */ -/* reuse GL_COLOR_ATTACHMENT2 */ -/* reuse GL_COLOR_ATTACHMENT3 */ -/* reuse GL_COLOR_ATTACHMENT4 */ -/* reuse GL_COLOR_ATTACHMENT5 */ -/* reuse GL_COLOR_ATTACHMENT6 */ -/* reuse GL_COLOR_ATTACHMENT7 */ -/* reuse GL_COLOR_ATTACHMENT8 */ -/* reuse GL_COLOR_ATTACHMENT9 */ -/* reuse GL_COLOR_ATTACHMENT10 */ -/* reuse GL_COLOR_ATTACHMENT11 */ -/* reuse GL_COLOR_ATTACHMENT12 */ -/* reuse GL_COLOR_ATTACHMENT13 */ -/* reuse GL_COLOR_ATTACHMENT14 */ -/* reuse GL_COLOR_ATTACHMENT15 */ -/* reuse GL_DEPTH_ATTACHMENT */ -/* reuse GL_STENCIL_ATTACHMENT */ -/* reuse GL_FRAMEBUFFER */ -/* reuse GL_RENDERBUFFER */ -/* reuse GL_RENDERBUFFER_WIDTH */ -/* reuse GL_RENDERBUFFER_HEIGHT */ -/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ -/* reuse GL_STENCIL_INDEX1 */ -/* reuse GL_STENCIL_INDEX4 */ -/* reuse GL_STENCIL_INDEX8 */ -/* reuse GL_STENCIL_INDEX16 */ -/* reuse GL_RENDERBUFFER_RED_SIZE */ -/* reuse GL_RENDERBUFFER_GREEN_SIZE */ -/* reuse GL_RENDERBUFFER_BLUE_SIZE */ -/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ -/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ -/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ -/* reuse GL_MAX_SAMPLES */ -/* Reuse tokens from ARB_framebuffer_sRGB */ -/* reuse GL_FRAMEBUFFER_SRGB */ -/* Reuse tokens from ARB_half_float_vertex */ -/* reuse GL_HALF_FLOAT */ -/* Reuse tokens from ARB_map_buffer_range */ -/* reuse GL_MAP_READ_BIT */ -/* reuse GL_MAP_WRITE_BIT */ -/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ -/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ -/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ -/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ -/* Reuse tokens from ARB_texture_compression_rgtc */ -/* reuse GL_COMPRESSED_RED_RGTC1 */ -/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ -/* reuse GL_COMPRESSED_RG_RGTC2 */ -/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ -/* Reuse tokens from ARB_texture_rg */ -/* reuse GL_RG */ -/* reuse GL_RG_INTEGER */ -/* reuse GL_R8 */ -/* reuse GL_R16 */ -/* reuse GL_RG8 */ -/* reuse GL_RG16 */ -/* reuse GL_R16F */ -/* reuse GL_R32F */ -/* reuse GL_RG16F */ -/* reuse GL_RG32F */ -/* reuse GL_R8I */ -/* reuse GL_R8UI */ -/* reuse GL_R16I */ -/* reuse GL_R16UI */ -/* reuse GL_R32I */ -/* reuse GL_R32UI */ -/* reuse GL_RG8I */ -/* reuse GL_RG8UI */ -/* reuse GL_RG16I */ -/* reuse GL_RG16UI */ -/* reuse GL_RG32I */ -/* reuse GL_RG32UI */ -/* Reuse tokens from ARB_vertex_array_object */ -/* reuse GL_VERTEX_ARRAY_BINDING */ -#endif - -#ifndef GL_VERSION_3_0_DEPRECATED -#define GL_CLAMP_VERTEX_COLOR 0x891A -#define GL_CLAMP_FRAGMENT_COLOR 0x891B -#define GL_ALPHA_INTEGER 0x8D97 -/* Reuse tokens from ARB_framebuffer_object */ -/* reuse GL_TEXTURE_LUMINANCE_TYPE */ -/* reuse GL_TEXTURE_INTENSITY_TYPE */ -#endif - -#ifndef GL_VERSION_3_1 -#define GL_SAMPLER_2D_RECT 0x8B63 -#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 -#define GL_SAMPLER_BUFFER 0x8DC2 -#define GL_INT_SAMPLER_2D_RECT 0x8DCD -#define GL_INT_SAMPLER_BUFFER 0x8DD0 -#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 -#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 -#define GL_TEXTURE_BUFFER 0x8C2A -#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B -#define GL_TEXTURE_BINDING_BUFFER 0x8C2C -#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D -#define GL_TEXTURE_BUFFER_FORMAT 0x8C2E -#define GL_TEXTURE_RECTANGLE 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 -#define GL_RED_SNORM 0x8F90 -#define GL_RG_SNORM 0x8F91 -#define GL_RGB_SNORM 0x8F92 -#define GL_RGBA_SNORM 0x8F93 -#define GL_R8_SNORM 0x8F94 -#define GL_RG8_SNORM 0x8F95 -#define GL_RGB8_SNORM 0x8F96 -#define GL_RGBA8_SNORM 0x8F97 -#define GL_R16_SNORM 0x8F98 -#define GL_RG16_SNORM 0x8F99 -#define GL_RGB16_SNORM 0x8F9A -#define GL_RGBA16_SNORM 0x8F9B -#define GL_SIGNED_NORMALIZED 0x8F9C -#define GL_PRIMITIVE_RESTART 0x8F9D -#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E -/* Reuse tokens from ARB_copy_buffer */ -/* reuse GL_COPY_READ_BUFFER */ -/* reuse GL_COPY_WRITE_BUFFER */ -/* Reuse tokens from ARB_draw_instanced (none) */ -/* Reuse tokens from ARB_uniform_buffer_object */ -/* reuse GL_UNIFORM_BUFFER */ -/* reuse GL_UNIFORM_BUFFER_BINDING */ -/* reuse GL_UNIFORM_BUFFER_START */ -/* reuse GL_UNIFORM_BUFFER_SIZE */ -/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ -/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ -/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ -/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ -/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ -/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ -/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ -/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ -/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ -/* reuse GL_UNIFORM_TYPE */ -/* reuse GL_UNIFORM_SIZE */ -/* reuse GL_UNIFORM_NAME_LENGTH */ -/* reuse GL_UNIFORM_BLOCK_INDEX */ -/* reuse GL_UNIFORM_OFFSET */ -/* reuse GL_UNIFORM_ARRAY_STRIDE */ -/* reuse GL_UNIFORM_MATRIX_STRIDE */ -/* reuse GL_UNIFORM_IS_ROW_MAJOR */ -/* reuse GL_UNIFORM_BLOCK_BINDING */ -/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ -/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ -/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ -/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ -/* reuse GL_INVALID_INDEX */ -#endif - -#ifndef GL_VERSION_3_2 -#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 -#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 -#define GL_LINES_ADJACENCY 0x000A -#define GL_LINE_STRIP_ADJACENCY 0x000B -#define GL_TRIANGLES_ADJACENCY 0x000C -#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D -#define GL_PROGRAM_POINT_SIZE 0x8642 -#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 -#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 -#define GL_GEOMETRY_SHADER 0x8DD9 -#define GL_GEOMETRY_VERTICES_OUT 0x8916 -#define GL_GEOMETRY_INPUT_TYPE 0x8917 -#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 -#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF -#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 -#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 -#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 -#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 -#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 -#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 -#define GL_CONTEXT_PROFILE_MASK 0x9126 -/* reuse GL_MAX_VARYING_COMPONENTS */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ -/* Reuse tokens from ARB_depth_clamp */ -/* reuse GL_DEPTH_CLAMP */ -/* Reuse tokens from ARB_draw_elements_base_vertex (none) */ -/* Reuse tokens from ARB_fragment_coord_conventions (none) */ -/* Reuse tokens from ARB_provoking_vertex */ -/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ -/* reuse GL_FIRST_VERTEX_CONVENTION */ -/* reuse GL_LAST_VERTEX_CONVENTION */ -/* reuse GL_PROVOKING_VERTEX */ -/* Reuse tokens from ARB_seamless_cube_map */ -/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ -/* Reuse tokens from ARB_sync */ -/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ -/* reuse GL_OBJECT_TYPE */ -/* reuse GL_SYNC_CONDITION */ -/* reuse GL_SYNC_STATUS */ -/* reuse GL_SYNC_FLAGS */ -/* reuse GL_SYNC_FENCE */ -/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ -/* reuse GL_UNSIGNALED */ -/* reuse GL_SIGNALED */ -/* reuse GL_ALREADY_SIGNALED */ -/* reuse GL_TIMEOUT_EXPIRED */ -/* reuse GL_CONDITION_SATISFIED */ -/* reuse GL_WAIT_FAILED */ -/* reuse GL_TIMEOUT_IGNORED */ -/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ -/* reuse GL_TIMEOUT_IGNORED */ -/* Reuse tokens from ARB_texture_multisample */ -/* reuse GL_SAMPLE_POSITION */ -/* reuse GL_SAMPLE_MASK */ -/* reuse GL_SAMPLE_MASK_VALUE */ -/* reuse GL_MAX_SAMPLE_MASK_WORDS */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE */ -/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ -/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_TEXTURE_SAMPLES */ -/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ -/* reuse GL_SAMPLER_2D_MULTISAMPLE */ -/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ -/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ -/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ -/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ -/* reuse GL_MAX_INTEGER_SAMPLES */ -/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ -#endif - -#ifndef GL_VERSION_3_3 -#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE -/* Reuse tokens from ARB_blend_func_extended */ -/* reuse GL_SRC1_COLOR */ -/* reuse GL_ONE_MINUS_SRC1_COLOR */ -/* reuse GL_ONE_MINUS_SRC1_ALPHA */ -/* reuse GL_MAX_DUAL_SOURCE_DRAW_BUFFERS */ -/* Reuse tokens from ARB_explicit_attrib_location (none) */ -/* Reuse tokens from ARB_occlusion_query2 */ -/* reuse GL_ANY_SAMPLES_PASSED */ -/* Reuse tokens from ARB_sampler_objects */ -/* reuse GL_SAMPLER_BINDING */ -/* Reuse tokens from ARB_shader_bit_encoding (none) */ -/* Reuse tokens from ARB_texture_rgb10_a2ui */ -/* reuse GL_RGB10_A2UI */ -/* Reuse tokens from ARB_texture_swizzle */ -/* reuse GL_TEXTURE_SWIZZLE_R */ -/* reuse GL_TEXTURE_SWIZZLE_G */ -/* reuse GL_TEXTURE_SWIZZLE_B */ -/* reuse GL_TEXTURE_SWIZZLE_A */ -/* reuse GL_TEXTURE_SWIZZLE_RGBA */ -/* Reuse tokens from ARB_timer_query */ -/* reuse GL_TIME_ELAPSED */ -/* reuse GL_TIMESTAMP */ -/* Reuse tokens from ARB_vertex_type_2_10_10_10_rev */ -/* reuse GL_INT_2_10_10_10_REV */ -#endif - -#ifndef GL_VERSION_4_0 -#define GL_SAMPLE_SHADING 0x8C36 -#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 -#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E -#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F -#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B -#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C -#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D -#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E -#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F -/* Reuse tokens from ARB_texture_query_lod (none) */ -/* Reuse tokens from ARB_draw_buffers_blend (none) */ -/* Reuse tokens from ARB_draw_indirect */ -/* reuse GL_DRAW_INDIRECT_BUFFER */ -/* reuse GL_DRAW_INDIRECT_BUFFER_BINDING */ -/* Reuse tokens from ARB_gpu_shader5 */ -/* reuse GL_GEOMETRY_SHADER_INVOCATIONS */ -/* reuse GL_MAX_GEOMETRY_SHADER_INVOCATIONS */ -/* reuse GL_MIN_FRAGMENT_INTERPOLATION_OFFSET */ -/* reuse GL_MAX_FRAGMENT_INTERPOLATION_OFFSET */ -/* reuse GL_FRAGMENT_INTERPOLATION_OFFSET_BITS */ -/* reuse GL_MAX_VERTEX_STREAMS */ -/* Reuse tokens from ARB_gpu_shader_fp64 */ -/* reuse GL_DOUBLE_VEC2 */ -/* reuse GL_DOUBLE_VEC3 */ -/* reuse GL_DOUBLE_VEC4 */ -/* reuse GL_DOUBLE_MAT2 */ -/* reuse GL_DOUBLE_MAT3 */ -/* reuse GL_DOUBLE_MAT4 */ -/* reuse GL_DOUBLE_MAT2x3 */ -/* reuse GL_DOUBLE_MAT2x4 */ -/* reuse GL_DOUBLE_MAT3x2 */ -/* reuse GL_DOUBLE_MAT3x4 */ -/* reuse GL_DOUBLE_MAT4x2 */ -/* reuse GL_DOUBLE_MAT4x3 */ -/* Reuse tokens from ARB_shader_subroutine */ -/* reuse GL_ACTIVE_SUBROUTINES */ -/* reuse GL_ACTIVE_SUBROUTINE_UNIFORMS */ -/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS */ -/* reuse GL_ACTIVE_SUBROUTINE_MAX_LENGTH */ -/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH */ -/* reuse GL_MAX_SUBROUTINES */ -/* reuse GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS */ -/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ -/* reuse GL_COMPATIBLE_SUBROUTINES */ -/* Reuse tokens from ARB_tessellation_shader */ -/* reuse GL_PATCHES */ -/* reuse GL_PATCH_VERTICES */ -/* reuse GL_PATCH_DEFAULT_INNER_LEVEL */ -/* reuse GL_PATCH_DEFAULT_OUTER_LEVEL */ -/* reuse GL_TESS_CONTROL_OUTPUT_VERTICES */ -/* reuse GL_TESS_GEN_MODE */ -/* reuse GL_TESS_GEN_SPACING */ -/* reuse GL_TESS_GEN_VERTEX_ORDER */ -/* reuse GL_TESS_GEN_POINT_MODE */ -/* reuse GL_ISOLINES */ -/* reuse GL_FRACTIONAL_ODD */ -/* reuse GL_FRACTIONAL_EVEN */ -/* reuse GL_MAX_PATCH_VERTICES */ -/* reuse GL_MAX_TESS_GEN_LEVEL */ -/* reuse GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS */ -/* reuse GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS */ -/* reuse GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_PATCH_COMPONENTS */ -/* reuse GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS */ -/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS */ -/* reuse GL_MAX_TESS_CONTROL_INPUT_COMPONENTS */ -/* reuse GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS */ -/* reuse GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER */ -/* reuse GL_TESS_EVALUATION_SHADER */ -/* reuse GL_TESS_CONTROL_SHADER */ -/* Reuse tokens from ARB_texture_buffer_object_rgb32 (none) */ -/* Reuse tokens from ARB_transform_feedback2 */ -/* reuse GL_TRANSFORM_FEEDBACK */ -/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED */ -/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE */ -/* reuse GL_TRANSFORM_FEEDBACK_BINDING */ -/* Reuse tokens from ARB_transform_feedback3 */ -/* reuse GL_MAX_TRANSFORM_FEEDBACK_BUFFERS */ -/* reuse GL_MAX_VERTEX_STREAMS */ -#endif - -#ifndef GL_VERSION_4_1 -/* Reuse tokens from ARB_ES2_compatibility */ -/* reuse GL_FIXED */ -/* reuse GL_IMPLEMENTATION_COLOR_READ_TYPE */ -/* reuse GL_IMPLEMENTATION_COLOR_READ_FORMAT */ -/* reuse GL_LOW_FLOAT */ -/* reuse GL_MEDIUM_FLOAT */ -/* reuse GL_HIGH_FLOAT */ -/* reuse GL_LOW_INT */ -/* reuse GL_MEDIUM_INT */ -/* reuse GL_HIGH_INT */ -/* reuse GL_SHADER_COMPILER */ -/* reuse GL_NUM_SHADER_BINARY_FORMATS */ -/* reuse GL_MAX_VERTEX_UNIFORM_VECTORS */ -/* reuse GL_MAX_VARYING_VECTORS */ -/* reuse GL_MAX_FRAGMENT_UNIFORM_VECTORS */ -/* reuse GL_RGB565 */ -/* Reuse tokens from ARB_get_program_binary */ -/* reuse GL_PROGRAM_BINARY_RETRIEVABLE_HINT */ -/* reuse GL_PROGRAM_BINARY_LENGTH */ -/* reuse GL_NUM_PROGRAM_BINARY_FORMATS */ -/* reuse GL_PROGRAM_BINARY_FORMATS */ -/* Reuse tokens from ARB_separate_shader_objects */ -/* reuse GL_VERTEX_SHADER_BIT */ -/* reuse GL_FRAGMENT_SHADER_BIT */ -/* reuse GL_GEOMETRY_SHADER_BIT */ -/* reuse GL_TESS_CONTROL_SHADER_BIT */ -/* reuse GL_TESS_EVALUATION_SHADER_BIT */ -/* reuse GL_ALL_SHADER_BITS */ -/* reuse GL_PROGRAM_SEPARABLE */ -/* reuse GL_ACTIVE_PROGRAM */ -/* reuse GL_PROGRAM_PIPELINE_BINDING */ -/* Reuse tokens from ARB_shader_precision (none) */ -/* Reuse tokens from ARB_vertex_attrib_64bit - all are in GL 3.0 and 4.0 already */ -/* Reuse tokens from ARB_viewport_array - some are in GL 1.1 and ARB_provoking_vertex already */ -/* reuse GL_MAX_VIEWPORTS */ -/* reuse GL_VIEWPORT_SUBPIXEL_BITS */ -/* reuse GL_VIEWPORT_BOUNDS_RANGE */ -/* reuse GL_LAYER_PROVOKING_VERTEX */ -/* reuse GL_VIEWPORT_INDEX_PROVOKING_VERTEX */ -/* reuse GL_UNDEFINED_VERTEX */ -#endif - -#ifndef GL_VERSION_4_2 -/* Reuse tokens from ARB_base_instance (none) */ -/* Reuse tokens from ARB_shading_language_420pack (none) */ -/* Reuse tokens from ARB_transform_feedback_instanced (none) */ -/* Reuse tokens from ARB_compressed_texture_pixel_storage */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_WIDTH */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_HEIGHT */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_DEPTH */ -/* reuse GL_UNPACK_COMPRESSED_BLOCK_SIZE */ -/* reuse GL_PACK_COMPRESSED_BLOCK_WIDTH */ -/* reuse GL_PACK_COMPRESSED_BLOCK_HEIGHT */ -/* reuse GL_PACK_COMPRESSED_BLOCK_DEPTH */ -/* reuse GL_PACK_COMPRESSED_BLOCK_SIZE */ -/* Reuse tokens from ARB_conservative_depth (none) */ -/* Reuse tokens from ARB_internalformat_query */ -/* reuse GL_NUM_SAMPLE_COUNTS */ -/* Reuse tokens from ARB_map_buffer_alignment */ -/* reuse GL_MIN_MAP_BUFFER_ALIGNMENT */ -/* Reuse tokens from ARB_shader_atomic_counters */ -/* reuse GL_ATOMIC_COUNTER_BUFFER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_BINDING */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_START */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_SIZE */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER */ -/* reuse GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_VERTEX_ATOMIC_COUNTERS */ -/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS */ -/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS */ -/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTERS */ -/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTERS */ -/* reuse GL_MAX_COMBINED_ATOMIC_COUNTERS */ -/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE */ -/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS */ -/* reuse GL_ACTIVE_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX */ -/* reuse GL_UNSIGNED_INT_ATOMIC_COUNTER */ -/* Reuse tokens from ARB_shader_image_load_store */ -/* reuse GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT */ -/* reuse GL_ELEMENT_ARRAY_BARRIER_BIT */ -/* reuse GL_UNIFORM_BARRIER_BIT */ -/* reuse GL_TEXTURE_FETCH_BARRIER_BIT */ -/* reuse GL_SHADER_IMAGE_ACCESS_BARRIER_BIT */ -/* reuse GL_COMMAND_BARRIER_BIT */ -/* reuse GL_PIXEL_BUFFER_BARRIER_BIT */ -/* reuse GL_TEXTURE_UPDATE_BARRIER_BIT */ -/* reuse GL_BUFFER_UPDATE_BARRIER_BIT */ -/* reuse GL_FRAMEBUFFER_BARRIER_BIT */ -/* reuse GL_TRANSFORM_FEEDBACK_BARRIER_BIT */ -/* reuse GL_ATOMIC_COUNTER_BARRIER_BIT */ -/* reuse GL_ALL_BARRIER_BITS */ -/* reuse GL_MAX_IMAGE_UNITS */ -/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ -/* reuse GL_IMAGE_BINDING_NAME */ -/* reuse GL_IMAGE_BINDING_LEVEL */ -/* reuse GL_IMAGE_BINDING_LAYERED */ -/* reuse GL_IMAGE_BINDING_LAYER */ -/* reuse GL_IMAGE_BINDING_ACCESS */ -/* reuse GL_IMAGE_1D */ -/* reuse GL_IMAGE_2D */ -/* reuse GL_IMAGE_3D */ -/* reuse GL_IMAGE_2D_RECT */ -/* reuse GL_IMAGE_CUBE */ -/* reuse GL_IMAGE_BUFFER */ -/* reuse GL_IMAGE_1D_ARRAY */ -/* reuse GL_IMAGE_2D_ARRAY */ -/* reuse GL_IMAGE_CUBE_MAP_ARRAY */ -/* reuse GL_IMAGE_2D_MULTISAMPLE */ -/* reuse GL_IMAGE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_INT_IMAGE_1D */ -/* reuse GL_INT_IMAGE_2D */ -/* reuse GL_INT_IMAGE_3D */ -/* reuse GL_INT_IMAGE_2D_RECT */ -/* reuse GL_INT_IMAGE_CUBE */ -/* reuse GL_INT_IMAGE_BUFFER */ -/* reuse GL_INT_IMAGE_1D_ARRAY */ -/* reuse GL_INT_IMAGE_2D_ARRAY */ -/* reuse GL_INT_IMAGE_CUBE_MAP_ARRAY */ -/* reuse GL_INT_IMAGE_2D_MULTISAMPLE */ -/* reuse GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_1D */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D */ -/* reuse GL_UNSIGNED_INT_IMAGE_3D */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_RECT */ -/* reuse GL_UNSIGNED_INT_IMAGE_CUBE */ -/* reuse GL_UNSIGNED_INT_IMAGE_BUFFER */ -/* reuse GL_UNSIGNED_INT_IMAGE_1D_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE */ -/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_MAX_IMAGE_SAMPLES */ -/* reuse GL_IMAGE_BINDING_FORMAT */ -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE */ -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS */ -/* reuse GL_MAX_VERTEX_IMAGE_UNIFORMS */ -/* reuse GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS */ -/* reuse GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS */ -/* reuse GL_MAX_GEOMETRY_IMAGE_UNIFORMS */ -/* reuse GL_MAX_FRAGMENT_IMAGE_UNIFORMS */ -/* reuse GL_MAX_COMBINED_IMAGE_UNIFORMS */ -/* Reuse tokens from ARB_shading_language_packing (none) */ -/* Reuse tokens from ARB_texture_storage */ -/* reuse GL_TEXTURE_IMMUTABLE_FORMAT */ -#endif - -#ifndef GL_VERSION_4_3 -#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 -#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E -/* Reuse tokens from ARB_arrays_of_arrays (none, GLSL only) */ -/* Reuse tokens from ARB_fragment_layer_viewport (none, GLSL only) */ -/* Reuse tokens from ARB_shader_image_size (none, GLSL only) */ -/* Reuse tokens from ARB_ES3_compatibility */ -/* reuse GL_COMPRESSED_RGB8_ETC2 */ -/* reuse GL_COMPRESSED_SRGB8_ETC2 */ -/* reuse GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ -/* reuse GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ -/* reuse GL_COMPRESSED_RGBA8_ETC2_EAC */ -/* reuse GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ -/* reuse GL_COMPRESSED_R11_EAC */ -/* reuse GL_COMPRESSED_SIGNED_R11_EAC */ -/* reuse GL_COMPRESSED_RG11_EAC */ -/* reuse GL_COMPRESSED_SIGNED_RG11_EAC */ -/* reuse GL_PRIMITIVE_RESTART_FIXED_INDEX */ -/* reuse GL_ANY_SAMPLES_PASSED_CONSERVATIVE */ -/* reuse GL_MAX_ELEMENT_INDEX */ -/* Reuse tokens from ARB_clear_buffer_object (none) */ -/* Reuse tokens from ARB_compute_shader */ -/* reuse GL_COMPUTE_SHADER */ -/* reuse GL_MAX_COMPUTE_UNIFORM_BLOCKS */ -/* reuse GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS */ -/* reuse GL_MAX_COMPUTE_IMAGE_UNIFORMS */ -/* reuse GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */ -/* reuse GL_MAX_COMPUTE_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS */ -/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTERS */ -/* reuse GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS */ -/* reuse GL_MAX_COMPUTE_LOCAL_INVOCATIONS */ -/* reuse GL_MAX_COMPUTE_WORK_GROUP_COUNT */ -/* reuse GL_MAX_COMPUTE_WORK_GROUP_SIZE */ -/* reuse GL_COMPUTE_LOCAL_WORK_SIZE */ -/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER */ -/* reuse GL_DISPATCH_INDIRECT_BUFFER */ -/* reuse GL_DISPATCH_INDIRECT_BUFFER_BINDING */ -/* Reuse tokens from ARB_copy_image (none) */ -/* Reuse tokens from KHR_debug */ -/* reuse GL_DEBUG_OUTPUT_SYNCHRONOUS */ -/* reuse GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH */ -/* reuse GL_DEBUG_CALLBACK_FUNCTION */ -/* reuse GL_DEBUG_CALLBACK_USER_PARAM */ -/* reuse GL_DEBUG_SOURCE_API */ -/* reuse GL_DEBUG_SOURCE_WINDOW_SYSTEM */ -/* reuse GL_DEBUG_SOURCE_SHADER_COMPILER */ -/* reuse GL_DEBUG_SOURCE_THIRD_PARTY */ -/* reuse GL_DEBUG_SOURCE_APPLICATION */ -/* reuse GL_DEBUG_SOURCE_OTHER */ -/* reuse GL_DEBUG_TYPE_ERROR */ -/* reuse GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR */ -/* reuse GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR */ -/* reuse GL_DEBUG_TYPE_PORTABILITY */ -/* reuse GL_DEBUG_TYPE_PERFORMANCE */ -/* reuse GL_DEBUG_TYPE_OTHER */ -/* reuse GL_MAX_DEBUG_MESSAGE_LENGTH */ -/* reuse GL_MAX_DEBUG_LOGGED_MESSAGES */ -/* reuse GL_DEBUG_LOGGED_MESSAGES */ -/* reuse GL_DEBUG_SEVERITY_HIGH */ -/* reuse GL_DEBUG_SEVERITY_MEDIUM */ -/* reuse GL_DEBUG_SEVERITY_LOW */ -/* reuse GL_DEBUG_TYPE_MARKER */ -/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ -/* reuse GL_DEBUG_TYPE_POP_GROUP */ -/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ -/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_BUFFER */ -/* reuse GL_SHADER */ -/* reuse GL_PROGRAM */ -/* reuse GL_QUERY */ -/* reuse GL_PROGRAM_PIPELINE */ -/* reuse GL_SAMPLER */ -/* reuse GL_DISPLAY_LIST */ -/* reuse GL_MAX_LABEL_LENGTH */ -/* reuse GL_DEBUG_OUTPUT */ -/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ -/* reuse GL_STACK_UNDERFLOW */ -/* reuse GL_STACK_OVERFLOW */ -/* Reuse tokens from ARB_explicit_uniform_location */ -/* reuse GL_MAX_UNIFORM_LOCATIONS */ -/* Reuse tokens from ARB_framebuffer_no_attachments */ -/* reuse GL_FRAMEBUFFER_DEFAULT_WIDTH */ -/* reuse GL_FRAMEBUFFER_DEFAULT_HEIGHT */ -/* reuse GL_FRAMEBUFFER_DEFAULT_LAYERS */ -/* reuse GL_FRAMEBUFFER_DEFAULT_SAMPLES */ -/* reuse GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS */ -/* reuse GL_MAX_FRAMEBUFFER_WIDTH */ -/* reuse GL_MAX_FRAMEBUFFER_HEIGHT */ -/* reuse GL_MAX_FRAMEBUFFER_LAYERS */ -/* reuse GL_MAX_FRAMEBUFFER_SAMPLES */ -/* Reuse tokens from ARB_internalformat_query2 */ -/* reuse GL_INTERNALFORMAT_SUPPORTED */ -/* reuse GL_INTERNALFORMAT_PREFERRED */ -/* reuse GL_INTERNALFORMAT_RED_SIZE */ -/* reuse GL_INTERNALFORMAT_GREEN_SIZE */ -/* reuse GL_INTERNALFORMAT_BLUE_SIZE */ -/* reuse GL_INTERNALFORMAT_ALPHA_SIZE */ -/* reuse GL_INTERNALFORMAT_DEPTH_SIZE */ -/* reuse GL_INTERNALFORMAT_STENCIL_SIZE */ -/* reuse GL_INTERNALFORMAT_SHARED_SIZE */ -/* reuse GL_INTERNALFORMAT_RED_TYPE */ -/* reuse GL_INTERNALFORMAT_GREEN_TYPE */ -/* reuse GL_INTERNALFORMAT_BLUE_TYPE */ -/* reuse GL_INTERNALFORMAT_ALPHA_TYPE */ -/* reuse GL_INTERNALFORMAT_DEPTH_TYPE */ -/* reuse GL_INTERNALFORMAT_STENCIL_TYPE */ -/* reuse GL_MAX_WIDTH */ -/* reuse GL_MAX_HEIGHT */ -/* reuse GL_MAX_DEPTH */ -/* reuse GL_MAX_LAYERS */ -/* reuse GL_MAX_COMBINED_DIMENSIONS */ -/* reuse GL_COLOR_COMPONENTS */ -/* reuse GL_DEPTH_COMPONENTS */ -/* reuse GL_STENCIL_COMPONENTS */ -/* reuse GL_COLOR_RENDERABLE */ -/* reuse GL_DEPTH_RENDERABLE */ -/* reuse GL_STENCIL_RENDERABLE */ -/* reuse GL_FRAMEBUFFER_RENDERABLE */ -/* reuse GL_FRAMEBUFFER_RENDERABLE_LAYERED */ -/* reuse GL_FRAMEBUFFER_BLEND */ -/* reuse GL_READ_PIXELS */ -/* reuse GL_READ_PIXELS_FORMAT */ -/* reuse GL_READ_PIXELS_TYPE */ -/* reuse GL_TEXTURE_IMAGE_FORMAT */ -/* reuse GL_TEXTURE_IMAGE_TYPE */ -/* reuse GL_GET_TEXTURE_IMAGE_FORMAT */ -/* reuse GL_GET_TEXTURE_IMAGE_TYPE */ -/* reuse GL_MIPMAP */ -/* reuse GL_MANUAL_GENERATE_MIPMAP */ -/* reuse GL_AUTO_GENERATE_MIPMAP */ -/* reuse GL_COLOR_ENCODING */ -/* reuse GL_SRGB_READ */ -/* reuse GL_SRGB_WRITE */ -/* reuse GL_FILTER */ -/* reuse GL_VERTEX_TEXTURE */ -/* reuse GL_TESS_CONTROL_TEXTURE */ -/* reuse GL_TESS_EVALUATION_TEXTURE */ -/* reuse GL_GEOMETRY_TEXTURE */ -/* reuse GL_FRAGMENT_TEXTURE */ -/* reuse GL_COMPUTE_TEXTURE */ -/* reuse GL_TEXTURE_SHADOW */ -/* reuse GL_TEXTURE_GATHER */ -/* reuse GL_TEXTURE_GATHER_SHADOW */ -/* reuse GL_SHADER_IMAGE_LOAD */ -/* reuse GL_SHADER_IMAGE_STORE */ -/* reuse GL_SHADER_IMAGE_ATOMIC */ -/* reuse GL_IMAGE_TEXEL_SIZE */ -/* reuse GL_IMAGE_COMPATIBILITY_CLASS */ -/* reuse GL_IMAGE_PIXEL_FORMAT */ -/* reuse GL_IMAGE_PIXEL_TYPE */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE */ -/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE */ -/* reuse GL_TEXTURE_COMPRESSED_BLOCK_WIDTH */ -/* reuse GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT */ -/* reuse GL_TEXTURE_COMPRESSED_BLOCK_SIZE */ -/* reuse GL_CLEAR_BUFFER */ -/* reuse GL_TEXTURE_VIEW */ -/* reuse GL_VIEW_COMPATIBILITY_CLASS */ -/* reuse GL_FULL_SUPPORT */ -/* reuse GL_CAVEAT_SUPPORT */ -/* reuse GL_IMAGE_CLASS_4_X_32 */ -/* reuse GL_IMAGE_CLASS_2_X_32 */ -/* reuse GL_IMAGE_CLASS_1_X_32 */ -/* reuse GL_IMAGE_CLASS_4_X_16 */ -/* reuse GL_IMAGE_CLASS_2_X_16 */ -/* reuse GL_IMAGE_CLASS_1_X_16 */ -/* reuse GL_IMAGE_CLASS_4_X_8 */ -/* reuse GL_IMAGE_CLASS_2_X_8 */ -/* reuse GL_IMAGE_CLASS_1_X_8 */ -/* reuse GL_IMAGE_CLASS_11_11_10 */ -/* reuse GL_IMAGE_CLASS_10_10_10_2 */ -/* reuse GL_VIEW_CLASS_128_BITS */ -/* reuse GL_VIEW_CLASS_96_BITS */ -/* reuse GL_VIEW_CLASS_64_BITS */ -/* reuse GL_VIEW_CLASS_48_BITS */ -/* reuse GL_VIEW_CLASS_32_BITS */ -/* reuse GL_VIEW_CLASS_24_BITS */ -/* reuse GL_VIEW_CLASS_16_BITS */ -/* reuse GL_VIEW_CLASS_8_BITS */ -/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGB */ -/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGBA */ -/* reuse GL_VIEW_CLASS_S3TC_DXT3_RGBA */ -/* reuse GL_VIEW_CLASS_S3TC_DXT5_RGBA */ -/* reuse GL_VIEW_CLASS_RGTC1_RED */ -/* reuse GL_VIEW_CLASS_RGTC2_RG */ -/* reuse GL_VIEW_CLASS_BPTC_UNORM */ -/* reuse GL_VIEW_CLASS_BPTC_FLOAT */ -/* Reuse tokens from ARB_invalidate_subdata (none) */ -/* Reuse tokens from ARB_multi_draw_indirect (none) */ -/* Reuse tokens from ARB_program_interface_query */ -/* reuse GL_UNIFORM */ -/* reuse GL_UNIFORM_BLOCK */ -/* reuse GL_PROGRAM_INPUT */ -/* reuse GL_PROGRAM_OUTPUT */ -/* reuse GL_BUFFER_VARIABLE */ -/* reuse GL_SHADER_STORAGE_BLOCK */ -/* reuse GL_VERTEX_SUBROUTINE */ -/* reuse GL_TESS_CONTROL_SUBROUTINE */ -/* reuse GL_TESS_EVALUATION_SUBROUTINE */ -/* reuse GL_GEOMETRY_SUBROUTINE */ -/* reuse GL_FRAGMENT_SUBROUTINE */ -/* reuse GL_COMPUTE_SUBROUTINE */ -/* reuse GL_VERTEX_SUBROUTINE_UNIFORM */ -/* reuse GL_TESS_CONTROL_SUBROUTINE_UNIFORM */ -/* reuse GL_TESS_EVALUATION_SUBROUTINE_UNIFORM */ -/* reuse GL_GEOMETRY_SUBROUTINE_UNIFORM */ -/* reuse GL_FRAGMENT_SUBROUTINE_UNIFORM */ -/* reuse GL_COMPUTE_SUBROUTINE_UNIFORM */ -/* reuse GL_TRANSFORM_FEEDBACK_VARYING */ -/* reuse GL_ACTIVE_RESOURCES */ -/* reuse GL_MAX_NAME_LENGTH */ -/* reuse GL_MAX_NUM_ACTIVE_VARIABLES */ -/* reuse GL_MAX_NUM_COMPATIBLE_SUBROUTINES */ -/* reuse GL_NAME_LENGTH */ -/* reuse GL_TYPE */ -/* reuse GL_ARRAY_SIZE */ -/* reuse GL_OFFSET */ -/* reuse GL_BLOCK_INDEX */ -/* reuse GL_ARRAY_STRIDE */ -/* reuse GL_MATRIX_STRIDE */ -/* reuse GL_IS_ROW_MAJOR */ -/* reuse GL_ATOMIC_COUNTER_BUFFER_INDEX */ -/* reuse GL_BUFFER_BINDING */ -/* reuse GL_BUFFER_DATA_SIZE */ -/* reuse GL_NUM_ACTIVE_VARIABLES */ -/* reuse GL_ACTIVE_VARIABLES */ -/* reuse GL_REFERENCED_BY_VERTEX_SHADER */ -/* reuse GL_REFERENCED_BY_TESS_CONTROL_SHADER */ -/* reuse GL_REFERENCED_BY_TESS_EVALUATION_SHADER */ -/* reuse GL_REFERENCED_BY_GEOMETRY_SHADER */ -/* reuse GL_REFERENCED_BY_FRAGMENT_SHADER */ -/* reuse GL_REFERENCED_BY_COMPUTE_SHADER */ -/* reuse GL_TOP_LEVEL_ARRAY_SIZE */ -/* reuse GL_TOP_LEVEL_ARRAY_STRIDE */ -/* reuse GL_LOCATION */ -/* reuse GL_LOCATION_INDEX */ -/* reuse GL_IS_PER_PATCH */ -/* Reuse tokens from ARB_robust_buffer_access_behavior (none) */ -/* Reuse tokens from ARB_shader_storage_buffer_object */ -/* reuse GL_SHADER_STORAGE_BUFFER */ -/* reuse GL_SHADER_STORAGE_BUFFER_BINDING */ -/* reuse GL_SHADER_STORAGE_BUFFER_START */ -/* reuse GL_SHADER_STORAGE_BUFFER_SIZE */ -/* reuse GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS */ -/* reuse GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS */ -/* reuse GL_MAX_SHADER_STORAGE_BLOCK_SIZE */ -/* reuse GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT */ -/* reuse GL_SHADER_STORAGE_BARRIER_BIT */ -/* reuse GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES */ -/* Reuse tokens from ARB_stencil_texturing */ -/* reuse GL_DEPTH_STENCIL_TEXTURE_MODE */ -/* Reuse tokens from ARB_texture_buffer_range */ -/* reuse GL_TEXTURE_BUFFER_OFFSET */ -/* reuse GL_TEXTURE_BUFFER_SIZE */ -/* reuse GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT */ -/* Reuse tokens from ARB_texture_query_levels (none) */ -/* Reuse tokens from ARB_texture_storage_multisample (none) */ -/* Reuse tokens from ARB_texture_view */ -/* reuse GL_TEXTURE_VIEW_MIN_LEVEL */ -/* reuse GL_TEXTURE_VIEW_NUM_LEVELS */ -/* reuse GL_TEXTURE_VIEW_MIN_LAYER */ -/* reuse GL_TEXTURE_VIEW_NUM_LAYERS */ -/* reuse GL_TEXTURE_IMMUTABLE_LEVELS */ -/* Reuse tokens from ARB_vertex_attrib_binding */ -/* reuse GL_VERTEX_ATTRIB_BINDING */ -/* reuse GL_VERTEX_ATTRIB_RELATIVE_OFFSET */ -/* reuse GL_VERTEX_BINDING_DIVISOR */ -/* reuse GL_VERTEX_BINDING_OFFSET */ -/* reuse GL_VERTEX_BINDING_STRIDE */ -/* reuse GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET */ -/* reuse GL_MAX_VERTEX_ATTRIB_BINDINGS */ -#endif - -#ifndef GL_ARB_multitexture -#define GL_TEXTURE0_ARB 0x84C0 -#define GL_TEXTURE1_ARB 0x84C1 -#define GL_TEXTURE2_ARB 0x84C2 -#define GL_TEXTURE3_ARB 0x84C3 -#define GL_TEXTURE4_ARB 0x84C4 -#define GL_TEXTURE5_ARB 0x84C5 -#define GL_TEXTURE6_ARB 0x84C6 -#define GL_TEXTURE7_ARB 0x84C7 -#define GL_TEXTURE8_ARB 0x84C8 -#define GL_TEXTURE9_ARB 0x84C9 -#define GL_TEXTURE10_ARB 0x84CA -#define GL_TEXTURE11_ARB 0x84CB -#define GL_TEXTURE12_ARB 0x84CC -#define GL_TEXTURE13_ARB 0x84CD -#define GL_TEXTURE14_ARB 0x84CE -#define GL_TEXTURE15_ARB 0x84CF -#define GL_TEXTURE16_ARB 0x84D0 -#define GL_TEXTURE17_ARB 0x84D1 -#define GL_TEXTURE18_ARB 0x84D2 -#define GL_TEXTURE19_ARB 0x84D3 -#define GL_TEXTURE20_ARB 0x84D4 -#define GL_TEXTURE21_ARB 0x84D5 -#define GL_TEXTURE22_ARB 0x84D6 -#define GL_TEXTURE23_ARB 0x84D7 -#define GL_TEXTURE24_ARB 0x84D8 -#define GL_TEXTURE25_ARB 0x84D9 -#define GL_TEXTURE26_ARB 0x84DA -#define GL_TEXTURE27_ARB 0x84DB -#define GL_TEXTURE28_ARB 0x84DC -#define GL_TEXTURE29_ARB 0x84DD -#define GL_TEXTURE30_ARB 0x84DE -#define GL_TEXTURE31_ARB 0x84DF -#define GL_ACTIVE_TEXTURE_ARB 0x84E0 -#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 -#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 -#endif - -#ifndef GL_ARB_transpose_matrix -#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 -#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 -#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 -#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 -#endif - -#ifndef GL_ARB_multisample -#define GL_MULTISAMPLE_ARB 0x809D -#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F -#define GL_SAMPLE_COVERAGE_ARB 0x80A0 -#define GL_SAMPLE_BUFFERS_ARB 0x80A8 -#define GL_SAMPLES_ARB 0x80A9 -#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA -#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB -#define GL_MULTISAMPLE_BIT_ARB 0x20000000 -#endif - -#ifndef GL_ARB_texture_env_add -#endif - -#ifndef GL_ARB_texture_cube_map -#define GL_NORMAL_MAP_ARB 0x8511 -#define GL_REFLECTION_MAP_ARB 0x8512 -#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C -#endif - -#ifndef GL_ARB_texture_compression -#define GL_COMPRESSED_ALPHA_ARB 0x84E9 -#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA -#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB -#define GL_COMPRESSED_INTENSITY_ARB 0x84EC -#define GL_COMPRESSED_RGB_ARB 0x84ED -#define GL_COMPRESSED_RGBA_ARB 0x84EE -#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF -#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 -#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 -#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 -#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 -#endif - -#ifndef GL_ARB_texture_border_clamp -#define GL_CLAMP_TO_BORDER_ARB 0x812D -#endif - -#ifndef GL_ARB_point_parameters -#define GL_POINT_SIZE_MIN_ARB 0x8126 -#define GL_POINT_SIZE_MAX_ARB 0x8127 -#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 -#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 -#endif - -#ifndef GL_ARB_vertex_blend -#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 -#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 -#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 -#define GL_VERTEX_BLEND_ARB 0x86A7 -#define GL_CURRENT_WEIGHT_ARB 0x86A8 -#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 -#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA -#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB -#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC -#define GL_WEIGHT_ARRAY_ARB 0x86AD -#define GL_MODELVIEW0_ARB 0x1700 -#define GL_MODELVIEW1_ARB 0x850A -#define GL_MODELVIEW2_ARB 0x8722 -#define GL_MODELVIEW3_ARB 0x8723 -#define GL_MODELVIEW4_ARB 0x8724 -#define GL_MODELVIEW5_ARB 0x8725 -#define GL_MODELVIEW6_ARB 0x8726 -#define GL_MODELVIEW7_ARB 0x8727 -#define GL_MODELVIEW8_ARB 0x8728 -#define GL_MODELVIEW9_ARB 0x8729 -#define GL_MODELVIEW10_ARB 0x872A -#define GL_MODELVIEW11_ARB 0x872B -#define GL_MODELVIEW12_ARB 0x872C -#define GL_MODELVIEW13_ARB 0x872D -#define GL_MODELVIEW14_ARB 0x872E -#define GL_MODELVIEW15_ARB 0x872F -#define GL_MODELVIEW16_ARB 0x8730 -#define GL_MODELVIEW17_ARB 0x8731 -#define GL_MODELVIEW18_ARB 0x8732 -#define GL_MODELVIEW19_ARB 0x8733 -#define GL_MODELVIEW20_ARB 0x8734 -#define GL_MODELVIEW21_ARB 0x8735 -#define GL_MODELVIEW22_ARB 0x8736 -#define GL_MODELVIEW23_ARB 0x8737 -#define GL_MODELVIEW24_ARB 0x8738 -#define GL_MODELVIEW25_ARB 0x8739 -#define GL_MODELVIEW26_ARB 0x873A -#define GL_MODELVIEW27_ARB 0x873B -#define GL_MODELVIEW28_ARB 0x873C -#define GL_MODELVIEW29_ARB 0x873D -#define GL_MODELVIEW30_ARB 0x873E -#define GL_MODELVIEW31_ARB 0x873F -#endif - -#ifndef GL_ARB_matrix_palette -#define GL_MATRIX_PALETTE_ARB 0x8840 -#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 -#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 -#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 -#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 -#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 -#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 -#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 -#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 -#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 -#endif - -#ifndef GL_ARB_texture_env_combine -#define GL_COMBINE_ARB 0x8570 -#define GL_COMBINE_RGB_ARB 0x8571 -#define GL_COMBINE_ALPHA_ARB 0x8572 -#define GL_SOURCE0_RGB_ARB 0x8580 -#define GL_SOURCE1_RGB_ARB 0x8581 -#define GL_SOURCE2_RGB_ARB 0x8582 -#define GL_SOURCE0_ALPHA_ARB 0x8588 -#define GL_SOURCE1_ALPHA_ARB 0x8589 -#define GL_SOURCE2_ALPHA_ARB 0x858A -#define GL_OPERAND0_RGB_ARB 0x8590 -#define GL_OPERAND1_RGB_ARB 0x8591 -#define GL_OPERAND2_RGB_ARB 0x8592 -#define GL_OPERAND0_ALPHA_ARB 0x8598 -#define GL_OPERAND1_ALPHA_ARB 0x8599 -#define GL_OPERAND2_ALPHA_ARB 0x859A -#define GL_RGB_SCALE_ARB 0x8573 -#define GL_ADD_SIGNED_ARB 0x8574 -#define GL_INTERPOLATE_ARB 0x8575 -#define GL_SUBTRACT_ARB 0x84E7 -#define GL_CONSTANT_ARB 0x8576 -#define GL_PRIMARY_COLOR_ARB 0x8577 -#define GL_PREVIOUS_ARB 0x8578 -#endif - -#ifndef GL_ARB_texture_env_crossbar -#endif - -#ifndef GL_ARB_texture_env_dot3 -#define GL_DOT3_RGB_ARB 0x86AE -#define GL_DOT3_RGBA_ARB 0x86AF -#endif - -#ifndef GL_ARB_texture_mirrored_repeat -#define GL_MIRRORED_REPEAT_ARB 0x8370 -#endif - -#ifndef GL_ARB_depth_texture -#define GL_DEPTH_COMPONENT16_ARB 0x81A5 -#define GL_DEPTH_COMPONENT24_ARB 0x81A6 -#define GL_DEPTH_COMPONENT32_ARB 0x81A7 -#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A -#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B -#endif - -#ifndef GL_ARB_shadow -#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C -#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D -#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E -#endif - -#ifndef GL_ARB_shadow_ambient -#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF -#endif - -#ifndef GL_ARB_window_pos -#endif - -#ifndef GL_ARB_vertex_program -#define GL_COLOR_SUM_ARB 0x8458 -#define GL_VERTEX_PROGRAM_ARB 0x8620 -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 -#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 -#define GL_PROGRAM_LENGTH_ARB 0x8627 -#define GL_PROGRAM_STRING_ARB 0x8628 -#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E -#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F -#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 -#define GL_CURRENT_MATRIX_ARB 0x8641 -#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 -#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 -#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 -#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B -#define GL_PROGRAM_BINDING_ARB 0x8677 -#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A -#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 -#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 -#define GL_PROGRAM_FORMAT_ARB 0x8876 -#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 -#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 -#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 -#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 -#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 -#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 -#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 -#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 -#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 -#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 -#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA -#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB -#define GL_PROGRAM_ATTRIBS_ARB 0x88AC -#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD -#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE -#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF -#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 -#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 -#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 -#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 -#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 -#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 -#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 -#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 -#define GL_MATRIX0_ARB 0x88C0 -#define GL_MATRIX1_ARB 0x88C1 -#define GL_MATRIX2_ARB 0x88C2 -#define GL_MATRIX3_ARB 0x88C3 -#define GL_MATRIX4_ARB 0x88C4 -#define GL_MATRIX5_ARB 0x88C5 -#define GL_MATRIX6_ARB 0x88C6 -#define GL_MATRIX7_ARB 0x88C7 -#define GL_MATRIX8_ARB 0x88C8 -#define GL_MATRIX9_ARB 0x88C9 -#define GL_MATRIX10_ARB 0x88CA -#define GL_MATRIX11_ARB 0x88CB -#define GL_MATRIX12_ARB 0x88CC -#define GL_MATRIX13_ARB 0x88CD -#define GL_MATRIX14_ARB 0x88CE -#define GL_MATRIX15_ARB 0x88CF -#define GL_MATRIX16_ARB 0x88D0 -#define GL_MATRIX17_ARB 0x88D1 -#define GL_MATRIX18_ARB 0x88D2 -#define GL_MATRIX19_ARB 0x88D3 -#define GL_MATRIX20_ARB 0x88D4 -#define GL_MATRIX21_ARB 0x88D5 -#define GL_MATRIX22_ARB 0x88D6 -#define GL_MATRIX23_ARB 0x88D7 -#define GL_MATRIX24_ARB 0x88D8 -#define GL_MATRIX25_ARB 0x88D9 -#define GL_MATRIX26_ARB 0x88DA -#define GL_MATRIX27_ARB 0x88DB -#define GL_MATRIX28_ARB 0x88DC -#define GL_MATRIX29_ARB 0x88DD -#define GL_MATRIX30_ARB 0x88DE -#define GL_MATRIX31_ARB 0x88DF -#endif - -#ifndef GL_ARB_fragment_program -#define GL_FRAGMENT_PROGRAM_ARB 0x8804 -#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 -#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 -#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 -#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 -#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 -#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A -#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B -#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C -#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D -#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E -#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F -#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 -#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 -#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 -#endif - -#ifndef GL_ARB_vertex_buffer_object -#define GL_BUFFER_SIZE_ARB 0x8764 -#define GL_BUFFER_USAGE_ARB 0x8765 -#define GL_ARRAY_BUFFER_ARB 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 -#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 -#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 -#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 -#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 -#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 -#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 -#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A -#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B -#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C -#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D -#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E -#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F -#define GL_READ_ONLY_ARB 0x88B8 -#define GL_WRITE_ONLY_ARB 0x88B9 -#define GL_READ_WRITE_ARB 0x88BA -#define GL_BUFFER_ACCESS_ARB 0x88BB -#define GL_BUFFER_MAPPED_ARB 0x88BC -#define GL_BUFFER_MAP_POINTER_ARB 0x88BD -#define GL_STREAM_DRAW_ARB 0x88E0 -#define GL_STREAM_READ_ARB 0x88E1 -#define GL_STREAM_COPY_ARB 0x88E2 -#define GL_STATIC_DRAW_ARB 0x88E4 -#define GL_STATIC_READ_ARB 0x88E5 -#define GL_STATIC_COPY_ARB 0x88E6 -#define GL_DYNAMIC_DRAW_ARB 0x88E8 -#define GL_DYNAMIC_READ_ARB 0x88E9 -#define GL_DYNAMIC_COPY_ARB 0x88EA -#endif - -#ifndef GL_ARB_occlusion_query -#define GL_QUERY_COUNTER_BITS_ARB 0x8864 -#define GL_CURRENT_QUERY_ARB 0x8865 -#define GL_QUERY_RESULT_ARB 0x8866 -#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 -#define GL_SAMPLES_PASSED_ARB 0x8914 -#endif - -#ifndef GL_ARB_shader_objects -#define GL_PROGRAM_OBJECT_ARB 0x8B40 -#define GL_SHADER_OBJECT_ARB 0x8B48 -#define GL_OBJECT_TYPE_ARB 0x8B4E -#define GL_OBJECT_SUBTYPE_ARB 0x8B4F -#define GL_FLOAT_VEC2_ARB 0x8B50 -#define GL_FLOAT_VEC3_ARB 0x8B51 -#define GL_FLOAT_VEC4_ARB 0x8B52 -#define GL_INT_VEC2_ARB 0x8B53 -#define GL_INT_VEC3_ARB 0x8B54 -#define GL_INT_VEC4_ARB 0x8B55 -#define GL_BOOL_ARB 0x8B56 -#define GL_BOOL_VEC2_ARB 0x8B57 -#define GL_BOOL_VEC3_ARB 0x8B58 -#define GL_BOOL_VEC4_ARB 0x8B59 -#define GL_FLOAT_MAT2_ARB 0x8B5A -#define GL_FLOAT_MAT3_ARB 0x8B5B -#define GL_FLOAT_MAT4_ARB 0x8B5C -#define GL_SAMPLER_1D_ARB 0x8B5D -#define GL_SAMPLER_2D_ARB 0x8B5E -#define GL_SAMPLER_3D_ARB 0x8B5F -#define GL_SAMPLER_CUBE_ARB 0x8B60 -#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 -#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 -#define GL_SAMPLER_2D_RECT_ARB 0x8B63 -#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 -#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 -#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 -#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 -#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 -#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 -#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 -#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 -#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 -#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 -#endif - -#ifndef GL_ARB_vertex_shader -#define GL_VERTEX_SHADER_ARB 0x8B31 -#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A -#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B -#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C -#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D -#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 -#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A -#endif - -#ifndef GL_ARB_fragment_shader -#define GL_FRAGMENT_SHADER_ARB 0x8B30 -#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 -#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B -#endif - -#ifndef GL_ARB_shading_language_100 -#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C -#endif - -#ifndef GL_ARB_texture_non_power_of_two -#endif - -#ifndef GL_ARB_point_sprite -#define GL_POINT_SPRITE_ARB 0x8861 -#define GL_COORD_REPLACE_ARB 0x8862 -#endif - -#ifndef GL_ARB_fragment_program_shadow -#endif - -#ifndef GL_ARB_draw_buffers -#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 -#define GL_DRAW_BUFFER0_ARB 0x8825 -#define GL_DRAW_BUFFER1_ARB 0x8826 -#define GL_DRAW_BUFFER2_ARB 0x8827 -#define GL_DRAW_BUFFER3_ARB 0x8828 -#define GL_DRAW_BUFFER4_ARB 0x8829 -#define GL_DRAW_BUFFER5_ARB 0x882A -#define GL_DRAW_BUFFER6_ARB 0x882B -#define GL_DRAW_BUFFER7_ARB 0x882C -#define GL_DRAW_BUFFER8_ARB 0x882D -#define GL_DRAW_BUFFER9_ARB 0x882E -#define GL_DRAW_BUFFER10_ARB 0x882F -#define GL_DRAW_BUFFER11_ARB 0x8830 -#define GL_DRAW_BUFFER12_ARB 0x8831 -#define GL_DRAW_BUFFER13_ARB 0x8832 -#define GL_DRAW_BUFFER14_ARB 0x8833 -#define GL_DRAW_BUFFER15_ARB 0x8834 -#endif - -#ifndef GL_ARB_texture_rectangle -#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 -#endif - -#ifndef GL_ARB_color_buffer_float -#define GL_RGBA_FLOAT_MODE_ARB 0x8820 -#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A -#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B -#define GL_CLAMP_READ_COLOR_ARB 0x891C -#define GL_FIXED_ONLY_ARB 0x891D -#endif - -#ifndef GL_ARB_half_float_pixel -#define GL_HALF_FLOAT_ARB 0x140B -#endif - -#ifndef GL_ARB_texture_float -#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 -#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 -#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 -#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 -#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 -#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 -#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 -#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 -#define GL_RGBA32F_ARB 0x8814 -#define GL_RGB32F_ARB 0x8815 -#define GL_ALPHA32F_ARB 0x8816 -#define GL_INTENSITY32F_ARB 0x8817 -#define GL_LUMINANCE32F_ARB 0x8818 -#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 -#define GL_RGBA16F_ARB 0x881A -#define GL_RGB16F_ARB 0x881B -#define GL_ALPHA16F_ARB 0x881C -#define GL_INTENSITY16F_ARB 0x881D -#define GL_LUMINANCE16F_ARB 0x881E -#define GL_LUMINANCE_ALPHA16F_ARB 0x881F -#endif - -#ifndef GL_ARB_pixel_buffer_object -#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB -#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC -#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED -#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF -#endif - -#ifndef GL_ARB_depth_buffer_float -#define GL_DEPTH_COMPONENT32F 0x8CAC -#define GL_DEPTH32F_STENCIL8 0x8CAD -#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD -#endif - -#ifndef GL_ARB_draw_instanced -#endif - -#ifndef GL_ARB_framebuffer_object -#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 -#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 -#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 -#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 -#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 -#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 -#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 -#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 -#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 -#define GL_FRAMEBUFFER_DEFAULT 0x8218 -#define GL_FRAMEBUFFER_UNDEFINED 0x8219 -#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A -#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 -#define GL_DEPTH_STENCIL 0x84F9 -#define GL_UNSIGNED_INT_24_8 0x84FA -#define GL_DEPTH24_STENCIL8 0x88F0 -#define GL_TEXTURE_STENCIL_SIZE 0x88F1 -#define GL_TEXTURE_RED_TYPE 0x8C10 -#define GL_TEXTURE_GREEN_TYPE 0x8C11 -#define GL_TEXTURE_BLUE_TYPE 0x8C12 -#define GL_TEXTURE_ALPHA_TYPE 0x8C13 -#define GL_TEXTURE_DEPTH_TYPE 0x8C16 -#define GL_UNSIGNED_NORMALIZED 0x8C17 -#define GL_FRAMEBUFFER_BINDING 0x8CA6 -#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING -#define GL_RENDERBUFFER_BINDING 0x8CA7 -#define GL_READ_FRAMEBUFFER 0x8CA8 -#define GL_DRAW_FRAMEBUFFER 0x8CA9 -#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA -#define GL_RENDERBUFFER_SAMPLES 0x8CAB -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 -#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC -#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD -#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_COLOR_ATTACHMENT1 0x8CE1 -#define GL_COLOR_ATTACHMENT2 0x8CE2 -#define GL_COLOR_ATTACHMENT3 0x8CE3 -#define GL_COLOR_ATTACHMENT4 0x8CE4 -#define GL_COLOR_ATTACHMENT5 0x8CE5 -#define GL_COLOR_ATTACHMENT6 0x8CE6 -#define GL_COLOR_ATTACHMENT7 0x8CE7 -#define GL_COLOR_ATTACHMENT8 0x8CE8 -#define GL_COLOR_ATTACHMENT9 0x8CE9 -#define GL_COLOR_ATTACHMENT10 0x8CEA -#define GL_COLOR_ATTACHMENT11 0x8CEB -#define GL_COLOR_ATTACHMENT12 0x8CEC -#define GL_COLOR_ATTACHMENT13 0x8CED -#define GL_COLOR_ATTACHMENT14 0x8CEE -#define GL_COLOR_ATTACHMENT15 0x8CEF -#define GL_DEPTH_ATTACHMENT 0x8D00 -#define GL_STENCIL_ATTACHMENT 0x8D20 -#define GL_FRAMEBUFFER 0x8D40 -#define GL_RENDERBUFFER 0x8D41 -#define GL_RENDERBUFFER_WIDTH 0x8D42 -#define GL_RENDERBUFFER_HEIGHT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 -#define GL_STENCIL_INDEX1 0x8D46 -#define GL_STENCIL_INDEX4 0x8D47 -#define GL_STENCIL_INDEX8 0x8D48 -#define GL_STENCIL_INDEX16 0x8D49 -#define GL_RENDERBUFFER_RED_SIZE 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 -#define GL_MAX_SAMPLES 0x8D57 -#endif - -#ifndef GL_ARB_framebuffer_object_DEPRECATED -#define GL_INDEX 0x8222 -#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 -#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 -#endif - -#ifndef GL_ARB_framebuffer_sRGB -#define GL_FRAMEBUFFER_SRGB 0x8DB9 -#endif - -#ifndef GL_ARB_geometry_shader4 -#define GL_LINES_ADJACENCY_ARB 0x000A -#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B -#define GL_TRIANGLES_ADJACENCY_ARB 0x000C -#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D -#define GL_PROGRAM_POINT_SIZE_ARB 0x8642 -#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29 -#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9 -#define GL_GEOMETRY_SHADER_ARB 0x8DD9 -#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA -#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB -#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC -#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD -#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE -#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF -#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0 -#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1 -/* reuse GL_MAX_VARYING_COMPONENTS */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ -#endif - -#ifndef GL_ARB_half_float_vertex -#define GL_HALF_FLOAT 0x140B -#endif - -#ifndef GL_ARB_instanced_arrays -#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE -#endif - -#ifndef GL_ARB_map_buffer_range -#define GL_MAP_READ_BIT 0x0001 -#define GL_MAP_WRITE_BIT 0x0002 -#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 -#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 -#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 -#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 -#endif - -#ifndef GL_ARB_texture_buffer_object -#define GL_TEXTURE_BUFFER_ARB 0x8C2A -#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B -#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C -#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D -#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E -#endif - -#ifndef GL_ARB_texture_compression_rgtc -#define GL_COMPRESSED_RED_RGTC1 0x8DBB -#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC -#define GL_COMPRESSED_RG_RGTC2 0x8DBD -#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE -#endif - -#ifndef GL_ARB_texture_rg -#define GL_RG 0x8227 -#define GL_RG_INTEGER 0x8228 -#define GL_R8 0x8229 -#define GL_R16 0x822A -#define GL_RG8 0x822B -#define GL_RG16 0x822C -#define GL_R16F 0x822D -#define GL_R32F 0x822E -#define GL_RG16F 0x822F -#define GL_RG32F 0x8230 -#define GL_R8I 0x8231 -#define GL_R8UI 0x8232 -#define GL_R16I 0x8233 -#define GL_R16UI 0x8234 -#define GL_R32I 0x8235 -#define GL_R32UI 0x8236 -#define GL_RG8I 0x8237 -#define GL_RG8UI 0x8238 -#define GL_RG16I 0x8239 -#define GL_RG16UI 0x823A -#define GL_RG32I 0x823B -#define GL_RG32UI 0x823C -#endif - -#ifndef GL_ARB_vertex_array_object -#define GL_VERTEX_ARRAY_BINDING 0x85B5 -#endif - -#ifndef GL_ARB_uniform_buffer_object -#define GL_UNIFORM_BUFFER 0x8A11 -#define GL_UNIFORM_BUFFER_BINDING 0x8A28 -#define GL_UNIFORM_BUFFER_START 0x8A29 -#define GL_UNIFORM_BUFFER_SIZE 0x8A2A -#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B -#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C -#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D -#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E -#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F -#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 -#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 -#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 -#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 -#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 -#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 -#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 -#define GL_UNIFORM_TYPE 0x8A37 -#define GL_UNIFORM_SIZE 0x8A38 -#define GL_UNIFORM_NAME_LENGTH 0x8A39 -#define GL_UNIFORM_BLOCK_INDEX 0x8A3A -#define GL_UNIFORM_OFFSET 0x8A3B -#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C -#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D -#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E -#define GL_UNIFORM_BLOCK_BINDING 0x8A3F -#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 -#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 -#define GL_INVALID_INDEX 0xFFFFFFFFu -#endif - -#ifndef GL_ARB_compatibility -/* ARB_compatibility just defines tokens from core 3.0 */ -#endif - -#ifndef GL_ARB_copy_buffer -#define GL_COPY_READ_BUFFER_BINDING 0x8F36 -#define GL_COPY_READ_BUFFER GL_COPY_READ_BUFFER_BINDING -#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37 -#define GL_COPY_WRITE_BUFFER GL_COPY_WRITE_BUFFER_BINDING -#endif - -#ifndef GL_ARB_shader_texture_lod -#endif - -#ifndef GL_ARB_depth_clamp -#define GL_DEPTH_CLAMP 0x864F -#endif - -#ifndef GL_ARB_draw_elements_base_vertex -#endif - -#ifndef GL_ARB_fragment_coord_conventions -#endif - -#ifndef GL_ARB_provoking_vertex -#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C -#define GL_FIRST_VERTEX_CONVENTION 0x8E4D -#define GL_LAST_VERTEX_CONVENTION 0x8E4E -#define GL_PROVOKING_VERTEX 0x8E4F -#endif - -#ifndef GL_ARB_seamless_cube_map -#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F -#endif - -#ifndef GL_ARB_sync -#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 -#define GL_OBJECT_TYPE 0x9112 -#define GL_SYNC_CONDITION 0x9113 -#define GL_SYNC_STATUS 0x9114 -#define GL_SYNC_FLAGS 0x9115 -#define GL_SYNC_FENCE 0x9116 -#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 -#define GL_UNSIGNALED 0x9118 -#define GL_SIGNALED 0x9119 -#define GL_ALREADY_SIGNALED 0x911A -#define GL_TIMEOUT_EXPIRED 0x911B -#define GL_CONDITION_SATISFIED 0x911C -#define GL_WAIT_FAILED 0x911D -#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 -#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull -#endif - -#ifndef GL_ARB_texture_multisample -#define GL_SAMPLE_POSITION 0x8E50 -#define GL_SAMPLE_MASK 0x8E51 -#define GL_SAMPLE_MASK_VALUE 0x8E52 -#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 -#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 -#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 -#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 -#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 -#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 -#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 -#define GL_TEXTURE_SAMPLES 0x9106 -#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 -#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 -#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 -#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A -#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B -#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C -#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D -#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E -#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F -#define GL_MAX_INTEGER_SAMPLES 0x9110 -#endif - -#ifndef GL_ARB_vertex_array_bgra -/* reuse GL_BGRA */ -#endif - -#ifndef GL_ARB_draw_buffers_blend -#endif - -#ifndef GL_ARB_sample_shading -#define GL_SAMPLE_SHADING_ARB 0x8C36 -#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 -#endif - -#ifndef GL_ARB_texture_cube_map_array -#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 -#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A -#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B -#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C -#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D -#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E -#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F -#endif - -#ifndef GL_ARB_texture_gather -#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E -#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F -#endif - -#ifndef GL_ARB_texture_query_lod -#endif - -#ifndef GL_ARB_shading_language_include -#define GL_SHADER_INCLUDE_ARB 0x8DAE -#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 -#define GL_NAMED_STRING_TYPE_ARB 0x8DEA -#endif - -#ifndef GL_ARB_texture_compression_bptc -#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C -#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D -#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E -#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F -#endif - -#ifndef GL_ARB_blend_func_extended -#define GL_SRC1_COLOR 0x88F9 -/* reuse GL_SRC1_ALPHA */ -#define GL_ONE_MINUS_SRC1_COLOR 0x88FA -#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB -#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC -#endif - -#ifndef GL_ARB_explicit_attrib_location -#endif - -#ifndef GL_ARB_occlusion_query2 -#define GL_ANY_SAMPLES_PASSED 0x8C2F -#endif - -#ifndef GL_ARB_sampler_objects -#define GL_SAMPLER_BINDING 0x8919 -#endif - -#ifndef GL_ARB_shader_bit_encoding -#endif - -#ifndef GL_ARB_texture_rgb10_a2ui -#define GL_RGB10_A2UI 0x906F -#endif - -#ifndef GL_ARB_texture_swizzle -#define GL_TEXTURE_SWIZZLE_R 0x8E42 -#define GL_TEXTURE_SWIZZLE_G 0x8E43 -#define GL_TEXTURE_SWIZZLE_B 0x8E44 -#define GL_TEXTURE_SWIZZLE_A 0x8E45 -#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 -#endif - -#ifndef GL_ARB_timer_query -#define GL_TIME_ELAPSED 0x88BF -#define GL_TIMESTAMP 0x8E28 -#endif - -#ifndef GL_ARB_vertex_type_2_10_10_10_rev -/* reuse GL_UNSIGNED_INT_2_10_10_10_REV */ -#define GL_INT_2_10_10_10_REV 0x8D9F -#endif - -#ifndef GL_ARB_draw_indirect -#define GL_DRAW_INDIRECT_BUFFER 0x8F3F -#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 -#endif - -#ifndef GL_ARB_gpu_shader5 -#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F -#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A -#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B -#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C -#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D -/* reuse GL_MAX_VERTEX_STREAMS */ -#endif - -#ifndef GL_ARB_gpu_shader_fp64 -/* reuse GL_DOUBLE */ -#define GL_DOUBLE_VEC2 0x8FFC -#define GL_DOUBLE_VEC3 0x8FFD -#define GL_DOUBLE_VEC4 0x8FFE -#define GL_DOUBLE_MAT2 0x8F46 -#define GL_DOUBLE_MAT3 0x8F47 -#define GL_DOUBLE_MAT4 0x8F48 -#define GL_DOUBLE_MAT2x3 0x8F49 -#define GL_DOUBLE_MAT2x4 0x8F4A -#define GL_DOUBLE_MAT3x2 0x8F4B -#define GL_DOUBLE_MAT3x4 0x8F4C -#define GL_DOUBLE_MAT4x2 0x8F4D -#define GL_DOUBLE_MAT4x3 0x8F4E -#endif - -#ifndef GL_ARB_shader_subroutine -#define GL_ACTIVE_SUBROUTINES 0x8DE5 -#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 -#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 -#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 -#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 -#define GL_MAX_SUBROUTINES 0x8DE7 -#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 -#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A -#define GL_COMPATIBLE_SUBROUTINES 0x8E4B -/* reuse GL_UNIFORM_SIZE */ -/* reuse GL_UNIFORM_NAME_LENGTH */ -#endif - -#ifndef GL_ARB_tessellation_shader -#define GL_PATCHES 0x000E -#define GL_PATCH_VERTICES 0x8E72 -#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 -#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 -#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 -#define GL_TESS_GEN_MODE 0x8E76 -#define GL_TESS_GEN_SPACING 0x8E77 -#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 -#define GL_TESS_GEN_POINT_MODE 0x8E79 -/* reuse GL_TRIANGLES */ -/* reuse GL_QUADS */ -#define GL_ISOLINES 0x8E7A -/* reuse GL_EQUAL */ -#define GL_FRACTIONAL_ODD 0x8E7B -#define GL_FRACTIONAL_EVEN 0x8E7C -/* reuse GL_CCW */ -/* reuse GL_CW */ -#define GL_MAX_PATCH_VERTICES 0x8E7D -#define GL_MAX_TESS_GEN_LEVEL 0x8E7E -#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F -#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 -#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 -#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 -#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 -#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 -#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 -#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 -#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 -#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A -#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C -#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D -#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E -#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F -#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 -#define GL_TESS_EVALUATION_SHADER 0x8E87 -#define GL_TESS_CONTROL_SHADER 0x8E88 -#endif - -#ifndef GL_ARB_texture_buffer_object_rgb32 -/* reuse GL_RGB32F */ -/* reuse GL_RGB32UI */ -/* reuse GL_RGB32I */ -#endif - -#ifndef GL_ARB_transform_feedback2 -#define GL_TRANSFORM_FEEDBACK 0x8E22 -#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 -#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED GL_TRANSFORM_FEEDBACK_PAUSED -#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 -#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE GL_TRANSFORM_FEEDBACK_ACTIVE -#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 -#endif - -#ifndef GL_ARB_transform_feedback3 -#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 -#define GL_MAX_VERTEX_STREAMS 0x8E71 -#endif - -#ifndef GL_ARB_ES2_compatibility -#define GL_FIXED 0x140C -#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A -#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B -#define GL_LOW_FLOAT 0x8DF0 -#define GL_MEDIUM_FLOAT 0x8DF1 -#define GL_HIGH_FLOAT 0x8DF2 -#define GL_LOW_INT 0x8DF3 -#define GL_MEDIUM_INT 0x8DF4 -#define GL_HIGH_INT 0x8DF5 -#define GL_SHADER_COMPILER 0x8DFA -#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 -#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB -#define GL_MAX_VARYING_VECTORS 0x8DFC -#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD -#define GL_RGB565 0x8D62 -#endif - -#ifndef GL_ARB_get_program_binary -#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 -#define GL_PROGRAM_BINARY_LENGTH 0x8741 -#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE -#define GL_PROGRAM_BINARY_FORMATS 0x87FF -#endif - -#ifndef GL_ARB_separate_shader_objects -#define GL_VERTEX_SHADER_BIT 0x00000001 -#define GL_FRAGMENT_SHADER_BIT 0x00000002 -#define GL_GEOMETRY_SHADER_BIT 0x00000004 -#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 -#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 -#define GL_ALL_SHADER_BITS 0xFFFFFFFF -#define GL_PROGRAM_SEPARABLE 0x8258 -#define GL_ACTIVE_PROGRAM 0x8259 -#define GL_PROGRAM_PIPELINE_BINDING 0x825A -#endif - -#ifndef GL_ARB_shader_precision -#endif - -#ifndef GL_ARB_vertex_attrib_64bit -/* reuse GL_RGB32I */ -/* reuse GL_DOUBLE_VEC2 */ -/* reuse GL_DOUBLE_VEC3 */ -/* reuse GL_DOUBLE_VEC4 */ -/* reuse GL_DOUBLE_MAT2 */ -/* reuse GL_DOUBLE_MAT3 */ -/* reuse GL_DOUBLE_MAT4 */ -/* reuse GL_DOUBLE_MAT2x3 */ -/* reuse GL_DOUBLE_MAT2x4 */ -/* reuse GL_DOUBLE_MAT3x2 */ -/* reuse GL_DOUBLE_MAT3x4 */ -/* reuse GL_DOUBLE_MAT4x2 */ -/* reuse GL_DOUBLE_MAT4x3 */ -#endif - -#ifndef GL_ARB_viewport_array -/* reuse GL_SCISSOR_BOX */ -/* reuse GL_VIEWPORT */ -/* reuse GL_DEPTH_RANGE */ -/* reuse GL_SCISSOR_TEST */ -#define GL_MAX_VIEWPORTS 0x825B -#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C -#define GL_VIEWPORT_BOUNDS_RANGE 0x825D -#define GL_LAYER_PROVOKING_VERTEX 0x825E -#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F -#define GL_UNDEFINED_VERTEX 0x8260 -/* reuse GL_FIRST_VERTEX_CONVENTION */ -/* reuse GL_LAST_VERTEX_CONVENTION */ -/* reuse GL_PROVOKING_VERTEX */ -#endif - -#ifndef GL_ARB_cl_event -#define GL_SYNC_CL_EVENT_ARB 0x8240 -#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 -#endif - -#ifndef GL_ARB_debug_output -#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 -#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 -#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 -#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 -#define GL_DEBUG_SOURCE_API_ARB 0x8246 -#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 -#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 -#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 -#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A -#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B -#define GL_DEBUG_TYPE_ERROR_ARB 0x824C -#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D -#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E -#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F -#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 -#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 -#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 -#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 -#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 -#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 -#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 -#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 -#endif - -#ifndef GL_ARB_robustness -/* reuse GL_NO_ERROR */ -#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 -#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 -#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 -#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 -#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 -#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 -#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 -#endif - -#ifndef GL_ARB_shader_stencil_export -#endif - -#ifndef GL_ARB_base_instance -#endif - -#ifndef GL_ARB_shading_language_420pack -#endif - -#ifndef GL_ARB_transform_feedback_instanced -#endif - -#ifndef GL_ARB_compressed_texture_pixel_storage -#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127 -#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128 -#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129 -#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A -#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B -#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C -#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D -#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E -#endif - -#ifndef GL_ARB_conservative_depth -#endif - -#ifndef GL_ARB_internalformat_query -#define GL_NUM_SAMPLE_COUNTS 0x9380 -#endif - -#ifndef GL_ARB_map_buffer_alignment -#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC -#endif - -#ifndef GL_ARB_shader_atomic_counters -#define GL_ATOMIC_COUNTER_BUFFER 0x92C0 -#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1 -#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2 -#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3 -#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4 -#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5 -#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9 -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB -#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC -#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD -#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE -#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF -#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0 -#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1 -#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2 -#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3 -#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4 -#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5 -#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6 -#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7 -#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8 -#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC -#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9 -#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA -#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB -#endif - -#ifndef GL_ARB_shader_image_load_store -#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001 -#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002 -#define GL_UNIFORM_BARRIER_BIT 0x00000004 -#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008 -#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020 -#define GL_COMMAND_BARRIER_BIT 0x00000040 -#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080 -#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100 -#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200 -#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400 -#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800 -#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000 -#define GL_ALL_BARRIER_BITS 0xFFFFFFFF -#define GL_MAX_IMAGE_UNITS 0x8F38 -#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39 -#define GL_IMAGE_BINDING_NAME 0x8F3A -#define GL_IMAGE_BINDING_LEVEL 0x8F3B -#define GL_IMAGE_BINDING_LAYERED 0x8F3C -#define GL_IMAGE_BINDING_LAYER 0x8F3D -#define GL_IMAGE_BINDING_ACCESS 0x8F3E -#define GL_IMAGE_1D 0x904C -#define GL_IMAGE_2D 0x904D -#define GL_IMAGE_3D 0x904E -#define GL_IMAGE_2D_RECT 0x904F -#define GL_IMAGE_CUBE 0x9050 -#define GL_IMAGE_BUFFER 0x9051 -#define GL_IMAGE_1D_ARRAY 0x9052 -#define GL_IMAGE_2D_ARRAY 0x9053 -#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 -#define GL_IMAGE_2D_MULTISAMPLE 0x9055 -#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056 -#define GL_INT_IMAGE_1D 0x9057 -#define GL_INT_IMAGE_2D 0x9058 -#define GL_INT_IMAGE_3D 0x9059 -#define GL_INT_IMAGE_2D_RECT 0x905A -#define GL_INT_IMAGE_CUBE 0x905B -#define GL_INT_IMAGE_BUFFER 0x905C -#define GL_INT_IMAGE_1D_ARRAY 0x905D -#define GL_INT_IMAGE_2D_ARRAY 0x905E -#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F -#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060 -#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061 -#define GL_UNSIGNED_INT_IMAGE_1D 0x9062 -#define GL_UNSIGNED_INT_IMAGE_2D 0x9063 -#define GL_UNSIGNED_INT_IMAGE_3D 0x9064 -#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065 -#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066 -#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 -#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068 -#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069 -#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A -#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B -#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C -#define GL_MAX_IMAGE_SAMPLES 0x906D -#define GL_IMAGE_BINDING_FORMAT 0x906E -#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7 -#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8 -#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9 -#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA -#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB -#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC -#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD -#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE -#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF -#endif - -#ifndef GL_ARB_shading_language_packing -#endif - -#ifndef GL_ARB_texture_storage -#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F -#endif - -#ifndef GL_KHR_texture_compression_astc_ldr -#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 -#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 -#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 -#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 -#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 -#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 -#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 -#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 -#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 -#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 -#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA -#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB -#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC -#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC -#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD -#endif - -#ifndef GL_KHR_debug -#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 -#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 -#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 -#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 -#define GL_DEBUG_SOURCE_API 0x8246 -#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 -#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 -#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 -#define GL_DEBUG_SOURCE_APPLICATION 0x824A -#define GL_DEBUG_SOURCE_OTHER 0x824B -#define GL_DEBUG_TYPE_ERROR 0x824C -#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D -#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E -#define GL_DEBUG_TYPE_PORTABILITY 0x824F -#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 -#define GL_DEBUG_TYPE_OTHER 0x8251 -#define GL_DEBUG_TYPE_MARKER 0x8268 -#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 -#define GL_DEBUG_TYPE_POP_GROUP 0x826A -#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B -#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C -#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D -#define GL_BUFFER 0x82E0 -#define GL_SHADER 0x82E1 -#define GL_PROGRAM 0x82E2 -#define GL_QUERY 0x82E3 -#define GL_PROGRAM_PIPELINE 0x82E4 -#define GL_SAMPLER 0x82E6 -#define GL_DISPLAY_LIST 0x82E7 -#define GL_MAX_LABEL_LENGTH 0x82E8 -#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 -#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 -#define GL_DEBUG_LOGGED_MESSAGES 0x9145 -#define GL_DEBUG_SEVERITY_HIGH 0x9146 -#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 -#define GL_DEBUG_SEVERITY_LOW 0x9148 -#define GL_DEBUG_OUTPUT 0x92E0 -#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 -/* reuse GL_STACK_UNDERFLOW */ -/* reuse GL_STACK_OVERFLOW */ -#endif - -#ifndef GL_ARB_arrays_of_arrays -#endif - -#ifndef GL_ARB_clear_buffer_object -#endif - -#ifndef GL_ARB_compute_shader -#define GL_COMPUTE_SHADER 0x91B9 -#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB -#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC -#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD -#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 -#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 -#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 -#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 -#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 -#define GL_MAX_COMPUTE_LOCAL_INVOCATIONS 0x90EB -#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE -#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF -#define GL_COMPUTE_LOCAL_WORK_SIZE 0x8267 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC -#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED -#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE -#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF -#define GL_COMPUTE_SHADER_BIT 0x00000020 -#endif - -#ifndef GL_ARB_copy_image -#endif - -#ifndef GL_ARB_debug_group -/* reuse GL_DEBUG_TYPE_MARKER */ -/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ -/* reuse GL_DEBUG_TYPE_POP_GROUP */ -/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ -/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ -/* reuse GL_STACK_UNDERFLOW */ -/* reuse GL_STACK_OVERFLOW */ -#endif - -#ifndef GL_ARB_debug_label -/* reuse GL_BUFFER */ -/* reuse GL_SHADER */ -/* reuse GL_PROGRAM */ -/* reuse GL_QUERY */ -/* reuse GL_PROGRAM_PIPELINE */ -/* reuse GL_SAMPLER */ -/* DISPLAY_LIST used in compatibility profile only */ -/* reuse GL_DISPLAY_LIST */ -/* reuse GL_MAX_LABEL_LENGTH */ -/* reuse GL_VERTEX_ARRAY */ -#endif - -#ifndef GL_ARB_debug_output2 -/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ -/* reuse GL_DEBUG_OUTPUT */ -#endif - -#ifndef GL_ARB_ES3_compatibility -#define GL_COMPRESSED_RGB8_ETC2 0x9274 -#define GL_COMPRESSED_SRGB8_ETC2 0x9275 -#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 -#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 -#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 -#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 -#define GL_COMPRESSED_R11_EAC 0x9270 -#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 -#define GL_COMPRESSED_RG11_EAC 0x9272 -#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 -#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 -#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A -#define GL_MAX_ELEMENT_INDEX 0x8D6B -#endif - -#ifndef GL_ARB_explicit_uniform_location -#define GL_MAX_UNIFORM_LOCATIONS 0x826E -#endif - -#ifndef GL_ARB_fragment_layer_viewport -#endif - -#ifndef GL_ARB_framebuffer_no_attachments -#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 -#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 -#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 -#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 -#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 -#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 -#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 -#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 -#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 -#endif - -#ifndef GL_ARB_internalformat_query2 -/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ -/* reuse GL_NUM_SAMPLE_COUNTS */ -/* reuse GL_RENDERBUFFER */ -/* reuse GL_SAMPLES */ -/* reuse GL_TEXTURE_1D */ -/* reuse GL_TEXTURE_1D_ARRAY */ -/* reuse GL_TEXTURE_2D */ -/* reuse GL_TEXTURE_2D_ARRAY */ -/* reuse GL_TEXTURE_3D */ -/* reuse GL_TEXTURE_CUBE_MAP */ -/* reuse GL_TEXTURE_CUBE_MAP_ARRAY */ -/* reuse GL_TEXTURE_RECTANGLE */ -/* reuse GL_TEXTURE_BUFFER */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE */ -/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ -/* reuse GL_TEXTURE_COMPRESSED */ -#define GL_INTERNALFORMAT_SUPPORTED 0x826F -#define GL_INTERNALFORMAT_PREFERRED 0x8270 -#define GL_INTERNALFORMAT_RED_SIZE 0x8271 -#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 -#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 -#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 -#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 -#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 -#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 -#define GL_INTERNALFORMAT_RED_TYPE 0x8278 -#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 -#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A -#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B -#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C -#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D -#define GL_MAX_WIDTH 0x827E -#define GL_MAX_HEIGHT 0x827F -#define GL_MAX_DEPTH 0x8280 -#define GL_MAX_LAYERS 0x8281 -#define GL_MAX_COMBINED_DIMENSIONS 0x8282 -#define GL_COLOR_COMPONENTS 0x8283 -#define GL_DEPTH_COMPONENTS 0x8284 -#define GL_STENCIL_COMPONENTS 0x8285 -#define GL_COLOR_RENDERABLE 0x8286 -#define GL_DEPTH_RENDERABLE 0x8287 -#define GL_STENCIL_RENDERABLE 0x8288 -#define GL_FRAMEBUFFER_RENDERABLE 0x8289 -#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A -#define GL_FRAMEBUFFER_BLEND 0x828B -#define GL_READ_PIXELS 0x828C -#define GL_READ_PIXELS_FORMAT 0x828D -#define GL_READ_PIXELS_TYPE 0x828E -#define GL_TEXTURE_IMAGE_FORMAT 0x828F -#define GL_TEXTURE_IMAGE_TYPE 0x8290 -#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 -#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 -#define GL_MIPMAP 0x8293 -#define GL_MANUAL_GENERATE_MIPMAP 0x8294 -#define GL_AUTO_GENERATE_MIPMAP 0x8295 -#define GL_COLOR_ENCODING 0x8296 -#define GL_SRGB_READ 0x8297 -#define GL_SRGB_WRITE 0x8298 -#define GL_SRGB_DECODE_ARB 0x8299 -#define GL_FILTER 0x829A -#define GL_VERTEX_TEXTURE 0x829B -#define GL_TESS_CONTROL_TEXTURE 0x829C -#define GL_TESS_EVALUATION_TEXTURE 0x829D -#define GL_GEOMETRY_TEXTURE 0x829E -#define GL_FRAGMENT_TEXTURE 0x829F -#define GL_COMPUTE_TEXTURE 0x82A0 -#define GL_TEXTURE_SHADOW 0x82A1 -#define GL_TEXTURE_GATHER 0x82A2 -#define GL_TEXTURE_GATHER_SHADOW 0x82A3 -#define GL_SHADER_IMAGE_LOAD 0x82A4 -#define GL_SHADER_IMAGE_STORE 0x82A5 -#define GL_SHADER_IMAGE_ATOMIC 0x82A6 -#define GL_IMAGE_TEXEL_SIZE 0x82A7 -#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 -#define GL_IMAGE_PIXEL_FORMAT 0x82A9 -#define GL_IMAGE_PIXEL_TYPE 0x82AA -#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC -#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD -#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE -#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF -#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 -#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 -#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 -#define GL_CLEAR_BUFFER 0x82B4 -#define GL_TEXTURE_VIEW 0x82B5 -#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 -#define GL_FULL_SUPPORT 0x82B7 -#define GL_CAVEAT_SUPPORT 0x82B8 -#define GL_IMAGE_CLASS_4_X_32 0x82B9 -#define GL_IMAGE_CLASS_2_X_32 0x82BA -#define GL_IMAGE_CLASS_1_X_32 0x82BB -#define GL_IMAGE_CLASS_4_X_16 0x82BC -#define GL_IMAGE_CLASS_2_X_16 0x82BD -#define GL_IMAGE_CLASS_1_X_16 0x82BE -#define GL_IMAGE_CLASS_4_X_8 0x82BF -#define GL_IMAGE_CLASS_2_X_8 0x82C0 -#define GL_IMAGE_CLASS_1_X_8 0x82C1 -#define GL_IMAGE_CLASS_11_11_10 0x82C2 -#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 -#define GL_VIEW_CLASS_128_BITS 0x82C4 -#define GL_VIEW_CLASS_96_BITS 0x82C5 -#define GL_VIEW_CLASS_64_BITS 0x82C6 -#define GL_VIEW_CLASS_48_BITS 0x82C7 -#define GL_VIEW_CLASS_32_BITS 0x82C8 -#define GL_VIEW_CLASS_24_BITS 0x82C9 -#define GL_VIEW_CLASS_16_BITS 0x82CA -#define GL_VIEW_CLASS_8_BITS 0x82CB -#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC -#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD -#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE -#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF -#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 -#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 -#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 -#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 -#endif - -#ifndef GL_ARB_invalidate_subdata -#endif - -#ifndef GL_ARB_multi_draw_indirect -#endif - -#ifndef GL_ARB_program_interface_query -#define GL_UNIFORM 0x92E1 -#define GL_UNIFORM_BLOCK 0x92E2 -#define GL_PROGRAM_INPUT 0x92E3 -#define GL_PROGRAM_OUTPUT 0x92E4 -#define GL_BUFFER_VARIABLE 0x92E5 -#define GL_SHADER_STORAGE_BLOCK 0x92E6 -/* reuse GL_ATOMIC_COUNTER_BUFFER */ -#define GL_VERTEX_SUBROUTINE 0x92E8 -#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 -#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA -#define GL_GEOMETRY_SUBROUTINE 0x92EB -#define GL_FRAGMENT_SUBROUTINE 0x92EC -#define GL_COMPUTE_SUBROUTINE 0x92ED -#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE -#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF -#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 -#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 -#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 -#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 -#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 -#define GL_ACTIVE_RESOURCES 0x92F5 -#define GL_MAX_NAME_LENGTH 0x92F6 -#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 -#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 -#define GL_NAME_LENGTH 0x92F9 -#define GL_TYPE 0x92FA -#define GL_ARRAY_SIZE 0x92FB -#define GL_OFFSET 0x92FC -#define GL_BLOCK_INDEX 0x92FD -#define GL_ARRAY_STRIDE 0x92FE -#define GL_MATRIX_STRIDE 0x92FF -#define GL_IS_ROW_MAJOR 0x9300 -#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 -#define GL_BUFFER_BINDING 0x9302 -#define GL_BUFFER_DATA_SIZE 0x9303 -#define GL_NUM_ACTIVE_VARIABLES 0x9304 -#define GL_ACTIVE_VARIABLES 0x9305 -#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 -#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 -#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 -#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 -#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A -#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B -#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C -#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D -#define GL_LOCATION 0x930E -#define GL_LOCATION_INDEX 0x930F -#define GL_IS_PER_PATCH 0x92E7 -/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ -/* reuse GL_COMPATIBLE_SUBROUTINES */ -#endif - -#ifndef GL_ARB_robust_buffer_access_behavior -#endif - -#ifndef GL_ARB_shader_image_size -#endif - -#ifndef GL_ARB_shader_storage_buffer_object -#define GL_SHADER_STORAGE_BUFFER 0x90D2 -#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 -#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 -#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 -#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 -#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 -#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 -#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 -#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA -#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB -#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC -#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD -#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE -#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF -#define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 -#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS -/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ -#endif - -#ifndef GL_ARB_stencil_texturing -#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA -#endif - -#ifndef GL_ARB_texture_buffer_range -#define GL_TEXTURE_BUFFER_OFFSET 0x919D -#define GL_TEXTURE_BUFFER_SIZE 0x919E -#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F -#endif - -#ifndef GL_ARB_texture_query_levels -#endif - -#ifndef GL_ARB_texture_storage_multisample -#endif - -#ifndef GL_ARB_texture_view -#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB -#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC -#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD -#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE -#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF -#endif - -#ifndef GL_ARB_vertex_attrib_binding -#define GL_VERTEX_ATTRIB_BINDING 0x82D4 -#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 -#define GL_VERTEX_BINDING_DIVISOR 0x82D6 -#define GL_VERTEX_BINDING_OFFSET 0x82D7 -#define GL_VERTEX_BINDING_STRIDE 0x82D8 -#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 -#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA -#endif - -#ifndef GL_ARB_robustness_isolation -#endif - -#ifndef GL_EXT_abgr -#define GL_ABGR_EXT 0x8000 -#endif - -#ifndef GL_EXT_blend_color -#define GL_CONSTANT_COLOR_EXT 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 -#define GL_CONSTANT_ALPHA_EXT 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 -#define GL_BLEND_COLOR_EXT 0x8005 -#endif - -#ifndef GL_EXT_polygon_offset -#define GL_POLYGON_OFFSET_EXT 0x8037 -#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 -#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 -#endif - -#ifndef GL_EXT_texture -#define GL_ALPHA4_EXT 0x803B -#define GL_ALPHA8_EXT 0x803C -#define GL_ALPHA12_EXT 0x803D -#define GL_ALPHA16_EXT 0x803E -#define GL_LUMINANCE4_EXT 0x803F -#define GL_LUMINANCE8_EXT 0x8040 -#define GL_LUMINANCE12_EXT 0x8041 -#define GL_LUMINANCE16_EXT 0x8042 -#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 -#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 -#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 -#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 -#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 -#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 -#define GL_INTENSITY_EXT 0x8049 -#define GL_INTENSITY4_EXT 0x804A -#define GL_INTENSITY8_EXT 0x804B -#define GL_INTENSITY12_EXT 0x804C -#define GL_INTENSITY16_EXT 0x804D -#define GL_RGB2_EXT 0x804E -#define GL_RGB4_EXT 0x804F -#define GL_RGB5_EXT 0x8050 -#define GL_RGB8_EXT 0x8051 -#define GL_RGB10_EXT 0x8052 -#define GL_RGB12_EXT 0x8053 -#define GL_RGB16_EXT 0x8054 -#define GL_RGBA2_EXT 0x8055 -#define GL_RGBA4_EXT 0x8056 -#define GL_RGB5_A1_EXT 0x8057 -#define GL_RGBA8_EXT 0x8058 -#define GL_RGB10_A2_EXT 0x8059 -#define GL_RGBA12_EXT 0x805A -#define GL_RGBA16_EXT 0x805B -#define GL_TEXTURE_RED_SIZE_EXT 0x805C -#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D -#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E -#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F -#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 -#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 -#define GL_REPLACE_EXT 0x8062 -#define GL_PROXY_TEXTURE_1D_EXT 0x8063 -#define GL_PROXY_TEXTURE_2D_EXT 0x8064 -#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 -#endif - -#ifndef GL_EXT_texture3D -#define GL_PACK_SKIP_IMAGES_EXT 0x806B -#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C -#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D -#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E -#define GL_TEXTURE_3D_EXT 0x806F -#define GL_PROXY_TEXTURE_3D_EXT 0x8070 -#define GL_TEXTURE_DEPTH_EXT 0x8071 -#define GL_TEXTURE_WRAP_R_EXT 0x8072 -#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 -#endif - -#ifndef GL_SGIS_texture_filter4 -#define GL_FILTER4_SGIS 0x8146 -#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 -#endif - -#ifndef GL_EXT_subtexture -#endif - -#ifndef GL_EXT_copy_texture -#endif - -#ifndef GL_EXT_histogram -#define GL_HISTOGRAM_EXT 0x8024 -#define GL_PROXY_HISTOGRAM_EXT 0x8025 -#define GL_HISTOGRAM_WIDTH_EXT 0x8026 -#define GL_HISTOGRAM_FORMAT_EXT 0x8027 -#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 -#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 -#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A -#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B -#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C -#define GL_HISTOGRAM_SINK_EXT 0x802D -#define GL_MINMAX_EXT 0x802E -#define GL_MINMAX_FORMAT_EXT 0x802F -#define GL_MINMAX_SINK_EXT 0x8030 -#define GL_TABLE_TOO_LARGE_EXT 0x8031 -#endif - -#ifndef GL_EXT_convolution -#define GL_CONVOLUTION_1D_EXT 0x8010 -#define GL_CONVOLUTION_2D_EXT 0x8011 -#define GL_SEPARABLE_2D_EXT 0x8012 -#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 -#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 -#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 -#define GL_REDUCE_EXT 0x8016 -#define GL_CONVOLUTION_FORMAT_EXT 0x8017 -#define GL_CONVOLUTION_WIDTH_EXT 0x8018 -#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 -#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A -#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B -#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C -#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D -#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E -#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F -#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 -#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 -#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 -#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 -#endif - -#ifndef GL_SGI_color_matrix -#define GL_COLOR_MATRIX_SGI 0x80B1 -#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 -#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 -#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 -#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 -#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 -#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 -#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 -#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 -#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA -#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB -#endif - -#ifndef GL_SGI_color_table -#define GL_COLOR_TABLE_SGI 0x80D0 -#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 -#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 -#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 -#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 -#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 -#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 -#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 -#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 -#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 -#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA -#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB -#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC -#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD -#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE -#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF -#endif - -#ifndef GL_SGIS_pixel_texture -#define GL_PIXEL_TEXTURE_SGIS 0x8353 -#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 -#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 -#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 -#endif - -#ifndef GL_SGIX_pixel_texture -#define GL_PIXEL_TEX_GEN_SGIX 0x8139 -#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B -#endif - -#ifndef GL_SGIS_texture4D -#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 -#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 -#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 -#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 -#define GL_TEXTURE_4D_SGIS 0x8134 -#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 -#define GL_TEXTURE_4DSIZE_SGIS 0x8136 -#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 -#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 -#define GL_TEXTURE_4D_BINDING_SGIS 0x814F -#endif - -#ifndef GL_SGI_texture_color_table -#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC -#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD -#endif - -#ifndef GL_EXT_cmyka -#define GL_CMYK_EXT 0x800C -#define GL_CMYKA_EXT 0x800D -#define GL_PACK_CMYK_HINT_EXT 0x800E -#define GL_UNPACK_CMYK_HINT_EXT 0x800F -#endif - -#ifndef GL_EXT_texture_object -#define GL_TEXTURE_PRIORITY_EXT 0x8066 -#define GL_TEXTURE_RESIDENT_EXT 0x8067 -#define GL_TEXTURE_1D_BINDING_EXT 0x8068 -#define GL_TEXTURE_2D_BINDING_EXT 0x8069 -#define GL_TEXTURE_3D_BINDING_EXT 0x806A -#endif - -#ifndef GL_SGIS_detail_texture -#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 -#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 -#define GL_LINEAR_DETAIL_SGIS 0x8097 -#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 -#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 -#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A -#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B -#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C -#endif - -#ifndef GL_SGIS_sharpen_texture -#define GL_LINEAR_SHARPEN_SGIS 0x80AD -#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE -#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF -#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 -#endif - -#ifndef GL_EXT_packed_pixels -#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 -#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 -#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 -#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 -#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 -#endif - -#ifndef GL_SGIS_texture_lod -#define GL_TEXTURE_MIN_LOD_SGIS 0x813A -#define GL_TEXTURE_MAX_LOD_SGIS 0x813B -#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C -#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D -#endif - -#ifndef GL_SGIS_multisample -#define GL_MULTISAMPLE_SGIS 0x809D -#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F -#define GL_SAMPLE_MASK_SGIS 0x80A0 -#define GL_1PASS_SGIS 0x80A1 -#define GL_2PASS_0_SGIS 0x80A2 -#define GL_2PASS_1_SGIS 0x80A3 -#define GL_4PASS_0_SGIS 0x80A4 -#define GL_4PASS_1_SGIS 0x80A5 -#define GL_4PASS_2_SGIS 0x80A6 -#define GL_4PASS_3_SGIS 0x80A7 -#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 -#define GL_SAMPLES_SGIS 0x80A9 -#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA -#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB -#define GL_SAMPLE_PATTERN_SGIS 0x80AC -#endif - -#ifndef GL_EXT_rescale_normal -#define GL_RESCALE_NORMAL_EXT 0x803A -#endif - -#ifndef GL_EXT_vertex_array -#define GL_VERTEX_ARRAY_EXT 0x8074 -#define GL_NORMAL_ARRAY_EXT 0x8075 -#define GL_COLOR_ARRAY_EXT 0x8076 -#define GL_INDEX_ARRAY_EXT 0x8077 -#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 -#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 -#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A -#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B -#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C -#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D -#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E -#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F -#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 -#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 -#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 -#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 -#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 -#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 -#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 -#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 -#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 -#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 -#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A -#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B -#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C -#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D -#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E -#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F -#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 -#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 -#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 -#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 -#endif - -#ifndef GL_EXT_misc_attribute -#endif - -#ifndef GL_SGIS_generate_mipmap -#define GL_GENERATE_MIPMAP_SGIS 0x8191 -#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 -#endif - -#ifndef GL_SGIX_clipmap -#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 -#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 -#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 -#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 -#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 -#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 -#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 -#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 -#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 -#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D -#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E -#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F -#endif - -#ifndef GL_SGIX_shadow -#define GL_TEXTURE_COMPARE_SGIX 0x819A -#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B -#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C -#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D -#endif - -#ifndef GL_SGIS_texture_edge_clamp -#define GL_CLAMP_TO_EDGE_SGIS 0x812F -#endif - -#ifndef GL_SGIS_texture_border_clamp -#define GL_CLAMP_TO_BORDER_SGIS 0x812D -#endif - -#ifndef GL_EXT_blend_minmax -#define GL_FUNC_ADD_EXT 0x8006 -#define GL_MIN_EXT 0x8007 -#define GL_MAX_EXT 0x8008 -#define GL_BLEND_EQUATION_EXT 0x8009 -#endif - -#ifndef GL_EXT_blend_subtract -#define GL_FUNC_SUBTRACT_EXT 0x800A -#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B -#endif - -#ifndef GL_EXT_blend_logic_op -#endif - -#ifndef GL_SGIX_interlace -#define GL_INTERLACE_SGIX 0x8094 -#endif - -#ifndef GL_SGIX_pixel_tiles -#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E -#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F -#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 -#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 -#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 -#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 -#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 -#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 -#endif - -#ifndef GL_SGIS_texture_select -#define GL_DUAL_ALPHA4_SGIS 0x8110 -#define GL_DUAL_ALPHA8_SGIS 0x8111 -#define GL_DUAL_ALPHA12_SGIS 0x8112 -#define GL_DUAL_ALPHA16_SGIS 0x8113 -#define GL_DUAL_LUMINANCE4_SGIS 0x8114 -#define GL_DUAL_LUMINANCE8_SGIS 0x8115 -#define GL_DUAL_LUMINANCE12_SGIS 0x8116 -#define GL_DUAL_LUMINANCE16_SGIS 0x8117 -#define GL_DUAL_INTENSITY4_SGIS 0x8118 -#define GL_DUAL_INTENSITY8_SGIS 0x8119 -#define GL_DUAL_INTENSITY12_SGIS 0x811A -#define GL_DUAL_INTENSITY16_SGIS 0x811B -#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C -#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D -#define GL_QUAD_ALPHA4_SGIS 0x811E -#define GL_QUAD_ALPHA8_SGIS 0x811F -#define GL_QUAD_LUMINANCE4_SGIS 0x8120 -#define GL_QUAD_LUMINANCE8_SGIS 0x8121 -#define GL_QUAD_INTENSITY4_SGIS 0x8122 -#define GL_QUAD_INTENSITY8_SGIS 0x8123 -#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 -#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 -#endif - -#ifndef GL_SGIX_sprite -#define GL_SPRITE_SGIX 0x8148 -#define GL_SPRITE_MODE_SGIX 0x8149 -#define GL_SPRITE_AXIS_SGIX 0x814A -#define GL_SPRITE_TRANSLATION_SGIX 0x814B -#define GL_SPRITE_AXIAL_SGIX 0x814C -#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D -#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E -#endif - -#ifndef GL_SGIX_texture_multi_buffer -#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E -#endif - -#ifndef GL_EXT_point_parameters -#define GL_POINT_SIZE_MIN_EXT 0x8126 -#define GL_POINT_SIZE_MAX_EXT 0x8127 -#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 -#define GL_DISTANCE_ATTENUATION_EXT 0x8129 -#endif - -#ifndef GL_SGIS_point_parameters -#define GL_POINT_SIZE_MIN_SGIS 0x8126 -#define GL_POINT_SIZE_MAX_SGIS 0x8127 -#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 -#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 -#endif - -#ifndef GL_SGIX_instruments -#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 -#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 -#endif - -#ifndef GL_SGIX_texture_scale_bias -#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 -#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A -#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B -#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C -#endif - -#ifndef GL_SGIX_framezoom -#define GL_FRAMEZOOM_SGIX 0x818B -#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C -#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D -#endif - -#ifndef GL_SGIX_tag_sample_buffer -#endif - -#ifndef GL_FfdMaskSGIX -#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 -#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 -#endif - -#ifndef GL_SGIX_polynomial_ffd -#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 -#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 -#define GL_DEFORMATIONS_MASK_SGIX 0x8196 -#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 -#endif - -#ifndef GL_SGIX_reference_plane -#define GL_REFERENCE_PLANE_SGIX 0x817D -#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E -#endif - -#ifndef GL_SGIX_flush_raster -#endif - -#ifndef GL_SGIX_depth_texture -#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 -#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 -#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 -#endif - -#ifndef GL_SGIS_fog_function -#define GL_FOG_FUNC_SGIS 0x812A -#define GL_FOG_FUNC_POINTS_SGIS 0x812B -#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C -#endif - -#ifndef GL_SGIX_fog_offset -#define GL_FOG_OFFSET_SGIX 0x8198 -#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 -#endif - -#ifndef GL_HP_image_transform -#define GL_IMAGE_SCALE_X_HP 0x8155 -#define GL_IMAGE_SCALE_Y_HP 0x8156 -#define GL_IMAGE_TRANSLATE_X_HP 0x8157 -#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 -#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 -#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A -#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B -#define GL_IMAGE_MAG_FILTER_HP 0x815C -#define GL_IMAGE_MIN_FILTER_HP 0x815D -#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E -#define GL_CUBIC_HP 0x815F -#define GL_AVERAGE_HP 0x8160 -#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 -#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 -#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 -#endif - -#ifndef GL_HP_convolution_border_modes -#define GL_IGNORE_BORDER_HP 0x8150 -#define GL_CONSTANT_BORDER_HP 0x8151 -#define GL_REPLICATE_BORDER_HP 0x8153 -#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 -#endif - -#ifndef GL_INGR_palette_buffer -#endif - -#ifndef GL_SGIX_texture_add_env -#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE -#endif - -#ifndef GL_EXT_color_subtable -#endif - -#ifndef GL_PGI_vertex_hints -#define GL_VERTEX_DATA_HINT_PGI 0x1A22A -#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B -#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C -#define GL_MAX_VERTEX_HINT_PGI 0x1A22D -#define GL_COLOR3_BIT_PGI 0x00010000 -#define GL_COLOR4_BIT_PGI 0x00020000 -#define GL_EDGEFLAG_BIT_PGI 0x00040000 -#define GL_INDEX_BIT_PGI 0x00080000 -#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 -#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 -#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 -#define GL_MAT_EMISSION_BIT_PGI 0x00800000 -#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 -#define GL_MAT_SHININESS_BIT_PGI 0x02000000 -#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 -#define GL_NORMAL_BIT_PGI 0x08000000 -#define GL_TEXCOORD1_BIT_PGI 0x10000000 -#define GL_TEXCOORD2_BIT_PGI 0x20000000 -#define GL_TEXCOORD3_BIT_PGI 0x40000000 -#define GL_TEXCOORD4_BIT_PGI 0x80000000 -#define GL_VERTEX23_BIT_PGI 0x00000004 -#define GL_VERTEX4_BIT_PGI 0x00000008 -#endif - -#ifndef GL_PGI_misc_hints -#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 -#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD -#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE -#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 -#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 -#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 -#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C -#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D -#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E -#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F -#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 -#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 -#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 -#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 -#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 -#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 -#define GL_CLIP_NEAR_HINT_PGI 0x1A220 -#define GL_CLIP_FAR_HINT_PGI 0x1A221 -#define GL_WIDE_LINE_HINT_PGI 0x1A222 -#define GL_BACK_NORMALS_HINT_PGI 0x1A223 -#endif - -#ifndef GL_EXT_paletted_texture -#define GL_COLOR_INDEX1_EXT 0x80E2 -#define GL_COLOR_INDEX2_EXT 0x80E3 -#define GL_COLOR_INDEX4_EXT 0x80E4 -#define GL_COLOR_INDEX8_EXT 0x80E5 -#define GL_COLOR_INDEX12_EXT 0x80E6 -#define GL_COLOR_INDEX16_EXT 0x80E7 -#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED -#endif - -#ifndef GL_EXT_clip_volume_hint -#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 -#endif - -#ifndef GL_SGIX_list_priority -#define GL_LIST_PRIORITY_SGIX 0x8182 -#endif - -#ifndef GL_SGIX_ir_instrument1 -#define GL_IR_INSTRUMENT1_SGIX 0x817F -#endif - -#ifndef GL_SGIX_calligraphic_fragment -#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 -#endif - -#ifndef GL_SGIX_texture_lod_bias -#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E -#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F -#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 -#endif - -#ifndef GL_SGIX_shadow_ambient -#define GL_SHADOW_AMBIENT_SGIX 0x80BF -#endif - -#ifndef GL_EXT_index_texture -#endif - -#ifndef GL_EXT_index_material -#define GL_INDEX_MATERIAL_EXT 0x81B8 -#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 -#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA -#endif - -#ifndef GL_EXT_index_func -#define GL_INDEX_TEST_EXT 0x81B5 -#define GL_INDEX_TEST_FUNC_EXT 0x81B6 -#define GL_INDEX_TEST_REF_EXT 0x81B7 -#endif - -#ifndef GL_EXT_index_array_formats -#define GL_IUI_V2F_EXT 0x81AD -#define GL_IUI_V3F_EXT 0x81AE -#define GL_IUI_N3F_V2F_EXT 0x81AF -#define GL_IUI_N3F_V3F_EXT 0x81B0 -#define GL_T2F_IUI_V2F_EXT 0x81B1 -#define GL_T2F_IUI_V3F_EXT 0x81B2 -#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 -#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 -#endif - -#ifndef GL_EXT_compiled_vertex_array -#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 -#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 -#endif - -#ifndef GL_EXT_cull_vertex -#define GL_CULL_VERTEX_EXT 0x81AA -#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB -#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC -#endif - -#ifndef GL_SGIX_ycrcb -#define GL_YCRCB_422_SGIX 0x81BB -#define GL_YCRCB_444_SGIX 0x81BC -#endif - -#ifndef GL_SGIX_fragment_lighting -#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 -#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 -#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 -#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 -#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 -#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 -#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 -#define GL_LIGHT_ENV_MODE_SGIX 0x8407 -#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 -#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 -#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A -#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B -#define GL_FRAGMENT_LIGHT0_SGIX 0x840C -#define GL_FRAGMENT_LIGHT1_SGIX 0x840D -#define GL_FRAGMENT_LIGHT2_SGIX 0x840E -#define GL_FRAGMENT_LIGHT3_SGIX 0x840F -#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 -#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 -#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 -#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 -#endif - -#ifndef GL_IBM_rasterpos_clip -#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 -#endif - -#ifndef GL_HP_texture_lighting -#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 -#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 -#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 -#endif - -#ifndef GL_EXT_draw_range_elements -#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 -#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 -#endif - -#ifndef GL_WIN_phong_shading -#define GL_PHONG_WIN 0x80EA -#define GL_PHONG_HINT_WIN 0x80EB -#endif - -#ifndef GL_WIN_specular_fog -#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC -#endif - -#ifndef GL_EXT_light_texture -#define GL_FRAGMENT_MATERIAL_EXT 0x8349 -#define GL_FRAGMENT_NORMAL_EXT 0x834A -#define GL_FRAGMENT_COLOR_EXT 0x834C -#define GL_ATTENUATION_EXT 0x834D -#define GL_SHADOW_ATTENUATION_EXT 0x834E -#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F -#define GL_TEXTURE_LIGHT_EXT 0x8350 -#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 -#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 -/* reuse GL_FRAGMENT_DEPTH_EXT */ -#endif - -#ifndef GL_SGIX_blend_alpha_minmax -#define GL_ALPHA_MIN_SGIX 0x8320 -#define GL_ALPHA_MAX_SGIX 0x8321 -#endif - -#ifndef GL_SGIX_impact_pixel_texture -#define GL_PIXEL_TEX_GEN_Q_CEILING_SGIX 0x8184 -#define GL_PIXEL_TEX_GEN_Q_ROUND_SGIX 0x8185 -#define GL_PIXEL_TEX_GEN_Q_FLOOR_SGIX 0x8186 -#define GL_PIXEL_TEX_GEN_ALPHA_REPLACE_SGIX 0x8187 -#define GL_PIXEL_TEX_GEN_ALPHA_NO_REPLACE_SGIX 0x8188 -#define GL_PIXEL_TEX_GEN_ALPHA_LS_SGIX 0x8189 -#define GL_PIXEL_TEX_GEN_ALPHA_MS_SGIX 0x818A -#endif - -#ifndef GL_EXT_bgra -#define GL_BGR_EXT 0x80E0 -#define GL_BGRA_EXT 0x80E1 -#endif - -#ifndef GL_SGIX_async -#define GL_ASYNC_MARKER_SGIX 0x8329 -#endif - -#ifndef GL_SGIX_async_pixel -#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C -#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D -#define GL_ASYNC_READ_PIXELS_SGIX 0x835E -#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F -#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 -#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 -#endif - -#ifndef GL_SGIX_async_histogram -#define GL_ASYNC_HISTOGRAM_SGIX 0x832C -#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D -#endif - -#ifndef GL_INTEL_texture_scissor -#endif - -#ifndef GL_INTEL_parallel_arrays -#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 -#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 -#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 -#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 -#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 -#endif - -#ifndef GL_HP_occlusion_test -#define GL_OCCLUSION_TEST_HP 0x8165 -#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 -#endif - -#ifndef GL_EXT_pixel_transform -#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 -#define GL_PIXEL_MAG_FILTER_EXT 0x8331 -#define GL_PIXEL_MIN_FILTER_EXT 0x8332 -#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 -#define GL_CUBIC_EXT 0x8334 -#define GL_AVERAGE_EXT 0x8335 -#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 -#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 -#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 -#endif - -#ifndef GL_EXT_pixel_transform_color_table -#endif - -#ifndef GL_EXT_shared_texture_palette -#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB -#endif - -#ifndef GL_EXT_separate_specular_color -#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 -#define GL_SINGLE_COLOR_EXT 0x81F9 -#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA -#endif - -#ifndef GL_EXT_secondary_color -#define GL_COLOR_SUM_EXT 0x8458 -#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 -#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A -#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B -#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C -#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D -#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E -#endif - -#ifndef GL_EXT_texture_perturb_normal -#define GL_PERTURB_EXT 0x85AE -#define GL_TEXTURE_NORMAL_EXT 0x85AF -#endif - -#ifndef GL_EXT_multi_draw_arrays -#endif - -#ifndef GL_EXT_fog_coord -#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 -#define GL_FOG_COORDINATE_EXT 0x8451 -#define GL_FRAGMENT_DEPTH_EXT 0x8452 -#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 -#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 -#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 -#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 -#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 -#endif - -#ifndef GL_REND_screen_coordinates -#define GL_SCREEN_COORDINATES_REND 0x8490 -#define GL_INVERTED_SCREEN_W_REND 0x8491 -#endif - -#ifndef GL_EXT_coordinate_frame -#define GL_TANGENT_ARRAY_EXT 0x8439 -#define GL_BINORMAL_ARRAY_EXT 0x843A -#define GL_CURRENT_TANGENT_EXT 0x843B -#define GL_CURRENT_BINORMAL_EXT 0x843C -#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E -#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F -#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 -#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 -#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 -#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 -#define GL_MAP1_TANGENT_EXT 0x8444 -#define GL_MAP2_TANGENT_EXT 0x8445 -#define GL_MAP1_BINORMAL_EXT 0x8446 -#define GL_MAP2_BINORMAL_EXT 0x8447 -#endif - -#ifndef GL_EXT_texture_env_combine -#define GL_COMBINE_EXT 0x8570 -#define GL_COMBINE_RGB_EXT 0x8571 -#define GL_COMBINE_ALPHA_EXT 0x8572 -#define GL_RGB_SCALE_EXT 0x8573 -#define GL_ADD_SIGNED_EXT 0x8574 -#define GL_INTERPOLATE_EXT 0x8575 -#define GL_CONSTANT_EXT 0x8576 -#define GL_PRIMARY_COLOR_EXT 0x8577 -#define GL_PREVIOUS_EXT 0x8578 -#define GL_SOURCE0_RGB_EXT 0x8580 -#define GL_SOURCE1_RGB_EXT 0x8581 -#define GL_SOURCE2_RGB_EXT 0x8582 -#define GL_SOURCE0_ALPHA_EXT 0x8588 -#define GL_SOURCE1_ALPHA_EXT 0x8589 -#define GL_SOURCE2_ALPHA_EXT 0x858A -#define GL_OPERAND0_RGB_EXT 0x8590 -#define GL_OPERAND1_RGB_EXT 0x8591 -#define GL_OPERAND2_RGB_EXT 0x8592 -#define GL_OPERAND0_ALPHA_EXT 0x8598 -#define GL_OPERAND1_ALPHA_EXT 0x8599 -#define GL_OPERAND2_ALPHA_EXT 0x859A -#endif - -#ifndef GL_APPLE_specular_vector -#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 -#endif - -#ifndef GL_APPLE_transform_hint -#define GL_TRANSFORM_HINT_APPLE 0x85B1 -#endif - -#ifndef GL_SGIX_fog_scale -#define GL_FOG_SCALE_SGIX 0x81FC -#define GL_FOG_SCALE_VALUE_SGIX 0x81FD -#endif - -#ifndef GL_SUNX_constant_data -#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 -#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 -#endif - -#ifndef GL_SUN_global_alpha -#define GL_GLOBAL_ALPHA_SUN 0x81D9 -#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA -#endif - -#ifndef GL_SUN_triangle_list -#define GL_RESTART_SUN 0x0001 -#define GL_REPLACE_MIDDLE_SUN 0x0002 -#define GL_REPLACE_OLDEST_SUN 0x0003 -#define GL_TRIANGLE_LIST_SUN 0x81D7 -#define GL_REPLACEMENT_CODE_SUN 0x81D8 -#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 -#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 -#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 -#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 -#define GL_R1UI_V3F_SUN 0x85C4 -#define GL_R1UI_C4UB_V3F_SUN 0x85C5 -#define GL_R1UI_C3F_V3F_SUN 0x85C6 -#define GL_R1UI_N3F_V3F_SUN 0x85C7 -#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 -#define GL_R1UI_T2F_V3F_SUN 0x85C9 -#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA -#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB -#endif - -#ifndef GL_SUN_vertex -#endif - -#ifndef GL_EXT_blend_func_separate -#define GL_BLEND_DST_RGB_EXT 0x80C8 -#define GL_BLEND_SRC_RGB_EXT 0x80C9 -#define GL_BLEND_DST_ALPHA_EXT 0x80CA -#define GL_BLEND_SRC_ALPHA_EXT 0x80CB -#endif - -#ifndef GL_INGR_color_clamp -#define GL_RED_MIN_CLAMP_INGR 0x8560 -#define GL_GREEN_MIN_CLAMP_INGR 0x8561 -#define GL_BLUE_MIN_CLAMP_INGR 0x8562 -#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 -#define GL_RED_MAX_CLAMP_INGR 0x8564 -#define GL_GREEN_MAX_CLAMP_INGR 0x8565 -#define GL_BLUE_MAX_CLAMP_INGR 0x8566 -#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 -#endif - -#ifndef GL_INGR_interlace_read -#define GL_INTERLACE_READ_INGR 0x8568 -#endif - -#ifndef GL_EXT_stencil_wrap -#define GL_INCR_WRAP_EXT 0x8507 -#define GL_DECR_WRAP_EXT 0x8508 -#endif - -#ifndef GL_EXT_422_pixels -#define GL_422_EXT 0x80CC -#define GL_422_REV_EXT 0x80CD -#define GL_422_AVERAGE_EXT 0x80CE -#define GL_422_REV_AVERAGE_EXT 0x80CF -#endif - -#ifndef GL_NV_texgen_reflection -#define GL_NORMAL_MAP_NV 0x8511 -#define GL_REFLECTION_MAP_NV 0x8512 -#endif - -#ifndef GL_EXT_texture_cube_map -#define GL_NORMAL_MAP_EXT 0x8511 -#define GL_REFLECTION_MAP_EXT 0x8512 -#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 -#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A -#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B -#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C -#endif - -#ifndef GL_SUN_convolution_border_modes -#define GL_WRAP_BORDER_SUN 0x81D4 -#endif - -#ifndef GL_EXT_texture_env_add -#endif - -#ifndef GL_EXT_texture_lod_bias -#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD -#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 -#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 -#endif - -#ifndef GL_EXT_texture_filter_anisotropic -#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE -#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF -#endif - -#ifndef GL_EXT_vertex_weighting -#define GL_MODELVIEW0_STACK_DEPTH_EXT GL_MODELVIEW_STACK_DEPTH -#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 -#define GL_MODELVIEW0_MATRIX_EXT GL_MODELVIEW_MATRIX -#define GL_MODELVIEW1_MATRIX_EXT 0x8506 -#define GL_VERTEX_WEIGHTING_EXT 0x8509 -#define GL_MODELVIEW0_EXT GL_MODELVIEW -#define GL_MODELVIEW1_EXT 0x850A -#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B -#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C -#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D -#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E -#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F -#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 -#endif - -#ifndef GL_NV_light_max_exponent -#define GL_MAX_SHININESS_NV 0x8504 -#define GL_MAX_SPOT_EXPONENT_NV 0x8505 -#endif - -#ifndef GL_NV_vertex_array_range -#define GL_VERTEX_ARRAY_RANGE_NV 0x851D -#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E -#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F -#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 -#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 -#endif - -#ifndef GL_NV_register_combiners -#define GL_REGISTER_COMBINERS_NV 0x8522 -#define GL_VARIABLE_A_NV 0x8523 -#define GL_VARIABLE_B_NV 0x8524 -#define GL_VARIABLE_C_NV 0x8525 -#define GL_VARIABLE_D_NV 0x8526 -#define GL_VARIABLE_E_NV 0x8527 -#define GL_VARIABLE_F_NV 0x8528 -#define GL_VARIABLE_G_NV 0x8529 -#define GL_CONSTANT_COLOR0_NV 0x852A -#define GL_CONSTANT_COLOR1_NV 0x852B -#define GL_PRIMARY_COLOR_NV 0x852C -#define GL_SECONDARY_COLOR_NV 0x852D -#define GL_SPARE0_NV 0x852E -#define GL_SPARE1_NV 0x852F -#define GL_DISCARD_NV 0x8530 -#define GL_E_TIMES_F_NV 0x8531 -#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 -#define GL_UNSIGNED_IDENTITY_NV 0x8536 -#define GL_UNSIGNED_INVERT_NV 0x8537 -#define GL_EXPAND_NORMAL_NV 0x8538 -#define GL_EXPAND_NEGATE_NV 0x8539 -#define GL_HALF_BIAS_NORMAL_NV 0x853A -#define GL_HALF_BIAS_NEGATE_NV 0x853B -#define GL_SIGNED_IDENTITY_NV 0x853C -#define GL_SIGNED_NEGATE_NV 0x853D -#define GL_SCALE_BY_TWO_NV 0x853E -#define GL_SCALE_BY_FOUR_NV 0x853F -#define GL_SCALE_BY_ONE_HALF_NV 0x8540 -#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 -#define GL_COMBINER_INPUT_NV 0x8542 -#define GL_COMBINER_MAPPING_NV 0x8543 -#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 -#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 -#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 -#define GL_COMBINER_MUX_SUM_NV 0x8547 -#define GL_COMBINER_SCALE_NV 0x8548 -#define GL_COMBINER_BIAS_NV 0x8549 -#define GL_COMBINER_AB_OUTPUT_NV 0x854A -#define GL_COMBINER_CD_OUTPUT_NV 0x854B -#define GL_COMBINER_SUM_OUTPUT_NV 0x854C -#define GL_MAX_GENERAL_COMBINERS_NV 0x854D -#define GL_NUM_GENERAL_COMBINERS_NV 0x854E -#define GL_COLOR_SUM_CLAMP_NV 0x854F -#define GL_COMBINER0_NV 0x8550 -#define GL_COMBINER1_NV 0x8551 -#define GL_COMBINER2_NV 0x8552 -#define GL_COMBINER3_NV 0x8553 -#define GL_COMBINER4_NV 0x8554 -#define GL_COMBINER5_NV 0x8555 -#define GL_COMBINER6_NV 0x8556 -#define GL_COMBINER7_NV 0x8557 -/* reuse GL_TEXTURE0_ARB */ -/* reuse GL_TEXTURE1_ARB */ -/* reuse GL_ZERO */ -/* reuse GL_NONE */ -/* reuse GL_FOG */ -#endif - -#ifndef GL_NV_fog_distance -#define GL_FOG_DISTANCE_MODE_NV 0x855A -#define GL_EYE_RADIAL_NV 0x855B -#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C -/* reuse GL_EYE_PLANE */ -#endif - -#ifndef GL_NV_texgen_emboss -#define GL_EMBOSS_LIGHT_NV 0x855D -#define GL_EMBOSS_CONSTANT_NV 0x855E -#define GL_EMBOSS_MAP_NV 0x855F -#endif - -#ifndef GL_NV_blend_square -#endif - -#ifndef GL_NV_texture_env_combine4 -#define GL_COMBINE4_NV 0x8503 -#define GL_SOURCE3_RGB_NV 0x8583 -#define GL_SOURCE3_ALPHA_NV 0x858B -#define GL_OPERAND3_RGB_NV 0x8593 -#define GL_OPERAND3_ALPHA_NV 0x859B -#endif - -#ifndef GL_MESA_resize_buffers -#endif - -#ifndef GL_MESA_window_pos -#endif - -#ifndef GL_EXT_texture_compression_s3tc -#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 -#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 -#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 -#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 -#endif - -#ifndef GL_IBM_cull_vertex -#define GL_CULL_VERTEX_IBM 103050 -#endif - -#ifndef GL_IBM_multimode_draw_arrays -#endif - -#ifndef GL_IBM_vertex_array_lists -#define GL_VERTEX_ARRAY_LIST_IBM 103070 -#define GL_NORMAL_ARRAY_LIST_IBM 103071 -#define GL_COLOR_ARRAY_LIST_IBM 103072 -#define GL_INDEX_ARRAY_LIST_IBM 103073 -#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 -#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 -#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 -#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 -#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 -#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 -#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 -#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 -#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 -#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 -#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 -#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 -#endif - -#ifndef GL_SGIX_subsample -#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 -#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 -#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 -#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 -#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 -#endif - -#ifndef GL_SGIX_ycrcb_subsample -#endif - -#ifndef GL_SGIX_ycrcba -#define GL_YCRCB_SGIX 0x8318 -#define GL_YCRCBA_SGIX 0x8319 -#endif - -#ifndef GL_SGI_depth_pass_instrument -#define GL_DEPTH_PASS_INSTRUMENT_SGIX 0x8310 -#define GL_DEPTH_PASS_INSTRUMENT_COUNTERS_SGIX 0x8311 -#define GL_DEPTH_PASS_INSTRUMENT_MAX_SGIX 0x8312 -#endif - -#ifndef GL_3DFX_texture_compression_FXT1 -#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 -#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 -#endif - -#ifndef GL_3DFX_multisample -#define GL_MULTISAMPLE_3DFX 0x86B2 -#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 -#define GL_SAMPLES_3DFX 0x86B4 -#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 -#endif - -#ifndef GL_3DFX_tbuffer -#endif - -#ifndef GL_EXT_multisample -#define GL_MULTISAMPLE_EXT 0x809D -#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F -#define GL_SAMPLE_MASK_EXT 0x80A0 -#define GL_1PASS_EXT 0x80A1 -#define GL_2PASS_0_EXT 0x80A2 -#define GL_2PASS_1_EXT 0x80A3 -#define GL_4PASS_0_EXT 0x80A4 -#define GL_4PASS_1_EXT 0x80A5 -#define GL_4PASS_2_EXT 0x80A6 -#define GL_4PASS_3_EXT 0x80A7 -#define GL_SAMPLE_BUFFERS_EXT 0x80A8 -#define GL_SAMPLES_EXT 0x80A9 -#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA -#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB -#define GL_SAMPLE_PATTERN_EXT 0x80AC -#define GL_MULTISAMPLE_BIT_EXT 0x20000000 -#endif - -#ifndef GL_SGIX_vertex_preclip -#define GL_VERTEX_PRECLIP_SGIX 0x83EE -#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF -#endif - -#ifndef GL_SGIX_convolution_accuracy -#define GL_CONVOLUTION_HINT_SGIX 0x8316 -#endif - -#ifndef GL_SGIX_resample -#define GL_PACK_RESAMPLE_SGIX 0x842C -#define GL_UNPACK_RESAMPLE_SGIX 0x842D -#define GL_RESAMPLE_REPLICATE_SGIX 0x842E -#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F -#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 -#endif - -#ifndef GL_SGIS_point_line_texgen -#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 -#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 -#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 -#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 -#define GL_EYE_POINT_SGIS 0x81F4 -#define GL_OBJECT_POINT_SGIS 0x81F5 -#define GL_EYE_LINE_SGIS 0x81F6 -#define GL_OBJECT_LINE_SGIS 0x81F7 -#endif - -#ifndef GL_SGIS_texture_color_mask -#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF -#endif - -#ifndef GL_EXT_texture_env_dot3 -#define GL_DOT3_RGB_EXT 0x8740 -#define GL_DOT3_RGBA_EXT 0x8741 -#endif - -#ifndef GL_ATI_texture_mirror_once -#define GL_MIRROR_CLAMP_ATI 0x8742 -#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 -#endif - -#ifndef GL_NV_fence -#define GL_ALL_COMPLETED_NV 0x84F2 -#define GL_FENCE_STATUS_NV 0x84F3 -#define GL_FENCE_CONDITION_NV 0x84F4 -#endif - -#ifndef GL_IBM_texture_mirrored_repeat -#define GL_MIRRORED_REPEAT_IBM 0x8370 -#endif - -#ifndef GL_NV_evaluators -#define GL_EVAL_2D_NV 0x86C0 -#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 -#define GL_MAP_TESSELLATION_NV 0x86C2 -#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 -#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 -#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 -#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 -#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 -#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 -#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 -#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA -#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB -#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC -#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD -#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE -#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF -#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 -#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 -#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 -#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 -#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 -#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 -#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 -#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 -#endif - -#ifndef GL_NV_packed_depth_stencil -#define GL_DEPTH_STENCIL_NV 0x84F9 -#define GL_UNSIGNED_INT_24_8_NV 0x84FA -#endif - -#ifndef GL_NV_register_combiners2 -#define GL_PER_STAGE_CONSTANTS_NV 0x8535 -#endif - -#ifndef GL_NV_texture_compression_vtc -#endif - -#ifndef GL_NV_texture_rectangle -#define GL_TEXTURE_RECTANGLE_NV 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 -#endif - -#ifndef GL_NV_texture_shader -#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C -#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D -#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E -#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 -#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA -#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB -#define GL_DSDT_MAG_INTENSITY_NV 0x86DC -#define GL_SHADER_CONSISTENT_NV 0x86DD -#define GL_TEXTURE_SHADER_NV 0x86DE -#define GL_SHADER_OPERATION_NV 0x86DF -#define GL_CULL_MODES_NV 0x86E0 -#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 -#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 -#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 -#define GL_OFFSET_TEXTURE_2D_MATRIX_NV GL_OFFSET_TEXTURE_MATRIX_NV -#define GL_OFFSET_TEXTURE_2D_SCALE_NV GL_OFFSET_TEXTURE_SCALE_NV -#define GL_OFFSET_TEXTURE_2D_BIAS_NV GL_OFFSET_TEXTURE_BIAS_NV -#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 -#define GL_CONST_EYE_NV 0x86E5 -#define GL_PASS_THROUGH_NV 0x86E6 -#define GL_CULL_FRAGMENT_NV 0x86E7 -#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 -#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 -#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA -#define GL_DOT_PRODUCT_NV 0x86EC -#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED -#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE -#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 -#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 -#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 -#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 -#define GL_HILO_NV 0x86F4 -#define GL_DSDT_NV 0x86F5 -#define GL_DSDT_MAG_NV 0x86F6 -#define GL_DSDT_MAG_VIB_NV 0x86F7 -#define GL_HILO16_NV 0x86F8 -#define GL_SIGNED_HILO_NV 0x86F9 -#define GL_SIGNED_HILO16_NV 0x86FA -#define GL_SIGNED_RGBA_NV 0x86FB -#define GL_SIGNED_RGBA8_NV 0x86FC -#define GL_SIGNED_RGB_NV 0x86FE -#define GL_SIGNED_RGB8_NV 0x86FF -#define GL_SIGNED_LUMINANCE_NV 0x8701 -#define GL_SIGNED_LUMINANCE8_NV 0x8702 -#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 -#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 -#define GL_SIGNED_ALPHA_NV 0x8705 -#define GL_SIGNED_ALPHA8_NV 0x8706 -#define GL_SIGNED_INTENSITY_NV 0x8707 -#define GL_SIGNED_INTENSITY8_NV 0x8708 -#define GL_DSDT8_NV 0x8709 -#define GL_DSDT8_MAG8_NV 0x870A -#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B -#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C -#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D -#define GL_HI_SCALE_NV 0x870E -#define GL_LO_SCALE_NV 0x870F -#define GL_DS_SCALE_NV 0x8710 -#define GL_DT_SCALE_NV 0x8711 -#define GL_MAGNITUDE_SCALE_NV 0x8712 -#define GL_VIBRANCE_SCALE_NV 0x8713 -#define GL_HI_BIAS_NV 0x8714 -#define GL_LO_BIAS_NV 0x8715 -#define GL_DS_BIAS_NV 0x8716 -#define GL_DT_BIAS_NV 0x8717 -#define GL_MAGNITUDE_BIAS_NV 0x8718 -#define GL_VIBRANCE_BIAS_NV 0x8719 -#define GL_TEXTURE_BORDER_VALUES_NV 0x871A -#define GL_TEXTURE_HI_SIZE_NV 0x871B -#define GL_TEXTURE_LO_SIZE_NV 0x871C -#define GL_TEXTURE_DS_SIZE_NV 0x871D -#define GL_TEXTURE_DT_SIZE_NV 0x871E -#define GL_TEXTURE_MAG_SIZE_NV 0x871F -#endif - -#ifndef GL_NV_texture_shader2 -#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF -#endif - -#ifndef GL_NV_vertex_array_range2 -#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 -#endif - -#ifndef GL_NV_vertex_program -#define GL_VERTEX_PROGRAM_NV 0x8620 -#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 -#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 -#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 -#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 -#define GL_CURRENT_ATTRIB_NV 0x8626 -#define GL_PROGRAM_LENGTH_NV 0x8627 -#define GL_PROGRAM_STRING_NV 0x8628 -#define GL_MODELVIEW_PROJECTION_NV 0x8629 -#define GL_IDENTITY_NV 0x862A -#define GL_INVERSE_NV 0x862B -#define GL_TRANSPOSE_NV 0x862C -#define GL_INVERSE_TRANSPOSE_NV 0x862D -#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E -#define GL_MAX_TRACK_MATRICES_NV 0x862F -#define GL_MATRIX0_NV 0x8630 -#define GL_MATRIX1_NV 0x8631 -#define GL_MATRIX2_NV 0x8632 -#define GL_MATRIX3_NV 0x8633 -#define GL_MATRIX4_NV 0x8634 -#define GL_MATRIX5_NV 0x8635 -#define GL_MATRIX6_NV 0x8636 -#define GL_MATRIX7_NV 0x8637 -#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 -#define GL_CURRENT_MATRIX_NV 0x8641 -#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 -#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 -#define GL_PROGRAM_PARAMETER_NV 0x8644 -#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 -#define GL_PROGRAM_TARGET_NV 0x8646 -#define GL_PROGRAM_RESIDENT_NV 0x8647 -#define GL_TRACK_MATRIX_NV 0x8648 -#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 -#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A -#define GL_PROGRAM_ERROR_POSITION_NV 0x864B -#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 -#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 -#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 -#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 -#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 -#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 -#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 -#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 -#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 -#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 -#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A -#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B -#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C -#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D -#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E -#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F -#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 -#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 -#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 -#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 -#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 -#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 -#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 -#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 -#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 -#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 -#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A -#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B -#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C -#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D -#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E -#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F -#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 -#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 -#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 -#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 -#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 -#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 -#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 -#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 -#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 -#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 -#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A -#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B -#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C -#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D -#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E -#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F -#endif - -#ifndef GL_SGIX_texture_coordinate_clamp -#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 -#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A -#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B -#endif - -#ifndef GL_SGIX_scalebias_hint -#define GL_SCALEBIAS_HINT_SGIX 0x8322 -#endif - -#ifndef GL_OML_interlace -#define GL_INTERLACE_OML 0x8980 -#define GL_INTERLACE_READ_OML 0x8981 -#endif - -#ifndef GL_OML_subsample -#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 -#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 -#endif - -#ifndef GL_OML_resample -#define GL_PACK_RESAMPLE_OML 0x8984 -#define GL_UNPACK_RESAMPLE_OML 0x8985 -#define GL_RESAMPLE_REPLICATE_OML 0x8986 -#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 -#define GL_RESAMPLE_AVERAGE_OML 0x8988 -#define GL_RESAMPLE_DECIMATE_OML 0x8989 -#endif - -#ifndef GL_NV_copy_depth_to_color -#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E -#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F -#endif - -#ifndef GL_ATI_envmap_bumpmap -#define GL_BUMP_ROT_MATRIX_ATI 0x8775 -#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 -#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 -#define GL_BUMP_TEX_UNITS_ATI 0x8778 -#define GL_DUDV_ATI 0x8779 -#define GL_DU8DV8_ATI 0x877A -#define GL_BUMP_ENVMAP_ATI 0x877B -#define GL_BUMP_TARGET_ATI 0x877C -#endif - -#ifndef GL_ATI_fragment_shader -#define GL_FRAGMENT_SHADER_ATI 0x8920 -#define GL_REG_0_ATI 0x8921 -#define GL_REG_1_ATI 0x8922 -#define GL_REG_2_ATI 0x8923 -#define GL_REG_3_ATI 0x8924 -#define GL_REG_4_ATI 0x8925 -#define GL_REG_5_ATI 0x8926 -#define GL_REG_6_ATI 0x8927 -#define GL_REG_7_ATI 0x8928 -#define GL_REG_8_ATI 0x8929 -#define GL_REG_9_ATI 0x892A -#define GL_REG_10_ATI 0x892B -#define GL_REG_11_ATI 0x892C -#define GL_REG_12_ATI 0x892D -#define GL_REG_13_ATI 0x892E -#define GL_REG_14_ATI 0x892F -#define GL_REG_15_ATI 0x8930 -#define GL_REG_16_ATI 0x8931 -#define GL_REG_17_ATI 0x8932 -#define GL_REG_18_ATI 0x8933 -#define GL_REG_19_ATI 0x8934 -#define GL_REG_20_ATI 0x8935 -#define GL_REG_21_ATI 0x8936 -#define GL_REG_22_ATI 0x8937 -#define GL_REG_23_ATI 0x8938 -#define GL_REG_24_ATI 0x8939 -#define GL_REG_25_ATI 0x893A -#define GL_REG_26_ATI 0x893B -#define GL_REG_27_ATI 0x893C -#define GL_REG_28_ATI 0x893D -#define GL_REG_29_ATI 0x893E -#define GL_REG_30_ATI 0x893F -#define GL_REG_31_ATI 0x8940 -#define GL_CON_0_ATI 0x8941 -#define GL_CON_1_ATI 0x8942 -#define GL_CON_2_ATI 0x8943 -#define GL_CON_3_ATI 0x8944 -#define GL_CON_4_ATI 0x8945 -#define GL_CON_5_ATI 0x8946 -#define GL_CON_6_ATI 0x8947 -#define GL_CON_7_ATI 0x8948 -#define GL_CON_8_ATI 0x8949 -#define GL_CON_9_ATI 0x894A -#define GL_CON_10_ATI 0x894B -#define GL_CON_11_ATI 0x894C -#define GL_CON_12_ATI 0x894D -#define GL_CON_13_ATI 0x894E -#define GL_CON_14_ATI 0x894F -#define GL_CON_15_ATI 0x8950 -#define GL_CON_16_ATI 0x8951 -#define GL_CON_17_ATI 0x8952 -#define GL_CON_18_ATI 0x8953 -#define GL_CON_19_ATI 0x8954 -#define GL_CON_20_ATI 0x8955 -#define GL_CON_21_ATI 0x8956 -#define GL_CON_22_ATI 0x8957 -#define GL_CON_23_ATI 0x8958 -#define GL_CON_24_ATI 0x8959 -#define GL_CON_25_ATI 0x895A -#define GL_CON_26_ATI 0x895B -#define GL_CON_27_ATI 0x895C -#define GL_CON_28_ATI 0x895D -#define GL_CON_29_ATI 0x895E -#define GL_CON_30_ATI 0x895F -#define GL_CON_31_ATI 0x8960 -#define GL_MOV_ATI 0x8961 -#define GL_ADD_ATI 0x8963 -#define GL_MUL_ATI 0x8964 -#define GL_SUB_ATI 0x8965 -#define GL_DOT3_ATI 0x8966 -#define GL_DOT4_ATI 0x8967 -#define GL_MAD_ATI 0x8968 -#define GL_LERP_ATI 0x8969 -#define GL_CND_ATI 0x896A -#define GL_CND0_ATI 0x896B -#define GL_DOT2_ADD_ATI 0x896C -#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D -#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E -#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F -#define GL_NUM_PASSES_ATI 0x8970 -#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 -#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 -#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 -#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 -#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 -#define GL_SWIZZLE_STR_ATI 0x8976 -#define GL_SWIZZLE_STQ_ATI 0x8977 -#define GL_SWIZZLE_STR_DR_ATI 0x8978 -#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 -#define GL_SWIZZLE_STRQ_ATI 0x897A -#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B -#define GL_RED_BIT_ATI 0x00000001 -#define GL_GREEN_BIT_ATI 0x00000002 -#define GL_BLUE_BIT_ATI 0x00000004 -#define GL_2X_BIT_ATI 0x00000001 -#define GL_4X_BIT_ATI 0x00000002 -#define GL_8X_BIT_ATI 0x00000004 -#define GL_HALF_BIT_ATI 0x00000008 -#define GL_QUARTER_BIT_ATI 0x00000010 -#define GL_EIGHTH_BIT_ATI 0x00000020 -#define GL_SATURATE_BIT_ATI 0x00000040 -#define GL_COMP_BIT_ATI 0x00000002 -#define GL_NEGATE_BIT_ATI 0x00000004 -#define GL_BIAS_BIT_ATI 0x00000008 -#endif - -#ifndef GL_ATI_pn_triangles -#define GL_PN_TRIANGLES_ATI 0x87F0 -#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 -#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 -#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 -#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 -#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 -#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 -#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 -#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 -#endif - -#ifndef GL_ATI_vertex_array_object -#define GL_STATIC_ATI 0x8760 -#define GL_DYNAMIC_ATI 0x8761 -#define GL_PRESERVE_ATI 0x8762 -#define GL_DISCARD_ATI 0x8763 -#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 -#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 -#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 -#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 -#endif - -#ifndef GL_EXT_vertex_shader -#define GL_VERTEX_SHADER_EXT 0x8780 -#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 -#define GL_OP_INDEX_EXT 0x8782 -#define GL_OP_NEGATE_EXT 0x8783 -#define GL_OP_DOT3_EXT 0x8784 -#define GL_OP_DOT4_EXT 0x8785 -#define GL_OP_MUL_EXT 0x8786 -#define GL_OP_ADD_EXT 0x8787 -#define GL_OP_MADD_EXT 0x8788 -#define GL_OP_FRAC_EXT 0x8789 -#define GL_OP_MAX_EXT 0x878A -#define GL_OP_MIN_EXT 0x878B -#define GL_OP_SET_GE_EXT 0x878C -#define GL_OP_SET_LT_EXT 0x878D -#define GL_OP_CLAMP_EXT 0x878E -#define GL_OP_FLOOR_EXT 0x878F -#define GL_OP_ROUND_EXT 0x8790 -#define GL_OP_EXP_BASE_2_EXT 0x8791 -#define GL_OP_LOG_BASE_2_EXT 0x8792 -#define GL_OP_POWER_EXT 0x8793 -#define GL_OP_RECIP_EXT 0x8794 -#define GL_OP_RECIP_SQRT_EXT 0x8795 -#define GL_OP_SUB_EXT 0x8796 -#define GL_OP_CROSS_PRODUCT_EXT 0x8797 -#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 -#define GL_OP_MOV_EXT 0x8799 -#define GL_OUTPUT_VERTEX_EXT 0x879A -#define GL_OUTPUT_COLOR0_EXT 0x879B -#define GL_OUTPUT_COLOR1_EXT 0x879C -#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D -#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E -#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F -#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 -#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 -#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 -#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 -#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 -#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 -#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 -#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 -#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 -#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 -#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA -#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB -#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC -#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD -#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE -#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF -#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 -#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 -#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 -#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 -#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 -#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 -#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 -#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 -#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 -#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 -#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA -#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB -#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC -#define GL_OUTPUT_FOG_EXT 0x87BD -#define GL_SCALAR_EXT 0x87BE -#define GL_VECTOR_EXT 0x87BF -#define GL_MATRIX_EXT 0x87C0 -#define GL_VARIANT_EXT 0x87C1 -#define GL_INVARIANT_EXT 0x87C2 -#define GL_LOCAL_CONSTANT_EXT 0x87C3 -#define GL_LOCAL_EXT 0x87C4 -#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 -#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 -#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 -#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 -#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 -#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA -#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB -#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC -#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD -#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE -#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF -#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 -#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 -#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 -#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 -#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 -#define GL_X_EXT 0x87D5 -#define GL_Y_EXT 0x87D6 -#define GL_Z_EXT 0x87D7 -#define GL_W_EXT 0x87D8 -#define GL_NEGATIVE_X_EXT 0x87D9 -#define GL_NEGATIVE_Y_EXT 0x87DA -#define GL_NEGATIVE_Z_EXT 0x87DB -#define GL_NEGATIVE_W_EXT 0x87DC -#define GL_ZERO_EXT 0x87DD -#define GL_ONE_EXT 0x87DE -#define GL_NEGATIVE_ONE_EXT 0x87DF -#define GL_NORMALIZED_RANGE_EXT 0x87E0 -#define GL_FULL_RANGE_EXT 0x87E1 -#define GL_CURRENT_VERTEX_EXT 0x87E2 -#define GL_MVP_MATRIX_EXT 0x87E3 -#define GL_VARIANT_VALUE_EXT 0x87E4 -#define GL_VARIANT_DATATYPE_EXT 0x87E5 -#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 -#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 -#define GL_VARIANT_ARRAY_EXT 0x87E8 -#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 -#define GL_INVARIANT_VALUE_EXT 0x87EA -#define GL_INVARIANT_DATATYPE_EXT 0x87EB -#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC -#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED -#endif - -#ifndef GL_ATI_vertex_streams -#define GL_MAX_VERTEX_STREAMS_ATI 0x876B -#define GL_VERTEX_STREAM0_ATI 0x876C -#define GL_VERTEX_STREAM1_ATI 0x876D -#define GL_VERTEX_STREAM2_ATI 0x876E -#define GL_VERTEX_STREAM3_ATI 0x876F -#define GL_VERTEX_STREAM4_ATI 0x8770 -#define GL_VERTEX_STREAM5_ATI 0x8771 -#define GL_VERTEX_STREAM6_ATI 0x8772 -#define GL_VERTEX_STREAM7_ATI 0x8773 -#define GL_VERTEX_SOURCE_ATI 0x8774 -#endif - -#ifndef GL_ATI_element_array -#define GL_ELEMENT_ARRAY_ATI 0x8768 -#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 -#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A -#endif - -#ifndef GL_SUN_mesh_array -#define GL_QUAD_MESH_SUN 0x8614 -#define GL_TRIANGLE_MESH_SUN 0x8615 -#endif - -#ifndef GL_SUN_slice_accum -#define GL_SLICE_ACCUM_SUN 0x85CC -#endif - -#ifndef GL_NV_multisample_filter_hint -#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 -#endif - -#ifndef GL_NV_depth_clamp -#define GL_DEPTH_CLAMP_NV 0x864F -#endif - -#ifndef GL_NV_occlusion_query -#define GL_PIXEL_COUNTER_BITS_NV 0x8864 -#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 -#define GL_PIXEL_COUNT_NV 0x8866 -#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 -#endif - -#ifndef GL_NV_point_sprite -#define GL_POINT_SPRITE_NV 0x8861 -#define GL_COORD_REPLACE_NV 0x8862 -#define GL_POINT_SPRITE_R_MODE_NV 0x8863 -#endif - -#ifndef GL_NV_texture_shader3 -#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 -#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 -#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 -#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 -#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 -#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 -#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 -#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 -#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 -#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 -#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A -#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B -#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C -#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D -#define GL_HILO8_NV 0x885E -#define GL_SIGNED_HILO8_NV 0x885F -#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 -#endif - -#ifndef GL_NV_vertex_program1_1 -#endif - -#ifndef GL_EXT_shadow_funcs -#endif - -#ifndef GL_EXT_stencil_two_side -#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 -#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 -#endif - -#ifndef GL_ATI_text_fragment_shader -#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 -#endif - -#ifndef GL_APPLE_client_storage -#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 -#endif - -#ifndef GL_APPLE_element_array -#define GL_ELEMENT_ARRAY_APPLE 0x8A0C -#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D -#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E -#endif - -#ifndef GL_APPLE_fence -#define GL_DRAW_PIXELS_APPLE 0x8A0A -#define GL_FENCE_APPLE 0x8A0B -#endif - -#ifndef GL_APPLE_vertex_array_object -#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 -#endif - -#ifndef GL_APPLE_vertex_array_range -#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D -#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E -#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F -#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 -#define GL_STORAGE_CLIENT_APPLE 0x85B4 -#define GL_STORAGE_CACHED_APPLE 0x85BE -#define GL_STORAGE_SHARED_APPLE 0x85BF -#endif - -#ifndef GL_APPLE_ycbcr_422 -#define GL_YCBCR_422_APPLE 0x85B9 -#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA -#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB -#endif - -#ifndef GL_S3_s3tc -#define GL_RGB_S3TC 0x83A0 -#define GL_RGB4_S3TC 0x83A1 -#define GL_RGBA_S3TC 0x83A2 -#define GL_RGBA4_S3TC 0x83A3 -#endif - -#ifndef GL_ATI_draw_buffers -#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 -#define GL_DRAW_BUFFER0_ATI 0x8825 -#define GL_DRAW_BUFFER1_ATI 0x8826 -#define GL_DRAW_BUFFER2_ATI 0x8827 -#define GL_DRAW_BUFFER3_ATI 0x8828 -#define GL_DRAW_BUFFER4_ATI 0x8829 -#define GL_DRAW_BUFFER5_ATI 0x882A -#define GL_DRAW_BUFFER6_ATI 0x882B -#define GL_DRAW_BUFFER7_ATI 0x882C -#define GL_DRAW_BUFFER8_ATI 0x882D -#define GL_DRAW_BUFFER9_ATI 0x882E -#define GL_DRAW_BUFFER10_ATI 0x882F -#define GL_DRAW_BUFFER11_ATI 0x8830 -#define GL_DRAW_BUFFER12_ATI 0x8831 -#define GL_DRAW_BUFFER13_ATI 0x8832 -#define GL_DRAW_BUFFER14_ATI 0x8833 -#define GL_DRAW_BUFFER15_ATI 0x8834 -#endif - -#ifndef GL_ATI_pixel_format_float -#define GL_TYPE_RGBA_FLOAT_ATI 0x8820 -#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 -#endif - -#ifndef GL_ATI_texture_env_combine3 -#define GL_MODULATE_ADD_ATI 0x8744 -#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 -#define GL_MODULATE_SUBTRACT_ATI 0x8746 -#endif - -#ifndef GL_ATI_texture_float -#define GL_RGBA_FLOAT32_ATI 0x8814 -#define GL_RGB_FLOAT32_ATI 0x8815 -#define GL_ALPHA_FLOAT32_ATI 0x8816 -#define GL_INTENSITY_FLOAT32_ATI 0x8817 -#define GL_LUMINANCE_FLOAT32_ATI 0x8818 -#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 -#define GL_RGBA_FLOAT16_ATI 0x881A -#define GL_RGB_FLOAT16_ATI 0x881B -#define GL_ALPHA_FLOAT16_ATI 0x881C -#define GL_INTENSITY_FLOAT16_ATI 0x881D -#define GL_LUMINANCE_FLOAT16_ATI 0x881E -#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F -#endif - -#ifndef GL_NV_float_buffer -#define GL_FLOAT_R_NV 0x8880 -#define GL_FLOAT_RG_NV 0x8881 -#define GL_FLOAT_RGB_NV 0x8882 -#define GL_FLOAT_RGBA_NV 0x8883 -#define GL_FLOAT_R16_NV 0x8884 -#define GL_FLOAT_R32_NV 0x8885 -#define GL_FLOAT_RG16_NV 0x8886 -#define GL_FLOAT_RG32_NV 0x8887 -#define GL_FLOAT_RGB16_NV 0x8888 -#define GL_FLOAT_RGB32_NV 0x8889 -#define GL_FLOAT_RGBA16_NV 0x888A -#define GL_FLOAT_RGBA32_NV 0x888B -#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C -#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D -#define GL_FLOAT_RGBA_MODE_NV 0x888E -#endif - -#ifndef GL_NV_fragment_program -#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 -#define GL_FRAGMENT_PROGRAM_NV 0x8870 -#define GL_MAX_TEXTURE_COORDS_NV 0x8871 -#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 -#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 -#define GL_PROGRAM_ERROR_STRING_NV 0x8874 -#endif - -#ifndef GL_NV_half_float -#define GL_HALF_FLOAT_NV 0x140B -#endif - -#ifndef GL_NV_pixel_data_range -#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 -#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 -#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A -#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B -#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C -#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D -#endif - -#ifndef GL_NV_primitive_restart -#define GL_PRIMITIVE_RESTART_NV 0x8558 -#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 -#endif - -#ifndef GL_NV_texture_expand_normal -#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F -#endif - -#ifndef GL_NV_vertex_program2 -#endif - -#ifndef GL_ATI_map_object_buffer -#endif - -#ifndef GL_ATI_separate_stencil -#define GL_STENCIL_BACK_FUNC_ATI 0x8800 -#define GL_STENCIL_BACK_FAIL_ATI 0x8801 -#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 -#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 -#endif - -#ifndef GL_ATI_vertex_attrib_array_object -#endif - -#ifndef GL_OES_read_format -#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A -#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B -#endif - -#ifndef GL_EXT_depth_bounds_test -#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 -#define GL_DEPTH_BOUNDS_EXT 0x8891 -#endif - -#ifndef GL_EXT_texture_mirror_clamp -#define GL_MIRROR_CLAMP_EXT 0x8742 -#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 -#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 -#endif - -#ifndef GL_EXT_blend_equation_separate -#define GL_BLEND_EQUATION_RGB_EXT 0x8009 -#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D -#endif - -#ifndef GL_MESA_pack_invert -#define GL_PACK_INVERT_MESA 0x8758 -#endif - -#ifndef GL_MESA_ycbcr_texture -#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA -#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB -#define GL_YCBCR_MESA 0x8757 -#endif - -#ifndef GL_EXT_pixel_buffer_object -#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB -#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC -#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED -#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF -#endif - -#ifndef GL_NV_fragment_program_option -#endif - -#ifndef GL_NV_fragment_program2 -#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 -#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 -#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 -#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 -#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 -#endif - -#ifndef GL_NV_vertex_program2_option -/* reuse GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV */ -/* reuse GL_MAX_PROGRAM_CALL_DEPTH_NV */ -#endif - -#ifndef GL_NV_vertex_program3 -/* reuse GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB */ -#endif - -#ifndef GL_EXT_framebuffer_object -#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 -#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 -#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 -#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 -#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA -#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB -#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC -#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD -#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF -#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 -#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 -#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 -#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 -#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 -#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 -#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 -#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 -#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 -#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 -#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA -#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB -#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC -#define GL_COLOR_ATTACHMENT13_EXT 0x8CED -#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE -#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF -#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 -#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 -#define GL_FRAMEBUFFER_EXT 0x8D40 -#define GL_RENDERBUFFER_EXT 0x8D41 -#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 -#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 -#define GL_STENCIL_INDEX1_EXT 0x8D46 -#define GL_STENCIL_INDEX4_EXT 0x8D47 -#define GL_STENCIL_INDEX8_EXT 0x8D48 -#define GL_STENCIL_INDEX16_EXT 0x8D49 -#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 -#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 -#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 -#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 -#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 -#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 -#endif - -#ifndef GL_GREMEDY_string_marker -#endif - -#ifndef GL_EXT_packed_depth_stencil -#define GL_DEPTH_STENCIL_EXT 0x84F9 -#define GL_UNSIGNED_INT_24_8_EXT 0x84FA -#define GL_DEPTH24_STENCIL8_EXT 0x88F0 -#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 -#endif - -#ifndef GL_EXT_stencil_clear_tag -#define GL_STENCIL_TAG_BITS_EXT 0x88F2 -#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3 -#endif - -#ifndef GL_EXT_texture_sRGB -#define GL_SRGB_EXT 0x8C40 -#define GL_SRGB8_EXT 0x8C41 -#define GL_SRGB_ALPHA_EXT 0x8C42 -#define GL_SRGB8_ALPHA8_EXT 0x8C43 -#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 -#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 -#define GL_SLUMINANCE_EXT 0x8C46 -#define GL_SLUMINANCE8_EXT 0x8C47 -#define GL_COMPRESSED_SRGB_EXT 0x8C48 -#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 -#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A -#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B -#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C -#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D -#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E -#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F -#endif - -#ifndef GL_EXT_framebuffer_blit -#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 -#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 -#define GL_DRAW_FRAMEBUFFER_BINDING_EXT GL_FRAMEBUFFER_BINDING_EXT -#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA -#endif - -#ifndef GL_EXT_framebuffer_multisample -#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 -#define GL_MAX_SAMPLES_EXT 0x8D57 -#endif - -#ifndef GL_MESAX_texture_stack -#define GL_TEXTURE_1D_STACK_MESAX 0x8759 -#define GL_TEXTURE_2D_STACK_MESAX 0x875A -#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B -#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C -#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D -#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E -#endif - -#ifndef GL_EXT_timer_query -#define GL_TIME_ELAPSED_EXT 0x88BF -#endif - -#ifndef GL_EXT_gpu_program_parameters -#endif - -#ifndef GL_APPLE_flush_buffer_range -#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12 -#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13 -#endif - -#ifndef GL_NV_gpu_program4 -#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904 -#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905 -#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906 -#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907 -#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908 -#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909 -#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5 -#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6 -#endif - -#ifndef GL_NV_geometry_program4 -#define GL_LINES_ADJACENCY_EXT 0x000A -#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B -#define GL_TRIANGLES_ADJACENCY_EXT 0x000C -#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D -#define GL_GEOMETRY_PROGRAM_NV 0x8C26 -#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27 -#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28 -#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA -#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB -#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC -#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29 -#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8 -#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 -#define GL_PROGRAM_POINT_SIZE_EXT 0x8642 -#endif - -#ifndef GL_EXT_geometry_shader4 -#define GL_GEOMETRY_SHADER_EXT 0x8DD9 -/* reuse GL_GEOMETRY_VERTICES_OUT_EXT */ -/* reuse GL_GEOMETRY_INPUT_TYPE_EXT */ -/* reuse GL_GEOMETRY_OUTPUT_TYPE_EXT */ -/* reuse GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT */ -#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD -#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE -#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B -#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF -#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0 -#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1 -/* reuse GL_LINES_ADJACENCY_EXT */ -/* reuse GL_LINE_STRIP_ADJACENCY_EXT */ -/* reuse GL_TRIANGLES_ADJACENCY_EXT */ -/* reuse GL_TRIANGLE_STRIP_ADJACENCY_EXT */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT */ -/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT */ -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ -/* reuse GL_PROGRAM_POINT_SIZE_EXT */ -#endif - -#ifndef GL_NV_vertex_program4 -#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD -#endif - -#ifndef GL_EXT_gpu_shader4 -#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0 -#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 -#define GL_SAMPLER_BUFFER_EXT 0x8DC2 -#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3 -#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 -#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5 -#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6 -#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7 -#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8 -#define GL_INT_SAMPLER_1D_EXT 0x8DC9 -#define GL_INT_SAMPLER_2D_EXT 0x8DCA -#define GL_INT_SAMPLER_3D_EXT 0x8DCB -#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC -#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD -#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE -#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF -#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0 -#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1 -#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2 -#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3 -#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4 -#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5 -#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6 -#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7 -#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8 -#endif - -#ifndef GL_EXT_draw_instanced -#endif - -#ifndef GL_EXT_packed_float -#define GL_R11F_G11F_B10F_EXT 0x8C3A -#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B -#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C -#endif - -#ifndef GL_EXT_texture_array -#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 -#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 -#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A -#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B -#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C -#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D -#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF -#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E -/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ -#endif - -#ifndef GL_EXT_texture_buffer_object -#define GL_TEXTURE_BUFFER_EXT 0x8C2A -#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B -#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C -#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D -#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E -#endif - -#ifndef GL_EXT_texture_compression_latc -#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70 -#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71 -#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 -#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73 -#endif - -#ifndef GL_EXT_texture_compression_rgtc -#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB -#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC -#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD -#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE -#endif - -#ifndef GL_EXT_texture_shared_exponent -#define GL_RGB9_E5_EXT 0x8C3D -#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E -#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F -#endif - -#ifndef GL_NV_depth_buffer_float -#define GL_DEPTH_COMPONENT32F_NV 0x8DAB -#define GL_DEPTH32F_STENCIL8_NV 0x8DAC -#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD -#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF -#endif - -#ifndef GL_NV_fragment_program4 -#endif - -#ifndef GL_NV_framebuffer_multisample_coverage -#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB -#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10 -#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11 -#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12 -#endif - -#ifndef GL_EXT_framebuffer_sRGB -#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 -#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA -#endif - -#ifndef GL_NV_geometry_shader4 -#endif - -#ifndef GL_NV_parameter_buffer_object -#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0 -#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1 -#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2 -#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3 -#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4 -#endif - -#ifndef GL_EXT_draw_buffers2 -#endif - -#ifndef GL_NV_transform_feedback -#define GL_BACK_PRIMARY_COLOR_NV 0x8C77 -#define GL_BACK_SECONDARY_COLOR_NV 0x8C78 -#define GL_TEXTURE_COORD_NV 0x8C79 -#define GL_CLIP_DISTANCE_NV 0x8C7A -#define GL_VERTEX_ID_NV 0x8C7B -#define GL_PRIMITIVE_ID_NV 0x8C7C -#define GL_GENERIC_ATTRIB_NV 0x8C7D -#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E -#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80 -#define GL_ACTIVE_VARYINGS_NV 0x8C81 -#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82 -#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83 -#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84 -#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85 -#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86 -#define GL_PRIMITIVES_GENERATED_NV 0x8C87 -#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88 -#define GL_RASTERIZER_DISCARD_NV 0x8C89 -#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_ATTRIBS_NV 0x8C8A -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B -#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C -#define GL_SEPARATE_ATTRIBS_NV 0x8C8D -#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E -#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F -#define GL_LAYER_NV 0x8DAA -#define GL_NEXT_BUFFER_NV -2 -#define GL_SKIP_COMPONENTS4_NV -3 -#define GL_SKIP_COMPONENTS3_NV -4 -#define GL_SKIP_COMPONENTS2_NV -5 -#define GL_SKIP_COMPONENTS1_NV -6 -#endif - -#ifndef GL_EXT_bindable_uniform -#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2 -#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3 -#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4 -#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED -#define GL_UNIFORM_BUFFER_EXT 0x8DEE -#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF -#endif - -#ifndef GL_EXT_texture_integer -#define GL_RGBA32UI_EXT 0x8D70 -#define GL_RGB32UI_EXT 0x8D71 -#define GL_ALPHA32UI_EXT 0x8D72 -#define GL_INTENSITY32UI_EXT 0x8D73 -#define GL_LUMINANCE32UI_EXT 0x8D74 -#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75 -#define GL_RGBA16UI_EXT 0x8D76 -#define GL_RGB16UI_EXT 0x8D77 -#define GL_ALPHA16UI_EXT 0x8D78 -#define GL_INTENSITY16UI_EXT 0x8D79 -#define GL_LUMINANCE16UI_EXT 0x8D7A -#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B -#define GL_RGBA8UI_EXT 0x8D7C -#define GL_RGB8UI_EXT 0x8D7D -#define GL_ALPHA8UI_EXT 0x8D7E -#define GL_INTENSITY8UI_EXT 0x8D7F -#define GL_LUMINANCE8UI_EXT 0x8D80 -#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81 -#define GL_RGBA32I_EXT 0x8D82 -#define GL_RGB32I_EXT 0x8D83 -#define GL_ALPHA32I_EXT 0x8D84 -#define GL_INTENSITY32I_EXT 0x8D85 -#define GL_LUMINANCE32I_EXT 0x8D86 -#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87 -#define GL_RGBA16I_EXT 0x8D88 -#define GL_RGB16I_EXT 0x8D89 -#define GL_ALPHA16I_EXT 0x8D8A -#define GL_INTENSITY16I_EXT 0x8D8B -#define GL_LUMINANCE16I_EXT 0x8D8C -#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D -#define GL_RGBA8I_EXT 0x8D8E -#define GL_RGB8I_EXT 0x8D8F -#define GL_ALPHA8I_EXT 0x8D90 -#define GL_INTENSITY8I_EXT 0x8D91 -#define GL_LUMINANCE8I_EXT 0x8D92 -#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93 -#define GL_RED_INTEGER_EXT 0x8D94 -#define GL_GREEN_INTEGER_EXT 0x8D95 -#define GL_BLUE_INTEGER_EXT 0x8D96 -#define GL_ALPHA_INTEGER_EXT 0x8D97 -#define GL_RGB_INTEGER_EXT 0x8D98 -#define GL_RGBA_INTEGER_EXT 0x8D99 -#define GL_BGR_INTEGER_EXT 0x8D9A -#define GL_BGRA_INTEGER_EXT 0x8D9B -#define GL_LUMINANCE_INTEGER_EXT 0x8D9C -#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D -#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E -#endif - -#ifndef GL_GREMEDY_frame_terminator -#endif - -#ifndef GL_NV_conditional_render -#define GL_QUERY_WAIT_NV 0x8E13 -#define GL_QUERY_NO_WAIT_NV 0x8E14 -#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15 -#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16 -#endif - -#ifndef GL_NV_present_video -#define GL_FRAME_NV 0x8E26 -#define GL_FIELDS_NV 0x8E27 -#define GL_CURRENT_TIME_NV 0x8E28 -#define GL_NUM_FILL_STREAMS_NV 0x8E29 -#define GL_PRESENT_TIME_NV 0x8E2A -#define GL_PRESENT_DURATION_NV 0x8E2B -#endif - -#ifndef GL_EXT_transform_feedback -#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E -#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84 -#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85 -#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F -#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C -#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D -#define GL_PRIMITIVES_GENERATED_EXT 0x8C87 -#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88 -#define GL_RASTERIZER_DISCARD_EXT 0x8C89 -#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80 -#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83 -#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F -#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76 -#endif - -#ifndef GL_EXT_direct_state_access -#define GL_PROGRAM_MATRIX_EXT 0x8E2D -#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E -#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F -#endif - -#ifndef GL_EXT_vertex_array_bgra -/* reuse GL_BGRA */ -#endif - -#ifndef GL_EXT_texture_swizzle -#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42 -#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43 -#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44 -#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45 -#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46 -#endif - -#ifndef GL_NV_explicit_multisample -#define GL_SAMPLE_POSITION_NV 0x8E50 -#define GL_SAMPLE_MASK_NV 0x8E51 -#define GL_SAMPLE_MASK_VALUE_NV 0x8E52 -#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53 -#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54 -#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55 -#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56 -#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57 -#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58 -#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59 -#endif - -#ifndef GL_NV_transform_feedback2 -#define GL_TRANSFORM_FEEDBACK_NV 0x8E22 -#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23 -#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24 -#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25 -#endif - -#ifndef GL_ATI_meminfo -#define GL_VBO_FREE_MEMORY_ATI 0x87FB -#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC -#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD -#endif - -#ifndef GL_AMD_performance_monitor -#define GL_COUNTER_TYPE_AMD 0x8BC0 -#define GL_COUNTER_RANGE_AMD 0x8BC1 -#define GL_UNSIGNED_INT64_AMD 0x8BC2 -#define GL_PERCENTAGE_AMD 0x8BC3 -#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 -#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 -#define GL_PERFMON_RESULT_AMD 0x8BC6 -#endif - -#ifndef GL_AMD_texture_texture4 -#endif - -#ifndef GL_AMD_vertex_shader_tesselator -#define GL_SAMPLER_BUFFER_AMD 0x9001 -#define GL_INT_SAMPLER_BUFFER_AMD 0x9002 -#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003 -#define GL_TESSELLATION_MODE_AMD 0x9004 -#define GL_TESSELLATION_FACTOR_AMD 0x9005 -#define GL_DISCRETE_AMD 0x9006 -#define GL_CONTINUOUS_AMD 0x9007 -#endif - -#ifndef GL_EXT_provoking_vertex -#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C -#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D -#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E -#define GL_PROVOKING_VERTEX_EXT 0x8E4F -#endif - -#ifndef GL_EXT_texture_snorm -#define GL_ALPHA_SNORM 0x9010 -#define GL_LUMINANCE_SNORM 0x9011 -#define GL_LUMINANCE_ALPHA_SNORM 0x9012 -#define GL_INTENSITY_SNORM 0x9013 -#define GL_ALPHA8_SNORM 0x9014 -#define GL_LUMINANCE8_SNORM 0x9015 -#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016 -#define GL_INTENSITY8_SNORM 0x9017 -#define GL_ALPHA16_SNORM 0x9018 -#define GL_LUMINANCE16_SNORM 0x9019 -#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A -#define GL_INTENSITY16_SNORM 0x901B -/* reuse GL_RED_SNORM */ -/* reuse GL_RG_SNORM */ -/* reuse GL_RGB_SNORM */ -/* reuse GL_RGBA_SNORM */ -/* reuse GL_R8_SNORM */ -/* reuse GL_RG8_SNORM */ -/* reuse GL_RGB8_SNORM */ -/* reuse GL_RGBA8_SNORM */ -/* reuse GL_R16_SNORM */ -/* reuse GL_RG16_SNORM */ -/* reuse GL_RGB16_SNORM */ -/* reuse GL_RGBA16_SNORM */ -/* reuse GL_SIGNED_NORMALIZED */ -#endif - -#ifndef GL_AMD_draw_buffers_blend -#endif - -#ifndef GL_APPLE_texture_range -#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7 -#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8 -#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC -#define GL_STORAGE_PRIVATE_APPLE 0x85BD -/* reuse GL_STORAGE_CACHED_APPLE */ -/* reuse GL_STORAGE_SHARED_APPLE */ -#endif - -#ifndef GL_APPLE_float_pixels -#define GL_HALF_APPLE 0x140B -#define GL_RGBA_FLOAT32_APPLE 0x8814 -#define GL_RGB_FLOAT32_APPLE 0x8815 -#define GL_ALPHA_FLOAT32_APPLE 0x8816 -#define GL_INTENSITY_FLOAT32_APPLE 0x8817 -#define GL_LUMINANCE_FLOAT32_APPLE 0x8818 -#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819 -#define GL_RGBA_FLOAT16_APPLE 0x881A -#define GL_RGB_FLOAT16_APPLE 0x881B -#define GL_ALPHA_FLOAT16_APPLE 0x881C -#define GL_INTENSITY_FLOAT16_APPLE 0x881D -#define GL_LUMINANCE_FLOAT16_APPLE 0x881E -#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F -#define GL_COLOR_FLOAT_APPLE 0x8A0F -#endif - -#ifndef GL_APPLE_vertex_program_evaluators -#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00 -#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01 -#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02 -#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03 -#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04 -#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05 -#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06 -#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07 -#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08 -#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09 -#endif - -#ifndef GL_APPLE_aux_depth_stencil -#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14 -#endif - -#ifndef GL_APPLE_object_purgeable -#define GL_BUFFER_OBJECT_APPLE 0x85B3 -#define GL_RELEASED_APPLE 0x8A19 -#define GL_VOLATILE_APPLE 0x8A1A -#define GL_RETAINED_APPLE 0x8A1B -#define GL_UNDEFINED_APPLE 0x8A1C -#define GL_PURGEABLE_APPLE 0x8A1D -#endif - -#ifndef GL_APPLE_row_bytes -#define GL_PACK_ROW_BYTES_APPLE 0x8A15 -#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16 -#endif - -#ifndef GL_APPLE_rgb_422 -#define GL_RGB_422_APPLE 0x8A1F -/* reuse GL_UNSIGNED_SHORT_8_8_APPLE */ -/* reuse GL_UNSIGNED_SHORT_8_8_REV_APPLE */ -#endif - -#ifndef GL_NV_video_capture -#define GL_VIDEO_BUFFER_NV 0x9020 -#define GL_VIDEO_BUFFER_BINDING_NV 0x9021 -#define GL_FIELD_UPPER_NV 0x9022 -#define GL_FIELD_LOWER_NV 0x9023 -#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV 0x9024 -#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025 -#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026 -#define GL_LAST_VIDEO_CAPTURE_STATUS_NV 0x9027 -#define GL_VIDEO_BUFFER_PITCH_NV 0x9028 -#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029 -#define GL_VIDEO_COLOR_CONVERSION_MAX_NV 0x902A -#define GL_VIDEO_COLOR_CONVERSION_MIN_NV 0x902B -#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C -#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D -#define GL_PARTIAL_SUCCESS_NV 0x902E -#define GL_SUCCESS_NV 0x902F -#define GL_FAILURE_NV 0x9030 -#define GL_YCBYCR8_422_NV 0x9031 -#define GL_YCBAYCR8A_4224_NV 0x9032 -#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV 0x9033 -#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034 -#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV 0x9035 -#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036 -#define GL_Z4Y12Z4CB12Z4CR12_444_NV 0x9037 -#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV 0x9038 -#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV 0x9039 -#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A -#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B -#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C -#endif - -#ifndef GL_NV_copy_image -#endif - -#ifndef GL_EXT_separate_shader_objects -#define GL_ACTIVE_PROGRAM_EXT 0x8B8D -#endif - -#ifndef GL_NV_parameter_buffer_object2 -#endif - -#ifndef GL_NV_shader_buffer_load -#define GL_BUFFER_GPU_ADDRESS_NV 0x8F1D -#define GL_GPU_ADDRESS_NV 0x8F34 -#define GL_MAX_SHADER_BUFFER_ADDRESS_NV 0x8F35 -#endif - -#ifndef GL_NV_vertex_buffer_unified_memory -#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E -#define GL_ELEMENT_ARRAY_UNIFIED_NV 0x8F1F -#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20 -#define GL_VERTEX_ARRAY_ADDRESS_NV 0x8F21 -#define GL_NORMAL_ARRAY_ADDRESS_NV 0x8F22 -#define GL_COLOR_ARRAY_ADDRESS_NV 0x8F23 -#define GL_INDEX_ARRAY_ADDRESS_NV 0x8F24 -#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25 -#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV 0x8F26 -#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27 -#define GL_FOG_COORD_ARRAY_ADDRESS_NV 0x8F28 -#define GL_ELEMENT_ARRAY_ADDRESS_NV 0x8F29 -#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV 0x8F2A -#define GL_VERTEX_ARRAY_LENGTH_NV 0x8F2B -#define GL_NORMAL_ARRAY_LENGTH_NV 0x8F2C -#define GL_COLOR_ARRAY_LENGTH_NV 0x8F2D -#define GL_INDEX_ARRAY_LENGTH_NV 0x8F2E -#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV 0x8F2F -#define GL_EDGE_FLAG_ARRAY_LENGTH_NV 0x8F30 -#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31 -#define GL_FOG_COORD_ARRAY_LENGTH_NV 0x8F32 -#define GL_ELEMENT_ARRAY_LENGTH_NV 0x8F33 -#define GL_DRAW_INDIRECT_UNIFIED_NV 0x8F40 -#define GL_DRAW_INDIRECT_ADDRESS_NV 0x8F41 -#define GL_DRAW_INDIRECT_LENGTH_NV 0x8F42 -#endif - -#ifndef GL_NV_texture_barrier -#endif - -#ifndef GL_AMD_shader_stencil_export -#endif - -#ifndef GL_AMD_seamless_cubemap_per_texture -/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ -#endif - -#ifndef GL_AMD_conservative_depth -#endif - -#ifndef GL_EXT_shader_image_load_store -#define GL_MAX_IMAGE_UNITS_EXT 0x8F38 -#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS_EXT 0x8F39 -#define GL_IMAGE_BINDING_NAME_EXT 0x8F3A -#define GL_IMAGE_BINDING_LEVEL_EXT 0x8F3B -#define GL_IMAGE_BINDING_LAYERED_EXT 0x8F3C -#define GL_IMAGE_BINDING_LAYER_EXT 0x8F3D -#define GL_IMAGE_BINDING_ACCESS_EXT 0x8F3E -#define GL_IMAGE_1D_EXT 0x904C -#define GL_IMAGE_2D_EXT 0x904D -#define GL_IMAGE_3D_EXT 0x904E -#define GL_IMAGE_2D_RECT_EXT 0x904F -#define GL_IMAGE_CUBE_EXT 0x9050 -#define GL_IMAGE_BUFFER_EXT 0x9051 -#define GL_IMAGE_1D_ARRAY_EXT 0x9052 -#define GL_IMAGE_2D_ARRAY_EXT 0x9053 -#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054 -#define GL_IMAGE_2D_MULTISAMPLE_EXT 0x9055 -#define GL_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9056 -#define GL_INT_IMAGE_1D_EXT 0x9057 -#define GL_INT_IMAGE_2D_EXT 0x9058 -#define GL_INT_IMAGE_3D_EXT 0x9059 -#define GL_INT_IMAGE_2D_RECT_EXT 0x905A -#define GL_INT_IMAGE_CUBE_EXT 0x905B -#define GL_INT_IMAGE_BUFFER_EXT 0x905C -#define GL_INT_IMAGE_1D_ARRAY_EXT 0x905D -#define GL_INT_IMAGE_2D_ARRAY_EXT 0x905E -#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F -#define GL_INT_IMAGE_2D_MULTISAMPLE_EXT 0x9060 -#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9061 -#define GL_UNSIGNED_INT_IMAGE_1D_EXT 0x9062 -#define GL_UNSIGNED_INT_IMAGE_2D_EXT 0x9063 -#define GL_UNSIGNED_INT_IMAGE_3D_EXT 0x9064 -#define GL_UNSIGNED_INT_IMAGE_2D_RECT_EXT 0x9065 -#define GL_UNSIGNED_INT_IMAGE_CUBE_EXT 0x9066 -#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067 -#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY_EXT 0x9068 -#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY_EXT 0x9069 -#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A -#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_EXT 0x906B -#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x906C -#define GL_MAX_IMAGE_SAMPLES_EXT 0x906D -#define GL_IMAGE_BINDING_FORMAT_EXT 0x906E -#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT_EXT 0x00000001 -#define GL_ELEMENT_ARRAY_BARRIER_BIT_EXT 0x00000002 -#define GL_UNIFORM_BARRIER_BIT_EXT 0x00000004 -#define GL_TEXTURE_FETCH_BARRIER_BIT_EXT 0x00000008 -#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT_EXT 0x00000020 -#define GL_COMMAND_BARRIER_BIT_EXT 0x00000040 -#define GL_PIXEL_BUFFER_BARRIER_BIT_EXT 0x00000080 -#define GL_TEXTURE_UPDATE_BARRIER_BIT_EXT 0x00000100 -#define GL_BUFFER_UPDATE_BARRIER_BIT_EXT 0x00000200 -#define GL_FRAMEBUFFER_BARRIER_BIT_EXT 0x00000400 -#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT_EXT 0x00000800 -#define GL_ATOMIC_COUNTER_BARRIER_BIT_EXT 0x00001000 -#define GL_ALL_BARRIER_BITS_EXT 0xFFFFFFFF -#endif - -#ifndef GL_EXT_vertex_attrib_64bit -/* reuse GL_DOUBLE */ -#define GL_DOUBLE_VEC2_EXT 0x8FFC -#define GL_DOUBLE_VEC3_EXT 0x8FFD -#define GL_DOUBLE_VEC4_EXT 0x8FFE -#define GL_DOUBLE_MAT2_EXT 0x8F46 -#define GL_DOUBLE_MAT3_EXT 0x8F47 -#define GL_DOUBLE_MAT4_EXT 0x8F48 -#define GL_DOUBLE_MAT2x3_EXT 0x8F49 -#define GL_DOUBLE_MAT2x4_EXT 0x8F4A -#define GL_DOUBLE_MAT3x2_EXT 0x8F4B -#define GL_DOUBLE_MAT3x4_EXT 0x8F4C -#define GL_DOUBLE_MAT4x2_EXT 0x8F4D -#define GL_DOUBLE_MAT4x3_EXT 0x8F4E -#endif - -#ifndef GL_NV_gpu_program5 -#define GL_MAX_GEOMETRY_PROGRAM_INVOCATIONS_NV 0x8E5A -#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B -#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C -#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D -#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5E -#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5F -#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44 -#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45 -#endif - -#ifndef GL_NV_gpu_shader5 -#define GL_INT64_NV 0x140E -#define GL_UNSIGNED_INT64_NV 0x140F -#define GL_INT8_NV 0x8FE0 -#define GL_INT8_VEC2_NV 0x8FE1 -#define GL_INT8_VEC3_NV 0x8FE2 -#define GL_INT8_VEC4_NV 0x8FE3 -#define GL_INT16_NV 0x8FE4 -#define GL_INT16_VEC2_NV 0x8FE5 -#define GL_INT16_VEC3_NV 0x8FE6 -#define GL_INT16_VEC4_NV 0x8FE7 -#define GL_INT64_VEC2_NV 0x8FE9 -#define GL_INT64_VEC3_NV 0x8FEA -#define GL_INT64_VEC4_NV 0x8FEB -#define GL_UNSIGNED_INT8_NV 0x8FEC -#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED -#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE -#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF -#define GL_UNSIGNED_INT16_NV 0x8FF0 -#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1 -#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2 -#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3 -#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5 -#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6 -#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7 -#define GL_FLOAT16_NV 0x8FF8 -#define GL_FLOAT16_VEC2_NV 0x8FF9 -#define GL_FLOAT16_VEC3_NV 0x8FFA -#define GL_FLOAT16_VEC4_NV 0x8FFB -/* reuse GL_PATCHES */ -#endif - -#ifndef GL_NV_shader_buffer_store -#define GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV 0x00000010 -/* reuse GL_READ_WRITE */ -/* reuse GL_WRITE_ONLY */ -#endif - -#ifndef GL_NV_tessellation_program5 -#define GL_MAX_PROGRAM_PATCH_ATTRIBS_NV 0x86D8 -#define GL_TESS_CONTROL_PROGRAM_NV 0x891E -#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F -#define GL_TESS_CONTROL_PROGRAM_PARAMETER_BUFFER_NV 0x8C74 -#define GL_TESS_EVALUATION_PROGRAM_PARAMETER_BUFFER_NV 0x8C75 -#endif - -#ifndef GL_NV_vertex_attrib_integer_64bit -/* reuse GL_INT64_NV */ -/* reuse GL_UNSIGNED_INT64_NV */ -#endif - -#ifndef GL_NV_multisample_coverage -#define GL_COVERAGE_SAMPLES_NV 0x80A9 -#define GL_COLOR_SAMPLES_NV 0x8E20 -#endif - -#ifndef GL_AMD_name_gen_delete -#define GL_DATA_BUFFER_AMD 0x9151 -#define GL_PERFORMANCE_MONITOR_AMD 0x9152 -#define GL_QUERY_OBJECT_AMD 0x9153 -#define GL_VERTEX_ARRAY_OBJECT_AMD 0x9154 -#define GL_SAMPLER_OBJECT_AMD 0x9155 -#endif - -#ifndef GL_AMD_debug_output -#define GL_MAX_DEBUG_LOGGED_MESSAGES_AMD 0x9144 -#define GL_DEBUG_LOGGED_MESSAGES_AMD 0x9145 -#define GL_DEBUG_SEVERITY_HIGH_AMD 0x9146 -#define GL_DEBUG_SEVERITY_MEDIUM_AMD 0x9147 -#define GL_DEBUG_SEVERITY_LOW_AMD 0x9148 -#define GL_DEBUG_CATEGORY_API_ERROR_AMD 0x9149 -#define GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD 0x914A -#define GL_DEBUG_CATEGORY_DEPRECATION_AMD 0x914B -#define GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD 0x914C -#define GL_DEBUG_CATEGORY_PERFORMANCE_AMD 0x914D -#define GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD 0x914E -#define GL_DEBUG_CATEGORY_APPLICATION_AMD 0x914F -#define GL_DEBUG_CATEGORY_OTHER_AMD 0x9150 -#endif - -#ifndef GL_NV_vdpau_interop -#define GL_SURFACE_STATE_NV 0x86EB -#define GL_SURFACE_REGISTERED_NV 0x86FD -#define GL_SURFACE_MAPPED_NV 0x8700 -#define GL_WRITE_DISCARD_NV 0x88BE -#endif - -#ifndef GL_AMD_transform_feedback3_lines_triangles -#endif - -#ifndef GL_AMD_depth_clamp_separate -#define GL_DEPTH_CLAMP_NEAR_AMD 0x901E -#define GL_DEPTH_CLAMP_FAR_AMD 0x901F -#endif - -#ifndef GL_EXT_texture_sRGB_decode -#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48 -#define GL_DECODE_EXT 0x8A49 -#define GL_SKIP_DECODE_EXT 0x8A4A -#endif - -#ifndef GL_NV_texture_multisample -#define GL_TEXTURE_COVERAGE_SAMPLES_NV 0x9045 -#define GL_TEXTURE_COLOR_SAMPLES_NV 0x9046 -#endif - -#ifndef GL_AMD_blend_minmax_factor -#define GL_FACTOR_MIN_AMD 0x901C -#define GL_FACTOR_MAX_AMD 0x901D -#endif - -#ifndef GL_AMD_sample_positions -#define GL_SUBSAMPLE_DISTANCE_AMD 0x883F -#endif - -#ifndef GL_EXT_x11_sync_object -#define GL_SYNC_X11_FENCE_EXT 0x90E1 -#endif - -#ifndef GL_AMD_multi_draw_indirect -#endif - -#ifndef GL_EXT_framebuffer_multisample_blit_scaled -#define GL_SCALED_RESOLVE_FASTEST_EXT 0x90BA -#define GL_SCALED_RESOLVE_NICEST_EXT 0x90BB -#endif - -#ifndef GL_NV_path_rendering -#define GL_PATH_FORMAT_SVG_NV 0x9070 -#define GL_PATH_FORMAT_PS_NV 0x9071 -#define GL_STANDARD_FONT_NAME_NV 0x9072 -#define GL_SYSTEM_FONT_NAME_NV 0x9073 -#define GL_FILE_NAME_NV 0x9074 -#define GL_PATH_STROKE_WIDTH_NV 0x9075 -#define GL_PATH_END_CAPS_NV 0x9076 -#define GL_PATH_INITIAL_END_CAP_NV 0x9077 -#define GL_PATH_TERMINAL_END_CAP_NV 0x9078 -#define GL_PATH_JOIN_STYLE_NV 0x9079 -#define GL_PATH_MITER_LIMIT_NV 0x907A -#define GL_PATH_DASH_CAPS_NV 0x907B -#define GL_PATH_INITIAL_DASH_CAP_NV 0x907C -#define GL_PATH_TERMINAL_DASH_CAP_NV 0x907D -#define GL_PATH_DASH_OFFSET_NV 0x907E -#define GL_PATH_CLIENT_LENGTH_NV 0x907F -#define GL_PATH_FILL_MODE_NV 0x9080 -#define GL_PATH_FILL_MASK_NV 0x9081 -#define GL_PATH_FILL_COVER_MODE_NV 0x9082 -#define GL_PATH_STROKE_COVER_MODE_NV 0x9083 -#define GL_PATH_STROKE_MASK_NV 0x9084 -#define GL_PATH_SAMPLE_QUALITY_NV 0x9085 -#define GL_PATH_STROKE_BOUND_NV 0x9086 -#define GL_PATH_STROKE_OVERSAMPLE_COUNT_NV 0x9087 -#define GL_COUNT_UP_NV 0x9088 -#define GL_COUNT_DOWN_NV 0x9089 -#define GL_PATH_OBJECT_BOUNDING_BOX_NV 0x908A -#define GL_CONVEX_HULL_NV 0x908B -#define GL_MULTI_HULLS_NV 0x908C -#define GL_BOUNDING_BOX_NV 0x908D -#define GL_TRANSLATE_X_NV 0x908E -#define GL_TRANSLATE_Y_NV 0x908F -#define GL_TRANSLATE_2D_NV 0x9090 -#define GL_TRANSLATE_3D_NV 0x9091 -#define GL_AFFINE_2D_NV 0x9092 -#define GL_PROJECTIVE_2D_NV 0x9093 -#define GL_AFFINE_3D_NV 0x9094 -#define GL_PROJECTIVE_3D_NV 0x9095 -#define GL_TRANSPOSE_AFFINE_2D_NV 0x9096 -#define GL_TRANSPOSE_PROJECTIVE_2D_NV 0x9097 -#define GL_TRANSPOSE_AFFINE_3D_NV 0x9098 -#define GL_TRANSPOSE_PROJECTIVE_3D_NV 0x9099 -#define GL_UTF8_NV 0x909A -#define GL_UTF16_NV 0x909B -#define GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV 0x909C -#define GL_PATH_COMMAND_COUNT_NV 0x909D -#define GL_PATH_COORD_COUNT_NV 0x909E -#define GL_PATH_DASH_ARRAY_COUNT_NV 0x909F -#define GL_PATH_COMPUTED_LENGTH_NV 0x90A0 -#define GL_PATH_FILL_BOUNDING_BOX_NV 0x90A1 -#define GL_PATH_STROKE_BOUNDING_BOX_NV 0x90A2 -#define GL_SQUARE_NV 0x90A3 -#define GL_ROUND_NV 0x90A4 -#define GL_TRIANGULAR_NV 0x90A5 -#define GL_BEVEL_NV 0x90A6 -#define GL_MITER_REVERT_NV 0x90A7 -#define GL_MITER_TRUNCATE_NV 0x90A8 -#define GL_SKIP_MISSING_GLYPH_NV 0x90A9 -#define GL_USE_MISSING_GLYPH_NV 0x90AA -#define GL_PATH_ERROR_POSITION_NV 0x90AB -#define GL_PATH_FOG_GEN_MODE_NV 0x90AC -#define GL_ACCUM_ADJACENT_PAIRS_NV 0x90AD -#define GL_ADJACENT_PAIRS_NV 0x90AE -#define GL_FIRST_TO_REST_NV 0x90AF -#define GL_PATH_GEN_MODE_NV 0x90B0 -#define GL_PATH_GEN_COEFF_NV 0x90B1 -#define GL_PATH_GEN_COLOR_FORMAT_NV 0x90B2 -#define GL_PATH_GEN_COMPONENTS_NV 0x90B3 -#define GL_PATH_STENCIL_FUNC_NV 0x90B7 -#define GL_PATH_STENCIL_REF_NV 0x90B8 -#define GL_PATH_STENCIL_VALUE_MASK_NV 0x90B9 -#define GL_PATH_STENCIL_DEPTH_OFFSET_FACTOR_NV 0x90BD -#define GL_PATH_STENCIL_DEPTH_OFFSET_UNITS_NV 0x90BE -#define GL_PATH_COVER_DEPTH_FUNC_NV 0x90BF -#define GL_PATH_DASH_OFFSET_RESET_NV 0x90B4 -#define GL_MOVE_TO_RESETS_NV 0x90B5 -#define GL_MOVE_TO_CONTINUES_NV 0x90B6 -#define GL_CLOSE_PATH_NV 0x00 -#define GL_MOVE_TO_NV 0x02 -#define GL_RELATIVE_MOVE_TO_NV 0x03 -#define GL_LINE_TO_NV 0x04 -#define GL_RELATIVE_LINE_TO_NV 0x05 -#define GL_HORIZONTAL_LINE_TO_NV 0x06 -#define GL_RELATIVE_HORIZONTAL_LINE_TO_NV 0x07 -#define GL_VERTICAL_LINE_TO_NV 0x08 -#define GL_RELATIVE_VERTICAL_LINE_TO_NV 0x09 -#define GL_QUADRATIC_CURVE_TO_NV 0x0A -#define GL_RELATIVE_QUADRATIC_CURVE_TO_NV 0x0B -#define GL_CUBIC_CURVE_TO_NV 0x0C -#define GL_RELATIVE_CUBIC_CURVE_TO_NV 0x0D -#define GL_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0E -#define GL_RELATIVE_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0F -#define GL_SMOOTH_CUBIC_CURVE_TO_NV 0x10 -#define GL_RELATIVE_SMOOTH_CUBIC_CURVE_TO_NV 0x11 -#define GL_SMALL_CCW_ARC_TO_NV 0x12 -#define GL_RELATIVE_SMALL_CCW_ARC_TO_NV 0x13 -#define GL_SMALL_CW_ARC_TO_NV 0x14 -#define GL_RELATIVE_SMALL_CW_ARC_TO_NV 0x15 -#define GL_LARGE_CCW_ARC_TO_NV 0x16 -#define GL_RELATIVE_LARGE_CCW_ARC_TO_NV 0x17 -#define GL_LARGE_CW_ARC_TO_NV 0x18 -#define GL_RELATIVE_LARGE_CW_ARC_TO_NV 0x19 -#define GL_RESTART_PATH_NV 0xF0 -#define GL_DUP_FIRST_CUBIC_CURVE_TO_NV 0xF2 -#define GL_DUP_LAST_CUBIC_CURVE_TO_NV 0xF4 -#define GL_RECT_NV 0xF6 -#define GL_CIRCULAR_CCW_ARC_TO_NV 0xF8 -#define GL_CIRCULAR_CW_ARC_TO_NV 0xFA -#define GL_CIRCULAR_TANGENT_ARC_TO_NV 0xFC -#define GL_ARC_TO_NV 0xFE -#define GL_RELATIVE_ARC_TO_NV 0xFF -#define GL_BOLD_BIT_NV 0x01 -#define GL_ITALIC_BIT_NV 0x02 -#define GL_GLYPH_WIDTH_BIT_NV 0x01 -#define GL_GLYPH_HEIGHT_BIT_NV 0x02 -#define GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV 0x04 -#define GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV 0x08 -#define GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV 0x10 -#define GL_GLYPH_VERTICAL_BEARING_X_BIT_NV 0x20 -#define GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV 0x40 -#define GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV 0x80 -#define GL_GLYPH_HAS_KERNING_NV 0x100 -#define GL_FONT_X_MIN_BOUNDS_NV 0x00010000 -#define GL_FONT_Y_MIN_BOUNDS_NV 0x00020000 -#define GL_FONT_X_MAX_BOUNDS_NV 0x00040000 -#define GL_FONT_Y_MAX_BOUNDS_NV 0x00080000 -#define GL_FONT_UNITS_PER_EM_NV 0x00100000 -#define GL_FONT_ASCENDER_NV 0x00200000 -#define GL_FONT_DESCENDER_NV 0x00400000 -#define GL_FONT_HEIGHT_NV 0x00800000 -#define GL_FONT_MAX_ADVANCE_WIDTH_NV 0x01000000 -#define GL_FONT_MAX_ADVANCE_HEIGHT_NV 0x02000000 -#define GL_FONT_UNDERLINE_POSITION_NV 0x04000000 -#define GL_FONT_UNDERLINE_THICKNESS_NV 0x08000000 -#define GL_FONT_HAS_KERNING_NV 0x10000000 -#endif - -#ifndef GL_AMD_pinned_memory -#define GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD 0x9160 -#endif - -#ifndef GL_AMD_stencil_operation_extended -#define GL_SET_AMD 0x874A -#define GL_REPLACE_VALUE_AMD 0x874B -#define GL_STENCIL_OP_VALUE_AMD 0x874C -#define GL_STENCIL_BACK_OP_VALUE_AMD 0x874D -#endif - -#ifndef GL_AMD_vertex_shader_viewport_index -#endif - -#ifndef GL_AMD_vertex_shader_layer -#endif - -#ifndef GL_NV_bindless_texture -#endif - -#ifndef GL_NV_shader_atomic_float -#endif - -#ifndef GL_AMD_query_buffer_object -#define GL_QUERY_BUFFER_AMD 0x9192 -#define GL_QUERY_BUFFER_BINDING_AMD 0x9193 -#define GL_QUERY_RESULT_NO_WAIT_AMD 0x9194 -#endif - - -/*************************************************************/ - -#include -#ifndef GL_VERSION_2_0 -/* GL type for program/shader text */ -typedef char GLchar; -#endif - -#ifndef GL_VERSION_1_5 -/* GL types for handling large vertex buffer objects */ -typedef ptrdiff_t GLintptr; -typedef ptrdiff_t GLsizeiptr; -#endif - -#ifndef GL_ARB_vertex_buffer_object -/* GL types for handling large vertex buffer objects */ -typedef ptrdiff_t GLintptrARB; -typedef ptrdiff_t GLsizeiptrARB; -#endif - -#ifndef GL_ARB_shader_objects -/* GL types for program/shader text and shader object handles */ -typedef char GLcharARB; -typedef unsigned int GLhandleARB; -#endif - -/* GL type for "half" precision (s10e5) float data in host memory */ -#ifndef GL_ARB_half_float_pixel -typedef unsigned short GLhalfARB; -#endif - -#ifndef GL_NV_half_float -typedef unsigned short GLhalfNV; -#endif - -#ifndef GLEXT_64_TYPES_DEFINED -/* This code block is duplicated in glxext.h, so must be protected */ -#define GLEXT_64_TYPES_DEFINED -/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ -/* (as used in the GL_EXT_timer_query extension). */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#include -#elif defined(__sun__) || defined(__digital__) -#include -#if defined(__STDC__) -#if defined(__arch64__) || defined(_LP64) -typedef long int int64_t; -typedef unsigned long int uint64_t; -#else -typedef long long int int64_t; -typedef unsigned long long int uint64_t; -#endif /* __arch64__ */ -#endif /* __STDC__ */ -#elif defined( __VMS ) || defined(__sgi) -#include -#elif defined(__SCO__) || defined(__USLC__) -#include -#elif defined(__UNIXOS2__) || defined(__SOL64__) -typedef long int int32_t; -typedef long long int int64_t; -typedef unsigned long long int uint64_t; -#elif defined(_WIN32) && defined(__GNUC__) -#include -#elif defined(_WIN32) -typedef __int32 int32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else -/* Fallback if nothing above works */ -#include -#endif -#endif - -#ifndef GL_EXT_timer_query -typedef int64_t GLint64EXT; -typedef uint64_t GLuint64EXT; -#endif - -#ifndef GL_ARB_sync -typedef int64_t GLint64; -typedef uint64_t GLuint64; -typedef struct __GLsync *GLsync; -#endif - -#ifndef GL_ARB_cl_event -/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */ -struct _cl_context; -struct _cl_event; -#endif - -#ifndef GL_ARB_debug_output -typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); -#endif - -#ifndef GL_AMD_debug_output -typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); -#endif - -#ifndef GL_KHR_debug -typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); -#endif - -#ifndef GL_NV_vdpau_interop -typedef GLintptr GLvdpauSurfaceNV; -#endif - -#ifndef GL_VERSION_1_2 -#define GL_VERSION_1_2 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -GLAPI void APIENTRY glBlendEquation (GLenum mode); -GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif - -#ifndef GL_VERSION_1_2_DEPRECATED -#define GL_VERSION_1_2_DEPRECATED 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -GLAPI void APIENTRY glColorTableParameterfv (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glColorTableParameteriv (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glCopyColorTable (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, GLvoid *table); -GLAPI void APIENTRY glGetColorTableParameterfv (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetColorTableParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); -GLAPI void APIENTRY glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); -GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); -GLAPI void APIENTRY glConvolutionParameterf (GLenum target, GLenum pname, GLfloat params); -GLAPI void APIENTRY glConvolutionParameterfv (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glConvolutionParameteri (GLenum target, GLenum pname, GLint params); -GLAPI void APIENTRY glConvolutionParameteriv (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, GLvoid *image); -GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); -GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); -GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -GLAPI void APIENTRY glGetHistogramParameterfv (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetHistogramParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glHistogram (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); -GLAPI void APIENTRY glMinmax (GLenum target, GLenum internalformat, GLboolean sink); -GLAPI void APIENTRY glResetHistogram (GLenum target); -GLAPI void APIENTRY glResetMinmax (GLenum target); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); -typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); -typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); -#endif - -#ifndef GL_VERSION_1_3 -#define GL_VERSION_1_3 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glActiveTexture (GLenum texture); -GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); -GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); -#endif - -#ifndef GL_VERSION_1_3_DEPRECATED -#define GL_VERSION_1_3_DEPRECATED 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glClientActiveTexture (GLenum texture); -GLAPI void APIENTRY glMultiTexCoord1d (GLenum target, GLdouble s); -GLAPI void APIENTRY glMultiTexCoord1dv (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord1f (GLenum target, GLfloat s); -GLAPI void APIENTRY glMultiTexCoord1fv (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord1i (GLenum target, GLint s); -GLAPI void APIENTRY glMultiTexCoord1iv (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord1s (GLenum target, GLshort s); -GLAPI void APIENTRY glMultiTexCoord1sv (GLenum target, const GLshort *v); -GLAPI void APIENTRY glMultiTexCoord2d (GLenum target, GLdouble s, GLdouble t); -GLAPI void APIENTRY glMultiTexCoord2dv (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord2f (GLenum target, GLfloat s, GLfloat t); -GLAPI void APIENTRY glMultiTexCoord2fv (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord2i (GLenum target, GLint s, GLint t); -GLAPI void APIENTRY glMultiTexCoord2iv (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord2s (GLenum target, GLshort s, GLshort t); -GLAPI void APIENTRY glMultiTexCoord2sv (GLenum target, const GLshort *v); -GLAPI void APIENTRY glMultiTexCoord3d (GLenum target, GLdouble s, GLdouble t, GLdouble r); -GLAPI void APIENTRY glMultiTexCoord3dv (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord3f (GLenum target, GLfloat s, GLfloat t, GLfloat r); -GLAPI void APIENTRY glMultiTexCoord3fv (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord3i (GLenum target, GLint s, GLint t, GLint r); -GLAPI void APIENTRY glMultiTexCoord3iv (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord3s (GLenum target, GLshort s, GLshort t, GLshort r); -GLAPI void APIENTRY glMultiTexCoord3sv (GLenum target, const GLshort *v); -GLAPI void APIENTRY glMultiTexCoord4d (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -GLAPI void APIENTRY glMultiTexCoord4dv (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -GLAPI void APIENTRY glMultiTexCoord4fv (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord4i (GLenum target, GLint s, GLint t, GLint r, GLint q); -GLAPI void APIENTRY glMultiTexCoord4iv (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord4s (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -GLAPI void APIENTRY glMultiTexCoord4sv (GLenum target, const GLshort *v); -GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *m); -GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *m); -GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *m); -GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *m); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); -#endif - -#ifndef GL_VERSION_1_4 -#define GL_VERSION_1_4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); -GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); -GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); -GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); -#endif - -#ifndef GL_VERSION_1_4_DEPRECATED -#define GL_VERSION_1_4_DEPRECATED 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFogCoordf (GLfloat coord); -GLAPI void APIENTRY glFogCoordfv (const GLfloat *coord); -GLAPI void APIENTRY glFogCoordd (GLdouble coord); -GLAPI void APIENTRY glFogCoorddv (const GLdouble *coord); -GLAPI void APIENTRY glFogCoordPointer (GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glSecondaryColor3b (GLbyte red, GLbyte green, GLbyte blue); -GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *v); -GLAPI void APIENTRY glSecondaryColor3d (GLdouble red, GLdouble green, GLdouble blue); -GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *v); -GLAPI void APIENTRY glSecondaryColor3f (GLfloat red, GLfloat green, GLfloat blue); -GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *v); -GLAPI void APIENTRY glSecondaryColor3i (GLint red, GLint green, GLint blue); -GLAPI void APIENTRY glSecondaryColor3iv (const GLint *v); -GLAPI void APIENTRY glSecondaryColor3s (GLshort red, GLshort green, GLshort blue); -GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *v); -GLAPI void APIENTRY glSecondaryColor3ub (GLubyte red, GLubyte green, GLubyte blue); -GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *v); -GLAPI void APIENTRY glSecondaryColor3ui (GLuint red, GLuint green, GLuint blue); -GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *v); -GLAPI void APIENTRY glSecondaryColor3us (GLushort red, GLushort green, GLushort blue); -GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *v); -GLAPI void APIENTRY glSecondaryColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glWindowPos2d (GLdouble x, GLdouble y); -GLAPI void APIENTRY glWindowPos2dv (const GLdouble *v); -GLAPI void APIENTRY glWindowPos2f (GLfloat x, GLfloat y); -GLAPI void APIENTRY glWindowPos2fv (const GLfloat *v); -GLAPI void APIENTRY glWindowPos2i (GLint x, GLint y); -GLAPI void APIENTRY glWindowPos2iv (const GLint *v); -GLAPI void APIENTRY glWindowPos2s (GLshort x, GLshort y); -GLAPI void APIENTRY glWindowPos2sv (const GLshort *v); -GLAPI void APIENTRY glWindowPos3d (GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glWindowPos3dv (const GLdouble *v); -GLAPI void APIENTRY glWindowPos3f (GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glWindowPos3fv (const GLfloat *v); -GLAPI void APIENTRY glWindowPos3i (GLint x, GLint y, GLint z); -GLAPI void APIENTRY glWindowPos3iv (const GLint *v); -GLAPI void APIENTRY glWindowPos3s (GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glWindowPos3sv (const GLshort *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); -typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); -typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); -typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); -typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); -typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); -#endif - -#ifndef GL_VERSION_1_5 -#define GL_VERSION_1_5 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); -GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); -GLAPI GLboolean APIENTRY glIsQuery (GLuint id); -GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); -GLAPI void APIENTRY glEndQuery (GLenum target); -GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); -GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); -GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); -GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); -GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); -GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); -GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); -GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); -GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); -GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); -GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); -typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); -typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); -typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); -typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); -#endif - -#ifndef GL_VERSION_2_0 -#define GL_VERSION_2_0 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); -GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); -GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); -GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); -GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); -GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); -GLAPI void APIENTRY glCompileShader (GLuint shader); -GLAPI GLuint APIENTRY glCreateProgram (void); -GLAPI GLuint APIENTRY glCreateShader (GLenum type); -GLAPI void APIENTRY glDeleteProgram (GLuint program); -GLAPI void APIENTRY glDeleteShader (GLuint shader); -GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); -GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); -GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); -GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); -GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); -GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); -GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); -GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); -GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid* *pointer); -GLAPI GLboolean APIENTRY glIsProgram (GLuint program); -GLAPI GLboolean APIENTRY glIsShader (GLuint shader); -GLAPI void APIENTRY glLinkProgram (GLuint program); -GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); -GLAPI void APIENTRY glUseProgram (GLuint program); -GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); -GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); -GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); -GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); -GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); -GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glValidateProgram (GLuint program); -GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); -GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); -GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); -GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); -GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); -typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); -typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); -typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); -typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); -typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); -typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); -typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); -typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); -typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); -typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); -typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); -typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); -typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); -typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_VERSION_2_1 -#define GL_VERSION_2_1 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -#endif - -#ifndef GL_VERSION_3_0 -#define GL_VERSION_3_0 1 -/* OpenGL 3.0 also reuses entry points from these extensions: */ -/* ARB_framebuffer_object */ -/* ARB_map_buffer_range */ -/* ARB_vertex_array_object */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); -GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); -GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); -GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); -GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); -GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); -GLAPI void APIENTRY glEndTransformFeedback (void); -GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); -GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); -GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); -GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); -GLAPI void APIENTRY glEndConditionalRender (void); -GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); -GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); -GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); -GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); -GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); -GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); -GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); -GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); -GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); -GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); -GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); -GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); -GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); -GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); -GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); -GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); -GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); -GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); -GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); -GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); -typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); -typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); -typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); -typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); -typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); -typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); -typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); -typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); -typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); -typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); -typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); -typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); -typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); -typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); -typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); -typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); -#endif - -#ifndef GL_VERSION_3_1 -#define GL_VERSION_3_1 1 -/* OpenGL 3.1 also reuses entry points from these extensions: */ -/* ARB_copy_buffer */ -/* ARB_uniform_buffer_object */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); -GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); -GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); -GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); -typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); -#endif - -#ifndef GL_VERSION_3_2 -#define GL_VERSION_3_2 1 -/* OpenGL 3.2 also reuses entry points from these extensions: */ -/* ARB_draw_elements_base_vertex */ -/* ARB_provoking_vertex */ -/* ARB_sync */ -/* ARB_texture_multisample */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); -GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); -GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); -#endif - -#ifndef GL_VERSION_3_3 -#define GL_VERSION_3_3 1 -/* OpenGL 3.3 also reuses entry points from these extensions: */ -/* ARB_blend_func_extended */ -/* ARB_sampler_objects */ -/* ARB_explicit_attrib_location, but it has none */ -/* ARB_occlusion_query2 (no entry points) */ -/* ARB_shader_bit_encoding (no entry points) */ -/* ARB_texture_rgb10_a2ui (no entry points) */ -/* ARB_texture_swizzle (no entry points) */ -/* ARB_timer_query */ -/* ARB_vertex_type_2_10_10_10_rev */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); -#endif - -#ifndef GL_VERSION_4_0 -#define GL_VERSION_4_0 1 -/* OpenGL 4.0 also reuses entry points from these extensions: */ -/* ARB_texture_query_lod (no entry points) */ -/* ARB_draw_indirect */ -/* ARB_gpu_shader5 (no entry points) */ -/* ARB_gpu_shader_fp64 */ -/* ARB_shader_subroutine */ -/* ARB_tessellation_shader */ -/* ARB_texture_buffer_object_rgb32 (no entry points) */ -/* ARB_texture_cube_map_array (no entry points) */ -/* ARB_texture_gather (no entry points) */ -/* ARB_transform_feedback2 */ -/* ARB_transform_feedback3 */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMinSampleShading (GLfloat value); -GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); -GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); -GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value); -typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif - -#ifndef GL_VERSION_4_1 -#define GL_VERSION_4_1 1 -/* OpenGL 4.1 reuses entry points from these extensions: */ -/* ARB_ES2_compatibility */ -/* ARB_get_program_binary */ -/* ARB_separate_shader_objects */ -/* ARB_shader_precision (no entry points) */ -/* ARB_vertex_attrib_64bit */ -/* ARB_viewport_array */ -#endif - -#ifndef GL_VERSION_4_2 -#define GL_VERSION_4_2 1 -/* OpenGL 4.2 reuses entry points from these extensions: */ -/* ARB_base_instance */ -/* ARB_shading_language_420pack (no entry points) */ -/* ARB_transform_feedback_instanced */ -/* ARB_compressed_texture_pixel_storage (no entry points) */ -/* ARB_conservative_depth (no entry points) */ -/* ARB_internalformat_query */ -/* ARB_map_buffer_alignment (no entry points) */ -/* ARB_shader_atomic_counters */ -/* ARB_shader_image_load_store */ -/* ARB_shading_language_packing (no entry points) */ -/* ARB_texture_storage */ -#endif - -#ifndef GL_VERSION_4_3 -#define GL_VERSION_4_3 1 -/* OpenGL 4.3 reuses entry points from these extensions: */ -/* ARB_arrays_of_arrays (no entry points, GLSL only) */ -/* ARB_fragment_layer_viewport (no entry points, GLSL only) */ -/* ARB_shader_image_size (no entry points, GLSL only) */ -/* ARB_ES3_compatibility (no entry points) */ -/* ARB_clear_buffer_object */ -/* ARB_compute_shader */ -/* ARB_copy_image */ -/* ARB_debug_group */ -/* ARB_debug_label */ -/* KHR_debug (ARB_debug_output promoted to KHR without suffixes) */ -/* ARB_debug_output2 (no entry points) */ -/* ARB_explicit_uniform_location (no entry points) */ -/* ARB_framebuffer_no_attachments */ -/* ARB_internalformat_query2 */ -/* ARB_invalidate_subdata */ -/* ARB_multi_draw_indirect */ -/* ARB_program_interface_query */ -/* ARB_robust_buffer_access_behavior (no entry points) */ -/* ARB_shader_storage_buffer_object */ -/* ARB_stencil_texturing (no entry points) */ -/* ARB_texture_buffer_range */ -/* ARB_texture_query_levels (no entry points) */ -/* ARB_texture_storage_multisample */ -/* ARB_texture_view */ -/* ARB_vertex_attrib_binding */ -#endif - -#ifndef GL_ARB_multitexture -#define GL_ARB_multitexture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glActiveTextureARB (GLenum texture); -GLAPI void APIENTRY glClientActiveTextureARB (GLenum texture); -GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum target, GLdouble s); -GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum target, GLfloat s); -GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum target, GLint s); -GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum target, GLshort s); -GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum target, const GLshort *v); -GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum target, GLdouble s, GLdouble t); -GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum target, GLfloat s, GLfloat t); -GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum target, GLint s, GLint t); -GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum target, GLshort s, GLshort t); -GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum target, const GLshort *v); -GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r); -GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r); -GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum target, GLint s, GLint t, GLint r); -GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum target, GLshort s, GLshort t, GLshort r); -GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum target, const GLshort *v); -GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum target, const GLdouble *v); -GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum target, const GLfloat *v); -GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum target, GLint s, GLint t, GLint r, GLint q); -GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum target, const GLint *v); -GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum target, const GLshort *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); -#endif - -#ifndef GL_ARB_transpose_matrix -#define GL_ARB_transpose_matrix 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *m); -GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *m); -GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *m); -GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *m); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); -typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); -#endif - -#ifndef GL_ARB_multisample -#define GL_ARB_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSampleCoverageARB (GLfloat value, GLboolean invert); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLfloat value, GLboolean invert); -#endif - -#ifndef GL_ARB_texture_env_add -#define GL_ARB_texture_env_add 1 -#endif - -#ifndef GL_ARB_texture_cube_map -#define GL_ARB_texture_cube_map 1 -#endif - -#ifndef GL_ARB_texture_compression -#define GL_ARB_texture_compression 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum target, GLint level, GLvoid *img); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); -#endif - -#ifndef GL_ARB_texture_border_clamp -#define GL_ARB_texture_border_clamp 1 -#endif - -#ifndef GL_ARB_point_parameters -#define GL_ARB_point_parameters 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameterfARB (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPointParameterfvARB (GLenum pname, const GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); -#endif - -#ifndef GL_ARB_vertex_blend -#define GL_ARB_vertex_blend 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glWeightbvARB (GLint size, const GLbyte *weights); -GLAPI void APIENTRY glWeightsvARB (GLint size, const GLshort *weights); -GLAPI void APIENTRY glWeightivARB (GLint size, const GLint *weights); -GLAPI void APIENTRY glWeightfvARB (GLint size, const GLfloat *weights); -GLAPI void APIENTRY glWeightdvARB (GLint size, const GLdouble *weights); -GLAPI void APIENTRY glWeightubvARB (GLint size, const GLubyte *weights); -GLAPI void APIENTRY glWeightusvARB (GLint size, const GLushort *weights); -GLAPI void APIENTRY glWeightuivARB (GLint size, const GLuint *weights); -GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glVertexBlendARB (GLint count); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); -typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); -typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); -typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); -typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); -typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); -typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); -typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); -typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); -#endif - -#ifndef GL_ARB_matrix_palette -#define GL_ARB_matrix_palette 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint index); -GLAPI void APIENTRY glMatrixIndexubvARB (GLint size, const GLubyte *indices); -GLAPI void APIENTRY glMatrixIndexusvARB (GLint size, const GLushort *indices); -GLAPI void APIENTRY glMatrixIndexuivARB (GLint size, const GLuint *indices); -GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); -typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); -typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); -typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); -typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_ARB_texture_env_combine -#define GL_ARB_texture_env_combine 1 -#endif - -#ifndef GL_ARB_texture_env_crossbar -#define GL_ARB_texture_env_crossbar 1 -#endif - -#ifndef GL_ARB_texture_env_dot3 -#define GL_ARB_texture_env_dot3 1 -#endif - -#ifndef GL_ARB_texture_mirrored_repeat -#define GL_ARB_texture_mirrored_repeat 1 -#endif - -#ifndef GL_ARB_depth_texture -#define GL_ARB_depth_texture 1 -#endif - -#ifndef GL_ARB_shadow -#define GL_ARB_shadow 1 -#endif - -#ifndef GL_ARB_shadow_ambient -#define GL_ARB_shadow_ambient 1 -#endif - -#ifndef GL_ARB_window_pos -#define GL_ARB_window_pos 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glWindowPos2dARB (GLdouble x, GLdouble y); -GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *v); -GLAPI void APIENTRY glWindowPos2fARB (GLfloat x, GLfloat y); -GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *v); -GLAPI void APIENTRY glWindowPos2iARB (GLint x, GLint y); -GLAPI void APIENTRY glWindowPos2ivARB (const GLint *v); -GLAPI void APIENTRY glWindowPos2sARB (GLshort x, GLshort y); -GLAPI void APIENTRY glWindowPos2svARB (const GLshort *v); -GLAPI void APIENTRY glWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *v); -GLAPI void APIENTRY glWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *v); -GLAPI void APIENTRY glWindowPos3iARB (GLint x, GLint y, GLint z); -GLAPI void APIENTRY glWindowPos3ivARB (const GLint *v); -GLAPI void APIENTRY glWindowPos3sARB (GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glWindowPos3svARB (const GLshort *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); -typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); -#endif - -#ifndef GL_ARB_vertex_program -#define GL_ARB_vertex_program 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttrib1dARB (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib1fARB (GLuint index, GLfloat x); -GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib1sARB (GLuint index, GLshort x); -GLAPI void APIENTRY glVertexAttrib1svARB (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib2dARB (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib2fARB (GLuint index, GLfloat x, GLfloat y); -GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib2sARB (GLuint index, GLshort x, GLshort y); -GLAPI void APIENTRY glVertexAttrib2svARB (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib3dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib3fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib3sARB (GLuint index, GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glVertexAttrib3svARB (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttrib4dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib4fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttrib4sARB (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI void APIENTRY glVertexAttrib4svARB (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttribPointerARB (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint index); -GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint index); -GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const GLvoid *string); -GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program); -GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs); -GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs); -GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); -GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); -GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); -GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); -GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params); -GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params); -GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params); -GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params); -GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, GLvoid *string); -GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint index, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVertexAttribivARB (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint index, GLenum pname, GLvoid* *pointer); -GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); -typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); -typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); -typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); -typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); -#endif - -#ifndef GL_ARB_fragment_program -#define GL_ARB_fragment_program 1 -/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ -#endif - -#ifndef GL_ARB_vertex_buffer_object -#define GL_ARB_vertex_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer); -GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers); -GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint *buffers); -GLAPI GLboolean APIENTRY glIsBufferARB (GLuint buffer); -GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); -GLAPI void APIENTRY glBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); -GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); -GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum target, GLenum access); -GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum target); -GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, GLvoid* *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); -typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); -typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); -typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); -typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); -typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); -#endif - -#ifndef GL_ARB_occlusion_query -#define GL_ARB_occlusion_query 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenQueriesARB (GLsizei n, GLuint *ids); -GLAPI void APIENTRY glDeleteQueriesARB (GLsizei n, const GLuint *ids); -GLAPI GLboolean APIENTRY glIsQueryARB (GLuint id); -GLAPI void APIENTRY glBeginQueryARB (GLenum target, GLuint id); -GLAPI void APIENTRY glEndQueryARB (GLenum target); -GLAPI void APIENTRY glGetQueryivARB (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetQueryObjectivARB (GLuint id, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint id, GLenum pname, GLuint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); -#endif - -#ifndef GL_ARB_shader_objects -#define GL_ARB_shader_objects 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB obj); -GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum pname); -GLAPI void APIENTRY glDetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj); -GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum shaderType); -GLAPI void APIENTRY glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); -GLAPI void APIENTRY glCompileShaderARB (GLhandleARB shaderObj); -GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); -GLAPI void APIENTRY glAttachObjectARB (GLhandleARB containerObj, GLhandleARB obj); -GLAPI void APIENTRY glLinkProgramARB (GLhandleARB programObj); -GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB programObj); -GLAPI void APIENTRY glValidateProgramARB (GLhandleARB programObj); -GLAPI void APIENTRY glUniform1fARB (GLint location, GLfloat v0); -GLAPI void APIENTRY glUniform2fARB (GLint location, GLfloat v0, GLfloat v1); -GLAPI void APIENTRY glUniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI void APIENTRY glUniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI void APIENTRY glUniform1iARB (GLint location, GLint v0); -GLAPI void APIENTRY glUniform2iARB (GLint location, GLint v0, GLint v1); -GLAPI void APIENTRY glUniform3iARB (GLint location, GLint v0, GLint v1, GLint v2); -GLAPI void APIENTRY glUniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI void APIENTRY glUniform1fvARB (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform2fvARB (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform3fvARB (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform4fvARB (GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glUniform1ivARB (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform2ivARB (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform3ivARB (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniform4ivARB (GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glUniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glUniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); -GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); -GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name); -GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params); -GLAPI void APIENTRY glGetUniformivARB (GLhandleARB programObj, GLint location, GLint *params); -GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); -typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); -typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); -typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); -typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); -typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); -typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); -typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); -typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); -typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); -typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); -typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); -typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); -#endif - -#ifndef GL_ARB_vertex_shader -#define GL_ARB_vertex_shader 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name); -GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); -typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); -#endif - -#ifndef GL_ARB_fragment_shader -#define GL_ARB_fragment_shader 1 -#endif - -#ifndef GL_ARB_shading_language_100 -#define GL_ARB_shading_language_100 1 -#endif - -#ifndef GL_ARB_texture_non_power_of_two -#define GL_ARB_texture_non_power_of_two 1 -#endif - -#ifndef GL_ARB_point_sprite -#define GL_ARB_point_sprite 1 -#endif - -#ifndef GL_ARB_fragment_program_shadow -#define GL_ARB_fragment_program_shadow 1 -#endif - -#ifndef GL_ARB_draw_buffers -#define GL_ARB_draw_buffers 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawBuffersARB (GLsizei n, const GLenum *bufs); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); -#endif - -#ifndef GL_ARB_texture_rectangle -#define GL_ARB_texture_rectangle 1 -#endif - -#ifndef GL_ARB_color_buffer_float -#define GL_ARB_color_buffer_float 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); -#endif - -#ifndef GL_ARB_half_float_pixel -#define GL_ARB_half_float_pixel 1 -#endif - -#ifndef GL_ARB_texture_float -#define GL_ARB_texture_float 1 -#endif - -#ifndef GL_ARB_pixel_buffer_object -#define GL_ARB_pixel_buffer_object 1 -#endif - -#ifndef GL_ARB_depth_buffer_float -#define GL_ARB_depth_buffer_float 1 -#endif - -#ifndef GL_ARB_draw_instanced -#define GL_ARB_draw_instanced 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); -#endif - -#ifndef GL_ARB_framebuffer_object -#define GL_ARB_framebuffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); -GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); -GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); -GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); -GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); -GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); -GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); -GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); -GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); -GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); -GLAPI void APIENTRY glGenerateMipmap (GLenum target); -GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); -typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); -typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); -typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); -typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); -typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); -typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -#endif - -#ifndef GL_ARB_framebuffer_sRGB -#define GL_ARB_framebuffer_sRGB 1 -#endif - -#ifndef GL_ARB_geometry_shader4 -#define GL_ARB_geometry_shader4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramParameteriARB (GLuint program, GLenum pname, GLint value); -GLAPI void APIENTRY glFramebufferTextureARB (GLenum target, GLenum attachment, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); -#endif - -#ifndef GL_ARB_half_float_vertex -#define GL_ARB_half_float_vertex 1 -#endif - -#ifndef GL_ARB_instanced_arrays -#define GL_ARB_instanced_arrays 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint index, GLuint divisor); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); -#endif - -#ifndef GL_ARB_map_buffer_range -#define GL_ARB_map_buffer_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); -GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); -typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); -#endif - -#ifndef GL_ARB_texture_buffer_object -#define GL_ARB_texture_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexBufferARB (GLenum target, GLenum internalformat, GLuint buffer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer); -#endif - -#ifndef GL_ARB_texture_compression_rgtc -#define GL_ARB_texture_compression_rgtc 1 -#endif - -#ifndef GL_ARB_texture_rg -#define GL_ARB_texture_rg 1 -#endif - -#ifndef GL_ARB_vertex_array_object -#define GL_ARB_vertex_array_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindVertexArray (GLuint array); -GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); -GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); -GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); -typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); -typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); -typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); -#endif - -#ifndef GL_ARB_uniform_buffer_object -#define GL_ARB_uniform_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); -GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); -GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); -GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); -GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); -typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); -typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -#endif - -#ifndef GL_ARB_compatibility -#define GL_ARB_compatibility 1 -#endif - -#ifndef GL_ARB_copy_buffer -#define GL_ARB_copy_buffer 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -#endif - -#ifndef GL_ARB_shader_texture_lod -#define GL_ARB_shader_texture_lod 1 -#endif - -#ifndef GL_ARB_depth_clamp -#define GL_ARB_depth_clamp 1 -#endif - -#ifndef GL_ARB_draw_elements_base_vertex -#define GL_ARB_draw_elements_base_vertex 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); -GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); -#endif - -#ifndef GL_ARB_fragment_coord_conventions -#define GL_ARB_fragment_coord_conventions 1 -#endif - -#ifndef GL_ARB_provoking_vertex -#define GL_ARB_provoking_vertex 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProvokingVertex (GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); -#endif - -#ifndef GL_ARB_seamless_cube_map -#define GL_ARB_seamless_cube_map 1 -#endif - -#ifndef GL_ARB_sync -#define GL_ARB_sync 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); -GLAPI GLboolean APIENTRY glIsSync (GLsync sync); -GLAPI void APIENTRY glDeleteSync (GLsync sync); -GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); -GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); -GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); -GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); -typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); -typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); -typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); -typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); -typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); -typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -#endif - -#ifndef GL_ARB_texture_multisample -#define GL_ARB_texture_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); -GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); -typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); -#endif - -#ifndef GL_ARB_vertex_array_bgra -#define GL_ARB_vertex_array_bgra 1 -#endif - -#ifndef GL_ARB_draw_buffers_blend -#define GL_ARB_draw_buffers_blend 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); -GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); -GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -#endif - -#ifndef GL_ARB_sample_shading -#define GL_ARB_sample_shading 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); -#endif - -#ifndef GL_ARB_texture_cube_map_array -#define GL_ARB_texture_cube_map_array 1 -#endif - -#ifndef GL_ARB_texture_gather -#define GL_ARB_texture_gather 1 -#endif - -#ifndef GL_ARB_texture_query_lod -#define GL_ARB_texture_query_lod 1 -#endif - -#ifndef GL_ARB_shading_language_include -#define GL_ARB_shading_language_include 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); -GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); -GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); -GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); -GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); -GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); -typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); -typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); -typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); -typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); -typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_texture_compression_bptc -#define GL_ARB_texture_compression_bptc 1 -#endif - -#ifndef GL_ARB_blend_func_extended -#define GL_ARB_blend_func_extended 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); -GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); -#endif - -#ifndef GL_ARB_explicit_attrib_location -#define GL_ARB_explicit_attrib_location 1 -#endif - -#ifndef GL_ARB_occlusion_query2 -#define GL_ARB_occlusion_query2 1 -#endif - -#ifndef GL_ARB_sampler_objects -#define GL_ARB_sampler_objects 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); -GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); -GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); -GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); -GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); -GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); -GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); -GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); -GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); -GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); -GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); -typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); -typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); -typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); -typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); -#endif - -#ifndef GL_ARB_shader_bit_encoding -#define GL_ARB_shader_bit_encoding 1 -#endif - -#ifndef GL_ARB_texture_rgb10_a2ui -#define GL_ARB_texture_rgb10_a2ui 1 -#endif - -#ifndef GL_ARB_texture_swizzle -#define GL_ARB_texture_swizzle 1 -#endif - -#ifndef GL_ARB_timer_query -#define GL_ARB_timer_query 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); -GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); -GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); -#endif - -#ifndef GL_ARB_vertex_type_2_10_10_10_rev -#define GL_ARB_vertex_type_2_10_10_10_rev 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); -GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); -GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); -GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); -GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); -GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); -GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); -GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); -GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); -GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); -GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); -GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); -GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); -GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); -GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); -GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); -GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); -GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); -typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); -typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); -typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); -typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); -typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); -typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); -typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); -typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); -typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); -#endif - -#ifndef GL_ARB_draw_indirect -#define GL_ARB_draw_indirect 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); -GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); -#endif - -#ifndef GL_ARB_gpu_shader5 -#define GL_ARB_gpu_shader5 1 -#endif - -#ifndef GL_ARB_gpu_shader_fp64 -#define GL_ARB_gpu_shader_fp64 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); -GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); -GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); -typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); -#endif - -#ifndef GL_ARB_shader_subroutine -#define GL_ARB_shader_subroutine 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); -GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); -GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); -GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); -GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); -GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); -typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); -typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); -typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); -#endif - -#ifndef GL_ARB_tessellation_shader -#define GL_ARB_tessellation_shader 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); -GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); -typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); -#endif - -#ifndef GL_ARB_texture_buffer_object_rgb32 -#define GL_ARB_texture_buffer_object_rgb32 1 -#endif - -#ifndef GL_ARB_transform_feedback2 -#define GL_ARB_transform_feedback2 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); -GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); -GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); -GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); -GLAPI void APIENTRY glPauseTransformFeedback (void); -GLAPI void APIENTRY glResumeTransformFeedback (void); -GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); -typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); -typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); -typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); -#endif - -#ifndef GL_ARB_transform_feedback3 -#define GL_ARB_transform_feedback3 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); -GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); -GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); -GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); -typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); -typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_ES2_compatibility -#define GL_ARB_ES2_compatibility 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glReleaseShaderCompiler (void); -GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); -GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); -GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f); -GLAPI void APIENTRY glClearDepthf (GLfloat d); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); -typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); -typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); -typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f); -typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d); -#endif - -#ifndef GL_ARB_get_program_binary -#define GL_ARB_get_program_binary 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); -GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); -GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); -typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); -#endif - -#ifndef GL_ARB_separate_shader_objects -#define GL_ARB_separate_shader_objects 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); -GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); -GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* const *strings); -GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); -GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); -GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); -GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); -GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); -GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); -GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); -GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); -GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); -GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); -GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); -GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); -GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); -GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); -GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); -GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); -GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); -typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* const *strings); -typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); -typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); -typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); -typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); -typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); -#endif - -#ifndef GL_ARB_vertex_attrib_64bit -#define GL_ARB_vertex_attrib_64bit 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); -#endif - -#ifndef GL_ARB_viewport_array -#define GL_ARB_viewport_array 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); -GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); -GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); -GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); -GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f); -GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); -GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); -typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); -typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f); -typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); -typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); -#endif - -#ifndef GL_ARB_cl_event -#define GL_ARB_cl_event 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); -#endif - -#ifndef GL_ARB_debug_output -#define GL_ARB_debug_output 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); -GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); -typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -#endif - -#ifndef GL_ARB_robustness -#define GL_ARB_robustness 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); -GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); -GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); -GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v); -GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values); -GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values); -GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values); -GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern); -GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); -GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); -GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); -GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); -GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); -GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); -GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); -GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); -GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); -GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); -typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); -typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); -typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); -typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values); -typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values); -typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values); -typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern); -typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); -typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); -typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); -typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); -typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); -typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); -typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); -typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); -typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); -typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); -typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); -#endif - -#ifndef GL_ARB_shader_stencil_export -#define GL_ARB_shader_stencil_export 1 -#endif - -#ifndef GL_ARB_base_instance -#define GL_ARB_base_instance 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); -GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); -#endif - -#ifndef GL_ARB_shading_language_420pack -#define GL_ARB_shading_language_420pack 1 -#endif - -#ifndef GL_ARB_transform_feedback_instanced -#define GL_ARB_transform_feedback_instanced 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); -GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); -#endif - -#ifndef GL_ARB_compressed_texture_pixel_storage -#define GL_ARB_compressed_texture_pixel_storage 1 -#endif - -#ifndef GL_ARB_conservative_depth -#define GL_ARB_conservative_depth 1 -#endif - -#ifndef GL_ARB_internalformat_query -#define GL_ARB_internalformat_query 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); -#endif - -#ifndef GL_ARB_map_buffer_alignment -#define GL_ARB_map_buffer_alignment 1 -#endif - -#ifndef GL_ARB_shader_atomic_counters -#define GL_ARB_shader_atomic_counters 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_shader_image_load_store -#define GL_ARB_shader_image_load_store 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); -GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); -typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); -#endif - -#ifndef GL_ARB_shading_language_packing -#define GL_ARB_shading_language_packing 1 -#endif - -#ifndef GL_ARB_texture_storage -#define GL_ARB_texture_storage 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -#endif - -#ifndef GL_KHR_texture_compression_astc_ldr -#define GL_KHR_texture_compression_astc_ldr 1 -#endif - -#ifndef GL_KHR_debug -#define GL_KHR_debug 1 -/* KHR_debug also reuses entry points from ARB_debug_group and ARB_debug_label */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); -GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); -GLAPI void APIENTRY glPopDebugGroup (void); -GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); -GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); -GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); -GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); -typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); -typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); -typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); -typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); -typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); -typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); -typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); -typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); -#endif - -#ifndef GL_ARB_arrays_of_arrays -#define GL_ARB_arrays_of_arrays 1 -#endif - -#ifndef GL_ARB_clear_buffer_object -#define GL_ARB_clear_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); -GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); -GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); -GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); -typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); -typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); -typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); -#endif - -#ifndef GL_ARB_compute_shader -#define GL_ARB_compute_shader 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); -GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); -typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); -#endif - -#ifndef GL_ARB_copy_image -#define GL_ARB_copy_image 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); -#endif - -#ifndef GL_ARB_debug_group -#define GL_ARB_debug_group 1 -/* ARB_debug_group reuses entry points from KHR_debug */ -#endif - -#ifndef GL_ARB_debug_label -#define GL_ARB_debug_label 1 -/* ARB_debug_label reuses entry points from KHR_debug */ -#endif - -#ifndef GL_ARB_debug_output2 -#define GL_ARB_debug_output2 1 -#endif - -#ifndef GL_ARB_ES3_compatibility -#define GL_ARB_ES3_compatibility 1 -#endif - -#ifndef GL_ARB_explicit_uniform_location -#define GL_ARB_explicit_uniform_location 1 -#endif - -#ifndef GL_ARB_fragment_layer_viewport -#define GL_ARB_fragment_layer_viewport 1 -#endif - -#ifndef GL_ARB_framebuffer_no_attachments -#define GL_ARB_framebuffer_no_attachments 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); -GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); -#endif - -#ifndef GL_ARB_internalformat_query2 -#define GL_ARB_internalformat_query2 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); -#endif - -#ifndef GL_ARB_invalidate_subdata -#define GL_ARB_invalidate_subdata 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); -GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); -GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); -GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); -GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); -GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); -typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); -typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); -typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); -#endif - -#ifndef GL_ARB_multi_draw_indirect -#define GL_ARB_multi_draw_indirect 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); -GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); -#endif - -#ifndef GL_ARB_program_interface_query -#define GL_ARB_program_interface_query 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); -GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); -GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); -GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); -GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); -GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); -typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); -typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); -typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); -#endif - -#ifndef GL_ARB_robust_buffer_access_behavior -#define GL_ARB_robust_buffer_access_behavior 1 -#endif - -#ifndef GL_ARB_shader_image_size -#define GL_ARB_shader_image_size 1 -#endif - -#ifndef GL_ARB_shader_storage_buffer_object -#define GL_ARB_shader_storage_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); -#endif - -#ifndef GL_ARB_stencil_texturing -#define GL_ARB_stencil_texturing 1 -#endif - -#ifndef GL_ARB_texture_buffer_range -#define GL_ARB_texture_buffer_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); -#endif - -#ifndef GL_ARB_texture_query_levels -#define GL_ARB_texture_query_levels 1 -#endif - -#ifndef GL_ARB_texture_storage_multisample -#define GL_ARB_texture_storage_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); -typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); -#endif - -#ifndef GL_ARB_texture_view -#define GL_ARB_texture_view 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); -#endif - -#ifndef GL_ARB_vertex_attrib_binding -#define GL_ARB_vertex_attrib_binding 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); -GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); -GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); -GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); -typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); -typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); -#endif - -#ifndef GL_ARB_robustness_isolation -#define GL_ARB_robustness_isolation 1 -#endif - -#ifndef GL_EXT_abgr -#define GL_EXT_abgr 1 -#endif - -#ifndef GL_EXT_blend_color -#define GL_EXT_blend_color 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendColorEXT (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -#endif - -#ifndef GL_EXT_polygon_offset -#define GL_EXT_polygon_offset 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat factor, GLfloat bias); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); -#endif - -#ifndef GL_EXT_texture -#define GL_EXT_texture 1 -#endif - -#ifndef GL_EXT_texture3D -#define GL_EXT_texture3D 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexImage3DEXT (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -#endif - -#ifndef GL_SGIS_texture_filter4 -#define GL_SGIS_texture_filter4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum target, GLenum filter, GLfloat *weights); -GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); -typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); -#endif - -#ifndef GL_EXT_subtexture -#define GL_EXT_subtexture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -#endif - -#ifndef GL_EXT_copy_texture -#define GL_EXT_copy_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -#endif - -#ifndef GL_EXT_histogram -#define GL_EXT_histogram 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glHistogramEXT (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); -GLAPI void APIENTRY glMinmaxEXT (GLenum target, GLenum internalformat, GLboolean sink); -GLAPI void APIENTRY glResetHistogramEXT (GLenum target); -GLAPI void APIENTRY glResetMinmaxEXT (GLenum target); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); -typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); -typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); -#endif - -#ifndef GL_EXT_convolution -#define GL_EXT_convolution 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); -GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); -GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum target, GLenum pname, GLfloat params); -GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum target, GLenum pname, GLint params); -GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *image); -GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); -GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); -typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); -typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); -#endif - -#ifndef GL_SGI_color_matrix -#define GL_SGI_color_matrix 1 -#endif - -#ifndef GL_SGI_color_table -#define GL_SGI_color_table 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorTableSGI (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glColorTableParameterivSGI (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glCopyColorTableSGI (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glGetColorTableSGI (GLenum target, GLenum format, GLenum type, GLvoid *table); -GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum target, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); -#endif - -#ifndef GL_SGIX_pixel_texture -#define GL_SGIX_pixel_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelTexGenSGIX (GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); -#endif - -#ifndef GL_SGIS_pixel_texture -#define GL_SGIS_pixel_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum pname, GLint param); -GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum pname, const GLint *params); -GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum pname, GLint *params); -GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum pname, GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); -#endif - -#ifndef GL_SGIS_texture4D -#define GL_SGIS_texture4D 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexImage4DSGIS (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); -#endif - -#ifndef GL_SGI_texture_color_table -#define GL_SGI_texture_color_table 1 -#endif - -#ifndef GL_EXT_cmyka -#define GL_EXT_cmyka 1 -#endif - -#ifndef GL_EXT_texture_object -#define GL_EXT_texture_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei n, const GLuint *textures, GLboolean *residences); -GLAPI void APIENTRY glBindTextureEXT (GLenum target, GLuint texture); -GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei n, const GLuint *textures); -GLAPI void APIENTRY glGenTexturesEXT (GLsizei n, GLuint *textures); -GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint texture); -GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei n, const GLuint *textures, const GLclampf *priorities); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); -typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); -typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); -typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); -typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); -typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); -#endif - -#ifndef GL_SGIS_detail_texture -#define GL_SGIS_detail_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); -GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); -typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); -#endif - -#ifndef GL_SGIS_sharpen_texture -#define GL_SGIS_sharpen_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); -GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); -typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); -#endif - -#ifndef GL_EXT_packed_pixels -#define GL_EXT_packed_pixels 1 -#endif - -#ifndef GL_SGIS_texture_lod -#define GL_SGIS_texture_lod 1 -#endif - -#ifndef GL_SGIS_multisample -#define GL_SGIS_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSampleMaskSGIS (GLclampf value, GLboolean invert); -GLAPI void APIENTRY glSamplePatternSGIS (GLenum pattern); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); -typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); -#endif - -#ifndef GL_EXT_rescale_normal -#define GL_EXT_rescale_normal 1 -#endif - -#ifndef GL_EXT_vertex_array -#define GL_EXT_vertex_array 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glArrayElementEXT (GLint i); -GLAPI void APIENTRY glColorPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -GLAPI void APIENTRY glDrawArraysEXT (GLenum mode, GLint first, GLsizei count); -GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei stride, GLsizei count, const GLboolean *pointer); -GLAPI void APIENTRY glGetPointervEXT (GLenum pname, GLvoid* *params); -GLAPI void APIENTRY glIndexPointerEXT (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -GLAPI void APIENTRY glNormalPointerEXT (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -GLAPI void APIENTRY glTexCoordPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -GLAPI void APIENTRY glVertexPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); -typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); -typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); -typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); -#endif - -#ifndef GL_EXT_misc_attribute -#define GL_EXT_misc_attribute 1 -#endif - -#ifndef GL_SGIS_generate_mipmap -#define GL_SGIS_generate_mipmap 1 -#endif - -#ifndef GL_SGIX_clipmap -#define GL_SGIX_clipmap 1 -#endif - -#ifndef GL_SGIX_shadow -#define GL_SGIX_shadow 1 -#endif - -#ifndef GL_SGIS_texture_edge_clamp -#define GL_SGIS_texture_edge_clamp 1 -#endif - -#ifndef GL_SGIS_texture_border_clamp -#define GL_SGIS_texture_border_clamp 1 -#endif - -#ifndef GL_EXT_blend_minmax -#define GL_EXT_blend_minmax 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationEXT (GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); -#endif - -#ifndef GL_EXT_blend_subtract -#define GL_EXT_blend_subtract 1 -#endif - -#ifndef GL_EXT_blend_logic_op -#define GL_EXT_blend_logic_op 1 -#endif - -#ifndef GL_SGIX_interlace -#define GL_SGIX_interlace 1 -#endif - -#ifndef GL_SGIX_pixel_tiles -#define GL_SGIX_pixel_tiles 1 -#endif - -#ifndef GL_SGIX_texture_select -#define GL_SGIX_texture_select 1 -#endif - -#ifndef GL_SGIX_sprite -#define GL_SGIX_sprite 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum pname, GLfloat param); -GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum pname, GLint param); -GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum pname, const GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); -#endif - -#ifndef GL_SGIX_texture_multi_buffer -#define GL_SGIX_texture_multi_buffer 1 -#endif - -#ifndef GL_EXT_point_parameters -#define GL_EXT_point_parameters 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameterfEXT (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPointParameterfvEXT (GLenum pname, const GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); -#endif - -#ifndef GL_SGIS_point_parameters -#define GL_SGIS_point_parameters 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameterfSGIS (GLenum pname, GLfloat param); -GLAPI void APIENTRY glPointParameterfvSGIS (GLenum pname, const GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); -#endif - -#ifndef GL_SGIX_instruments -#define GL_SGIX_instruments 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); -GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei size, GLint *buffer); -GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *marker_p); -GLAPI void APIENTRY glReadInstrumentsSGIX (GLint marker); -GLAPI void APIENTRY glStartInstrumentsSGIX (void); -GLAPI void APIENTRY glStopInstrumentsSGIX (GLint marker); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); -typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); -typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); -typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); -typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); -typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); -#endif - -#ifndef GL_SGIX_texture_scale_bias -#define GL_SGIX_texture_scale_bias 1 -#endif - -#ifndef GL_SGIX_framezoom -#define GL_SGIX_framezoom 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFrameZoomSGIX (GLint factor); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); -#endif - -#ifndef GL_SGIX_tag_sample_buffer -#define GL_SGIX_tag_sample_buffer 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTagSampleBufferSGIX (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); -#endif - -#ifndef GL_SGIX_polynomial_ffd -#define GL_SGIX_polynomial_ffd 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); -GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); -GLAPI void APIENTRY glDeformSGIX (GLbitfield mask); -GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield mask); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); -typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); -typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); -typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); -#endif - -#ifndef GL_SGIX_reference_plane -#define GL_SGIX_reference_plane 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *equation); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); -#endif - -#ifndef GL_SGIX_flush_raster -#define GL_SGIX_flush_raster 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFlushRasterSGIX (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); -#endif - -#ifndef GL_SGIX_depth_texture -#define GL_SGIX_depth_texture 1 -#endif - -#ifndef GL_SGIS_fog_function -#define GL_SGIS_fog_function 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFogFuncSGIS (GLsizei n, const GLfloat *points); -GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *points); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); -typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); -#endif - -#ifndef GL_SGIX_fog_offset -#define GL_SGIX_fog_offset 1 -#endif - -#ifndef GL_HP_image_transform -#define GL_HP_image_transform 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glImageTransformParameteriHP (GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glImageTransformParameterfHP (GLenum target, GLenum pname, GLfloat param); -GLAPI void APIENTRY glImageTransformParameterivHP (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum target, GLenum pname, GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); -#endif - -#ifndef GL_HP_convolution_border_modes -#define GL_HP_convolution_border_modes 1 -#endif - -#ifndef GL_SGIX_texture_add_env -#define GL_SGIX_texture_add_env 1 -#endif - -#ifndef GL_EXT_color_subtable -#define GL_EXT_color_subtable 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); -GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); -typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); -#endif - -#ifndef GL_PGI_vertex_hints -#define GL_PGI_vertex_hints 1 -#endif - -#ifndef GL_PGI_misc_hints -#define GL_PGI_misc_hints 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glHintPGI (GLenum target, GLint mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); -#endif - -#ifndef GL_EXT_paletted_texture -#define GL_EXT_paletted_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, GLvoid *data); -GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); -typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); -#endif - -#ifndef GL_EXT_clip_volume_hint -#define GL_EXT_clip_volume_hint 1 -#endif - -#ifndef GL_SGIX_list_priority -#define GL_SGIX_list_priority 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint list, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetListParameterivSGIX (GLuint list, GLenum pname, GLint *params); -GLAPI void APIENTRY glListParameterfSGIX (GLuint list, GLenum pname, GLfloat param); -GLAPI void APIENTRY glListParameterfvSGIX (GLuint list, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glListParameteriSGIX (GLuint list, GLenum pname, GLint param); -GLAPI void APIENTRY glListParameterivSGIX (GLuint list, GLenum pname, const GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); -#endif - -#ifndef GL_SGIX_ir_instrument1 -#define GL_SGIX_ir_instrument1 1 -#endif - -#ifndef GL_SGIX_calligraphic_fragment -#define GL_SGIX_calligraphic_fragment 1 -#endif - -#ifndef GL_SGIX_texture_lod_bias -#define GL_SGIX_texture_lod_bias 1 -#endif - -#ifndef GL_SGIX_shadow_ambient -#define GL_SGIX_shadow_ambient 1 -#endif - -#ifndef GL_EXT_index_texture -#define GL_EXT_index_texture 1 -#endif - -#ifndef GL_EXT_index_material -#define GL_EXT_index_material 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glIndexMaterialEXT (GLenum face, GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); -#endif - -#ifndef GL_EXT_index_func -#define GL_EXT_index_func 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glIndexFuncEXT (GLenum func, GLclampf ref); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); -#endif - -#ifndef GL_EXT_index_array_formats -#define GL_EXT_index_array_formats 1 -#endif - -#ifndef GL_EXT_compiled_vertex_array -#define GL_EXT_compiled_vertex_array 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glLockArraysEXT (GLint first, GLsizei count); -GLAPI void APIENTRY glUnlockArraysEXT (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); -#endif - -#ifndef GL_EXT_cull_vertex -#define GL_EXT_cull_vertex 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCullParameterdvEXT (GLenum pname, GLdouble *params); -GLAPI void APIENTRY glCullParameterfvEXT (GLenum pname, GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); -#endif - -#ifndef GL_SGIX_ycrcb -#define GL_SGIX_ycrcb 1 -#endif - -#ifndef GL_SGIX_fragment_lighting -#define GL_SGIX_fragment_lighting 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum face, GLenum mode); -GLAPI void APIENTRY glFragmentLightfSGIX (GLenum light, GLenum pname, GLfloat param); -GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum light, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glFragmentLightiSGIX (GLenum light, GLenum pname, GLint param); -GLAPI void APIENTRY glFragmentLightivSGIX (GLenum light, GLenum pname, const GLint *params); -GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum pname, GLfloat param); -GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum pname, GLint param); -GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum pname, const GLint *params); -GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum face, GLenum pname, GLfloat param); -GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum face, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum face, GLenum pname, GLint param); -GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum face, GLenum pname, const GLint *params); -GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum light, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum light, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum face, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum face, GLenum pname, GLint *params); -GLAPI void APIENTRY glLightEnviSGIX (GLenum pname, GLint param); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); -#endif - -#ifndef GL_IBM_rasterpos_clip -#define GL_IBM_rasterpos_clip 1 -#endif - -#ifndef GL_HP_texture_lighting -#define GL_HP_texture_lighting 1 -#endif - -#ifndef GL_EXT_draw_range_elements -#define GL_EXT_draw_range_elements 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); -#endif - -#ifndef GL_WIN_phong_shading -#define GL_WIN_phong_shading 1 -#endif - -#ifndef GL_WIN_specular_fog -#define GL_WIN_specular_fog 1 -#endif - -#ifndef GL_EXT_light_texture -#define GL_EXT_light_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glApplyTextureEXT (GLenum mode); -GLAPI void APIENTRY glTextureLightEXT (GLenum pname); -GLAPI void APIENTRY glTextureMaterialEXT (GLenum face, GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); -typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); -#endif - -#ifndef GL_SGIX_blend_alpha_minmax -#define GL_SGIX_blend_alpha_minmax 1 -#endif - -#ifndef GL_EXT_bgra -#define GL_EXT_bgra 1 -#endif - -#ifndef GL_SGIX_async -#define GL_SGIX_async 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint marker); -GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *markerp); -GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *markerp); -GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei range); -GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint marker, GLsizei range); -GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint marker); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); -typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); -typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); -typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); -typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); -typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); -#endif - -#ifndef GL_SGIX_async_pixel -#define GL_SGIX_async_pixel 1 -#endif - -#ifndef GL_SGIX_async_histogram -#define GL_SGIX_async_histogram 1 -#endif - -#ifndef GL_INTEL_parallel_arrays -#define GL_INTEL_parallel_arrays 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); -GLAPI void APIENTRY glNormalPointervINTEL (GLenum type, const GLvoid* *pointer); -GLAPI void APIENTRY glColorPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); -GLAPI void APIENTRY glTexCoordPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); -typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); -typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); -typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); -#endif - -#ifndef GL_HP_occlusion_test -#define GL_HP_occlusion_test 1 -#endif - -#ifndef GL_EXT_pixel_transform -#define GL_EXT_pixel_transform 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum target, GLenum pname, GLfloat param); -GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); -#endif - -#ifndef GL_EXT_pixel_transform_color_table -#define GL_EXT_pixel_transform_color_table 1 -#endif - -#ifndef GL_EXT_shared_texture_palette -#define GL_EXT_shared_texture_palette 1 -#endif - -#ifndef GL_EXT_separate_specular_color -#define GL_EXT_separate_specular_color 1 -#endif - -#ifndef GL_EXT_secondary_color -#define GL_EXT_secondary_color 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte red, GLbyte green, GLbyte blue); -GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *v); -GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble red, GLdouble green, GLdouble blue); -GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *v); -GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat red, GLfloat green, GLfloat blue); -GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *v); -GLAPI void APIENTRY glSecondaryColor3iEXT (GLint red, GLint green, GLint blue); -GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *v); -GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort red, GLshort green, GLshort blue); -GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *v); -GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte red, GLubyte green, GLubyte blue); -GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *v); -GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint red, GLuint green, GLuint blue); -GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *v); -GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort red, GLushort green, GLushort blue); -GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *v); -GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_EXT_texture_perturb_normal -#define GL_EXT_texture_perturb_normal 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureNormalEXT (GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); -#endif - -#ifndef GL_EXT_multi_draw_arrays -#define GL_EXT_multi_draw_arrays 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); -#endif - -#ifndef GL_EXT_fog_coord -#define GL_EXT_fog_coord 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFogCoordfEXT (GLfloat coord); -GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *coord); -GLAPI void APIENTRY glFogCoorddEXT (GLdouble coord); -GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *coord); -GLAPI void APIENTRY glFogCoordPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); -typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); -typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); -typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); -typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_REND_screen_coordinates -#define GL_REND_screen_coordinates 1 -#endif - -#ifndef GL_EXT_coordinate_frame -#define GL_EXT_coordinate_frame 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTangent3bEXT (GLbyte tx, GLbyte ty, GLbyte tz); -GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *v); -GLAPI void APIENTRY glTangent3dEXT (GLdouble tx, GLdouble ty, GLdouble tz); -GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *v); -GLAPI void APIENTRY glTangent3fEXT (GLfloat tx, GLfloat ty, GLfloat tz); -GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *v); -GLAPI void APIENTRY glTangent3iEXT (GLint tx, GLint ty, GLint tz); -GLAPI void APIENTRY glTangent3ivEXT (const GLint *v); -GLAPI void APIENTRY glTangent3sEXT (GLshort tx, GLshort ty, GLshort tz); -GLAPI void APIENTRY glTangent3svEXT (const GLshort *v); -GLAPI void APIENTRY glBinormal3bEXT (GLbyte bx, GLbyte by, GLbyte bz); -GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *v); -GLAPI void APIENTRY glBinormal3dEXT (GLdouble bx, GLdouble by, GLdouble bz); -GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *v); -GLAPI void APIENTRY glBinormal3fEXT (GLfloat bx, GLfloat by, GLfloat bz); -GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *v); -GLAPI void APIENTRY glBinormal3iEXT (GLint bx, GLint by, GLint bz); -GLAPI void APIENTRY glBinormal3ivEXT (const GLint *v); -GLAPI void APIENTRY glBinormal3sEXT (GLshort bx, GLshort by, GLshort bz); -GLAPI void APIENTRY glBinormal3svEXT (const GLshort *v); -GLAPI void APIENTRY glTangentPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glBinormalPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); -typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); -typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); -typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); -typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); -typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); -typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); -typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); -typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); -typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); -typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); -typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_EXT_texture_env_combine -#define GL_EXT_texture_env_combine 1 -#endif - -#ifndef GL_APPLE_specular_vector -#define GL_APPLE_specular_vector 1 -#endif - -#ifndef GL_APPLE_transform_hint -#define GL_APPLE_transform_hint 1 -#endif - -#ifndef GL_SGIX_fog_scale -#define GL_SGIX_fog_scale 1 -#endif - -#ifndef GL_SUNX_constant_data -#define GL_SUNX_constant_data 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFinishTextureSUNX (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); -#endif - -#ifndef GL_SUN_global_alpha -#define GL_SUN_global_alpha 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte factor); -GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort factor); -GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint factor); -GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat factor); -GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble factor); -GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte factor); -GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort factor); -GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint factor); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); -typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); -#endif - -#ifndef GL_SUN_triangle_list -#define GL_SUN_triangle_list 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint code); -GLAPI void APIENTRY glReplacementCodeusSUN (GLushort code); -GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte code); -GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *code); -GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *code); -GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *code); -GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum type, GLsizei stride, const GLvoid* *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); -#endif - -#ifndef GL_SUN_vertex -#define GL_SUN_vertex 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); -GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *c, const GLfloat *v); -GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *c, const GLfloat *v); -GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *c, const GLfloat *v); -GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *c, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *tc, const GLfloat *v); -GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *tc, const GLfloat *v); -GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *tc, const GLubyte *c, const GLfloat *v); -GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *v); -GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint rc, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *rc, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *rc, const GLubyte *c, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); -#endif - -#ifndef GL_EXT_blend_func_separate -#define GL_EXT_blend_func_separate 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -#endif - -#ifndef GL_INGR_blend_func_separate -#define GL_INGR_blend_func_separate 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); -#endif - -#ifndef GL_INGR_color_clamp -#define GL_INGR_color_clamp 1 -#endif - -#ifndef GL_INGR_interlace_read -#define GL_INGR_interlace_read 1 -#endif - -#ifndef GL_EXT_stencil_wrap -#define GL_EXT_stencil_wrap 1 -#endif - -#ifndef GL_EXT_422_pixels -#define GL_EXT_422_pixels 1 -#endif - -#ifndef GL_NV_texgen_reflection -#define GL_NV_texgen_reflection 1 -#endif - -#ifndef GL_SUN_convolution_border_modes -#define GL_SUN_convolution_border_modes 1 -#endif - -#ifndef GL_EXT_texture_env_add -#define GL_EXT_texture_env_add 1 -#endif - -#ifndef GL_EXT_texture_lod_bias -#define GL_EXT_texture_lod_bias 1 -#endif - -#ifndef GL_EXT_texture_filter_anisotropic -#define GL_EXT_texture_filter_anisotropic 1 -#endif - -#ifndef GL_EXT_vertex_weighting -#define GL_EXT_vertex_weighting 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight); -GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight); -GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); -#endif - -#ifndef GL_NV_light_max_exponent -#define GL_NV_light_max_exponent 1 -#endif - -#ifndef GL_NV_vertex_array_range -#define GL_NV_vertex_array_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); -GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei length, const GLvoid *pointer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); -typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); -#endif - -#ifndef GL_NV_register_combiners -#define GL_NV_register_combiners 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCombinerParameterfvNV (GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glCombinerParameterfNV (GLenum pname, GLfloat param); -GLAPI void APIENTRY glCombinerParameterivNV (GLenum pname, const GLint *params); -GLAPI void APIENTRY glCombinerParameteriNV (GLenum pname, GLint param); -GLAPI void APIENTRY glCombinerInputNV (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); -GLAPI void APIENTRY glCombinerOutputNV (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); -GLAPI void APIENTRY glFinalCombinerInputNV (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); -GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum stage, GLenum portion, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum variable, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum variable, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); -typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); -typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); -typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); -#endif - -#ifndef GL_NV_fog_distance -#define GL_NV_fog_distance 1 -#endif - -#ifndef GL_NV_texgen_emboss -#define GL_NV_texgen_emboss 1 -#endif - -#ifndef GL_NV_blend_square -#define GL_NV_blend_square 1 -#endif - -#ifndef GL_NV_texture_env_combine4 -#define GL_NV_texture_env_combine4 1 -#endif - -#ifndef GL_MESA_resize_buffers -#define GL_MESA_resize_buffers 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glResizeBuffersMESA (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); -#endif - -#ifndef GL_MESA_window_pos -#define GL_MESA_window_pos 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glWindowPos2dMESA (GLdouble x, GLdouble y); -GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *v); -GLAPI void APIENTRY glWindowPos2fMESA (GLfloat x, GLfloat y); -GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *v); -GLAPI void APIENTRY glWindowPos2iMESA (GLint x, GLint y); -GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *v); -GLAPI void APIENTRY glWindowPos2sMESA (GLshort x, GLshort y); -GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *v); -GLAPI void APIENTRY glWindowPos3dMESA (GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *v); -GLAPI void APIENTRY glWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *v); -GLAPI void APIENTRY glWindowPos3iMESA (GLint x, GLint y, GLint z); -GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *v); -GLAPI void APIENTRY glWindowPos3sMESA (GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *v); -GLAPI void APIENTRY glWindowPos4dMESA (GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *v); -GLAPI void APIENTRY glWindowPos4fMESA (GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *v); -GLAPI void APIENTRY glWindowPos4iMESA (GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *v); -GLAPI void APIENTRY glWindowPos4sMESA (GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); -typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); -typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); -#endif - -#ifndef GL_IBM_cull_vertex -#define GL_IBM_cull_vertex 1 -#endif - -#ifndef GL_IBM_multimode_draw_arrays -#define GL_IBM_multimode_draw_arrays 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); -GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); -typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); -#endif - -#ifndef GL_IBM_vertex_array_lists -#define GL_IBM_vertex_array_lists 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint stride, const GLboolean* *pointer, GLint ptrstride); -GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -GLAPI void APIENTRY glIndexPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -GLAPI void APIENTRY glNormalPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -GLAPI void APIENTRY glTexCoordPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -GLAPI void APIENTRY glVertexPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); -#endif - -#ifndef GL_SGIX_subsample -#define GL_SGIX_subsample 1 -#endif - -#ifndef GL_SGIX_ycrcba -#define GL_SGIX_ycrcba 1 -#endif - -#ifndef GL_SGIX_ycrcb_subsample -#define GL_SGIX_ycrcb_subsample 1 -#endif - -#ifndef GL_SGIX_depth_pass_instrument -#define GL_SGIX_depth_pass_instrument 1 -#endif - -#ifndef GL_3DFX_texture_compression_FXT1 -#define GL_3DFX_texture_compression_FXT1 1 -#endif - -#ifndef GL_3DFX_multisample -#define GL_3DFX_multisample 1 -#endif - -#ifndef GL_3DFX_tbuffer -#define GL_3DFX_tbuffer 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTbufferMask3DFX (GLuint mask); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); -#endif - -#ifndef GL_EXT_multisample -#define GL_EXT_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSampleMaskEXT (GLclampf value, GLboolean invert); -GLAPI void APIENTRY glSamplePatternEXT (GLenum pattern); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); -typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); -#endif - -#ifndef GL_SGIX_vertex_preclip -#define GL_SGIX_vertex_preclip 1 -#endif - -#ifndef GL_SGIX_convolution_accuracy -#define GL_SGIX_convolution_accuracy 1 -#endif - -#ifndef GL_SGIX_resample -#define GL_SGIX_resample 1 -#endif - -#ifndef GL_SGIS_point_line_texgen -#define GL_SGIS_point_line_texgen 1 -#endif - -#ifndef GL_SGIS_texture_color_mask -#define GL_SGIS_texture_color_mask 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); -#endif - -#ifndef GL_SGIX_igloo_interface -#define GL_SGIX_igloo_interface 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum pname, const GLvoid *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); -#endif - -#ifndef GL_EXT_texture_env_dot3 -#define GL_EXT_texture_env_dot3 1 -#endif - -#ifndef GL_ATI_texture_mirror_once -#define GL_ATI_texture_mirror_once 1 -#endif - -#ifndef GL_NV_fence -#define GL_NV_fence 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences); -GLAPI void APIENTRY glGenFencesNV (GLsizei n, GLuint *fences); -GLAPI GLboolean APIENTRY glIsFenceNV (GLuint fence); -GLAPI GLboolean APIENTRY glTestFenceNV (GLuint fence); -GLAPI void APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params); -GLAPI void APIENTRY glFinishFenceNV (GLuint fence); -GLAPI void APIENTRY glSetFenceNV (GLuint fence, GLenum condition); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); -typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); -typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); -typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); -typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); -#endif - -#ifndef GL_NV_evaluators -#define GL_NV_evaluators 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); -GLAPI void APIENTRY glMapParameterivNV (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glMapParameterfvNV (GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glGetMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); -GLAPI void APIENTRY glGetMapParameterivNV (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMapParameterfvNV (GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum target, GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glEvalMapsNV (GLenum target, GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); -typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); -typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); -#endif - -#ifndef GL_NV_packed_depth_stencil -#define GL_NV_packed_depth_stencil 1 -#endif - -#ifndef GL_NV_register_combiners2 -#define GL_NV_register_combiners2 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum stage, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum stage, GLenum pname, GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); -#endif - -#ifndef GL_NV_texture_compression_vtc -#define GL_NV_texture_compression_vtc 1 -#endif - -#ifndef GL_NV_texture_rectangle -#define GL_NV_texture_rectangle 1 -#endif - -#ifndef GL_NV_texture_shader -#define GL_NV_texture_shader 1 -#endif - -#ifndef GL_NV_texture_shader2 -#define GL_NV_texture_shader2 1 -#endif - -#ifndef GL_NV_vertex_array_range2 -#define GL_NV_vertex_array_range2 1 -#endif - -#ifndef GL_NV_vertex_program -#define GL_NV_vertex_program 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei n, const GLuint *programs, GLboolean *residences); -GLAPI void APIENTRY glBindProgramNV (GLenum target, GLuint id); -GLAPI void APIENTRY glDeleteProgramsNV (GLsizei n, const GLuint *programs); -GLAPI void APIENTRY glExecuteProgramNV (GLenum target, GLuint id, const GLfloat *params); -GLAPI void APIENTRY glGenProgramsNV (GLsizei n, GLuint *programs); -GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum target, GLuint index, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetProgramivNV (GLuint id, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetProgramStringNV (GLuint id, GLenum pname, GLubyte *program); -GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum target, GLuint address, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint index, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVertexAttribivNV (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint index, GLenum pname, GLvoid* *pointer); -GLAPI GLboolean APIENTRY glIsProgramNV (GLuint id); -GLAPI void APIENTRY glLoadProgramNV (GLenum target, GLuint id, GLsizei len, const GLubyte *program); -GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v); -GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v); -GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs); -GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform); -GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glVertexAttrib1dNV (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib1fNV (GLuint index, GLfloat x); -GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib1sNV (GLuint index, GLshort x); -GLAPI void APIENTRY glVertexAttrib1svNV (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib2dNV (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y); -GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib2sNV (GLuint index, GLshort x, GLshort y); -GLAPI void APIENTRY glVertexAttrib2svNV (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib3dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib3fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib3sNV (GLuint index, GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glVertexAttrib3svNV (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttrib4fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint index, const GLfloat *v); -GLAPI void APIENTRY glVertexAttrib4sNV (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI void APIENTRY glVertexAttrib4svNV (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint index, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint index, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glVertexAttribs1svNV (GLuint index, GLsizei count, const GLshort *v); -GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint index, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint index, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glVertexAttribs2svNV (GLuint index, GLsizei count, const GLshort *v); -GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint index, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint index, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glVertexAttribs3svNV (GLuint index, GLsizei count, const GLshort *v); -GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint index, GLsizei count, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint index, GLsizei count, const GLfloat *v); -GLAPI void APIENTRY glVertexAttribs4svNV (GLuint index, GLsizei count, const GLshort *v); -GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint index, GLsizei count, const GLubyte *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); -typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); -typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); -typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); -typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); -typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); -typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); -typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); -#endif - -#ifndef GL_SGIX_texture_coordinate_clamp -#define GL_SGIX_texture_coordinate_clamp 1 -#endif - -#ifndef GL_SGIX_scalebias_hint -#define GL_SGIX_scalebias_hint 1 -#endif - -#ifndef GL_OML_interlace -#define GL_OML_interlace 1 -#endif - -#ifndef GL_OML_subsample -#define GL_OML_subsample 1 -#endif - -#ifndef GL_OML_resample -#define GL_OML_resample 1 -#endif - -#ifndef GL_NV_copy_depth_to_color -#define GL_NV_copy_depth_to_color 1 -#endif - -#ifndef GL_ATI_envmap_bumpmap -#define GL_ATI_envmap_bumpmap 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexBumpParameterivATI (GLenum pname, const GLint *param); -GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum pname, const GLfloat *param); -GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum pname, GLint *param); -GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum pname, GLfloat *param); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); -typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); -typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); -typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); -#endif - -#ifndef GL_ATI_fragment_shader -#define GL_ATI_fragment_shader 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint range); -GLAPI void APIENTRY glBindFragmentShaderATI (GLuint id); -GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint id); -GLAPI void APIENTRY glBeginFragmentShaderATI (void); -GLAPI void APIENTRY glEndFragmentShaderATI (void); -GLAPI void APIENTRY glPassTexCoordATI (GLuint dst, GLuint coord, GLenum swizzle); -GLAPI void APIENTRY glSampleMapATI (GLuint dst, GLuint interp, GLenum swizzle); -GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); -GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); -GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); -GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); -GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); -GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); -GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint dst, const GLfloat *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); -typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); -typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); -typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); -typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); -typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); -typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); -typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); -typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); -typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); -typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); -typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); -typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); -#endif - -#ifndef GL_ATI_pn_triangles -#define GL_ATI_pn_triangles 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPNTrianglesiATI (GLenum pname, GLint param); -GLAPI void APIENTRY glPNTrianglesfATI (GLenum pname, GLfloat param); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); -#endif - -#ifndef GL_ATI_vertex_array_object -#define GL_ATI_vertex_array_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei size, const GLvoid *pointer, GLenum usage); -GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint buffer); -GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); -GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint buffer, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetObjectBufferivATI (GLuint buffer, GLenum pname, GLint *params); -GLAPI void APIENTRY glFreeObjectBufferATI (GLuint buffer); -GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); -GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum array, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetArrayObjectivATI (GLenum array, GLenum pname, GLint *params); -GLAPI void APIENTRY glVariantArrayObjectATI (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); -GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint id, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint id, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); -typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); -typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); -typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); -typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); -#endif - -#ifndef GL_EXT_vertex_shader -#define GL_EXT_vertex_shader 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBeginVertexShaderEXT (void); -GLAPI void APIENTRY glEndVertexShaderEXT (void); -GLAPI void APIENTRY glBindVertexShaderEXT (GLuint id); -GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint range); -GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint id); -GLAPI void APIENTRY glShaderOp1EXT (GLenum op, GLuint res, GLuint arg1); -GLAPI void APIENTRY glShaderOp2EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2); -GLAPI void APIENTRY glShaderOp3EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); -GLAPI void APIENTRY glSwizzleEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); -GLAPI void APIENTRY glWriteMaskEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); -GLAPI void APIENTRY glInsertComponentEXT (GLuint res, GLuint src, GLuint num); -GLAPI void APIENTRY glExtractComponentEXT (GLuint res, GLuint src, GLuint num); -GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); -GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const GLvoid *addr); -GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const GLvoid *addr); -GLAPI void APIENTRY glVariantbvEXT (GLuint id, const GLbyte *addr); -GLAPI void APIENTRY glVariantsvEXT (GLuint id, const GLshort *addr); -GLAPI void APIENTRY glVariantivEXT (GLuint id, const GLint *addr); -GLAPI void APIENTRY glVariantfvEXT (GLuint id, const GLfloat *addr); -GLAPI void APIENTRY glVariantdvEXT (GLuint id, const GLdouble *addr); -GLAPI void APIENTRY glVariantubvEXT (GLuint id, const GLubyte *addr); -GLAPI void APIENTRY glVariantusvEXT (GLuint id, const GLushort *addr); -GLAPI void APIENTRY glVariantuivEXT (GLuint id, const GLuint *addr); -GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); -GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id); -GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id); -GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum light, GLenum value); -GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum face, GLenum value); -GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum unit, GLenum coord, GLenum value); -GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum unit, GLenum value); -GLAPI GLuint APIENTRY glBindParameterEXT (GLenum value); -GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint id, GLenum cap); -GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); -GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint id, GLenum value, GLint *data); -GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); -GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum value, GLvoid* *data); -GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); -GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint id, GLenum value, GLint *data); -GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); -GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); -GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint id, GLenum value, GLint *data); -GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint id, GLenum value, GLfloat *data); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); -typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); -typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); -typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); -typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); -typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); -typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); -typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); -typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); -typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); -typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); -typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); -typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); -typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); -typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); -typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); -typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); -typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); -typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); -typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); -typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); -typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); -typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); -typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); -typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); -typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); -typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); -typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); -typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); -typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); -typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); -typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); -typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); -typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); -typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); -typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); -typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); -#endif - -#ifndef GL_ATI_vertex_streams -#define GL_ATI_vertex_streams 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexStream1sATI (GLenum stream, GLshort x); -GLAPI void APIENTRY glVertexStream1svATI (GLenum stream, const GLshort *coords); -GLAPI void APIENTRY glVertexStream1iATI (GLenum stream, GLint x); -GLAPI void APIENTRY glVertexStream1ivATI (GLenum stream, const GLint *coords); -GLAPI void APIENTRY glVertexStream1fATI (GLenum stream, GLfloat x); -GLAPI void APIENTRY glVertexStream1fvATI (GLenum stream, const GLfloat *coords); -GLAPI void APIENTRY glVertexStream1dATI (GLenum stream, GLdouble x); -GLAPI void APIENTRY glVertexStream1dvATI (GLenum stream, const GLdouble *coords); -GLAPI void APIENTRY glVertexStream2sATI (GLenum stream, GLshort x, GLshort y); -GLAPI void APIENTRY glVertexStream2svATI (GLenum stream, const GLshort *coords); -GLAPI void APIENTRY glVertexStream2iATI (GLenum stream, GLint x, GLint y); -GLAPI void APIENTRY glVertexStream2ivATI (GLenum stream, const GLint *coords); -GLAPI void APIENTRY glVertexStream2fATI (GLenum stream, GLfloat x, GLfloat y); -GLAPI void APIENTRY glVertexStream2fvATI (GLenum stream, const GLfloat *coords); -GLAPI void APIENTRY glVertexStream2dATI (GLenum stream, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexStream2dvATI (GLenum stream, const GLdouble *coords); -GLAPI void APIENTRY glVertexStream3sATI (GLenum stream, GLshort x, GLshort y, GLshort z); -GLAPI void APIENTRY glVertexStream3svATI (GLenum stream, const GLshort *coords); -GLAPI void APIENTRY glVertexStream3iATI (GLenum stream, GLint x, GLint y, GLint z); -GLAPI void APIENTRY glVertexStream3ivATI (GLenum stream, const GLint *coords); -GLAPI void APIENTRY glVertexStream3fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glVertexStream3fvATI (GLenum stream, const GLfloat *coords); -GLAPI void APIENTRY glVertexStream3dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexStream3dvATI (GLenum stream, const GLdouble *coords); -GLAPI void APIENTRY glVertexStream4sATI (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); -GLAPI void APIENTRY glVertexStream4svATI (GLenum stream, const GLshort *coords); -GLAPI void APIENTRY glVertexStream4iATI (GLenum stream, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glVertexStream4ivATI (GLenum stream, const GLint *coords); -GLAPI void APIENTRY glVertexStream4fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glVertexStream4fvATI (GLenum stream, const GLfloat *coords); -GLAPI void APIENTRY glVertexStream4dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexStream4dvATI (GLenum stream, const GLdouble *coords); -GLAPI void APIENTRY glNormalStream3bATI (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); -GLAPI void APIENTRY glNormalStream3bvATI (GLenum stream, const GLbyte *coords); -GLAPI void APIENTRY glNormalStream3sATI (GLenum stream, GLshort nx, GLshort ny, GLshort nz); -GLAPI void APIENTRY glNormalStream3svATI (GLenum stream, const GLshort *coords); -GLAPI void APIENTRY glNormalStream3iATI (GLenum stream, GLint nx, GLint ny, GLint nz); -GLAPI void APIENTRY glNormalStream3ivATI (GLenum stream, const GLint *coords); -GLAPI void APIENTRY glNormalStream3fATI (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); -GLAPI void APIENTRY glNormalStream3fvATI (GLenum stream, const GLfloat *coords); -GLAPI void APIENTRY glNormalStream3dATI (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); -GLAPI void APIENTRY glNormalStream3dvATI (GLenum stream, const GLdouble *coords); -GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum stream); -GLAPI void APIENTRY glVertexBlendEnviATI (GLenum pname, GLint param); -GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum pname, GLfloat param); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); -typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); -typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); -typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); -typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); -#endif - -#ifndef GL_ATI_element_array -#define GL_ATI_element_array 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glElementPointerATI (GLenum type, const GLvoid *pointer); -GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count); -GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); -#endif - -#ifndef GL_SUN_mesh_array -#define GL_SUN_mesh_array 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum mode, GLint first, GLsizei count, GLsizei width); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); -#endif - -#ifndef GL_SUN_slice_accum -#define GL_SUN_slice_accum 1 -#endif - -#ifndef GL_NV_multisample_filter_hint -#define GL_NV_multisample_filter_hint 1 -#endif - -#ifndef GL_NV_depth_clamp -#define GL_NV_depth_clamp 1 -#endif - -#ifndef GL_NV_occlusion_query -#define GL_NV_occlusion_query 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei n, GLuint *ids); -GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei n, const GLuint *ids); -GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint id); -GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint id); -GLAPI void APIENTRY glEndOcclusionQueryNV (void); -GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint id, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint id, GLenum pname, GLuint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); -typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); -typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); -#endif - -#ifndef GL_NV_point_sprite -#define GL_NV_point_sprite 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPointParameteriNV (GLenum pname, GLint param); -GLAPI void APIENTRY glPointParameterivNV (GLenum pname, const GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); -#endif - -#ifndef GL_NV_texture_shader3 -#define GL_NV_texture_shader3 1 -#endif - -#ifndef GL_NV_vertex_program1_1 -#define GL_NV_vertex_program1_1 1 -#endif - -#ifndef GL_EXT_shadow_funcs -#define GL_EXT_shadow_funcs 1 -#endif - -#ifndef GL_EXT_stencil_two_side -#define GL_EXT_stencil_two_side 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum face); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); -#endif - -#ifndef GL_ATI_text_fragment_shader -#define GL_ATI_text_fragment_shader 1 -#endif - -#ifndef GL_APPLE_client_storage -#define GL_APPLE_client_storage 1 -#endif - -#ifndef GL_APPLE_element_array -#define GL_APPLE_element_array 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glElementPointerAPPLE (GLenum type, const GLvoid *pointer); -GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum mode, GLint first, GLsizei count); -GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); -GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); -typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); -#endif - -#ifndef GL_APPLE_fence -#define GL_APPLE_fence 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenFencesAPPLE (GLsizei n, GLuint *fences); -GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei n, const GLuint *fences); -GLAPI void APIENTRY glSetFenceAPPLE (GLuint fence); -GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint fence); -GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint fence); -GLAPI void APIENTRY glFinishFenceAPPLE (GLuint fence); -GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum object, GLuint name); -GLAPI void APIENTRY glFinishObjectAPPLE (GLenum object, GLint name); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); -typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); -typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); -typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); -typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); -typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); -#endif - -#ifndef GL_APPLE_vertex_array_object -#define GL_APPLE_vertex_array_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint array); -GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei n, const GLuint *arrays); -GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei n, GLuint *arrays); -GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint array); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); -typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); -typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); -typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); -#endif - -#ifndef GL_APPLE_vertex_array_range -#define GL_APPLE_vertex_array_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei length, GLvoid *pointer); -GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei length, GLvoid *pointer); -GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum pname, GLint param); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); -typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); -typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); -#endif - -#ifndef GL_APPLE_ycbcr_422 -#define GL_APPLE_ycbcr_422 1 -#endif - -#ifndef GL_S3_s3tc -#define GL_S3_s3tc 1 -#endif - -#ifndef GL_ATI_draw_buffers -#define GL_ATI_draw_buffers 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawBuffersATI (GLsizei n, const GLenum *bufs); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); -#endif - -#ifndef GL_ATI_pixel_format_float -#define GL_ATI_pixel_format_float 1 -/* This is really a WGL extension, but defines some associated GL enums. - * ATI does not export "GL_ATI_pixel_format_float" in the GL_EXTENSIONS string. - */ -#endif - -#ifndef GL_ATI_texture_env_combine3 -#define GL_ATI_texture_env_combine3 1 -#endif - -#ifndef GL_ATI_texture_float -#define GL_ATI_texture_float 1 -#endif - -#ifndef GL_NV_float_buffer -#define GL_NV_float_buffer 1 -#endif - -#ifndef GL_NV_fragment_program -#define GL_NV_fragment_program 1 -/* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); -GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); -GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); -GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); -typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); -typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); -typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); -#endif - -#ifndef GL_NV_half_float -#define GL_NV_half_float 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertex2hNV (GLhalfNV x, GLhalfNV y); -GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glVertex3hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z); -GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glVertex4hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); -GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glNormal3hNV (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); -GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); -GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glColor4hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); -GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV s); -GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV s, GLhalfNV t); -GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r); -GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); -GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum target, GLhalfNV s); -GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum target, const GLhalfNV *v); -GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum target, GLhalfNV s, GLhalfNV t); -GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum target, const GLhalfNV *v); -GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); -GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum target, const GLhalfNV *v); -GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); -GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum target, const GLhalfNV *v); -GLAPI void APIENTRY glFogCoordhNV (GLhalfNV fog); -GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *fog); -GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); -GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *v); -GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV weight); -GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *weight); -GLAPI void APIENTRY glVertexAttrib1hNV (GLuint index, GLhalfNV x); -GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint index, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttrib2hNV (GLuint index, GLhalfNV x, GLhalfNV y); -GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint index, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttrib3hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); -GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint index, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttrib4hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); -GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint index, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint index, GLsizei n, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint index, GLsizei n, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint index, GLsizei n, const GLhalfNV *v); -GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint index, GLsizei n, const GLhalfNV *v); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); -typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); -typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); -typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); -typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); -typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); -typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); -typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); -typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); -typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); -typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); -typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); -typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); -typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); -typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); -typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); -typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); -typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); -typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); -typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); -typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); -typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); -#endif - -#ifndef GL_NV_pixel_data_range -#define GL_NV_pixel_data_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, const GLvoid *pointer); -GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); -#endif - -#ifndef GL_NV_primitive_restart -#define GL_NV_primitive_restart 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPrimitiveRestartNV (void); -GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint index); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); -typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); -#endif - -#ifndef GL_NV_texture_expand_normal -#define GL_NV_texture_expand_normal 1 -#endif - -#ifndef GL_NV_vertex_program2 -#define GL_NV_vertex_program2 1 -#endif - -#ifndef GL_ATI_map_object_buffer -#define GL_ATI_map_object_buffer 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint buffer); -GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint buffer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); -#endif - -#ifndef GL_ATI_separate_stencil -#define GL_ATI_separate_stencil 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glStencilOpSeparateATI (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); -typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); -#endif - -#ifndef GL_ATI_vertex_attrib_array_object -#define GL_ATI_vertex_attrib_array_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); -GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint index, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint index, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); -#endif - -#ifndef GL_OES_read_format -#define GL_OES_read_format 1 -#endif - -#ifndef GL_EXT_depth_bounds_test -#define GL_EXT_depth_bounds_test 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDepthBoundsEXT (GLclampd zmin, GLclampd zmax); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); -#endif - -#ifndef GL_EXT_texture_mirror_clamp -#define GL_EXT_texture_mirror_clamp 1 -#endif - -#ifndef GL_EXT_blend_equation_separate -#define GL_EXT_blend_equation_separate 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum modeRGB, GLenum modeAlpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); -#endif - -#ifndef GL_MESA_pack_invert -#define GL_MESA_pack_invert 1 -#endif - -#ifndef GL_MESA_ycbcr_texture -#define GL_MESA_ycbcr_texture 1 -#endif - -#ifndef GL_EXT_pixel_buffer_object -#define GL_EXT_pixel_buffer_object 1 -#endif - -#ifndef GL_NV_fragment_program_option -#define GL_NV_fragment_program_option 1 -#endif - -#ifndef GL_NV_fragment_program2 -#define GL_NV_fragment_program2 1 -#endif - -#ifndef GL_NV_vertex_program2_option -#define GL_NV_vertex_program2_option 1 -#endif - -#ifndef GL_NV_vertex_program3 -#define GL_NV_vertex_program3 1 -#endif - -#ifndef GL_EXT_framebuffer_object -#define GL_EXT_framebuffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint renderbuffer); -GLAPI void APIENTRY glBindRenderbufferEXT (GLenum target, GLuint renderbuffer); -GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers); -GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers); -GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum target, GLenum pname, GLint *params); -GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint framebuffer); -GLAPI void APIENTRY glBindFramebufferEXT (GLenum target, GLuint framebuffer); -GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers); -GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei n, GLuint *framebuffers); -GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum target); -GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum target, GLenum attachment, GLenum pname, GLint *params); -GLAPI void APIENTRY glGenerateMipmapEXT (GLenum target); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); -typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); -typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); -typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); -typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); -typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); -#endif - -#ifndef GL_GREMEDY_string_marker -#define GL_GREMEDY_string_marker 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei len, const GLvoid *string); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); -#endif - -#ifndef GL_EXT_packed_depth_stencil -#define GL_EXT_packed_depth_stencil 1 -#endif - -#ifndef GL_EXT_stencil_clear_tag -#define GL_EXT_stencil_clear_tag 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glStencilClearTagEXT (GLsizei stencilTagBits, GLuint stencilClearTag); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag); -#endif - -#ifndef GL_EXT_texture_sRGB -#define GL_EXT_texture_sRGB 1 -#endif - -#ifndef GL_EXT_framebuffer_blit -#define GL_EXT_framebuffer_blit 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlitFramebufferEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -#endif - -#ifndef GL_EXT_framebuffer_multisample -#define GL_EXT_framebuffer_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -#endif - -#ifndef GL_MESAX_texture_stack -#define GL_MESAX_texture_stack 1 -#endif - -#ifndef GL_EXT_timer_query -#define GL_EXT_timer_query 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64EXT *params); -GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64EXT *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64EXT *params); -typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64EXT *params); -#endif - -#ifndef GL_EXT_gpu_program_parameters -#define GL_EXT_gpu_program_parameters 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); -GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); -#endif - -#ifndef GL_APPLE_flush_buffer_range -#define GL_APPLE_flush_buffer_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum target, GLintptr offset, GLsizeiptr size); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size); -#endif - -#ifndef GL_NV_gpu_program4 -#define GL_NV_gpu_program4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum target, GLuint index, const GLint *params); -GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); -GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); -GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); -GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum target, GLuint index, const GLint *params); -GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); -GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); -GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); -GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum target, GLuint index, GLint *params); -GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum target, GLuint index, GLuint *params); -GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum target, GLuint index, GLint *params); -GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum target, GLuint index, GLuint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); -typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); -typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); -#endif - -#ifndef GL_NV_geometry_program4 -#define GL_NV_geometry_program4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramVertexLimitNV (GLenum target, GLint limit); -GLAPI void APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level); -GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); -#endif - -#ifndef GL_EXT_geometry_shader4 -#define GL_EXT_geometry_shader4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); -#endif - -#ifndef GL_NV_vertex_program4 -#define GL_NV_vertex_program4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint index, GLint x); -GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint index, GLint x, GLint y); -GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint index, GLint x, GLint y, GLint z); -GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint index, GLuint x); -GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint index, GLuint x, GLuint y); -GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint index, GLuint x, GLuint y, GLuint z); -GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint index, const GLint *v); -GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint index, const GLuint *v); -GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint index, const GLbyte *v); -GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint index, const GLshort *v); -GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint index, const GLubyte *v); -GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint index, const GLushort *v); -GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint index, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint index, GLenum pname, GLuint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params); -#endif - -#ifndef GL_EXT_gpu_shader4 -#define GL_EXT_gpu_shader4 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetUniformuivEXT (GLuint program, GLint location, GLuint *params); -GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name); -GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint program, const GLchar *name); -GLAPI void APIENTRY glUniform1uiEXT (GLint location, GLuint v0); -GLAPI void APIENTRY glUniform2uiEXT (GLint location, GLuint v0, GLuint v1); -GLAPI void APIENTRY glUniform3uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI void APIENTRY glUniform4uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI void APIENTRY glUniform1uivEXT (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform2uivEXT (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform3uivEXT (GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glUniform4uivEXT (GLint location, GLsizei count, const GLuint *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params); -typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0); -typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1); -typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); -typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); -#endif - -#ifndef GL_EXT_draw_instanced -#define GL_EXT_draw_instanced 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount); -GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); -#endif - -#ifndef GL_EXT_packed_float -#define GL_EXT_packed_float 1 -#endif - -#ifndef GL_EXT_texture_array -#define GL_EXT_texture_array 1 -#endif - -#ifndef GL_EXT_texture_buffer_object -#define GL_EXT_texture_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer); -#endif - -#ifndef GL_EXT_texture_compression_latc -#define GL_EXT_texture_compression_latc 1 -#endif - -#ifndef GL_EXT_texture_compression_rgtc -#define GL_EXT_texture_compression_rgtc 1 -#endif - -#ifndef GL_EXT_texture_shared_exponent -#define GL_EXT_texture_shared_exponent 1 -#endif - -#ifndef GL_NV_depth_buffer_float -#define GL_NV_depth_buffer_float 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDepthRangedNV (GLdouble zNear, GLdouble zFar); -GLAPI void APIENTRY glClearDepthdNV (GLdouble depth); -GLAPI void APIENTRY glDepthBoundsdNV (GLdouble zmin, GLdouble zmax); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar); -typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth); -typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax); -#endif - -#ifndef GL_NV_fragment_program4 -#define GL_NV_fragment_program4 1 -#endif - -#ifndef GL_NV_framebuffer_multisample_coverage -#define GL_NV_framebuffer_multisample_coverage 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); -#endif - -#ifndef GL_EXT_framebuffer_sRGB -#define GL_EXT_framebuffer_sRGB 1 -#endif - -#ifndef GL_NV_geometry_shader4 -#define GL_NV_geometry_shader4 1 -#endif - -#ifndef GL_NV_parameter_buffer_object -#define GL_NV_parameter_buffer_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); -GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); -GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); -typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); -typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); -#endif - -#ifndef GL_EXT_draw_buffers2 -#define GL_EXT_draw_buffers2 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum target, GLuint index, GLboolean *data); -GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum target, GLuint index, GLint *data); -GLAPI void APIENTRY glEnableIndexedEXT (GLenum target, GLuint index); -GLAPI void APIENTRY glDisableIndexedEXT (GLenum target, GLuint index); -GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum target, GLuint index); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); -typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data); -typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data); -typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index); -typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index); -typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index); -#endif - -#ifndef GL_NV_transform_feedback -#define GL_NV_transform_feedback 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum primitiveMode); -GLAPI void APIENTRY glEndTransformFeedbackNV (void); -GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLuint count, const GLint *attribs, GLenum bufferMode); -GLAPI void APIENTRY glBindBufferRangeNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI void APIENTRY glBindBufferOffsetNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset); -GLAPI void APIENTRY glBindBufferBaseNV (GLenum target, GLuint index, GLuint buffer); -GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); -GLAPI void APIENTRY glActiveVaryingNV (GLuint program, const GLchar *name); -GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint program, const GLchar *name); -GLAPI void APIENTRY glGetActiveVaryingNV (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint program, GLuint index, GLint *location); -GLAPI void APIENTRY glTransformFeedbackStreamAttribsNV (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode); -typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void); -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLuint count, const GLint *attribs, GLenum bufferMode); -typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); -typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer); -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); -typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name); -typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name); -typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location); -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKSTREAMATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); -#endif - -#ifndef GL_EXT_bindable_uniform -#define GL_EXT_bindable_uniform 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glUniformBufferEXT (GLuint program, GLint location, GLuint buffer); -GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint program, GLint location); -GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint program, GLint location); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer); -typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location); -typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location); -#endif - -#ifndef GL_EXT_texture_integer -#define GL_EXT_texture_integer 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params); -GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params); -GLAPI void APIENTRY glClearColorIiEXT (GLint red, GLint green, GLint blue, GLint alpha); -GLAPI void APIENTRY glClearColorIuiEXT (GLuint red, GLuint green, GLuint blue, GLuint alpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha); -typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha); -#endif - -#ifndef GL_GREMEDY_frame_terminator -#define GL_GREMEDY_frame_terminator 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glFrameTerminatorGREMEDY (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void); -#endif - -#ifndef GL_NV_conditional_render -#define GL_NV_conditional_render 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode); -GLAPI void APIENTRY glEndConditionalRenderNV (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode); -typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void); -#endif - -#ifndef GL_NV_present_video -#define GL_NV_present_video 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); -GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); -GLAPI void APIENTRY glGetVideoivNV (GLuint video_slot, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVideouivNV (GLuint video_slot, GLenum pname, GLuint *params); -GLAPI void APIENTRY glGetVideoi64vNV (GLuint video_slot, GLenum pname, GLint64EXT *params); -GLAPI void APIENTRY glGetVideoui64vNV (GLuint video_slot, GLenum pname, GLuint64EXT *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); -typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); -typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params); -typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params); -#endif - -#ifndef GL_EXT_transform_feedback -#define GL_EXT_transform_feedback 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum primitiveMode); -GLAPI void APIENTRY glEndTransformFeedbackEXT (void); -GLAPI void APIENTRY glBindBufferRangeEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset); -GLAPI void APIENTRY glBindBufferBaseEXT (GLenum target, GLuint index, GLuint buffer); -GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); -GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode); -typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void); -typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); -typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer); -typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); -typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); -#endif - -#ifndef GL_EXT_direct_state_access -#define GL_EXT_direct_state_access 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield mask); -GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield mask); -GLAPI void APIENTRY glMatrixLoadfEXT (GLenum mode, const GLfloat *m); -GLAPI void APIENTRY glMatrixLoaddEXT (GLenum mode, const GLdouble *m); -GLAPI void APIENTRY glMatrixMultfEXT (GLenum mode, const GLfloat *m); -GLAPI void APIENTRY glMatrixMultdEXT (GLenum mode, const GLdouble *m); -GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum mode); -GLAPI void APIENTRY glMatrixRotatefEXT (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glMatrixRotatedEXT (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glMatrixScalefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glMatrixScaledEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); -GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glMatrixFrustumEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); -GLAPI void APIENTRY glMatrixOrthoEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); -GLAPI void APIENTRY glMatrixPopEXT (GLenum mode); -GLAPI void APIENTRY glMatrixPushEXT (GLenum mode); -GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum mode, const GLfloat *m); -GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum mode, const GLdouble *m); -GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum mode, const GLfloat *m); -GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum mode, const GLdouble *m); -GLAPI void APIENTRY glTextureParameterfEXT (GLuint texture, GLenum target, GLenum pname, GLfloat param); -GLAPI void APIENTRY glTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glTextureParameteriEXT (GLuint texture, GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetTextureImageEXT (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); -GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); -GLAPI void APIENTRY glTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); -GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); -GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); -GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -GLAPI void APIENTRY glBindMultiTextureEXT (GLenum texunit, GLenum target, GLuint texture); -GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum array, GLuint index); -GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum array, GLuint index); -GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); -GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glMultiTexEnviEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); -GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glMultiTexGendEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); -GLAPI void APIENTRY glMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); -GLAPI void APIENTRY glMultiTexGenfEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); -GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glMultiTexGeniEXT (GLenum texunit, GLenum coord, GLenum pname, GLint param); -GLAPI void APIENTRY glMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); -GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum target, GLuint index, GLfloat *data); -GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum target, GLuint index, GLdouble *data); -GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum target, GLuint index, GLvoid* *data); -GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint texture, GLenum target, GLint lod, GLvoid *img); -GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); -GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum texunit, GLenum target, GLint lod, GLvoid *img); -GLAPI void APIENTRY glNamedProgramStringEXT (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); -GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint program, GLenum target, GLuint index, const GLdouble *params); -GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint program, GLenum target, GLuint index, const GLfloat *params); -GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint program, GLenum target, GLuint index, GLdouble *params); -GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint program, GLenum target, GLuint index, GLfloat *params); -GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint program, GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint program, GLenum target, GLenum pname, GLvoid *string); -GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); -GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); -GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint program, GLenum target, GLuint index, const GLint *params); -GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); -GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint program, GLenum target, GLuint index, const GLuint *params); -GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); -GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint program, GLenum target, GLuint index, GLint *params); -GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint program, GLenum target, GLuint index, GLuint *params); -GLAPI void APIENTRY glTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, const GLuint *params); -GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, GLuint *params); -GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); -GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); -GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, GLuint *params); -GLAPI void APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0); -GLAPI void APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1); -GLAPI void APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -GLAPI void APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -GLAPI void APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0); -GLAPI void APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1); -GLAPI void APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -GLAPI void APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); -GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0); -GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1); -GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); -GLAPI void APIENTRY glNamedBufferDataEXT (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); -GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); -GLAPI GLvoid* APIENTRY glMapNamedBufferEXT (GLuint buffer, GLenum access); -GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint buffer); -GLAPI GLvoid* APIENTRY glMapNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); -GLAPI void APIENTRY glFlushMappedNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length); -GLAPI void APIENTRY glNamedCopyBufferSubDataEXT (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint buffer, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint buffer, GLenum pname, GLvoid* *params); -GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); -GLAPI void APIENTRY glTextureBufferEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); -GLAPI void APIENTRY glMultiTexBufferEXT (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); -GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint renderbuffer, GLenum pname, GLint *params); -GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint framebuffer, GLenum target); -GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); -GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint texture, GLenum target); -GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum texunit, GLenum target); -GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint framebuffer, GLenum mode); -GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint framebuffer, GLsizei n, const GLenum *bufs); -GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint framebuffer, GLenum mode); -GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); -GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); -GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); -GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); -GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); -GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint texture, GLenum target, GLuint renderbuffer); -GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum texunit, GLenum target, GLuint renderbuffer); -GLAPI void APIENTRY glProgramUniform1dEXT (GLuint program, GLint location, GLdouble x); -GLAPI void APIENTRY glProgramUniform2dEXT (GLuint program, GLint location, GLdouble x, GLdouble y); -GLAPI void APIENTRY glProgramUniform3dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glProgramUniform4dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glProgramUniform1dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform2dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform3dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniform4dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix2x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix3x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -GLAPI void APIENTRY glProgramUniformMatrix4x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); -typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); -typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m); -typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m); -typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m); -typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m); -typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); -typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); -typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); -typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode); -typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); -typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); -typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); -typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); -typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); -typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); -typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); -typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); -typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); -typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); -typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture); -typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); -typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); -typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); -typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); -typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); -typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param); -typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data); -typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data); -typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLvoid* *data); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, GLvoid *img); -typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); -typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, GLvoid *img); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params); -typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params); -typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params); -typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, GLvoid *string); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params); -typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); -typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params); -typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params); -typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params); -typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); -typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); -typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); -typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access); -typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer); -typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); -typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); -typedef void (APIENTRYP PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, GLvoid* *params); -typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); -typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); -typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); -typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params); -typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target); -typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target); -typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); -typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs); -typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); -typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); -typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); -typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DEXTPROC) (GLuint program, GLint location, GLdouble x); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); -#endif - -#ifndef GL_EXT_vertex_array_bgra -#define GL_EXT_vertex_array_bgra 1 -#endif - -#ifndef GL_EXT_texture_swizzle -#define GL_EXT_texture_swizzle 1 -#endif - -#ifndef GL_NV_explicit_multisample -#define GL_NV_explicit_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetMultisamplefvNV (GLenum pname, GLuint index, GLfloat *val); -GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint index, GLbitfield mask); -GLAPI void APIENTRY glTexRenderbufferNV (GLenum target, GLuint renderbuffer); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val); -typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask); -typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer); -#endif - -#ifndef GL_NV_transform_feedback2 -#define GL_NV_transform_feedback2 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum target, GLuint id); -GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei n, const GLuint *ids); -GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei n, GLuint *ids); -GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint id); -GLAPI void APIENTRY glPauseTransformFeedbackNV (void); -GLAPI void APIENTRY glResumeTransformFeedbackNV (void); -GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum mode, GLuint id); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id); -typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids); -typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids); -typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id); -typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void); -typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void); -typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id); -#endif - -#ifndef GL_ATI_meminfo -#define GL_ATI_meminfo 1 -#endif - -#ifndef GL_AMD_performance_monitor -#define GL_AMD_performance_monitor 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); -GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); -GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); -GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); -GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data); -GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); -GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); -GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); -GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint monitor); -GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint monitor); -GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); -typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); -typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); -typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); -typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data); -typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); -typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); -typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); -typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); -typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); -typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); -#endif - -#ifndef GL_AMD_texture_texture4 -#define GL_AMD_texture_texture4 1 -#endif - -#ifndef GL_AMD_vertex_shader_tesselator -#define GL_AMD_vertex_shader_tesselator 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTessellationFactorAMD (GLfloat factor); -GLAPI void APIENTRY glTessellationModeAMD (GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor); -typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode); -#endif - -#ifndef GL_EXT_provoking_vertex -#define GL_EXT_provoking_vertex 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProvokingVertexEXT (GLenum mode); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode); -#endif - -#ifndef GL_EXT_texture_snorm -#define GL_EXT_texture_snorm 1 -#endif - -#ifndef GL_AMD_draw_buffers_blend -#define GL_AMD_draw_buffers_blend 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint buf, GLenum src, GLenum dst); -GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint buf, GLenum mode); -GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst); -typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); -typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode); -typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); -#endif - -#ifndef GL_APPLE_texture_range -#define GL_APPLE_texture_range 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureRangeAPPLE (GLenum target, GLsizei length, const GLvoid *pointer); -GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum target, GLenum pname, GLvoid* *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, GLvoid* *params); -#endif - -#ifndef GL_APPLE_float_pixels -#define GL_APPLE_float_pixels 1 -#endif - -#ifndef GL_APPLE_vertex_program_evaluators -#define GL_APPLE_vertex_program_evaluators 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint index, GLenum pname); -GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint index, GLenum pname); -GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint index, GLenum pname); -GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); -GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); -GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); -GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); -typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname); -typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); -typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); -typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); -typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); -#endif - -#ifndef GL_APPLE_aux_depth_stencil -#define GL_APPLE_aux_depth_stencil 1 -#endif - -#ifndef GL_APPLE_object_purgeable -#define GL_APPLE_object_purgeable 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); -GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); -GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum objectType, GLuint name, GLenum pname, GLint *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); -typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); -typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params); -#endif - -#ifndef GL_APPLE_row_bytes -#define GL_APPLE_row_bytes 1 -#endif - -#ifndef GL_APPLE_rgb_422 -#define GL_APPLE_rgb_422 1 -#endif - -#ifndef GL_NV_video_capture -#define GL_NV_video_capture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint video_capture_slot); -GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); -GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); -GLAPI void APIENTRY glEndVideoCaptureNV (GLuint video_capture_slot); -GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint video_capture_slot, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); -GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); -GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); -GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); -GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); -GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); -GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot); -typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); -typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); -typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot); -typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); -typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); -typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); -typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); -typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); -typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); -#endif - -#ifndef GL_NV_copy_image -#define GL_NV_copy_image 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glCopyImageSubDataNV (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); -#endif - -#ifndef GL_EXT_separate_shader_objects -#define GL_EXT_separate_shader_objects 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glUseShaderProgramEXT (GLenum type, GLuint program); -GLAPI void APIENTRY glActiveProgramEXT (GLuint program); -GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum type, const GLchar *string); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program); -typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program); -typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string); -#endif - -#ifndef GL_NV_parameter_buffer_object2 -#define GL_NV_parameter_buffer_object2 1 -#endif - -#ifndef GL_NV_shader_buffer_load -#define GL_NV_shader_buffer_load 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMakeBufferResidentNV (GLenum target, GLenum access); -GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum target); -GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum target); -GLAPI void APIENTRY glMakeNamedBufferResidentNV (GLuint buffer, GLenum access); -GLAPI void APIENTRY glMakeNamedBufferNonResidentNV (GLuint buffer); -GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint buffer); -GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum target, GLenum pname, GLuint64EXT *params); -GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint buffer, GLenum pname, GLuint64EXT *params); -GLAPI void APIENTRY glGetIntegerui64vNV (GLenum value, GLuint64EXT *result); -GLAPI void APIENTRY glUniformui64NV (GLint location, GLuint64EXT value); -GLAPI void APIENTRY glUniformui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glGetUniformui64vNV (GLuint program, GLint location, GLuint64EXT *params); -GLAPI void APIENTRY glProgramUniformui64NV (GLuint program, GLint location, GLuint64EXT value); -GLAPI void APIENTRY glProgramUniformui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access); -typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target); -typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target); -typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access); -typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERNONRESIDENTNVPROC) (GLuint buffer); -typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer); -typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params); -typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params); -typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result); -typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value); -typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -#endif - -#ifndef GL_NV_vertex_buffer_unified_memory -#define GL_NV_vertex_buffer_unified_memory 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBufferAddressRangeNV (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); -GLAPI void APIENTRY glVertexFormatNV (GLint size, GLenum type, GLsizei stride); -GLAPI void APIENTRY glNormalFormatNV (GLenum type, GLsizei stride); -GLAPI void APIENTRY glColorFormatNV (GLint size, GLenum type, GLsizei stride); -GLAPI void APIENTRY glIndexFormatNV (GLenum type, GLsizei stride); -GLAPI void APIENTRY glTexCoordFormatNV (GLint size, GLenum type, GLsizei stride); -GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei stride); -GLAPI void APIENTRY glSecondaryColorFormatNV (GLint size, GLenum type, GLsizei stride); -GLAPI void APIENTRY glFogCoordFormatNV (GLenum type, GLsizei stride); -GLAPI void APIENTRY glVertexAttribFormatNV (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); -GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); -GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum value, GLuint index, GLuint64EXT *result); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); -typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride); -typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); -typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); -typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result); -#endif - -#ifndef GL_NV_texture_barrier -#define GL_NV_texture_barrier 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTextureBarrierNV (void); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void); -#endif - -#ifndef GL_AMD_shader_stencil_export -#define GL_AMD_shader_stencil_export 1 -#endif - -#ifndef GL_AMD_seamless_cubemap_per_texture -#define GL_AMD_seamless_cubemap_per_texture 1 -#endif - -#ifndef GL_AMD_conservative_depth -#define GL_AMD_conservative_depth 1 -#endif - -#ifndef GL_EXT_shader_image_load_store -#define GL_EXT_shader_image_load_store 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glBindImageTextureEXT (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); -GLAPI void APIENTRY glMemoryBarrierEXT (GLbitfield barriers); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREEXTPROC) (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); -typedef void (APIENTRYP PFNGLMEMORYBARRIEREXTPROC) (GLbitfield barriers); -#endif - -#ifndef GL_EXT_vertex_attrib_64bit -#define GL_EXT_vertex_attrib_64bit 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribL1dEXT (GLuint index, GLdouble x); -GLAPI void APIENTRY glVertexAttribL2dEXT (GLuint index, GLdouble x, GLdouble y); -GLAPI void APIENTRY glVertexAttribL3dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z); -GLAPI void APIENTRY glVertexAttribL4dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -GLAPI void APIENTRY glVertexAttribL1dvEXT (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL2dvEXT (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL3dvEXT (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribL4dvEXT (GLuint index, const GLdouble *v); -GLAPI void APIENTRY glVertexAttribLPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -GLAPI void APIENTRY glGetVertexAttribLdvEXT (GLuint index, GLenum pname, GLdouble *params); -GLAPI void APIENTRY glVertexArrayVertexAttribLOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DEXTPROC) (GLuint index, GLdouble x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DEXTPROC) (GLuint index, GLdouble x, GLdouble y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVEXTPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVEXTPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVEXTPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVEXTPROC) (GLuint index, const GLdouble *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVEXTPROC) (GLuint index, GLenum pname, GLdouble *params); -typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); -#endif - -#ifndef GL_NV_gpu_program5 -#define GL_NV_gpu_program5 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glProgramSubroutineParametersuivNV (GLenum target, GLsizei count, const GLuint *params); -GLAPI void APIENTRY glGetProgramSubroutineParameteruivNV (GLenum target, GLuint index, GLuint *param); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLPROGRAMSUBROUTINEPARAMETERSUIVNVPROC) (GLenum target, GLsizei count, const GLuint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMSUBROUTINEPARAMETERUIVNVPROC) (GLenum target, GLuint index, GLuint *param); -#endif - -#ifndef GL_NV_gpu_shader5 -#define GL_NV_gpu_shader5 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glUniform1i64NV (GLint location, GLint64EXT x); -GLAPI void APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y); -GLAPI void APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); -GLAPI void APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); -GLAPI void APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x); -GLAPI void APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y); -GLAPI void APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); -GLAPI void APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); -GLAPI void APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params); -GLAPI void APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x); -GLAPI void APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); -GLAPI void APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); -GLAPI void APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); -GLAPI void APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -GLAPI void APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x); -GLAPI void APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); -GLAPI void APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); -GLAPI void APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); -GLAPI void APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -GLAPI void APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x); -typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y); -typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); -typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); -typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x); -typedef void (APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y); -typedef void (APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); -typedef void (APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); -typedef void (APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); -#endif - -#ifndef GL_NV_shader_buffer_store -#define GL_NV_shader_buffer_store 1 -#endif - -#ifndef GL_NV_tessellation_program5 -#define GL_NV_tessellation_program5 1 -#endif - -#ifndef GL_NV_vertex_attrib_integer_64bit -#define GL_NV_vertex_attrib_integer_64bit 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVertexAttribL1i64NV (GLuint index, GLint64EXT x); -GLAPI void APIENTRY glVertexAttribL2i64NV (GLuint index, GLint64EXT x, GLint64EXT y); -GLAPI void APIENTRY glVertexAttribL3i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); -GLAPI void APIENTRY glVertexAttribL4i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); -GLAPI void APIENTRY glVertexAttribL1i64vNV (GLuint index, const GLint64EXT *v); -GLAPI void APIENTRY glVertexAttribL2i64vNV (GLuint index, const GLint64EXT *v); -GLAPI void APIENTRY glVertexAttribL3i64vNV (GLuint index, const GLint64EXT *v); -GLAPI void APIENTRY glVertexAttribL4i64vNV (GLuint index, const GLint64EXT *v); -GLAPI void APIENTRY glVertexAttribL1ui64NV (GLuint index, GLuint64EXT x); -GLAPI void APIENTRY glVertexAttribL2ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y); -GLAPI void APIENTRY glVertexAttribL3ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); -GLAPI void APIENTRY glVertexAttribL4ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); -GLAPI void APIENTRY glVertexAttribL1ui64vNV (GLuint index, const GLuint64EXT *v); -GLAPI void APIENTRY glVertexAttribL2ui64vNV (GLuint index, const GLuint64EXT *v); -GLAPI void APIENTRY glVertexAttribL3ui64vNV (GLuint index, const GLuint64EXT *v); -GLAPI void APIENTRY glVertexAttribL4ui64vNV (GLuint index, const GLuint64EXT *v); -GLAPI void APIENTRY glGetVertexAttribLi64vNV (GLuint index, GLenum pname, GLint64EXT *params); -GLAPI void APIENTRY glGetVertexAttribLui64vNV (GLuint index, GLenum pname, GLuint64EXT *params); -GLAPI void APIENTRY glVertexAttribLFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64NVPROC) (GLuint index, GLint64EXT x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64VNVPROC) (GLuint index, const GLint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64VNVPROC) (GLuint index, const GLint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64VNVPROC) (GLuint index, const GLint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64VNVPROC) (GLuint index, const GLint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64NVPROC) (GLuint index, GLuint64EXT x); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VNVPROC) (GLuint index, const GLuint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64VNVPROC) (GLuint index, const GLuint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64VNVPROC) (GLuint index, const GLuint64EXT *v); -typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64VNVPROC) (GLuint index, const GLuint64EXT *v); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLI64VNVPROC) (GLuint index, GLenum pname, GLint64EXT *params); -typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VNVPROC) (GLuint index, GLenum pname, GLuint64EXT *params); -typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); -#endif - -#ifndef GL_NV_multisample_coverage -#define GL_NV_multisample_coverage 1 -#endif - -#ifndef GL_AMD_name_gen_delete -#define GL_AMD_name_gen_delete 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glGenNamesAMD (GLenum identifier, GLuint num, GLuint *names); -GLAPI void APIENTRY glDeleteNamesAMD (GLenum identifier, GLuint num, const GLuint *names); -GLAPI GLboolean APIENTRY glIsNameAMD (GLenum identifier, GLuint name); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLGENNAMESAMDPROC) (GLenum identifier, GLuint num, GLuint *names); -typedef void (APIENTRYP PFNGLDELETENAMESAMDPROC) (GLenum identifier, GLuint num, const GLuint *names); -typedef GLboolean (APIENTRYP PFNGLISNAMEAMDPROC) (GLenum identifier, GLuint name); -#endif - -#ifndef GL_AMD_debug_output -#define GL_AMD_debug_output 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glDebugMessageEnableAMD (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -GLAPI void APIENTRY glDebugMessageInsertAMD (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); -GLAPI void APIENTRY glDebugMessageCallbackAMD (GLDEBUGPROCAMD callback, GLvoid *userParam); -GLAPI GLuint APIENTRY glGetDebugMessageLogAMD (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLDEBUGMESSAGEENABLEAMDPROC) (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); -typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTAMDPROC) (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); -typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, GLvoid *userParam); -typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGAMDPROC) (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message); -#endif - -#ifndef GL_NV_vdpau_interop -#define GL_NV_vdpau_interop 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glVDPAUInitNV (const GLvoid *vdpDevice, const GLvoid *getProcAddress); -GLAPI void APIENTRY glVDPAUFiniNV (void); -GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceNV (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); -GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterOutputSurfaceNV (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); -GLAPI void APIENTRY glVDPAUIsSurfaceNV (GLvdpauSurfaceNV surface); -GLAPI void APIENTRY glVDPAUUnregisterSurfaceNV (GLvdpauSurfaceNV surface); -GLAPI void APIENTRY glVDPAUGetSurfaceivNV (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -GLAPI void APIENTRY glVDPAUSurfaceAccessNV (GLvdpauSurfaceNV surface, GLenum access); -GLAPI void APIENTRY glVDPAUMapSurfacesNV (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); -GLAPI void APIENTRY glVDPAUUnmapSurfacesNV (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLVDPAUINITNVPROC) (const GLvoid *vdpDevice, const GLvoid *getProcAddress); -typedef void (APIENTRYP PFNGLVDPAUFININVPROC) (void); -typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACENVPROC) (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); -typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC) (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); -typedef void (APIENTRYP PFNGLVDPAUISSURFACENVPROC) (GLvdpauSurfaceNV surface); -typedef void (APIENTRYP PFNGLVDPAUUNREGISTERSURFACENVPROC) (GLvdpauSurfaceNV surface); -typedef void (APIENTRYP PFNGLVDPAUGETSURFACEIVNVPROC) (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); -typedef void (APIENTRYP PFNGLVDPAUSURFACEACCESSNVPROC) (GLvdpauSurfaceNV surface, GLenum access); -typedef void (APIENTRYP PFNGLVDPAUMAPSURFACESNVPROC) (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); -typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); -#endif - -#ifndef GL_AMD_transform_feedback3_lines_triangles -#define GL_AMD_transform_feedback3_lines_triangles 1 -#endif - -#ifndef GL_AMD_depth_clamp_separate -#define GL_AMD_depth_clamp_separate 1 -#endif - -#ifndef GL_EXT_texture_sRGB_decode -#define GL_EXT_texture_sRGB_decode 1 -#endif - -#ifndef GL_NV_texture_multisample -#define GL_NV_texture_multisample 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glTexImage2DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); -GLAPI void APIENTRY glTexImage3DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); -GLAPI void APIENTRY glTextureImage2DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); -GLAPI void APIENTRY glTextureImage3DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); -GLAPI void APIENTRY glTextureImage2DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); -GLAPI void APIENTRY glTextureImage3DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); -typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations); -typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations); -#endif - -#ifndef GL_AMD_blend_minmax_factor -#define GL_AMD_blend_minmax_factor 1 -#endif - -#ifndef GL_AMD_sample_positions -#define GL_AMD_sample_positions 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glSetMultisamplefvAMD (GLenum pname, GLuint index, const GLfloat *val); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSETMULTISAMPLEFVAMDPROC) (GLenum pname, GLuint index, const GLfloat *val); -#endif - -#ifndef GL_EXT_x11_sync_object -#define GL_EXT_x11_sync_object 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLsync APIENTRY glImportSyncEXT (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLsync (APIENTRYP PFNGLIMPORTSYNCEXTPROC) (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags); -#endif - -#ifndef GL_AMD_multi_draw_indirect -#define GL_AMD_multi_draw_indirect 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glMultiDrawArraysIndirectAMD (GLenum mode, const GLvoid *indirect, GLsizei primcount, GLsizei stride); -GLAPI void APIENTRY glMultiDrawElementsIndirectAMD (GLenum mode, GLenum type, const GLvoid *indirect, GLsizei primcount, GLsizei stride); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTAMDPROC) (GLenum mode, const GLvoid *indirect, GLsizei primcount, GLsizei stride); -typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTAMDPROC) (GLenum mode, GLenum type, const GLvoid *indirect, GLsizei primcount, GLsizei stride); -#endif - -#ifndef GL_EXT_framebuffer_multisample_blit_scaled -#define GL_EXT_framebuffer_multisample_blit_scaled 1 -#endif - -#ifndef GL_NV_path_rendering -#define GL_NV_path_rendering 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLuint APIENTRY glGenPathsNV (GLsizei range); -GLAPI void APIENTRY glDeletePathsNV (GLuint path, GLsizei range); -GLAPI GLboolean APIENTRY glIsPathNV (GLuint path); -GLAPI void APIENTRY glPathCommandsNV (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -GLAPI void APIENTRY glPathCoordsNV (GLuint path, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -GLAPI void APIENTRY glPathSubCommandsNV (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -GLAPI void APIENTRY glPathSubCoordsNV (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -GLAPI void APIENTRY glPathStringNV (GLuint path, GLenum format, GLsizei length, const GLvoid *pathString); -GLAPI void APIENTRY glPathGlyphsNV (GLuint firstPathName, GLenum fontTarget, const GLvoid *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const GLvoid *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); -GLAPI void APIENTRY glPathGlyphRangeNV (GLuint firstPathName, GLenum fontTarget, const GLvoid *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); -GLAPI void APIENTRY glWeightPathsNV (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights); -GLAPI void APIENTRY glCopyPathNV (GLuint resultPath, GLuint srcPath); -GLAPI void APIENTRY glInterpolatePathsNV (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight); -GLAPI void APIENTRY glTransformPathNV (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues); -GLAPI void APIENTRY glPathParameterivNV (GLuint path, GLenum pname, const GLint *value); -GLAPI void APIENTRY glPathParameteriNV (GLuint path, GLenum pname, GLint value); -GLAPI void APIENTRY glPathParameterfvNV (GLuint path, GLenum pname, const GLfloat *value); -GLAPI void APIENTRY glPathParameterfNV (GLuint path, GLenum pname, GLfloat value); -GLAPI void APIENTRY glPathDashArrayNV (GLuint path, GLsizei dashCount, const GLfloat *dashArray); -GLAPI void APIENTRY glPathStencilFuncNV (GLenum func, GLint ref, GLuint mask); -GLAPI void APIENTRY glPathStencilDepthOffsetNV (GLfloat factor, GLfloat units); -GLAPI void APIENTRY glStencilFillPathNV (GLuint path, GLenum fillMode, GLuint mask); -GLAPI void APIENTRY glStencilStrokePathNV (GLuint path, GLint reference, GLuint mask); -GLAPI void APIENTRY glStencilFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues); -GLAPI void APIENTRY glStencilStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues); -GLAPI void APIENTRY glPathCoverDepthFuncNV (GLenum func); -GLAPI void APIENTRY glPathColorGenNV (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs); -GLAPI void APIENTRY glPathTexGenNV (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs); -GLAPI void APIENTRY glPathFogGenNV (GLenum genMode); -GLAPI void APIENTRY glCoverFillPathNV (GLuint path, GLenum coverMode); -GLAPI void APIENTRY glCoverStrokePathNV (GLuint path, GLenum coverMode); -GLAPI void APIENTRY glCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); -GLAPI void APIENTRY glCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); -GLAPI void APIENTRY glGetPathParameterivNV (GLuint path, GLenum pname, GLint *value); -GLAPI void APIENTRY glGetPathParameterfvNV (GLuint path, GLenum pname, GLfloat *value); -GLAPI void APIENTRY glGetPathCommandsNV (GLuint path, GLubyte *commands); -GLAPI void APIENTRY glGetPathCoordsNV (GLuint path, GLfloat *coords); -GLAPI void APIENTRY glGetPathDashArrayNV (GLuint path, GLfloat *dashArray); -GLAPI void APIENTRY glGetPathMetricsNV (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics); -GLAPI void APIENTRY glGetPathMetricRangeNV (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics); -GLAPI void APIENTRY glGetPathSpacingNV (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing); -GLAPI void APIENTRY glGetPathColorGenivNV (GLenum color, GLenum pname, GLint *value); -GLAPI void APIENTRY glGetPathColorGenfvNV (GLenum color, GLenum pname, GLfloat *value); -GLAPI void APIENTRY glGetPathTexGenivNV (GLenum texCoordSet, GLenum pname, GLint *value); -GLAPI void APIENTRY glGetPathTexGenfvNV (GLenum texCoordSet, GLenum pname, GLfloat *value); -GLAPI GLboolean APIENTRY glIsPointInFillPathNV (GLuint path, GLuint mask, GLfloat x, GLfloat y); -GLAPI GLboolean APIENTRY glIsPointInStrokePathNV (GLuint path, GLfloat x, GLfloat y); -GLAPI GLfloat APIENTRY glGetPathLengthNV (GLuint path, GLsizei startSegment, GLsizei numSegments); -GLAPI GLboolean APIENTRY glPointAlongPathNV (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLuint (APIENTRYP PFNGLGENPATHSNVPROC) (GLsizei range); -typedef void (APIENTRYP PFNGLDELETEPATHSNVPROC) (GLuint path, GLsizei range); -typedef GLboolean (APIENTRYP PFNGLISPATHNVPROC) (GLuint path); -typedef void (APIENTRYP PFNGLPATHCOMMANDSNVPROC) (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -typedef void (APIENTRYP PFNGLPATHCOORDSNVPROC) (GLuint path, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -typedef void (APIENTRYP PFNGLPATHSUBCOMMANDSNVPROC) (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -typedef void (APIENTRYP PFNGLPATHSUBCOORDSNVPROC) (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const GLvoid *coords); -typedef void (APIENTRYP PFNGLPATHSTRINGNVPROC) (GLuint path, GLenum format, GLsizei length, const GLvoid *pathString); -typedef void (APIENTRYP PFNGLPATHGLYPHSNVPROC) (GLuint firstPathName, GLenum fontTarget, const GLvoid *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const GLvoid *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); -typedef void (APIENTRYP PFNGLPATHGLYPHRANGENVPROC) (GLuint firstPathName, GLenum fontTarget, const GLvoid *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale); -typedef void (APIENTRYP PFNGLWEIGHTPATHSNVPROC) (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights); -typedef void (APIENTRYP PFNGLCOPYPATHNVPROC) (GLuint resultPath, GLuint srcPath); -typedef void (APIENTRYP PFNGLINTERPOLATEPATHSNVPROC) (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight); -typedef void (APIENTRYP PFNGLTRANSFORMPATHNVPROC) (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues); -typedef void (APIENTRYP PFNGLPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, const GLint *value); -typedef void (APIENTRYP PFNGLPATHPARAMETERINVPROC) (GLuint path, GLenum pname, GLint value); -typedef void (APIENTRYP PFNGLPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, const GLfloat *value); -typedef void (APIENTRYP PFNGLPATHPARAMETERFNVPROC) (GLuint path, GLenum pname, GLfloat value); -typedef void (APIENTRYP PFNGLPATHDASHARRAYNVPROC) (GLuint path, GLsizei dashCount, const GLfloat *dashArray); -typedef void (APIENTRYP PFNGLPATHSTENCILFUNCNVPROC) (GLenum func, GLint ref, GLuint mask); -typedef void (APIENTRYP PFNGLPATHSTENCILDEPTHOFFSETNVPROC) (GLfloat factor, GLfloat units); -typedef void (APIENTRYP PFNGLSTENCILFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask); -typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask); -typedef void (APIENTRYP PFNGLSTENCILFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues); -typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues); -typedef void (APIENTRYP PFNGLPATHCOVERDEPTHFUNCNVPROC) (GLenum func); -typedef void (APIENTRYP PFNGLPATHCOLORGENNVPROC) (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs); -typedef void (APIENTRYP PFNGLPATHTEXGENNVPROC) (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs); -typedef void (APIENTRYP PFNGLPATHFOGGENNVPROC) (GLenum genMode); -typedef void (APIENTRYP PFNGLCOVERFILLPATHNVPROC) (GLuint path, GLenum coverMode); -typedef void (APIENTRYP PFNGLCOVERSTROKEPATHNVPROC) (GLuint path, GLenum coverMode); -typedef void (APIENTRYP PFNGLCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); -typedef void (APIENTRYP PFNGLCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues); -typedef void (APIENTRYP PFNGLGETPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, GLint *value); -typedef void (APIENTRYP PFNGLGETPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, GLfloat *value); -typedef void (APIENTRYP PFNGLGETPATHCOMMANDSNVPROC) (GLuint path, GLubyte *commands); -typedef void (APIENTRYP PFNGLGETPATHCOORDSNVPROC) (GLuint path, GLfloat *coords); -typedef void (APIENTRYP PFNGLGETPATHDASHARRAYNVPROC) (GLuint path, GLfloat *dashArray); -typedef void (APIENTRYP PFNGLGETPATHMETRICSNVPROC) (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics); -typedef void (APIENTRYP PFNGLGETPATHMETRICRANGENVPROC) (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics); -typedef void (APIENTRYP PFNGLGETPATHSPACINGNVPROC) (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const GLvoid *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing); -typedef void (APIENTRYP PFNGLGETPATHCOLORGENIVNVPROC) (GLenum color, GLenum pname, GLint *value); -typedef void (APIENTRYP PFNGLGETPATHCOLORGENFVNVPROC) (GLenum color, GLenum pname, GLfloat *value); -typedef void (APIENTRYP PFNGLGETPATHTEXGENIVNVPROC) (GLenum texCoordSet, GLenum pname, GLint *value); -typedef void (APIENTRYP PFNGLGETPATHTEXGENFVNVPROC) (GLenum texCoordSet, GLenum pname, GLfloat *value); -typedef GLboolean (APIENTRYP PFNGLISPOINTINFILLPATHNVPROC) (GLuint path, GLuint mask, GLfloat x, GLfloat y); -typedef GLboolean (APIENTRYP PFNGLISPOINTINSTROKEPATHNVPROC) (GLuint path, GLfloat x, GLfloat y); -typedef GLfloat (APIENTRYP PFNGLGETPATHLENGTHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments); -typedef GLboolean (APIENTRYP PFNGLPOINTALONGPATHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY); -#endif - -#ifndef GL_AMD_pinned_memory -#define GL_AMD_pinned_memory 1 -#endif - -#ifndef GL_AMD_stencil_operation_extended -#define GL_AMD_stencil_operation_extended 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI void APIENTRY glStencilOpValueAMD (GLenum face, GLuint value); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef void (APIENTRYP PFNGLSTENCILOPVALUEAMDPROC) (GLenum face, GLuint value); -#endif - -#ifndef GL_AMD_vertex_shader_viewport_index -#define GL_AMD_vertex_shader_viewport_index 1 -#endif - -#ifndef GL_AMD_vertex_shader_layer -#define GL_AMD_vertex_shader_layer 1 -#endif - -#ifndef GL_NV_bindless_texture -#define GL_NV_bindless_texture 1 -#ifdef GL_GLEXT_PROTOTYPES -GLAPI GLuint64 APIENTRY glGetTextureHandleNV (GLuint texture); -GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleNV (GLuint texture, GLuint sampler); -GLAPI void APIENTRY glMakeTextureHandleResidentNV (GLuint64 handle); -GLAPI void APIENTRY glMakeTextureHandleNonResidentNV (GLuint64 handle); -GLAPI GLuint64 APIENTRY glGetImageHandleNV (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); -GLAPI void APIENTRY glMakeImageHandleResidentNV (GLuint64 handle, GLenum access); -GLAPI void APIENTRY glMakeImageHandleNonResidentNV (GLuint64 handle); -GLAPI void APIENTRY glUniformHandleui64NV (GLint location, GLuint64 value); -GLAPI void APIENTRY glUniformHandleui64vNV (GLint location, GLsizei count, const GLuint64 *value); -GLAPI void APIENTRY glProgramUniformHandleui64NV (GLuint program, GLint location, GLuint64 value); -GLAPI void APIENTRY glProgramUniformHandleui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64 *values); -GLAPI GLboolean APIENTRY glIsTextureHandleResidentNV (GLuint64 handle); -GLAPI GLboolean APIENTRY glIsImageHandleResidentNV (GLuint64 handle); -#endif /* GL_GLEXT_PROTOTYPES */ -typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLENVPROC) (GLuint texture); -typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLENVPROC) (GLuint texture, GLuint sampler); -typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle); -typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTNVPROC) (GLuint64 handle); -typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLENVPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); -typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle, GLenum access); -typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTNVPROC) (GLuint64 handle); -typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64NVPROC) (GLint location, GLuint64 value); -typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VNVPROC) (GLint location, GLsizei count, const GLuint64 *value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64NVPROC) (GLuint program, GLint location, GLuint64 value); -typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values); -typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle); -typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle); -#endif - -#ifndef GL_NV_shader_atomic_float -#define GL_NV_shader_atomic_float 1 -#endif - -#ifndef GL_AMD_query_buffer_object -#define GL_AMD_query_buffer_object 1 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/GL3/glxext.h b/include/GL3/glxext.h deleted file mode 100644 index e640ff7e3..000000000 --- a/include/GL3/glxext.h +++ /dev/null @@ -1,1001 +0,0 @@ -#ifndef __glxext_h_ -#define __glxext_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* -** Copyright (c) 2007-2012 The Khronos Group Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and/or associated documentation files (the -** "Materials"), to deal in the Materials without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Materials, and to -** permit persons to whom the Materials are furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be included -** in all copies or substantial portions of the Materials. -** -** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -*/ - -/* Function declaration macros - to move into glplatform.h */ - -#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) -#define WIN32_LEAN_AND_MEAN 1 -#include -#endif - -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef APIENTRYP -#define APIENTRYP APIENTRY * -#endif -#ifndef GLAPI -#define GLAPI extern -#endif - -/*************************************************************/ - -/* Header file version number, required by OpenGL ABI for Linux */ -/* glxext.h last updated 2012/02/29 */ -/* Current version at http://www.opengl.org/registry/ */ -#define GLX_GLXEXT_VERSION 33 - -#ifndef GLX_VERSION_1_3 -#define GLX_WINDOW_BIT 0x00000001 -#define GLX_PIXMAP_BIT 0x00000002 -#define GLX_PBUFFER_BIT 0x00000004 -#define GLX_RGBA_BIT 0x00000001 -#define GLX_COLOR_INDEX_BIT 0x00000002 -#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 -#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 -#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 -#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 -#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 -#define GLX_AUX_BUFFERS_BIT 0x00000010 -#define GLX_DEPTH_BUFFER_BIT 0x00000020 -#define GLX_STENCIL_BUFFER_BIT 0x00000040 -#define GLX_ACCUM_BUFFER_BIT 0x00000080 -#define GLX_CONFIG_CAVEAT 0x20 -#define GLX_X_VISUAL_TYPE 0x22 -#define GLX_TRANSPARENT_TYPE 0x23 -#define GLX_TRANSPARENT_INDEX_VALUE 0x24 -#define GLX_TRANSPARENT_RED_VALUE 0x25 -#define GLX_TRANSPARENT_GREEN_VALUE 0x26 -#define GLX_TRANSPARENT_BLUE_VALUE 0x27 -#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 -#define GLX_DONT_CARE 0xFFFFFFFF -#define GLX_NONE 0x8000 -#define GLX_SLOW_CONFIG 0x8001 -#define GLX_TRUE_COLOR 0x8002 -#define GLX_DIRECT_COLOR 0x8003 -#define GLX_PSEUDO_COLOR 0x8004 -#define GLX_STATIC_COLOR 0x8005 -#define GLX_GRAY_SCALE 0x8006 -#define GLX_STATIC_GRAY 0x8007 -#define GLX_TRANSPARENT_RGB 0x8008 -#define GLX_TRANSPARENT_INDEX 0x8009 -#define GLX_VISUAL_ID 0x800B -#define GLX_SCREEN 0x800C -#define GLX_NON_CONFORMANT_CONFIG 0x800D -#define GLX_DRAWABLE_TYPE 0x8010 -#define GLX_RENDER_TYPE 0x8011 -#define GLX_X_RENDERABLE 0x8012 -#define GLX_FBCONFIG_ID 0x8013 -#define GLX_RGBA_TYPE 0x8014 -#define GLX_COLOR_INDEX_TYPE 0x8015 -#define GLX_MAX_PBUFFER_WIDTH 0x8016 -#define GLX_MAX_PBUFFER_HEIGHT 0x8017 -#define GLX_MAX_PBUFFER_PIXELS 0x8018 -#define GLX_PRESERVED_CONTENTS 0x801B -#define GLX_LARGEST_PBUFFER 0x801C -#define GLX_WIDTH 0x801D -#define GLX_HEIGHT 0x801E -#define GLX_EVENT_MASK 0x801F -#define GLX_DAMAGED 0x8020 -#define GLX_SAVED 0x8021 -#define GLX_WINDOW 0x8022 -#define GLX_PBUFFER 0x8023 -#define GLX_PBUFFER_HEIGHT 0x8040 -#define GLX_PBUFFER_WIDTH 0x8041 -#endif - -#ifndef GLX_VERSION_1_4 -#define GLX_SAMPLE_BUFFERS 100000 -#define GLX_SAMPLES 100001 -#endif - -#ifndef GLX_ARB_get_proc_address -#endif - -#ifndef GLX_ARB_multisample -#define GLX_SAMPLE_BUFFERS_ARB 100000 -#define GLX_SAMPLES_ARB 100001 -#endif - -#ifndef GLX_ARB_vertex_buffer_object -#define GLX_CONTEXT_ALLOW_BUFFER_BYTE_ORDER_MISMATCH_ARB 0x2095 -#endif - -#ifndef GLX_ARB_fbconfig_float -#define GLX_RGBA_FLOAT_TYPE_ARB 0x20B9 -#define GLX_RGBA_FLOAT_BIT_ARB 0x00000004 -#endif - -#ifndef GLX_ARB_framebuffer_sRGB -#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2 -#endif - -#ifndef GLX_ARB_create_context -#define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 -#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 -#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define GLX_CONTEXT_FLAGS_ARB 0x2094 -#endif - -#ifndef GLX_ARB_create_context_profile -#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 -#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 -#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 -#endif - -#ifndef GLX_ARB_create_context_robustness -#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 -#define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 -#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 -#define GLX_NO_RESET_NOTIFICATION_ARB 0x8261 -#endif - -#ifndef GLX_SGIS_multisample -#define GLX_SAMPLE_BUFFERS_SGIS 100000 -#define GLX_SAMPLES_SGIS 100001 -#endif - -#ifndef GLX_EXT_visual_info -#define GLX_X_VISUAL_TYPE_EXT 0x22 -#define GLX_TRANSPARENT_TYPE_EXT 0x23 -#define GLX_TRANSPARENT_INDEX_VALUE_EXT 0x24 -#define GLX_TRANSPARENT_RED_VALUE_EXT 0x25 -#define GLX_TRANSPARENT_GREEN_VALUE_EXT 0x26 -#define GLX_TRANSPARENT_BLUE_VALUE_EXT 0x27 -#define GLX_TRANSPARENT_ALPHA_VALUE_EXT 0x28 -#define GLX_NONE_EXT 0x8000 -#define GLX_TRUE_COLOR_EXT 0x8002 -#define GLX_DIRECT_COLOR_EXT 0x8003 -#define GLX_PSEUDO_COLOR_EXT 0x8004 -#define GLX_STATIC_COLOR_EXT 0x8005 -#define GLX_GRAY_SCALE_EXT 0x8006 -#define GLX_STATIC_GRAY_EXT 0x8007 -#define GLX_TRANSPARENT_RGB_EXT 0x8008 -#define GLX_TRANSPARENT_INDEX_EXT 0x8009 -#endif - -#ifndef GLX_SGI_swap_control -#endif - -#ifndef GLX_SGI_video_sync -#endif - -#ifndef GLX_SGI_make_current_read -#endif - -#ifndef GLX_SGIX_video_source -#endif - -#ifndef GLX_EXT_visual_rating -#define GLX_VISUAL_CAVEAT_EXT 0x20 -#define GLX_SLOW_VISUAL_EXT 0x8001 -#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D -/* reuse GLX_NONE_EXT */ -#endif - -#ifndef GLX_EXT_import_context -#define GLX_SHARE_CONTEXT_EXT 0x800A -#define GLX_VISUAL_ID_EXT 0x800B -#define GLX_SCREEN_EXT 0x800C -#endif - -#ifndef GLX_SGIX_fbconfig -#define GLX_WINDOW_BIT_SGIX 0x00000001 -#define GLX_PIXMAP_BIT_SGIX 0x00000002 -#define GLX_RGBA_BIT_SGIX 0x00000001 -#define GLX_COLOR_INDEX_BIT_SGIX 0x00000002 -#define GLX_DRAWABLE_TYPE_SGIX 0x8010 -#define GLX_RENDER_TYPE_SGIX 0x8011 -#define GLX_X_RENDERABLE_SGIX 0x8012 -#define GLX_FBCONFIG_ID_SGIX 0x8013 -#define GLX_RGBA_TYPE_SGIX 0x8014 -#define GLX_COLOR_INDEX_TYPE_SGIX 0x8015 -/* reuse GLX_SCREEN_EXT */ -#endif - -#ifndef GLX_SGIX_pbuffer -#define GLX_PBUFFER_BIT_SGIX 0x00000004 -#define GLX_BUFFER_CLOBBER_MASK_SGIX 0x08000000 -#define GLX_FRONT_LEFT_BUFFER_BIT_SGIX 0x00000001 -#define GLX_FRONT_RIGHT_BUFFER_BIT_SGIX 0x00000002 -#define GLX_BACK_LEFT_BUFFER_BIT_SGIX 0x00000004 -#define GLX_BACK_RIGHT_BUFFER_BIT_SGIX 0x00000008 -#define GLX_AUX_BUFFERS_BIT_SGIX 0x00000010 -#define GLX_DEPTH_BUFFER_BIT_SGIX 0x00000020 -#define GLX_STENCIL_BUFFER_BIT_SGIX 0x00000040 -#define GLX_ACCUM_BUFFER_BIT_SGIX 0x00000080 -#define GLX_SAMPLE_BUFFERS_BIT_SGIX 0x00000100 -#define GLX_MAX_PBUFFER_WIDTH_SGIX 0x8016 -#define GLX_MAX_PBUFFER_HEIGHT_SGIX 0x8017 -#define GLX_MAX_PBUFFER_PIXELS_SGIX 0x8018 -#define GLX_OPTIMAL_PBUFFER_WIDTH_SGIX 0x8019 -#define GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX 0x801A -#define GLX_PRESERVED_CONTENTS_SGIX 0x801B -#define GLX_LARGEST_PBUFFER_SGIX 0x801C -#define GLX_WIDTH_SGIX 0x801D -#define GLX_HEIGHT_SGIX 0x801E -#define GLX_EVENT_MASK_SGIX 0x801F -#define GLX_DAMAGED_SGIX 0x8020 -#define GLX_SAVED_SGIX 0x8021 -#define GLX_WINDOW_SGIX 0x8022 -#define GLX_PBUFFER_SGIX 0x8023 -#endif - -#ifndef GLX_SGI_cushion -#endif - -#ifndef GLX_SGIX_video_resize -#define GLX_SYNC_FRAME_SGIX 0x00000000 -#define GLX_SYNC_SWAP_SGIX 0x00000001 -#endif - -#ifndef GLX_SGIX_dmbuffer -#define GLX_DIGITAL_MEDIA_PBUFFER_SGIX 0x8024 -#endif - -#ifndef GLX_SGIX_swap_group -#endif - -#ifndef GLX_SGIX_swap_barrier -#endif - -#ifndef GLX_SGIS_blended_overlay -#define GLX_BLENDED_RGBA_SGIS 0x8025 -#endif - -#ifndef GLX_SGIS_shared_multisample -#define GLX_MULTISAMPLE_SUB_RECT_WIDTH_SGIS 0x8026 -#define GLX_MULTISAMPLE_SUB_RECT_HEIGHT_SGIS 0x8027 -#endif - -#ifndef GLX_SUN_get_transparent_index -#endif - -#ifndef GLX_3DFX_multisample -#define GLX_SAMPLE_BUFFERS_3DFX 0x8050 -#define GLX_SAMPLES_3DFX 0x8051 -#endif - -#ifndef GLX_MESA_copy_sub_buffer -#endif - -#ifndef GLX_MESA_pixmap_colormap -#endif - -#ifndef GLX_MESA_release_buffers -#endif - -#ifndef GLX_MESA_set_3dfx_mode -#define GLX_3DFX_WINDOW_MODE_MESA 0x1 -#define GLX_3DFX_FULLSCREEN_MODE_MESA 0x2 -#endif - -#ifndef GLX_SGIX_visual_select_group -#define GLX_VISUAL_SELECT_GROUP_SGIX 0x8028 -#endif - -#ifndef GLX_OML_swap_method -#define GLX_SWAP_METHOD_OML 0x8060 -#define GLX_SWAP_EXCHANGE_OML 0x8061 -#define GLX_SWAP_COPY_OML 0x8062 -#define GLX_SWAP_UNDEFINED_OML 0x8063 -#endif - -#ifndef GLX_OML_sync_control -#endif - -#ifndef GLX_NV_float_buffer -#define GLX_FLOAT_COMPONENTS_NV 0x20B0 -#endif - -#ifndef GLX_SGIX_hyperpipe -#define GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX 80 -#define GLX_BAD_HYPERPIPE_CONFIG_SGIX 91 -#define GLX_BAD_HYPERPIPE_SGIX 92 -#define GLX_HYPERPIPE_DISPLAY_PIPE_SGIX 0x00000001 -#define GLX_HYPERPIPE_RENDER_PIPE_SGIX 0x00000002 -#define GLX_PIPE_RECT_SGIX 0x00000001 -#define GLX_PIPE_RECT_LIMITS_SGIX 0x00000002 -#define GLX_HYPERPIPE_STEREO_SGIX 0x00000003 -#define GLX_HYPERPIPE_PIXEL_AVERAGE_SGIX 0x00000004 -#define GLX_HYPERPIPE_ID_SGIX 0x8030 -#endif - -#ifndef GLX_MESA_agp_offset -#endif - -#ifndef GLX_EXT_fbconfig_packed_float -#define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1 -#define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008 -#endif - -#ifndef GLX_EXT_framebuffer_sRGB -#define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2 -#endif - -#ifndef GLX_EXT_texture_from_pixmap -#define GLX_TEXTURE_1D_BIT_EXT 0x00000001 -#define GLX_TEXTURE_2D_BIT_EXT 0x00000002 -#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 -#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 -#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 -#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 -#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 -#define GLX_Y_INVERTED_EXT 0x20D4 -#define GLX_TEXTURE_FORMAT_EXT 0x20D5 -#define GLX_TEXTURE_TARGET_EXT 0x20D6 -#define GLX_MIPMAP_TEXTURE_EXT 0x20D7 -#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8 -#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9 -#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA -#define GLX_TEXTURE_1D_EXT 0x20DB -#define GLX_TEXTURE_2D_EXT 0x20DC -#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD -#define GLX_FRONT_LEFT_EXT 0x20DE -#define GLX_FRONT_RIGHT_EXT 0x20DF -#define GLX_BACK_LEFT_EXT 0x20E0 -#define GLX_BACK_RIGHT_EXT 0x20E1 -#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT -#define GLX_BACK_EXT GLX_BACK_LEFT_EXT -#define GLX_AUX0_EXT 0x20E2 -#define GLX_AUX1_EXT 0x20E3 -#define GLX_AUX2_EXT 0x20E4 -#define GLX_AUX3_EXT 0x20E5 -#define GLX_AUX4_EXT 0x20E6 -#define GLX_AUX5_EXT 0x20E7 -#define GLX_AUX6_EXT 0x20E8 -#define GLX_AUX7_EXT 0x20E9 -#define GLX_AUX8_EXT 0x20EA -#define GLX_AUX9_EXT 0x20EB -#endif - -#ifndef GLX_NV_present_video -#define GLX_NUM_VIDEO_SLOTS_NV 0x20F0 -#endif - -#ifndef GLX_NV_video_out -#define GLX_VIDEO_OUT_COLOR_NV 0x20C3 -#define GLX_VIDEO_OUT_ALPHA_NV 0x20C4 -#define GLX_VIDEO_OUT_DEPTH_NV 0x20C5 -#define GLX_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 -#define GLX_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 -#define GLX_VIDEO_OUT_FRAME_NV 0x20C8 -#define GLX_VIDEO_OUT_FIELD_1_NV 0x20C9 -#define GLX_VIDEO_OUT_FIELD_2_NV 0x20CA -#define GLX_VIDEO_OUT_STACKED_FIELDS_1_2_NV 0x20CB -#define GLX_VIDEO_OUT_STACKED_FIELDS_2_1_NV 0x20CC -#endif - -#ifndef GLX_NV_swap_group -#endif - -#ifndef GLX_NV_video_capture -#define GLX_DEVICE_ID_NV 0x20CD -#define GLX_UNIQUE_ID_NV 0x20CE -#define GLX_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF -#endif - -#ifndef GLX_EXT_swap_control -#define GLX_SWAP_INTERVAL_EXT 0x20F1 -#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2 -#endif - -#ifndef GLX_NV_copy_image -#endif - -#ifndef GLX_INTEL_swap_event -#define GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK 0x04000000 -#define GLX_EXCHANGE_COMPLETE_INTEL 0x8180 -#define GLX_COPY_COMPLETE_INTEL 0x8181 -#define GLX_FLIP_COMPLETE_INTEL 0x8182 -#endif - -#ifndef GLX_NV_multisample_coverage -#define GLX_COVERAGE_SAMPLES_NV 100001 -#define GLX_COLOR_SAMPLES_NV 0x20B3 -#endif - -#ifndef GLX_AMD_gpu_association -#define GLX_GPU_VENDOR_AMD 0x1F00 -#define GLX_GPU_RENDERER_STRING_AMD 0x1F01 -#define GLX_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 -#define GLX_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 -#define GLX_GPU_RAM_AMD 0x21A3 -#define GLX_GPU_CLOCK_AMD 0x21A4 -#define GLX_GPU_NUM_PIPES_AMD 0x21A5 -#define GLX_GPU_NUM_SIMD_AMD 0x21A6 -#define GLX_GPU_NUM_RB_AMD 0x21A7 -#define GLX_GPU_NUM_SPI_AMD 0x21A8 -#endif - -#ifndef GLX_EXT_create_context_es2_profile -#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 -#endif - -#ifndef GLX_EXT_swap_control_tear -#define GLX_LATE_SWAPS_TEAR_EXT 0x20F3 -#endif - - -/*************************************************************/ - -#ifndef GLX_ARB_get_proc_address -typedef void (*__GLXextFuncPtr)(void); -#endif - -#ifndef GLX_SGIX_video_source -typedef XID GLXVideoSourceSGIX; -#endif - -#ifndef GLX_SGIX_fbconfig -typedef XID GLXFBConfigIDSGIX; -typedef struct __GLXFBConfigRec *GLXFBConfigSGIX; -#endif - -#ifndef GLX_SGIX_pbuffer -typedef XID GLXPbufferSGIX; -typedef struct { - int type; - unsigned long serial; /* # of last request processed by server */ - Bool send_event; /* true if this came for SendEvent request */ - Display *display; /* display the event was read from */ - GLXDrawable drawable; /* i.d. of Drawable */ - int event_type; /* GLX_DAMAGED_SGIX or GLX_SAVED_SGIX */ - int draw_type; /* GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX */ - unsigned int mask; /* mask indicating which buffers are affected*/ - int x, y; - int width, height; - int count; /* if nonzero, at least this many more */ -} GLXBufferClobberEventSGIX; -#endif - -#ifndef GLX_NV_video_output -typedef unsigned int GLXVideoDeviceNV; -#endif - -#ifndef GLX_NV_video_capture -typedef XID GLXVideoCaptureDeviceNV; -#endif - -#ifndef GLEXT_64_TYPES_DEFINED -/* This code block is duplicated in glext.h, so must be protected */ -#define GLEXT_64_TYPES_DEFINED -/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ -/* (as used in the GLX_OML_sync_control extension). */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#include -#elif defined(__sun__) || defined(__digital__) -#include -#if defined(__STDC__) -#if defined(__arch64__) || defined(_LP64) -typedef long int int64_t; -typedef unsigned long int uint64_t; -#else -typedef long long int int64_t; -typedef unsigned long long int uint64_t; -#endif /* __arch64__ */ -#endif /* __STDC__ */ -#elif defined( __VMS ) || defined(__sgi) -#include -#elif defined(__SCO__) || defined(__USLC__) -#include -#elif defined(__UNIXOS2__) || defined(__SOL64__) -typedef long int int32_t; -typedef long long int int64_t; -typedef unsigned long long int uint64_t; -#elif defined(_WIN32) && defined(__GNUC__) -#include -#elif defined(_WIN32) -typedef __int32 int32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else -#include /* Fallback option */ -#endif -#endif - -#ifndef GLX_VERSION_1_3 -#define GLX_VERSION_1_3 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern GLXFBConfig * glXGetFBConfigs (Display *dpy, int screen, int *nelements); -extern GLXFBConfig * glXChooseFBConfig (Display *dpy, int screen, const int *attrib_list, int *nelements); -extern int glXGetFBConfigAttrib (Display *dpy, GLXFBConfig config, int attribute, int *value); -extern XVisualInfo * glXGetVisualFromFBConfig (Display *dpy, GLXFBConfig config); -extern GLXWindow glXCreateWindow (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); -extern void glXDestroyWindow (Display *dpy, GLXWindow win); -extern GLXPixmap glXCreatePixmap (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); -extern void glXDestroyPixmap (Display *dpy, GLXPixmap pixmap); -extern GLXPbuffer glXCreatePbuffer (Display *dpy, GLXFBConfig config, const int *attrib_list); -extern void glXDestroyPbuffer (Display *dpy, GLXPbuffer pbuf); -extern void glXQueryDrawable (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); -extern GLXContext glXCreateNewContext (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); -extern Bool glXMakeContextCurrent (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); -extern GLXDrawable glXGetCurrentReadDrawable (void); -extern Display * glXGetCurrentDisplay (void); -extern int glXQueryContext (Display *dpy, GLXContext ctx, int attribute, int *value); -extern void glXSelectEvent (Display *dpy, GLXDrawable draw, unsigned long event_mask); -extern void glXGetSelectedEvent (Display *dpy, GLXDrawable draw, unsigned long *event_mask); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef GLXFBConfig * ( * PFNGLXGETFBCONFIGSPROC) (Display *dpy, int screen, int *nelements); -typedef GLXFBConfig * ( * PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements); -typedef int ( * PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value); -typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config); -typedef GLXWindow ( * PFNGLXCREATEWINDOWPROC) (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); -typedef void ( * PFNGLXDESTROYWINDOWPROC) (Display *dpy, GLXWindow win); -typedef GLXPixmap ( * PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); -typedef void ( * PFNGLXDESTROYPIXMAPPROC) (Display *dpy, GLXPixmap pixmap); -typedef GLXPbuffer ( * PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list); -typedef void ( * PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf); -typedef void ( * PFNGLXQUERYDRAWABLEPROC) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); -typedef GLXContext ( * PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); -typedef Bool ( * PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); -typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLEPROC) (void); -typedef Display * ( * PFNGLXGETCURRENTDISPLAYPROC) (void); -typedef int ( * PFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value); -typedef void ( * PFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask); -typedef void ( * PFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask); -#endif - -#ifndef GLX_VERSION_1_4 -#define GLX_VERSION_1_4 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern __GLXextFuncPtr glXGetProcAddress (const GLubyte *procName); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName); -#endif - -#ifndef GLX_ARB_get_proc_address -#define GLX_ARB_get_proc_address 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *procName); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSARBPROC) (const GLubyte *procName); -#endif - -#ifndef GLX_ARB_multisample -#define GLX_ARB_multisample 1 -#endif - -#ifndef GLX_ARB_fbconfig_float -#define GLX_ARB_fbconfig_float 1 -#endif - -#ifndef GLX_ARB_framebuffer_sRGB -#define GLX_ARB_framebuffer_sRGB 1 -#endif - -#ifndef GLX_ARB_create_context -#define GLX_ARB_create_context 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern GLXContext glXCreateContextAttribsARB (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); -#endif - -#ifndef GLX_ARB_create_context_profile -#define GLX_ARB_create_context_profile 1 -#endif - -#ifndef GLX_ARB_create_context_robustness -#define GLX_ARB_create_context_robustness 1 -#endif - -#ifndef GLX_SGIS_multisample -#define GLX_SGIS_multisample 1 -#endif - -#ifndef GLX_EXT_visual_info -#define GLX_EXT_visual_info 1 -#endif - -#ifndef GLX_SGI_swap_control -#define GLX_SGI_swap_control 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern int glXSwapIntervalSGI (int interval); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval); -#endif - -#ifndef GLX_SGI_video_sync -#define GLX_SGI_video_sync 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern int glXGetVideoSyncSGI (unsigned int *count); -extern int glXWaitVideoSyncSGI (int divisor, int remainder, unsigned int *count); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef int ( * PFNGLXGETVIDEOSYNCSGIPROC) (unsigned int *count); -typedef int ( * PFNGLXWAITVIDEOSYNCSGIPROC) (int divisor, int remainder, unsigned int *count); -#endif - -#ifndef GLX_SGI_make_current_read -#define GLX_SGI_make_current_read 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Bool glXMakeCurrentReadSGI (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); -extern GLXDrawable glXGetCurrentReadDrawableSGI (void); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Bool ( * PFNGLXMAKECURRENTREADSGIPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); -typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLESGIPROC) (void); -#endif - -#ifndef GLX_SGIX_video_source -#define GLX_SGIX_video_source 1 -#ifdef _VL_H -#ifdef GLX_GLXEXT_PROTOTYPES -extern GLXVideoSourceSGIX glXCreateGLXVideoSourceSGIX (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode); -extern void glXDestroyGLXVideoSourceSGIX (Display *dpy, GLXVideoSourceSGIX glxvideosource); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef GLXVideoSourceSGIX ( * PFNGLXCREATEGLXVIDEOSOURCESGIXPROC) (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode); -typedef void ( * PFNGLXDESTROYGLXVIDEOSOURCESGIXPROC) (Display *dpy, GLXVideoSourceSGIX glxvideosource); -#endif /* _VL_H */ -#endif - -#ifndef GLX_EXT_visual_rating -#define GLX_EXT_visual_rating 1 -#endif - -#ifndef GLX_EXT_import_context -#define GLX_EXT_import_context 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Display * glXGetCurrentDisplayEXT (void); -extern int glXQueryContextInfoEXT (Display *dpy, GLXContext context, int attribute, int *value); -extern GLXContextID glXGetContextIDEXT (const GLXContext context); -extern GLXContext glXImportContextEXT (Display *dpy, GLXContextID contextID); -extern void glXFreeContextEXT (Display *dpy, GLXContext context); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Display * ( * PFNGLXGETCURRENTDISPLAYEXTPROC) (void); -typedef int ( * PFNGLXQUERYCONTEXTINFOEXTPROC) (Display *dpy, GLXContext context, int attribute, int *value); -typedef GLXContextID ( * PFNGLXGETCONTEXTIDEXTPROC) (const GLXContext context); -typedef GLXContext ( * PFNGLXIMPORTCONTEXTEXTPROC) (Display *dpy, GLXContextID contextID); -typedef void ( * PFNGLXFREECONTEXTEXTPROC) (Display *dpy, GLXContext context); -#endif - -#ifndef GLX_SGIX_fbconfig -#define GLX_SGIX_fbconfig 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern int glXGetFBConfigAttribSGIX (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value); -extern GLXFBConfigSGIX * glXChooseFBConfigSGIX (Display *dpy, int screen, int *attrib_list, int *nelements); -extern GLXPixmap glXCreateGLXPixmapWithConfigSGIX (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap); -extern GLXContext glXCreateContextWithConfigSGIX (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct); -extern XVisualInfo * glXGetVisualFromFBConfigSGIX (Display *dpy, GLXFBConfigSGIX config); -extern GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX (Display *dpy, XVisualInfo *vis); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef int ( * PFNGLXGETFBCONFIGATTRIBSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value); -typedef GLXFBConfigSGIX * ( * PFNGLXCHOOSEFBCONFIGSGIXPROC) (Display *dpy, int screen, int *attrib_list, int *nelements); -typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap); -typedef GLXContext ( * PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct); -typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config); -typedef GLXFBConfigSGIX ( * PFNGLXGETFBCONFIGFROMVISUALSGIXPROC) (Display *dpy, XVisualInfo *vis); -#endif - -#ifndef GLX_SGIX_pbuffer -#define GLX_SGIX_pbuffer 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern GLXPbufferSGIX glXCreateGLXPbufferSGIX (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list); -extern void glXDestroyGLXPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuf); -extern int glXQueryGLXPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value); -extern void glXSelectEventSGIX (Display *dpy, GLXDrawable drawable, unsigned long mask); -extern void glXGetSelectedEventSGIX (Display *dpy, GLXDrawable drawable, unsigned long *mask); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef GLXPbufferSGIX ( * PFNGLXCREATEGLXPBUFFERSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list); -typedef void ( * PFNGLXDESTROYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf); -typedef int ( * PFNGLXQUERYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value); -typedef void ( * PFNGLXSELECTEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long mask); -typedef void ( * PFNGLXGETSELECTEDEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long *mask); -#endif - -#ifndef GLX_SGI_cushion -#define GLX_SGI_cushion 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXCushionSGI (Display *dpy, Window window, float cushion); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXCUSHIONSGIPROC) (Display *dpy, Window window, float cushion); -#endif - -#ifndef GLX_SGIX_video_resize -#define GLX_SGIX_video_resize 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern int glXBindChannelToWindowSGIX (Display *display, int screen, int channel, Window window); -extern int glXChannelRectSGIX (Display *display, int screen, int channel, int x, int y, int w, int h); -extern int glXQueryChannelRectSGIX (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh); -extern int glXQueryChannelDeltasSGIX (Display *display, int screen, int channel, int *x, int *y, int *w, int *h); -extern int glXChannelRectSyncSGIX (Display *display, int screen, int channel, GLenum synctype); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef int ( * PFNGLXBINDCHANNELTOWINDOWSGIXPROC) (Display *display, int screen, int channel, Window window); -typedef int ( * PFNGLXCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int x, int y, int w, int h); -typedef int ( * PFNGLXQUERYCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh); -typedef int ( * PFNGLXQUERYCHANNELDELTASSGIXPROC) (Display *display, int screen, int channel, int *x, int *y, int *w, int *h); -typedef int ( * PFNGLXCHANNELRECTSYNCSGIXPROC) (Display *display, int screen, int channel, GLenum synctype); -#endif - -#ifndef GLX_SGIX_dmbuffer -#define GLX_SGIX_dmbuffer 1 -#ifdef _DM_BUFFER_H_ -#ifdef GLX_GLXEXT_PROTOTYPES -extern Bool glXAssociateDMPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Bool ( * PFNGLXASSOCIATEDMPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer); -#endif /* _DM_BUFFER_H_ */ -#endif - -#ifndef GLX_SGIX_swap_group -#define GLX_SGIX_swap_group 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXJoinSwapGroupSGIX (Display *dpy, GLXDrawable drawable, GLXDrawable member); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXJOINSWAPGROUPSGIXPROC) (Display *dpy, GLXDrawable drawable, GLXDrawable member); -#endif - -#ifndef GLX_SGIX_swap_barrier -#define GLX_SGIX_swap_barrier 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXBindSwapBarrierSGIX (Display *dpy, GLXDrawable drawable, int barrier); -extern Bool glXQueryMaxSwapBarriersSGIX (Display *dpy, int screen, int *max); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXBINDSWAPBARRIERSGIXPROC) (Display *dpy, GLXDrawable drawable, int barrier); -typedef Bool ( * PFNGLXQUERYMAXSWAPBARRIERSSGIXPROC) (Display *dpy, int screen, int *max); -#endif - -#ifndef GLX_SUN_get_transparent_index -#define GLX_SUN_get_transparent_index 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Status glXGetTransparentIndexSUN (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Status ( * PFNGLXGETTRANSPARENTINDEXSUNPROC) (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex); -#endif - -#ifndef GLX_MESA_copy_sub_buffer -#define GLX_MESA_copy_sub_buffer 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXCopySubBufferMESA (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXCOPYSUBBUFFERMESAPROC) (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); -#endif - -#ifndef GLX_MESA_pixmap_colormap -#define GLX_MESA_pixmap_colormap 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern GLXPixmap glXCreateGLXPixmapMESA (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPMESAPROC) (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap); -#endif - -#ifndef GLX_MESA_release_buffers -#define GLX_MESA_release_buffers 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Bool glXReleaseBuffersMESA (Display *dpy, GLXDrawable drawable); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Bool ( * PFNGLXRELEASEBUFFERSMESAPROC) (Display *dpy, GLXDrawable drawable); -#endif - -#ifndef GLX_MESA_set_3dfx_mode -#define GLX_MESA_set_3dfx_mode 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Bool glXSet3DfxModeMESA (int mode); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Bool ( * PFNGLXSET3DFXMODEMESAPROC) (int mode); -#endif - -#ifndef GLX_SGIX_visual_select_group -#define GLX_SGIX_visual_select_group 1 -#endif - -#ifndef GLX_OML_swap_method -#define GLX_OML_swap_method 1 -#endif - -#ifndef GLX_OML_sync_control -#define GLX_OML_sync_control 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Bool glXGetSyncValuesOML (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc); -extern Bool glXGetMscRateOML (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); -extern int64_t glXSwapBuffersMscOML (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder); -extern Bool glXWaitForMscOML (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); -extern Bool glXWaitForSbcOML (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Bool ( * PFNGLXGETSYNCVALUESOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc); -typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); -typedef int64_t ( * PFNGLXSWAPBUFFERSMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder); -typedef Bool ( * PFNGLXWAITFORMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); -typedef Bool ( * PFNGLXWAITFORSBCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); -#endif - -#ifndef GLX_NV_float_buffer -#define GLX_NV_float_buffer 1 -#endif - -#ifndef GLX_SGIX_hyperpipe -#define GLX_SGIX_hyperpipe 1 - -typedef struct { - char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; - int networkId; -} GLXHyperpipeNetworkSGIX; - -typedef struct { - char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; - int channel; - unsigned int - participationType; - int timeSlice; -} GLXHyperpipeConfigSGIX; - -typedef struct { - char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; - int srcXOrigin, srcYOrigin, srcWidth, srcHeight; - int destXOrigin, destYOrigin, destWidth, destHeight; -} GLXPipeRect; - -typedef struct { - char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; - int XOrigin, YOrigin, maxHeight, maxWidth; -} GLXPipeRectLimits; - -#ifdef GLX_GLXEXT_PROTOTYPES -extern GLXHyperpipeNetworkSGIX * glXQueryHyperpipeNetworkSGIX (Display *dpy, int *npipes); -extern int glXHyperpipeConfigSGIX (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId); -extern GLXHyperpipeConfigSGIX * glXQueryHyperpipeConfigSGIX (Display *dpy, int hpId, int *npipes); -extern int glXDestroyHyperpipeConfigSGIX (Display *dpy, int hpId); -extern int glXBindHyperpipeSGIX (Display *dpy, int hpId); -extern int glXQueryHyperpipeBestAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList); -extern int glXHyperpipeAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *attribList); -extern int glXQueryHyperpipeAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef GLXHyperpipeNetworkSGIX * ( * PFNGLXQUERYHYPERPIPENETWORKSGIXPROC) (Display *dpy, int *npipes); -typedef int ( * PFNGLXHYPERPIPECONFIGSGIXPROC) (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId); -typedef GLXHyperpipeConfigSGIX * ( * PFNGLXQUERYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId, int *npipes); -typedef int ( * PFNGLXDESTROYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId); -typedef int ( * PFNGLXBINDHYPERPIPESGIXPROC) (Display *dpy, int hpId); -typedef int ( * PFNGLXQUERYHYPERPIPEBESTATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList); -typedef int ( * PFNGLXHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList); -typedef int ( * PFNGLXQUERYHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList); -#endif - -#ifndef GLX_MESA_agp_offset -#define GLX_MESA_agp_offset 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern unsigned int glXGetAGPOffsetMESA (const void *pointer); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef unsigned int ( * PFNGLXGETAGPOFFSETMESAPROC) (const void *pointer); -#endif - -#ifndef GLX_EXT_fbconfig_packed_float -#define GLX_EXT_fbconfig_packed_float 1 -#endif - -#ifndef GLX_EXT_framebuffer_sRGB -#define GLX_EXT_framebuffer_sRGB 1 -#endif - -#ifndef GLX_EXT_texture_from_pixmap -#define GLX_EXT_texture_from_pixmap 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXBindTexImageEXT (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); -extern void glXReleaseTexImageEXT (Display *dpy, GLXDrawable drawable, int buffer); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXBINDTEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); -typedef void ( * PFNGLXRELEASETEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer); -#endif - -#ifndef GLX_NV_present_video -#define GLX_NV_present_video 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern unsigned int * glXEnumerateVideoDevicesNV (Display *dpy, int screen, int *nelements); -extern int glXBindVideoDeviceNV (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef unsigned int * ( * PFNGLXENUMERATEVIDEODEVICESNVPROC) (Display *dpy, int screen, int *nelements); -typedef int ( * PFNGLXBINDVIDEODEVICENVPROC) (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list); -#endif - -#ifndef GLX_NV_video_output -#define GLX_NV_video_output 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern int glXGetVideoDeviceNV (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice); -extern int glXReleaseVideoDeviceNV (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice); -extern int glXBindVideoImageNV (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer); -extern int glXReleaseVideoImageNV (Display *dpy, GLXPbuffer pbuf); -extern int glXSendPbufferToVideoNV (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock); -extern int glXGetVideoInfoNV (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef int ( * PFNGLXGETVIDEODEVICENVPROC) (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice); -typedef int ( * PFNGLXRELEASEVIDEODEVICENVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice); -typedef int ( * PFNGLXBINDVIDEOIMAGENVPROC) (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer); -typedef int ( * PFNGLXRELEASEVIDEOIMAGENVPROC) (Display *dpy, GLXPbuffer pbuf); -typedef int ( * PFNGLXSENDPBUFFERTOVIDEONVPROC) (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock); -typedef int ( * PFNGLXGETVIDEOINFONVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); -#endif - -#ifndef GLX_NV_swap_group -#define GLX_NV_swap_group 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern Bool glXJoinSwapGroupNV (Display *dpy, GLXDrawable drawable, GLuint group); -extern Bool glXBindSwapBarrierNV (Display *dpy, GLuint group, GLuint barrier); -extern Bool glXQuerySwapGroupNV (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier); -extern Bool glXQueryMaxSwapGroupsNV (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers); -extern Bool glXQueryFrameCountNV (Display *dpy, int screen, GLuint *count); -extern Bool glXResetFrameCountNV (Display *dpy, int screen); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef Bool ( * PFNGLXJOINSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint group); -typedef Bool ( * PFNGLXBINDSWAPBARRIERNVPROC) (Display *dpy, GLuint group, GLuint barrier); -typedef Bool ( * PFNGLXQUERYSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier); -typedef Bool ( * PFNGLXQUERYMAXSWAPGROUPSNVPROC) (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers); -typedef Bool ( * PFNGLXQUERYFRAMECOUNTNVPROC) (Display *dpy, int screen, GLuint *count); -typedef Bool ( * PFNGLXRESETFRAMECOUNTNVPROC) (Display *dpy, int screen); -#endif - -#ifndef GLX_NV_video_capture -#define GLX_NV_video_capture 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern int glXBindVideoCaptureDeviceNV (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device); -extern GLXVideoCaptureDeviceNV * glXEnumerateVideoCaptureDevicesNV (Display *dpy, int screen, int *nelements); -extern void glXLockVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device); -extern int glXQueryVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value); -extern void glXReleaseVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef int ( * PFNGLXBINDVIDEOCAPTUREDEVICENVPROC) (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device); -typedef GLXVideoCaptureDeviceNV * ( * PFNGLXENUMERATEVIDEOCAPTUREDEVICESNVPROC) (Display *dpy, int screen, int *nelements); -typedef void ( * PFNGLXLOCKVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device); -typedef int ( * PFNGLXQUERYVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value); -typedef void ( * PFNGLXRELEASEVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device); -#endif - -#ifndef GLX_EXT_swap_control -#define GLX_EXT_swap_control 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXSwapIntervalEXT (Display *dpy, GLXDrawable drawable, int interval); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXSWAPINTERVALEXTPROC) (Display *dpy, GLXDrawable drawable, int interval); -#endif - -#ifndef GLX_NV_copy_image -#define GLX_NV_copy_image 1 -#ifdef GLX_GLXEXT_PROTOTYPES -extern void glXCopyImageSubDataNV (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); -#endif /* GLX_GLXEXT_PROTOTYPES */ -typedef void ( * PFNGLXCOPYIMAGESUBDATANVPROC) (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); -#endif - -#ifndef GLX_INTEL_swap_event -#define GLX_INTEL_swap_event 1 -#endif - -#ifndef GLX_NV_multisample_coverage -#define GLX_NV_multisample_coverage 1 -#endif - -#ifndef GLX_EXT_swap_control_tear -#define GLX_EXT_swap_control_tear 1 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/GL3/wglext.h b/include/GL3/wglext.h deleted file mode 100644 index b5dc7bf7f..000000000 --- a/include/GL3/wglext.h +++ /dev/null @@ -1,943 +0,0 @@ -#ifndef __wglext_h_ -#define __wglext_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* -** Copyright (c) 2007-2012 The Khronos Group Inc. -** -** Permission is hereby granted, free of charge, to any person obtaining a -** copy of this software and/or associated documentation files (the -** "Materials"), to deal in the Materials without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Materials, and to -** permit persons to whom the Materials are furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be included -** in all copies or substantial portions of the Materials. -** -** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -*/ - -/* Function declaration macros - to move into glplatform.h */ - -#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) -#define WIN32_LEAN_AND_MEAN 1 -#include -#endif - -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef APIENTRYP -#define APIENTRYP APIENTRY * -#endif -#ifndef GLAPI -#define GLAPI extern -#endif - -/*************************************************************/ - -/* Header file version number */ -/* wglext.h last updated 2012/01/04 */ -/* Current version at http://www.opengl.org/registry/ */ -#define WGL_WGLEXT_VERSION 24 - -#ifndef WGL_ARB_buffer_region -#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001 -#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002 -#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004 -#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008 -#endif - -#ifndef WGL_ARB_multisample -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 -#endif - -#ifndef WGL_ARB_extensions_string -#endif - -#ifndef WGL_ARB_pixel_format -#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_DRAW_TO_BITMAP_ARB 0x2002 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_NEED_PALETTE_ARB 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 -#define WGL_SWAP_METHOD_ARB 0x2007 -#define WGL_NUMBER_OVERLAYS_ARB 0x2008 -#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 -#define WGL_TRANSPARENT_ARB 0x200A -#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 -#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 -#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 -#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A -#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B -#define WGL_SHARE_DEPTH_ARB 0x200C -#define WGL_SHARE_STENCIL_ARB 0x200D -#define WGL_SHARE_ACCUM_ARB 0x200E -#define WGL_SUPPORT_GDI_ARB 0x200F -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_STEREO_ARB 0x2012 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 -#define WGL_GREEN_BITS_ARB 0x2017 -#define WGL_GREEN_SHIFT_ARB 0x2018 -#define WGL_BLUE_BITS_ARB 0x2019 -#define WGL_BLUE_SHIFT_ARB 0x201A -#define WGL_ALPHA_BITS_ARB 0x201B -#define WGL_ALPHA_SHIFT_ARB 0x201C -#define WGL_ACCUM_BITS_ARB 0x201D -#define WGL_ACCUM_RED_BITS_ARB 0x201E -#define WGL_ACCUM_GREEN_BITS_ARB 0x201F -#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 -#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 -#define WGL_AUX_BUFFERS_ARB 0x2024 -#define WGL_NO_ACCELERATION_ARB 0x2025 -#define WGL_GENERIC_ACCELERATION_ARB 0x2026 -#define WGL_FULL_ACCELERATION_ARB 0x2027 -#define WGL_SWAP_EXCHANGE_ARB 0x2028 -#define WGL_SWAP_COPY_ARB 0x2029 -#define WGL_SWAP_UNDEFINED_ARB 0x202A -#define WGL_TYPE_RGBA_ARB 0x202B -#define WGL_TYPE_COLORINDEX_ARB 0x202C -#endif - -#ifndef WGL_ARB_make_current_read -#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043 -#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 -#endif - -#ifndef WGL_ARB_pbuffer -#define WGL_DRAW_TO_PBUFFER_ARB 0x202D -#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E -#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F -#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 -#define WGL_PBUFFER_LARGEST_ARB 0x2033 -#define WGL_PBUFFER_WIDTH_ARB 0x2034 -#define WGL_PBUFFER_HEIGHT_ARB 0x2035 -#define WGL_PBUFFER_LOST_ARB 0x2036 -#endif - -#ifndef WGL_ARB_render_texture -#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 -#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 -#define WGL_TEXTURE_FORMAT_ARB 0x2072 -#define WGL_TEXTURE_TARGET_ARB 0x2073 -#define WGL_MIPMAP_TEXTURE_ARB 0x2074 -#define WGL_TEXTURE_RGB_ARB 0x2075 -#define WGL_TEXTURE_RGBA_ARB 0x2076 -#define WGL_NO_TEXTURE_ARB 0x2077 -#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 -#define WGL_TEXTURE_1D_ARB 0x2079 -#define WGL_TEXTURE_2D_ARB 0x207A -#define WGL_MIPMAP_LEVEL_ARB 0x207B -#define WGL_CUBE_MAP_FACE_ARB 0x207C -#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D -#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E -#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F -#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 -#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 -#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 -#define WGL_FRONT_LEFT_ARB 0x2083 -#define WGL_FRONT_RIGHT_ARB 0x2084 -#define WGL_BACK_LEFT_ARB 0x2085 -#define WGL_BACK_RIGHT_ARB 0x2086 -#define WGL_AUX0_ARB 0x2087 -#define WGL_AUX1_ARB 0x2088 -#define WGL_AUX2_ARB 0x2089 -#define WGL_AUX3_ARB 0x208A -#define WGL_AUX4_ARB 0x208B -#define WGL_AUX5_ARB 0x208C -#define WGL_AUX6_ARB 0x208D -#define WGL_AUX7_ARB 0x208E -#define WGL_AUX8_ARB 0x208F -#define WGL_AUX9_ARB 0x2090 -#endif - -#ifndef WGL_ARB_pixel_format_float -#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0 -#endif - -#ifndef WGL_ARB_framebuffer_sRGB -#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9 -#endif - -#ifndef WGL_ARB_create_context -#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 -#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 -#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 -#define WGL_CONTEXT_FLAGS_ARB 0x2094 -#define ERROR_INVALID_VERSION_ARB 0x2095 -#endif - -#ifndef WGL_ARB_create_context_profile -#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 -#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 -#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 -#define ERROR_INVALID_PROFILE_ARB 0x2096 -#endif - -#ifndef WGL_ARB_create_context_robustness -#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 -#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 -#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 -#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 -#endif - -#ifndef WGL_EXT_make_current_read -#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043 -#endif - -#ifndef WGL_EXT_pixel_format -#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000 -#define WGL_DRAW_TO_WINDOW_EXT 0x2001 -#define WGL_DRAW_TO_BITMAP_EXT 0x2002 -#define WGL_ACCELERATION_EXT 0x2003 -#define WGL_NEED_PALETTE_EXT 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006 -#define WGL_SWAP_METHOD_EXT 0x2007 -#define WGL_NUMBER_OVERLAYS_EXT 0x2008 -#define WGL_NUMBER_UNDERLAYS_EXT 0x2009 -#define WGL_TRANSPARENT_EXT 0x200A -#define WGL_TRANSPARENT_VALUE_EXT 0x200B -#define WGL_SHARE_DEPTH_EXT 0x200C -#define WGL_SHARE_STENCIL_EXT 0x200D -#define WGL_SHARE_ACCUM_EXT 0x200E -#define WGL_SUPPORT_GDI_EXT 0x200F -#define WGL_SUPPORT_OPENGL_EXT 0x2010 -#define WGL_DOUBLE_BUFFER_EXT 0x2011 -#define WGL_STEREO_EXT 0x2012 -#define WGL_PIXEL_TYPE_EXT 0x2013 -#define WGL_COLOR_BITS_EXT 0x2014 -#define WGL_RED_BITS_EXT 0x2015 -#define WGL_RED_SHIFT_EXT 0x2016 -#define WGL_GREEN_BITS_EXT 0x2017 -#define WGL_GREEN_SHIFT_EXT 0x2018 -#define WGL_BLUE_BITS_EXT 0x2019 -#define WGL_BLUE_SHIFT_EXT 0x201A -#define WGL_ALPHA_BITS_EXT 0x201B -#define WGL_ALPHA_SHIFT_EXT 0x201C -#define WGL_ACCUM_BITS_EXT 0x201D -#define WGL_ACCUM_RED_BITS_EXT 0x201E -#define WGL_ACCUM_GREEN_BITS_EXT 0x201F -#define WGL_ACCUM_BLUE_BITS_EXT 0x2020 -#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021 -#define WGL_DEPTH_BITS_EXT 0x2022 -#define WGL_STENCIL_BITS_EXT 0x2023 -#define WGL_AUX_BUFFERS_EXT 0x2024 -#define WGL_NO_ACCELERATION_EXT 0x2025 -#define WGL_GENERIC_ACCELERATION_EXT 0x2026 -#define WGL_FULL_ACCELERATION_EXT 0x2027 -#define WGL_SWAP_EXCHANGE_EXT 0x2028 -#define WGL_SWAP_COPY_EXT 0x2029 -#define WGL_SWAP_UNDEFINED_EXT 0x202A -#define WGL_TYPE_RGBA_EXT 0x202B -#define WGL_TYPE_COLORINDEX_EXT 0x202C -#endif - -#ifndef WGL_EXT_pbuffer -#define WGL_DRAW_TO_PBUFFER_EXT 0x202D -#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E -#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F -#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030 -#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031 -#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032 -#define WGL_PBUFFER_LARGEST_EXT 0x2033 -#define WGL_PBUFFER_WIDTH_EXT 0x2034 -#define WGL_PBUFFER_HEIGHT_EXT 0x2035 -#endif - -#ifndef WGL_EXT_depth_float -#define WGL_DEPTH_FLOAT_EXT 0x2040 -#endif - -#ifndef WGL_3DFX_multisample -#define WGL_SAMPLE_BUFFERS_3DFX 0x2060 -#define WGL_SAMPLES_3DFX 0x2061 -#endif - -#ifndef WGL_EXT_multisample -#define WGL_SAMPLE_BUFFERS_EXT 0x2041 -#define WGL_SAMPLES_EXT 0x2042 -#endif - -#ifndef WGL_I3D_digital_video_control -#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050 -#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051 -#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052 -#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053 -#endif - -#ifndef WGL_I3D_gamma -#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E -#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F -#endif - -#ifndef WGL_I3D_genlock -#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044 -#define WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D 0x2045 -#define WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D 0x2046 -#define WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D 0x2047 -#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048 -#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049 -#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A -#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B -#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C -#endif - -#ifndef WGL_I3D_image_buffer -#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001 -#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002 -#endif - -#ifndef WGL_I3D_swap_frame_lock -#endif - -#ifndef WGL_NV_render_depth_texture -#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 -#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 -#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 -#define WGL_DEPTH_COMPONENT_NV 0x20A7 -#endif - -#ifndef WGL_NV_render_texture_rectangle -#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 -#define WGL_TEXTURE_RECTANGLE_NV 0x20A2 -#endif - -#ifndef WGL_ATI_pixel_format_float -#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 -#endif - -#ifndef WGL_NV_float_buffer -#define WGL_FLOAT_COMPONENTS_NV 0x20B0 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 -#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 -#define WGL_TEXTURE_FLOAT_R_NV 0x20B5 -#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 -#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 -#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 -#endif - -#ifndef WGL_3DL_stereo_control -#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055 -#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056 -#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057 -#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058 -#endif - -#ifndef WGL_EXT_pixel_format_packed_float -#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 -#endif - -#ifndef WGL_EXT_framebuffer_sRGB -#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 -#endif - -#ifndef WGL_NV_present_video -#define WGL_NUM_VIDEO_SLOTS_NV 0x20F0 -#endif - -#ifndef WGL_NV_video_out -#define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0 -#define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1 -#define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2 -#define WGL_VIDEO_OUT_COLOR_NV 0x20C3 -#define WGL_VIDEO_OUT_ALPHA_NV 0x20C4 -#define WGL_VIDEO_OUT_DEPTH_NV 0x20C5 -#define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 -#define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 -#define WGL_VIDEO_OUT_FRAME 0x20C8 -#define WGL_VIDEO_OUT_FIELD_1 0x20C9 -#define WGL_VIDEO_OUT_FIELD_2 0x20CA -#define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB -#define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC -#endif - -#ifndef WGL_NV_swap_group -#endif - -#ifndef WGL_NV_gpu_affinity -#define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0 -#define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1 -#endif - -#ifndef WGL_AMD_gpu_association -#define WGL_GPU_VENDOR_AMD 0x1F00 -#define WGL_GPU_RENDERER_STRING_AMD 0x1F01 -#define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 -#define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 -#define WGL_GPU_RAM_AMD 0x21A3 -#define WGL_GPU_CLOCK_AMD 0x21A4 -#define WGL_GPU_NUM_PIPES_AMD 0x21A5 -#define WGL_GPU_NUM_SIMD_AMD 0x21A6 -#define WGL_GPU_NUM_RB_AMD 0x21A7 -#define WGL_GPU_NUM_SPI_AMD 0x21A8 -#endif - -#ifndef WGL_NV_video_capture -#define WGL_UNIQUE_ID_NV 0x20CE -#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF -#endif - -#ifndef WGL_NV_copy_image -#endif - -#ifndef WGL_NV_multisample_coverage -#define WGL_COVERAGE_SAMPLES_NV 0x2042 -#define WGL_COLOR_SAMPLES_NV 0x20B9 -#endif - -#ifndef WGL_EXT_create_context_es2_profile -#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 -#endif - -#ifndef WGL_NV_DX_interop -#define WGL_ACCESS_READ_ONLY_NV 0x00000000 -#define WGL_ACCESS_READ_WRITE_NV 0x00000001 -#define WGL_ACCESS_WRITE_DISCARD_NV 0x00000002 -#endif - -#ifndef WGL_NV_DX_interop2 -#endif - -#ifndef WGL_EXT_swap_control_tear -#endif - - -/*************************************************************/ - -#ifndef WGL_ARB_pbuffer -DECLARE_HANDLE(HPBUFFERARB); -#endif -#ifndef WGL_EXT_pbuffer -DECLARE_HANDLE(HPBUFFEREXT); -#endif -#ifndef WGL_NV_present_video -DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); -#endif -#ifndef WGL_NV_video_output -DECLARE_HANDLE(HPVIDEODEV); -#endif -#ifndef WGL_NV_gpu_affinity -DECLARE_HANDLE(HPGPUNV); -DECLARE_HANDLE(HGPUNV); - -typedef struct _GPU_DEVICE { - DWORD cb; - CHAR DeviceName[32]; - CHAR DeviceString[128]; - DWORD Flags; - RECT rcVirtualScreen; -} GPU_DEVICE, *PGPU_DEVICE; -#endif -#ifndef WGL_NV_video_capture -DECLARE_HANDLE(HVIDEOINPUTDEVICENV); -#endif - -#ifndef WGL_ARB_buffer_region -#define WGL_ARB_buffer_region 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType); -extern VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion); -extern BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height); -extern BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType); -typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion); -typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height); -typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); -#endif - -#ifndef WGL_ARB_multisample -#define WGL_ARB_multisample 1 -#endif - -#ifndef WGL_ARB_extensions_string -#define WGL_ARB_extensions_string 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern const char * WINAPI wglGetExtensionsStringARB (HDC hdc); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); -#endif - -#ifndef WGL_ARB_pixel_format -#define WGL_ARB_pixel_format 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); -extern BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); -extern BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); -typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); -typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -#endif - -#ifndef WGL_ARB_make_current_read -#define WGL_ARB_make_current_read 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); -extern HDC WINAPI wglGetCurrentReadDCARB (void); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); -typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void); -#endif - -#ifndef WGL_ARB_pbuffer -#define WGL_ARB_pbuffer 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); -extern HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer); -extern int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC); -extern BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer); -extern BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); -typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer); -typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC); -typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer); -typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); -#endif - -#ifndef WGL_ARB_render_texture -#define WGL_ARB_render_texture 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); -extern BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); -extern BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); -typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); -typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList); -#endif - -#ifndef WGL_ARB_pixel_format_float -#define WGL_ARB_pixel_format_float 1 -#endif - -#ifndef WGL_ARB_framebuffer_sRGB -#define WGL_ARB_framebuffer_sRGB 1 -#endif - -#ifndef WGL_ARB_create_context -#define WGL_ARB_create_context 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList); -#endif - -#ifndef WGL_ARB_create_context_profile -#define WGL_ARB_create_context_profile 1 -#endif - -#ifndef WGL_ARB_create_context_robustness -#define WGL_ARB_create_context_robustness 1 -#endif - -#ifndef WGL_EXT_display_color_table -#define WGL_EXT_display_color_table 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id); -extern GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length); -extern GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id); -extern VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id); -typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length); -typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id); -typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id); -#endif - -#ifndef WGL_EXT_extensions_string -#define WGL_EXT_extensions_string 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern const char * WINAPI wglGetExtensionsStringEXT (void); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void); -#endif - -#ifndef WGL_EXT_make_current_read -#define WGL_EXT_make_current_read 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); -extern HDC WINAPI wglGetCurrentReadDCEXT (void); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); -typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void); -#endif - -#ifndef WGL_EXT_pbuffer -#define WGL_EXT_pbuffer 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); -extern HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer); -extern int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC); -extern BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer); -extern BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); -typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer); -typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC); -typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer); -typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); -#endif - -#ifndef WGL_EXT_pixel_format -#define WGL_EXT_pixel_format 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); -extern BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); -extern BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); -typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); -typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -#endif - -#ifndef WGL_EXT_swap_control -#define WGL_EXT_swap_control 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglSwapIntervalEXT (int interval); -extern int WINAPI wglGetSwapIntervalEXT (void); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); -typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void); -#endif - -#ifndef WGL_EXT_depth_float -#define WGL_EXT_depth_float 1 -#endif - -#ifndef WGL_NV_vertex_array_range -#define WGL_NV_vertex_array_range 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern void* WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); -extern void WINAPI wglFreeMemoryNV (void *pointer); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef void* (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); -typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer); -#endif - -#ifndef WGL_3DFX_multisample -#define WGL_3DFX_multisample 1 -#endif - -#ifndef WGL_EXT_multisample -#define WGL_EXT_multisample 1 -#endif - -#ifndef WGL_OML_sync_control -#define WGL_OML_sync_control 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); -extern BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator); -extern INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); -extern INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); -extern BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); -extern BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); -typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator); -typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); -typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); -typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); -typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); -#endif - -#ifndef WGL_I3D_digital_video_control -#define WGL_I3D_digital_video_control 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue); -extern BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); -typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); -#endif - -#ifndef WGL_I3D_gamma -#define WGL_I3D_gamma 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue); -extern BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue); -extern BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); -extern BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); -typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); -typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); -typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); -#endif - -#ifndef WGL_I3D_genlock -#define WGL_I3D_genlock 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglEnableGenlockI3D (HDC hDC); -extern BOOL WINAPI wglDisableGenlockI3D (HDC hDC); -extern BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag); -extern BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource); -extern BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource); -extern BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge); -extern BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge); -extern BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate); -extern BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate); -extern BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay); -extern BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay); -extern BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC); -typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC); -typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag); -typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource); -typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource); -typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge); -typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge); -typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate); -typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate); -typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay); -typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay); -typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); -#endif - -#ifndef WGL_I3D_image_buffer -#define WGL_I3D_image_buffer 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags); -extern BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress); -extern BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); -extern BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags); -typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress); -typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); -typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count); -#endif - -#ifndef WGL_I3D_swap_frame_lock -#define WGL_I3D_swap_frame_lock 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglEnableFrameLockI3D (void); -extern BOOL WINAPI wglDisableFrameLockI3D (void); -extern BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag); -extern BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void); -typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void); -typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag); -typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag); -#endif - -#ifndef WGL_I3D_swap_frame_usage -#define WGL_I3D_swap_frame_usage 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetFrameUsageI3D (float *pUsage); -extern BOOL WINAPI wglBeginFrameTrackingI3D (void); -extern BOOL WINAPI wglEndFrameTrackingI3D (void); -extern BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage); -typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void); -typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void); -typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); -#endif - -#ifndef WGL_ATI_pixel_format_float -#define WGL_ATI_pixel_format_float 1 -#endif - -#ifndef WGL_NV_float_buffer -#define WGL_NV_float_buffer 1 -#endif - -#ifndef WGL_3DL_stereo_control -#define WGL_3DL_stereo_control 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState); -#endif - -#ifndef WGL_EXT_pixel_format_packed_float -#define WGL_EXT_pixel_format_packed_float 1 -#endif - -#ifndef WGL_EXT_framebuffer_sRGB -#define WGL_EXT_framebuffer_sRGB 1 -#endif - -#ifndef WGL_NV_present_video -#define WGL_NV_present_video 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern int WINAPI wglEnumerateVideoDevicesNV (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); -extern BOOL WINAPI wglBindVideoDeviceNV (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); -extern BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); -typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); -typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue); -#endif - -#ifndef WGL_NV_video_output -#define WGL_NV_video_output 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); -extern BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice); -extern BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); -extern BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer); -extern BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); -extern BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); -typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice); -typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); -typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer); -typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); -typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); -#endif - -#ifndef WGL_NV_swap_group -#define WGL_NV_swap_group 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group); -extern BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier); -extern BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier); -extern BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); -extern BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count); -extern BOOL WINAPI wglResetFrameCountNV (HDC hDC); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group); -typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier); -typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier); -typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); -typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count); -typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC); -#endif - -#ifndef WGL_NV_gpu_affinity -#define WGL_NV_gpu_affinity 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu); -extern BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); -extern HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList); -extern BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); -extern BOOL WINAPI wglDeleteDCNV (HDC hdc); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu); -typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); -typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList); -typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); -typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc); -#endif - -#ifndef WGL_AMD_gpu_association -#define WGL_AMD_gpu_association 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids); -extern INT WINAPI wglGetGPUInfoAMD (UINT id, int property, GLenum dataType, UINT size, void *data); -extern UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc); -extern HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id); -extern HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList); -extern BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc); -extern BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc); -extern HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void); -extern VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids); -typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, int property, GLenum dataType, UINT size, void *data); -typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc); -typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id); -typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList); -typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc); -typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc); -typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void); -typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -#endif - -#ifndef WGL_NV_video_capture -#define WGL_NV_video_capture 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); -extern UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); -extern BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); -extern BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); -extern BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); -typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); -typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); -typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); -typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); -#endif - -#ifndef WGL_NV_copy_image -#define WGL_NV_copy_image 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); -#endif - -#ifndef WGL_NV_multisample_coverage -#define WGL_NV_multisample_coverage 1 -#endif - -#ifndef WGL_NV_DX_interop -#define WGL_NV_DX_interop 1 -#ifdef WGL_WGLEXT_PROTOTYPES -extern BOOL WINAPI wglDXSetResourceShareHandleNV (void *dxObject, HANDLE shareHandle); -extern HANDLE WINAPI wglDXOpenDeviceNV (void *dxDevice); -extern BOOL WINAPI wglDXCloseDeviceNV (HANDLE hDevice); -extern HANDLE WINAPI wglDXRegisterObjectNV (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access); -extern BOOL WINAPI wglDXUnregisterObjectNV (HANDLE hDevice, HANDLE hObject); -extern BOOL WINAPI wglDXObjectAccessNV (HANDLE hObject, GLenum access); -extern BOOL WINAPI wglDXLockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects); -extern BOOL WINAPI wglDXUnlockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects); -#endif /* WGL_WGLEXT_PROTOTYPES */ -typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void *dxObject, HANDLE shareHandle); -typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice); -typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice); -typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access); -typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject); -typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access); -typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects); -typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects); -#endif - -#ifndef WGL_NV_DX_interop2 -#define WGL_NV_DX_interop2 1 -#endif - -#ifndef WGL_EXT_swap_control_tear -#define WGL_EXT_swap_control_tear 1 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index ea844a904..9adee291f 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -54,139 +54,139 @@ class NAZARA_API NzOpenGL static void Uninitialize(); }; -NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; -NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader; -NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery; -NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; -NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer; -NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; -NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture; -NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; -NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc; -NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData; -NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; -NAZARA_API extern PFNGLCLEARPROC glClear; -NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor; -NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth; -NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil; -NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; -NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader; -NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; -NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; -NAZARA_API extern PFNGLCULLFACEPROC glCullFace; -NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; -NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; -NAZARA_API extern PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControl; -NAZARA_API extern PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsert; -NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallback; -NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; -NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; -NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; -NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; -NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; -NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader; -NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; -NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; -NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc; -NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask; -NAZARA_API extern PFNGLDISABLEPROC glDisable; -NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; -NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays; -NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; -NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; -NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements; -NAZARA_API extern PFNGLENDQUERYPROC glEndQuery; -NAZARA_API extern PFNGLFLUSHPROC glFlush; -NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; -NAZARA_API extern PFNGLENABLEPROC glEnable; -NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; -NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; -NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers; -NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; -NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries; -NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; -NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures; -NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; -NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; -NAZARA_API extern PFNGLGETDEBUGMESSAGELOGARBPROC glGetDebugMessageLog; -NAZARA_API extern PFNGLGETERRORPROC glGetError; -NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv; -NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; -NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; -NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv; -NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; -NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; -NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; -NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv; -NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; -NAZARA_API extern PFNGLGETSTRINGPROC glGetString; -NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi; -NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; -NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; -NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; -NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; -NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; -NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; -NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram; -NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer; -NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; -NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei; -NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode; -NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; -NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; -NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; -NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; -NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; -NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; -NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; -NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; -NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels; -NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; -NAZARA_API extern PFNGLSCISSORPROC glScissor; -NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource; -NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc; -NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp; -NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; -NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; -NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; -NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; -NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; -NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; -NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; -NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; -NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; -NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; -NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; -NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d; -NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f; -NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i; -NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv; -NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv; -NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv; -NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv; -NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv; -NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv; -NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; -NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; -NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; -NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram; -NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; -NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; -NAZARA_API extern PFNGLVIEWPORTPROC glViewport; +NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; +NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader; +NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery; +NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; +NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer; +NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; +NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture; +NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; +NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc; +NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData; +NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; +NAZARA_API extern PFNGLCLEARPROC glClear; +NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor; +NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth; +NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil; +NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; +NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader; +NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; +NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; +NAZARA_API extern PFNGLCULLFACEPROC glCullFace; +NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; +NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; +NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; +NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; +NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; +NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; +NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; +NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; +NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; +NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; +NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader; +NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; +NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; +NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc; +NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask; +NAZARA_API extern PFNGLDISABLEPROC glDisable; +NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; +NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays; +NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; +NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; +NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements; +NAZARA_API extern PFNGLENDQUERYPROC glEndQuery; +NAZARA_API extern PFNGLFLUSHPROC glFlush; +NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +NAZARA_API extern PFNGLENABLEPROC glEnable; +NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; +NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; +NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers; +NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries; +NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; +NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures; +NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; +NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; +NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; +NAZARA_API extern PFNGLGETERRORPROC glGetError; +NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv; +NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; +NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; +NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv; +NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; +NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; +NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; +NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv; +NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; +NAZARA_API extern PFNGLGETSTRINGPROC glGetString; +NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi; +NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; +NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; +NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; +NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; +NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; +NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; +NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram; +NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer; +NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei; +NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode; +NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; +NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; +NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; +NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; +NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; +NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; +NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; +NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; +NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels; +NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; +NAZARA_API extern PFNGLSCISSORPROC glScissor; +NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource; +NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc; +NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp; +NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; +NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; +NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; +NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; +NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; +NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; +NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; +NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; +NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; +NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; +NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; +NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d; +NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f; +NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i; +NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv; +NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv; +NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv; +NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv; +NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv; +NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv; +NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; +NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; +NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; +NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram; +NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; +NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; +NAZARA_API extern PFNGLVIEWPORTPROC glViewport; #if defined(NAZARA_PLATFORM_WINDOWS) -NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; -NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; -NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; -NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; -NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; +NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; +NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; +NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; +NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; +NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; #elif defined(NAZARA_PLATFORM_LINUX) -NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; -NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval; +NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; +NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval; #endif #endif // NAZARA_OPENGL_HPP diff --git a/include/Utfcpp/utf8.h b/include/Utfcpp/utf8.h deleted file mode 100644 index 82b13f59f..000000000 --- a/include/Utfcpp/utf8.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include "utf8/checked.h" -#include "utf8/unchecked.h" - -#endif // header guard diff --git a/include/Utfcpp/utf8/checked.h b/include/Utfcpp/utf8/checked.h deleted file mode 100644 index b6a5f9d84..000000000 --- a/include/Utfcpp/utf8/checked.h +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include "core.h" -#include - -namespace utf8 -{ - // Base for the exceptions that may be thrown from the library - class exception : public std::exception { - }; - - // Exceptions that may be thrown from the library functions. - class invalid_code_point : public exception { - uint32_t cp; - public: - invalid_code_point(uint32_t cp) : cp(cp) {} - virtual const char* what() const throw() { return "Invalid code point"; } - uint32_t code_point() const {return cp;} - }; - - class invalid_utf8 : public exception { - uint8_t u8; - public: - invalid_utf8 (uint8_t u) : u8(u) {} - virtual const char* what() const throw() { return "Invalid UTF-8"; } - uint8_t utf8_octet() const {return u8;} - }; - - class invalid_utf16 : public exception { - uint16_t u16; - public: - invalid_utf16 (uint16_t u) : u16(u) {} - virtual const char* what() const throw() { return "Invalid UTF-16"; } - uint16_t utf16_word() const {return u16;} - }; - - class not_enough_room : public exception { - public: - virtual const char* what() const throw() { return "Not enough space"; } - }; - - /// The library API - functions intended to be called by the users - - template - output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement) - { - while (start != end) { - octet_iterator sequence_start = start; - internal::utf_error err_code = internal::validate_next(start, end); - switch (err_code) { - case internal::UTF8_OK : - for (octet_iterator it = sequence_start; it != start; ++it) - *out++ = *it; - break; - case internal::NOT_ENOUGH_ROOM: - throw not_enough_room(); - case internal::INVALID_LEAD: - append (replacement, out); - ++start; - break; - case internal::INCOMPLETE_SEQUENCE: - case internal::OVERLONG_SEQUENCE: - case internal::INVALID_CODE_POINT: - append (replacement, out); - ++start; - // just one replacement mark for the sequence - while (internal::is_trail(*start) && start != end) - ++start; - break; - } - } - return out; - } - - template - inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out) - { - static const uint32_t replacement_marker = internal::mask16(0xfffd); - return replace_invalid(start, end, out, replacement_marker); - } - - template - octet_iterator append(uint32_t cp, octet_iterator result) - { - if (!internal::is_code_point_valid(cp)) - throw invalid_code_point(cp); - - if (cp < 0x80) // one octet - *(result++) = static_cast(cp); - else if (cp < 0x800) { // two octets - *(result++) = static_cast((cp >> 6) | 0xc0); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else if (cp < 0x10000) { // three octets - *(result++) = static_cast((cp >> 12) | 0xe0); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else { // four octets - *(result++) = static_cast((cp >> 18) | 0xf0); - *(result++) = static_cast(((cp >> 12) & 0x3f) | 0x80); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - return result; - } - - template - uint32_t next(octet_iterator& it, octet_iterator end) - { - uint32_t cp = 0; - internal::utf_error err_code = internal::validate_next(it, end, &cp); - switch (err_code) { - case internal::UTF8_OK : - break; - case internal::NOT_ENOUGH_ROOM : - throw not_enough_room(); - case internal::INVALID_LEAD : - case internal::INCOMPLETE_SEQUENCE : - case internal::OVERLONG_SEQUENCE : - throw invalid_utf8(*it); - case internal::INVALID_CODE_POINT : - throw invalid_code_point(cp); - } - return cp; - } - - template - uint32_t peek_next(octet_iterator it, octet_iterator end) - { - return next(it, end); - } - - template - uint32_t prior(octet_iterator& it, octet_iterator start) - { - // can't do much if it == start - if (it == start) - throw not_enough_room(); - - octet_iterator end = it; - // Go back until we hit either a lead octet or start - while (internal::is_trail(*(--it))) - if (it == start) - throw invalid_utf8(*it); // error - no lead byte in the sequence - return peek_next(it, end); - } - - /// Deprecated in versions that include "prior" - template - uint32_t previous(octet_iterator& it, octet_iterator pass_start) - { - octet_iterator end = it; - while (internal::is_trail(*(--it))) - if (it == pass_start) - throw invalid_utf8(*it); // error - no lead byte in the sequence - octet_iterator temp = it; - return next(temp, end); - } - - template - void advance (octet_iterator& it, distance_type n, octet_iterator end) - { - for (distance_type i = 0; i < n; ++i) - next(it, end); - } - - template - typename std::iterator_traits::difference_type - distance (octet_iterator first, octet_iterator last) - { - typename std::iterator_traits::difference_type dist; - for (dist = 0; first < last; ++dist) - next(first, last); - return dist; - } - - template - octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) - { - while (start != end) { - uint32_t cp = internal::mask16(*start++); - // Take care of surrogate pairs first - if (internal::is_lead_surrogate(cp)) { - if (start != end) { - uint32_t trail_surrogate = internal::mask16(*start++); - if (internal::is_trail_surrogate(trail_surrogate)) - cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; - else - throw invalid_utf16(static_cast(trail_surrogate)); - } - else - throw invalid_utf16(static_cast(cp)); - - } - // Lone trail surrogate - else if (internal::is_trail_surrogate(cp)) - throw invalid_utf16(static_cast(cp)); - - result = append(cp, result); - } - return result; - } - - template - u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) - { - while (start != end) { - uint32_t cp = next(start, end); - if (cp > 0xffff) { //make a surrogate pair - *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); - *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); - } - else - *result++ = static_cast(cp); - } - return result; - } - - template - octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) - { - while (start != end) - result = append(*(start++), result); - - return result; - } - - template - u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) - { - while (start != end) - (*result++) = next(start, end); - - return result; - } - - // The iterator class - template - class iterator : public std::iterator { - octet_iterator it; - octet_iterator range_start; - octet_iterator range_end; - public: - iterator () {}; - explicit iterator (const octet_iterator& octet_it, - const octet_iterator& range_start, - const octet_iterator& range_end) : - it(octet_it), range_start(range_start), range_end(range_end) - { - if (it < range_start || it > range_end) - throw std::out_of_range("Invalid utf-8 iterator position"); - } - // the default "big three" are OK - octet_iterator base () const { return it; } - uint32_t operator * () const - { - octet_iterator temp = it; - return next(temp, range_end); - } - bool operator == (const iterator& rhs) const - { - if (range_start != rhs.range_start || range_end != rhs.range_end) - throw std::logic_error("Comparing utf-8 iterators defined with different ranges"); - return (it == rhs.it); - } - bool operator != (const iterator& rhs) const - { - return !(operator == (rhs)); - } - iterator& operator ++ () - { - next(it, range_end); - return *this; - } - iterator operator ++ (int) - { - iterator temp = *this; - next(it, range_end); - return temp; - } - iterator& operator -- () - { - prior(it, range_start); - return *this; - } - iterator operator -- (int) - { - iterator temp = *this; - prior(it, range_start); - return temp; - } - }; // class iterator - -} // namespace utf8 - -#endif //header guard - - diff --git a/include/Utfcpp/utf8/core.h b/include/Utfcpp/utf8/core.h deleted file mode 100644 index f58529e53..000000000 --- a/include/Utfcpp/utf8/core.h +++ /dev/null @@ -1,351 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include - -namespace utf8 -{ -// Helper code - not intended to be directly called by the library users. May be changed at any time -namespace internal -{ - // Unicode constants - // Leading (high) surrogates: 0xd800 - 0xdbff - // Trailing (low) surrogates: 0xdc00 - 0xdfff - const uint16_t LEAD_SURROGATE_MIN = 0xd800u; - const uint16_t LEAD_SURROGATE_MAX = 0xdbffu; - const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u; - const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu; - const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10); - const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN; - - // Maximum valid value for a Unicode code point - const uint32_t CODE_POINT_MAX = 0x0010ffffu; - - template - inline uint8_t mask8(octet_type oc) - { - return static_cast(0xff & oc); - } - template - inline uint16_t mask16(u16_type oc) - { - return static_cast(0xffff & oc); - } - template - inline bool is_trail(octet_type oc) - { - return ((mask8(oc) >> 6) == 0x2); - } - - template - inline bool is_lead_surrogate(u16 cp) - { - return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX); - } - - template - inline bool is_trail_surrogate(u16 cp) - { - return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); - } - - template - inline bool is_surrogate(u16 cp) - { - return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); - } - - template - inline bool is_code_point_valid(u32 cp) - { - return (cp <= CODE_POINT_MAX && !is_surrogate(cp)); - } - - template - inline typename std::iterator_traits::difference_type - sequence_length(octet_iterator lead_it) - { - uint8_t lead = mask8(*lead_it); - if (lead < 0x80) - return 1; - else if ((lead >> 5) == 0x6) - return 2; - else if ((lead >> 4) == 0xe) - return 3; - else if ((lead >> 3) == 0x1e) - return 4; - else - return 0; - } - - template - inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length) - { - if (cp < 0x80) { - if (length != 1) - return true; - } - else if (cp < 0x800) { - if (length != 2) - return true; - } - else if (cp < 0x10000) { - if (length != 3) - return true; - } - - return false; - } - - enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT}; - - /// get_sequence_x functions decode utf-8 sequences of the length x - - template - utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t* code_point) - { - if (it != end) { - if (code_point) - *code_point = mask8(*it); - return UTF8_OK; - } - return NOT_ENOUGH_ROOM; - } - - template - utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t* code_point) - { - utf_error ret_code = NOT_ENOUGH_ROOM; - - if (it != end) { - uint32_t cp = mask8(*it); - if (++it != end) { - if (is_trail(*it)) { - cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f); - - if (code_point) - *code_point = cp; - ret_code = UTF8_OK; - } - else - ret_code = INCOMPLETE_SEQUENCE; - } - else - ret_code = NOT_ENOUGH_ROOM; - } - - return ret_code; - } - - template - utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t* code_point) - { - utf_error ret_code = NOT_ENOUGH_ROOM; - - if (it != end) { - uint32_t cp = mask8(*it); - if (++it != end) { - if (is_trail(*it)) { - cp = ((cp << 12) & 0xffff) + ((mask8(*it) << 6) & 0xfff); - if (++it != end) { - if (is_trail(*it)) { - cp += (*it) & 0x3f; - - if (code_point) - *code_point = cp; - ret_code = UTF8_OK; - } - else - ret_code = INCOMPLETE_SEQUENCE; - } - else - ret_code = NOT_ENOUGH_ROOM; - } - else - ret_code = INCOMPLETE_SEQUENCE; - } - else - ret_code = NOT_ENOUGH_ROOM; - } - - return ret_code; - } - - template - utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t* code_point) - { - utf_error ret_code = NOT_ENOUGH_ROOM; - - if (it != end) { - uint32_t cp = mask8(*it); - if (++it != end) { - if (is_trail(*it)) { - cp = ((cp << 18) & 0x1fffff) + ((mask8(*it) << 12) & 0x3ffff); - if (++it != end) { - if (is_trail(*it)) { - cp += (mask8(*it) << 6) & 0xfff; - if (++it != end) { - if (is_trail(*it)) { - cp += (*it) & 0x3f; - - if (code_point) - *code_point = cp; - ret_code = UTF8_OK; - } - else - ret_code = INCOMPLETE_SEQUENCE; - } - else - ret_code = NOT_ENOUGH_ROOM; - } - else - ret_code = INCOMPLETE_SEQUENCE; - } - else - ret_code = NOT_ENOUGH_ROOM; - } - else - ret_code = INCOMPLETE_SEQUENCE; - } - else - ret_code = NOT_ENOUGH_ROOM; - } - - return ret_code; - } - - template - utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t* code_point) - { - // Save the original value of it so we can go back in case of failure - // Of course, it does not make much sense with i.e. stream iterators - octet_iterator original_it = it; - - uint32_t cp = 0; - // Determine the sequence length based on the lead octet - typedef typename std::iterator_traits::difference_type octet_difference_type; - octet_difference_type length = sequence_length(it); - if (length == 0) - return INVALID_LEAD; - - // Now that we have a valid sequence length, get trail octets and calculate the code point - utf_error err = UTF8_OK; - switch (length) { - case 1: - err = get_sequence_1(it, end, &cp); - break; - case 2: - err = get_sequence_2(it, end, &cp); - break; - case 3: - err = get_sequence_3(it, end, &cp); - break; - case 4: - err = get_sequence_4(it, end, &cp); - break; - } - - if (err == UTF8_OK) { - // Decoding succeeded. Now, security checks... - if (is_code_point_valid(cp)) { - if (!is_overlong_sequence(cp, length)){ - // Passed! Return here. - if (code_point) - *code_point = cp; - ++it; - return UTF8_OK; - } - else - err = OVERLONG_SEQUENCE; - } - else - err = INVALID_CODE_POINT; - } - - // Failure branch - restore the original value of the iterator - it = original_it; - return err; - } - - template - inline utf_error validate_next(octet_iterator& it, octet_iterator end) { - return validate_next(it, end, 0); - } - -} // namespace internal - - /// The library API - functions intended to be called by the users - - // Byte order mark - const uint8_t bom[] = {0xef, 0xbb, 0xbf}; - - template - octet_iterator find_invalid(octet_iterator start, octet_iterator end) - { - octet_iterator result = start; - while (result != end) { - internal::utf_error err_code = internal::validate_next(result, end); - if (err_code != internal::UTF8_OK) - return result; - } - return result; - } - - template - inline bool is_valid(octet_iterator start, octet_iterator end) - { - return (find_invalid(start, end) == end); - } - - template - inline bool starts_with_bom (octet_iterator it, octet_iterator end) - { - return ( - ((it != end) && (internal::mask8(*it++)) == bom[0]) && - ((it != end) && (internal::mask8(*it++)) == bom[1]) && - ((it != end) && (internal::mask8(*it)) == bom[2]) - ); - } - - //Deprecated in release 2.3 - template - inline bool is_bom (octet_iterator it) - { - return ( - (internal::mask8(*it++)) == bom[0] && - (internal::mask8(*it++)) == bom[1] && - (internal::mask8(*it)) == bom[2] - ); - } -} // namespace utf8 - -#endif // header guard - - diff --git a/include/Utfcpp/utf8/unchecked.h b/include/Utfcpp/utf8/unchecked.h deleted file mode 100644 index 2f3eb4d1d..000000000 --- a/include/Utfcpp/utf8/unchecked.h +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include "core.h" - -namespace utf8 -{ - namespace unchecked - { - template - octet_iterator append(uint32_t cp, octet_iterator result) - { - if (cp < 0x80) // one octet - *(result++) = static_cast(cp); - else if (cp < 0x800) { // two octets - *(result++) = static_cast((cp >> 6) | 0xc0); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else if (cp < 0x10000) { // three octets - *(result++) = static_cast((cp >> 12) | 0xe0); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else { // four octets - *(result++) = static_cast((cp >> 18) | 0xf0); - *(result++) = static_cast(((cp >> 12) & 0x3f)| 0x80); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - return result; - } - - template - uint32_t next(octet_iterator& it) - { - uint32_t cp = internal::mask8(*it); - typename std::iterator_traits::difference_type length = utf8::internal::sequence_length(it); - switch (length) { - case 1: - break; - case 2: - it++; - cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f); - break; - case 3: - ++it; - cp = ((cp << 12) & 0xffff) + ((internal::mask8(*it) << 6) & 0xfff); - ++it; - cp += (*it) & 0x3f; - break; - case 4: - ++it; - cp = ((cp << 18) & 0x1fffff) + ((internal::mask8(*it) << 12) & 0x3ffff); - ++it; - cp += (internal::mask8(*it) << 6) & 0xfff; - ++it; - cp += (*it) & 0x3f; - break; - } - ++it; - return cp; - } - - template - uint32_t peek_next(octet_iterator it) - { - return next(it); - } - - template - uint32_t prior(octet_iterator& it) - { - while (internal::is_trail(*(--it))) ; - octet_iterator temp = it; - return next(temp); - } - - // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous) - template - inline uint32_t previous(octet_iterator& it) - { - return prior(it); - } - - template - void advance (octet_iterator& it, distance_type n) - { - for (distance_type i = 0; i < n; ++i) - next(it); - } - - template - typename std::iterator_traits::difference_type - distance (octet_iterator first, octet_iterator last) - { - typename std::iterator_traits::difference_type dist; - for (dist = 0; first < last; ++dist) - next(first); - return dist; - } - - template - octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) - { - while (start != end) { - uint32_t cp = internal::mask16(*start++); - // Take care of surrogate pairs first - if (internal::is_lead_surrogate(cp)) { - uint32_t trail_surrogate = internal::mask16(*start++); - cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; - } - result = append(cp, result); - } - return result; - } - - template - u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) - { - while (start < end) { - uint32_t cp = next(start); - if (cp > 0xffff) { //make a surrogate pair - *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); - *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); - } - else - *result++ = static_cast(cp); - } - return result; - } - - template - octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) - { - while (start != end) - result = append(*(start++), result); - - return result; - } - - template - u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) - { - while (start < end) - (*result++) = next(start); - - return result; - } - - // The iterator class - template - class iterator : public std::iterator { - octet_iterator it; - public: - iterator () {}; - explicit iterator (const octet_iterator& octet_it): it(octet_it) {} - // the default "big three" are OK - octet_iterator base () const { return it; } - uint32_t operator * () const - { - octet_iterator temp = it; - return next(temp); - } - bool operator == (const iterator& rhs) const - { - return (it == rhs.it); - } - bool operator != (const iterator& rhs) const - { - return !(operator == (rhs)); - } - iterator& operator ++ () - { - std::advance(it, internal::sequence_length(it)); - return *this; - } - iterator operator ++ (int) - { - iterator temp = *this; - std::advance(it, internal::sequence_length(it)); - return temp; - } - iterator& operator -- () - { - prior(it); - return *this; - } - iterator operator -- (int) - { - iterator temp = *this; - prior(it); - return temp; - } - }; // class iterator - - } // namespace utf8::unchecked -} // namespace utf8 - - -#endif // header guard - diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 89545800d..a8dfda1ea 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -350,7 +350,24 @@ bool NzOpenGL::Initialize() openGLextensions[NzOpenGL::AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic"); // DebugOutput - if (IsSupported("GL_ARB_debug_output")) + if (openGLversion >= 430 || IsSupported("GL_KHR_debug")) + { + try + { + glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); + glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); + glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); + + openGLextensions[NzOpenGL::DebugOutput] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load GL_KHR_debug: " + NzString(e.what())); + } + } + + if (!openGLextensions[NzOpenGL::DebugOutput] && IsSupported("GL_ARB_debug_output")) { try { @@ -550,137 +567,137 @@ void NzOpenGL::Uninitialize() UnloadLibrary(); } -PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; -PFNGLATTACHSHADERPROC glAttachShader = nullptr; -PFNGLBEGINQUERYPROC glBeginQuery = nullptr; -PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; -PFNGLBINDBUFFERPROC glBindBuffer = nullptr; -PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; -PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; -PFNGLBINDTEXTUREPROC glBindTexture = nullptr; -PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; -PFNGLBLENDFUNCPROC glBlendFunc = nullptr; -PFNGLBUFFERDATAPROC glBufferData = nullptr; -PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; -PFNGLCLEARPROC glClear = nullptr; -PFNGLCLEARCOLORPROC glClearColor = nullptr; -PFNGLCLEARDEPTHPROC glClearDepth = nullptr; -PFNGLCLEARSTENCILPROC glClearStencil = nullptr; -PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; -PFNGLCREATESHADERPROC glCreateShader = nullptr; -PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; -PFNGLCOLORMASKPROC glColorMask = nullptr; -PFNGLCULLFACEPROC glCullFace = nullptr; -PFNGLCOMPILESHADERPROC glCompileShader = nullptr; -PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; -PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControl = nullptr; -PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsert = nullptr; -PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallback = nullptr; -PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; -PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; -PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; -PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; -PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; -PFNGLDELETESHADERPROC glDeleteShader = nullptr; -PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; -PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; -PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; -PFNGLDEPTHMASKPROC glDepthMask = nullptr; -PFNGLDISABLEPROC glDisable = nullptr; +PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; +PFNGLATTACHSHADERPROC glAttachShader = nullptr; +PFNGLBEGINQUERYPROC glBeginQuery = nullptr; +PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; +PFNGLBINDBUFFERPROC glBindBuffer = nullptr; +PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; +PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; +PFNGLBINDTEXTUREPROC glBindTexture = nullptr; +PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; +PFNGLBLENDFUNCPROC glBlendFunc = nullptr; +PFNGLBUFFERDATAPROC glBufferData = nullptr; +PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; +PFNGLCLEARPROC glClear = nullptr; +PFNGLCLEARCOLORPROC glClearColor = nullptr; +PFNGLCLEARDEPTHPROC glClearDepth = nullptr; +PFNGLCLEARSTENCILPROC glClearStencil = nullptr; +PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; +PFNGLCREATESHADERPROC glCreateShader = nullptr; +PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; +PFNGLCOLORMASKPROC glColorMask = nullptr; +PFNGLCULLFACEPROC glCullFace = nullptr; +PFNGLCOMPILESHADERPROC glCompileShader = nullptr; +PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; +PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; +PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; +PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; +PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; +PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; +PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; +PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; +PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; +PFNGLDELETESHADERPROC glDeleteShader = nullptr; +PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; +PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; +PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; +PFNGLDEPTHMASKPROC glDepthMask = nullptr; +PFNGLDISABLEPROC glDisable = nullptr; PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; -PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; -PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; -PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; -PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; -PFNGLENDQUERYPROC glEndQuery = nullptr; -PFNGLFLUSHPROC glFlush = nullptr; -PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; -PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; -PFNGLENABLEPROC glEnable = nullptr; -PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; -PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; -PFNGLGENBUFFERSPROC glGenBuffers = nullptr; -PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; -PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; -PFNGLGENQUERIESPROC glGenQueries = nullptr; -PFNGLGENTEXTURESPROC glGenTextures = nullptr; -PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; -PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; -PFNGLGETDEBUGMESSAGELOGARBPROC glGetDebugMessageLog = nullptr; -PFNGLGETERRORPROC glGetError = nullptr; -PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; -PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; -PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; -PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; -PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; -PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; -PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; -PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; -PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; -PFNGLGETSTRINGPROC glGetString = nullptr; -PFNGLGETSTRINGIPROC glGetStringi = nullptr; -PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; -PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; -PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; -PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; -PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; -PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; -PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; -PFNGLMAPBUFFERPROC glMapBuffer = nullptr; -PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; -PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; -PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; -PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; -PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; -PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; -PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; -PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; -PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; -PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; -PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; -PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; -PFNGLREADPIXELSPROC glReadPixels = nullptr; -PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; -PFNGLSCISSORPROC glScissor = nullptr; -PFNGLSHADERSOURCEPROC glShaderSource = nullptr; -PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; -PFNGLSTENCILOPPROC glStencilOp = nullptr; -PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; -PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; -PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; -PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; -PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; -PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; -PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; -PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; -PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; -PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; -PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; -PFNGLUNIFORM1DPROC glUniform1d = nullptr; -PFNGLUNIFORM1FPROC glUniform1f = nullptr; -PFNGLUNIFORM1IPROC glUniform1i = nullptr; -PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; -PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; -PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; -PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; -PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; -PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; -PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; -PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; -PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; -PFNGLUSEPROGRAMPROC glUseProgram = nullptr; -PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; -PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; -PFNGLVIEWPORTPROC glViewport = nullptr; +PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; +PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; +PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; +PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; +PFNGLENDQUERYPROC glEndQuery = nullptr; +PFNGLFLUSHPROC glFlush = nullptr; +PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; +PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; +PFNGLENABLEPROC glEnable = nullptr; +PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; +PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; +PFNGLGENBUFFERSPROC glGenBuffers = nullptr; +PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; +PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; +PFNGLGENQUERIESPROC glGenQueries = nullptr; +PFNGLGENTEXTURESPROC glGenTextures = nullptr; +PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; +PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; +PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; +PFNGLGETERRORPROC glGetError = nullptr; +PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; +PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; +PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; +PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; +PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; +PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; +PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; +PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; +PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; +PFNGLGETSTRINGPROC glGetString = nullptr; +PFNGLGETSTRINGIPROC glGetStringi = nullptr; +PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; +PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; +PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; +PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; +PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; +PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; +PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; +PFNGLMAPBUFFERPROC glMapBuffer = nullptr; +PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; +PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; +PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; +PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; +PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; +PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; +PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; +PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; +PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; +PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; +PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; +PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; +PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; +PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; +PFNGLREADPIXELSPROC glReadPixels = nullptr; +PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; +PFNGLSCISSORPROC glScissor = nullptr; +PFNGLSHADERSOURCEPROC glShaderSource = nullptr; +PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; +PFNGLSTENCILOPPROC glStencilOp = nullptr; +PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; +PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; +PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; +PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; +PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; +PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; +PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; +PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; +PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; +PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; +PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; +PFNGLUNIFORM1DPROC glUniform1d = nullptr; +PFNGLUNIFORM1FPROC glUniform1f = nullptr; +PFNGLUNIFORM1IPROC glUniform1i = nullptr; +PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; +PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; +PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; +PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; +PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; +PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; +PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; +PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; +PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; +PFNGLUSEPROGRAMPROC glUseProgram = nullptr; +PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; +PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; +PFNGLVIEWPORTPROC glViewport = nullptr; #if defined(NAZARA_PLATFORM_WINDOWS) -PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; -PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; -PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; -PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; -PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; +PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; +PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; +PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; +PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; +PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; #elif defined(NAZARA_PLATFORM_LINUX) -PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; -PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = nullptr; +PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; +PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = nullptr; #endif diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index d4a7e6ce3..a44420423 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -17,7 +17,7 @@ m_parent(parent) #ifdef NAZARA_DEBUG if (!m_parent) { - NazaraError("Parent mesh is null"); + NazaraError("Parent mesh must be valid"); throw std::invalid_argument("Parent mesh must be valid"); } #endif @@ -30,7 +30,7 @@ void NzSubMesh::Animate(unsigned int frameA, unsigned int frameB, float interpol #if NAZARA_UTILITY_SAFE if (!m_parent->HasAnimation()) { - NazaraError("SubMesh is not animated"); + NazaraError("SubMesh has no animation"); return; } From 5619ddb0b1ab1c7eaa371b82a37dfde485c33428 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 10 Aug 2012 03:21:37 +0200 Subject: [PATCH 04/31] Changed all the files encoding to UTF-8 Named modules in licence informations --- .../include/Nazara/ModuleName/ClassName.hpp | 2 +- .../include/Nazara/ModuleName/Config.hpp | 8 +- .../include/Nazara/ModuleName/Debug.hpp | 2 +- .../include/Nazara/ModuleName/DebugOff.hpp | 2 +- .../include/Nazara/ModuleName/ModuleName.hpp | 2 +- .../src/Nazara/ModuleName/ClassName.cpp | 2 +- .../src/Nazara/ModuleName/Debug/Leaks.cpp | 2 +- .../src/Nazara/ModuleName/ModuleName.cpp | 12 +-- include/Nazara/Core.hpp | 2 +- include/Nazara/Core/ByteArray.hpp | 8 +- include/Nazara/Core/Clock.hpp | 4 +- include/Nazara/Core/Color.hpp | 4 +- include/Nazara/Core/Color.inl | 6 +- include/Nazara/Core/ConditionVariable.hpp | 4 +- include/Nazara/Core/Config.hpp | 2 +- include/Nazara/Core/Core.hpp | 4 +- include/Nazara/Core/Debug.hpp | 4 +- .../Nazara/Core/Debug/MemoryLeakTracker.hpp | 4 +- include/Nazara/Core/DebugOff.hpp | 4 +- include/Nazara/Core/Directory.hpp | 4 +- include/Nazara/Core/DynLib.hpp | 6 +- include/Nazara/Core/Endianness.hpp | 6 +- include/Nazara/Core/Endianness.inl | 4 +- include/Nazara/Core/Enums.hpp | 4 +- include/Nazara/Core/Error.hpp | 4 +- include/Nazara/Core/File.hpp | 16 ++-- include/Nazara/Core/Format.hpp | 4 +- include/Nazara/Core/Functor.hpp | 6 +- include/Nazara/Core/Functor.inl | 4 +- include/Nazara/Core/Hash.hpp | 4 +- include/Nazara/Core/Hash/CRC32.hpp | 4 +- include/Nazara/Core/Hash/Fletcher16.hpp | 2 +- include/Nazara/Core/Hash/MD5.hpp | 2 +- include/Nazara/Core/Hash/SHA224.hpp | 2 +- include/Nazara/Core/Hash/SHA256.hpp | 2 +- include/Nazara/Core/Hash/SHA384.hpp | 2 +- include/Nazara/Core/Hash/SHA512.hpp | 2 +- include/Nazara/Core/Hash/Whirlpool.hpp | 2 +- include/Nazara/Core/HashDigest.hpp | 4 +- include/Nazara/Core/HashImpl.hpp | 4 +- include/Nazara/Core/Hashable.hpp | 2 +- include/Nazara/Core/Initializer.hpp | 4 +- include/Nazara/Core/Initializer.inl | 4 +- include/Nazara/Core/InputStream.hpp | 4 +- include/Nazara/Core/LockGuard.hpp | 4 +- include/Nazara/Core/Log.hpp | 4 +- include/Nazara/Core/MemoryStream.hpp | 4 +- include/Nazara/Core/Mutex.hpp | 4 +- include/Nazara/Core/NonCopyable.hpp | 4 +- include/Nazara/Core/Resource.hpp | 6 +- include/Nazara/Core/Semaphore.hpp | 4 +- include/Nazara/Core/String.hpp | 18 ++--- include/Nazara/Core/StringStream.hpp | 4 +- include/Nazara/Core/Thread.hpp | 6 +- include/Nazara/Core/Thread.inl | 4 +- include/Nazara/Core/ThreadSafety.hpp | 6 +- include/Nazara/Core/ThreadSafetyOff.hpp | 6 +- include/Nazara/Core/Tuple.hpp | 4 +- include/Nazara/Core/Tuple.inl | 8 +- include/Nazara/Core/Unicode.hpp | 12 +-- include/Nazara/Debug.hpp | 4 +- include/Nazara/DebugOff.hpp | 4 +- include/Nazara/Math.hpp | 7 +- include/Nazara/Math/Basic.hpp | 4 +- include/Nazara/Math/Basic.inl | 14 ++-- include/Nazara/Math/Config.hpp | 20 ++--- include/Nazara/Math/Cube.hpp | 4 +- include/Nazara/Math/Cube.inl | 4 +- include/Nazara/Math/EulerAngles.hpp | 5 +- include/Nazara/Math/EulerAngles.inl | 4 +- include/Nazara/Math/Math.hpp | 23 ------ include/Nazara/Math/Matrix4.hpp | 4 +- include/Nazara/Math/Matrix4.inl | 8 +- include/Nazara/Math/Quaternion.hpp | 5 +- include/Nazara/Math/Quaternion.inl | 11 ++- include/Nazara/Math/Rect.hpp | 4 +- include/Nazara/Math/Rect.inl | 4 +- include/Nazara/Math/Vector2.hpp | 4 +- include/Nazara/Math/Vector2.inl | 4 +- include/Nazara/Math/Vector3.hpp | 4 +- include/Nazara/Math/Vector3.inl | 4 +- include/Nazara/Math/Vector4.hpp | 4 +- include/Nazara/Math/Vector4.inl | 6 +- include/Nazara/Noise.hpp | 4 +- include/Nazara/Noise/ComplexNoiseBase.hpp | 4 +- include/Nazara/Noise/Config.hpp | 10 +-- include/Nazara/Noise/Debug.hpp | 4 +- include/Nazara/Noise/DebugOff.hpp | 4 +- include/Nazara/Noise/Noise.hpp | 4 +- include/Nazara/Noise/NoiseBase.hpp | 4 +- include/Nazara/Noise/NoiseMachine.hpp | 4 +- include/Nazara/Noise/Perlin2D.hpp | 4 +- include/Nazara/Noise/Perlin2D.inl | 4 +- include/Nazara/Noise/Perlin3D.hpp | 4 +- include/Nazara/Noise/Perlin3D.inl | 4 +- include/Nazara/Noise/Perlin4D.hpp | 4 +- include/Nazara/Noise/Perlin4D.inl | 4 +- include/Nazara/Noise/Simplex2D.hpp | 4 +- include/Nazara/Noise/Simplex2D.inl | 4 +- include/Nazara/Noise/Simplex3D.hpp | 4 +- include/Nazara/Noise/Simplex3D.inl | 4 +- include/Nazara/Noise/Simplex4D.hpp | 4 +- include/Nazara/Noise/Simplex4D.inl | 4 +- include/Nazara/Prerequesites.hpp | 32 ++++++-- include/Nazara/Renderer.hpp | 4 +- include/Nazara/Renderer/Config.hpp | 14 ++-- include/Nazara/Renderer/Context.hpp | 4 +- include/Nazara/Renderer/ContextParameters.hpp | 4 +- include/Nazara/Renderer/Debug.hpp | 4 +- include/Nazara/Renderer/DebugOff.hpp | 4 +- include/Nazara/Renderer/Enums.hpp | 4 +- include/Nazara/Renderer/OcclusionQuery.hpp | 4 +- include/Nazara/Renderer/OpenGL.hpp | 6 +- include/Nazara/Renderer/RenderTarget.hpp | 4 +- .../Renderer/RenderTargetParameters.hpp | 4 +- include/Nazara/Renderer/RenderWindow.hpp | 6 +- include/Nazara/Renderer/Renderer.hpp | 4 +- include/Nazara/Renderer/Shader.hpp | 4 +- include/Nazara/Renderer/Texture.hpp | 4 +- include/Nazara/Utility.hpp | 4 +- include/Nazara/Utility/Animation.hpp | 4 +- include/Nazara/Utility/AxisAlignedBox.hpp | 6 +- include/Nazara/Utility/Buffer.hpp | 4 +- include/Nazara/Utility/BufferImpl.hpp | 4 +- include/Nazara/Utility/Config.hpp | 20 ++--- include/Nazara/Utility/Cursor.hpp | 4 +- include/Nazara/Utility/Debug.hpp | 4 +- include/Nazara/Utility/DebugOff.hpp | 4 +- include/Nazara/Utility/Enums.hpp | 6 +- include/Nazara/Utility/Event.hpp | 34 ++++---- include/Nazara/Utility/Icon.hpp | 4 +- include/Nazara/Utility/Image.hpp | 4 +- include/Nazara/Utility/IndexBuffer.hpp | 4 +- include/Nazara/Utility/Keyboard.hpp | 16 ++-- include/Nazara/Utility/KeyframeMesh.hpp | 4 +- include/Nazara/Utility/Mesh.hpp | 4 +- include/Nazara/Utility/Mouse.hpp | 6 +- include/Nazara/Utility/PixelFormat.hpp | 4 +- include/Nazara/Utility/PixelFormat.inl | 6 +- include/Nazara/Utility/ResourceLoader.hpp | 4 +- include/Nazara/Utility/ResourceLoader.inl | 14 ++-- include/Nazara/Utility/StaticMesh.hpp | 4 +- include/Nazara/Utility/SubMesh.hpp | 4 +- include/Nazara/Utility/Utility.hpp | 4 +- include/Nazara/Utility/VertexBuffer.hpp | 4 +- include/Nazara/Utility/VertexDeclaration.hpp | 4 +- include/Nazara/Utility/VideoMode.hpp | 6 +- include/Nazara/Utility/Window.hpp | 6 +- include/Nazara/Utility/WindowHandle.hpp | 4 +- src/Nazara/Core/ByteArray.cpp | 13 ++- src/Nazara/Core/Clock.cpp | 4 +- src/Nazara/Core/Color.cpp | 4 +- src/Nazara/Core/ConditionVariable.cpp | 4 +- src/Nazara/Core/Core.cpp | 12 +-- src/Nazara/Core/Debug/Leaks.cpp | 4 +- src/Nazara/Core/Debug/MemoryLeakTracker.cpp | 2 +- src/Nazara/Core/Directory.cpp | 12 +-- src/Nazara/Core/DynLib.cpp | 4 +- src/Nazara/Core/Error.cpp | 6 +- src/Nazara/Core/File.cpp | 18 ++--- src/Nazara/Core/Hash.cpp | 4 +- src/Nazara/Core/Hash/CRC32.cpp | 6 +- src/Nazara/Core/Hash/Fletcher16.cpp | 4 +- src/Nazara/Core/Hash/MD5.cpp | 4 +- src/Nazara/Core/Hash/SHA/Internal.cpp | 4 +- src/Nazara/Core/Hash/SHA/Internal.hpp | 4 +- src/Nazara/Core/Hash/SHA1.cpp | 4 +- src/Nazara/Core/Hash/SHA224.cpp | 4 +- src/Nazara/Core/Hash/SHA256.cpp | 4 +- src/Nazara/Core/Hash/SHA384.cpp | 4 +- src/Nazara/Core/Hash/SHA512.cpp | 4 +- src/Nazara/Core/Hash/Whirlpool.cpp | 4 +- src/Nazara/Core/HashDigest.cpp | 4 +- src/Nazara/Core/Hashable.cpp | 4 +- src/Nazara/Core/InputStream.cpp | 4 +- src/Nazara/Core/LockGuard.cpp | 4 +- src/Nazara/Core/Log.cpp | 4 +- src/Nazara/Core/MemoryStream.cpp | 4 +- src/Nazara/Core/Mutex.cpp | 4 +- src/Nazara/Core/Resource.cpp | 4 +- src/Nazara/Core/Semaphore.cpp | 4 +- src/Nazara/Core/String.cpp | 80 +++++++++---------- src/Nazara/Core/StringStream.cpp | 4 +- src/Nazara/Core/Thread.cpp | 6 +- src/Nazara/Core/Unicode.cpp | 16 ++-- src/Nazara/Core/Win32/ClockImpl.cpp | 2 +- src/Nazara/Core/Win32/ClockImpl.hpp | 2 +- .../Core/Win32/ConditionVariableImpl.cpp | 2 +- .../Core/Win32/ConditionVariableImpl.hpp | 2 +- src/Nazara/Core/Win32/DirectoryImpl.cpp | 2 +- src/Nazara/Core/Win32/DirectoryImpl.hpp | 2 +- src/Nazara/Core/Win32/DynLibImpl.cpp | 2 +- src/Nazara/Core/Win32/DynLibImpl.hpp | 2 +- src/Nazara/Core/Win32/FileImpl.cpp | 2 +- src/Nazara/Core/Win32/FileImpl.hpp | 2 +- src/Nazara/Core/Win32/MutexImpl.cpp | 2 +- src/Nazara/Core/Win32/MutexImpl.hpp | 2 +- src/Nazara/Core/Win32/SemaphoreImpl.cpp | 2 +- src/Nazara/Core/Win32/SemaphoreImpl.hpp | 2 +- src/Nazara/Core/Win32/ThreadImpl.cpp | 2 +- src/Nazara/Core/Win32/ThreadImpl.hpp | 2 +- src/Nazara/Core/Win32/Time.cpp | 2 +- src/Nazara/Core/Win32/Time.hpp | 2 +- src/Nazara/Noise/ComplexNoiseBase.cpp | 4 +- src/Nazara/Noise/Debug/Leaks.cpp | 4 +- src/Nazara/Noise/Noise.cpp | 14 ++-- src/Nazara/Noise/NoiseBase.cpp | 4 +- src/Nazara/Noise/NoiseMachine.cpp | 4 +- src/Nazara/Renderer/Context.cpp | 18 ++--- src/Nazara/Renderer/ContextParameters.cpp | 14 ++-- src/Nazara/Renderer/Debug/Leaks.cpp | 4 +- src/Nazara/Renderer/GLSLShader.cpp | 30 +++---- src/Nazara/Renderer/GLSLShader.hpp | 4 +- src/Nazara/Renderer/HardwareBuffer.cpp | 24 +++--- src/Nazara/Renderer/HardwareBuffer.hpp | 4 +- src/Nazara/Renderer/OcclusionQuery.cpp | 4 +- src/Nazara/Renderer/OpenGL.cpp | 34 ++++---- src/Nazara/Renderer/RenderTarget.cpp | 6 +- src/Nazara/Renderer/RenderWindow.cpp | 8 +- src/Nazara/Renderer/Renderer.cpp | 52 ++++++------ src/Nazara/Renderer/Shader.cpp | 4 +- src/Nazara/Renderer/ShaderImpl.cpp | 4 +- src/Nazara/Renderer/ShaderImpl.hpp | 4 +- src/Nazara/Renderer/Texture.cpp | 26 +++--- src/Nazara/Renderer/Win32/ContextImpl.cpp | 8 +- src/Nazara/Renderer/Win32/ContextImpl.hpp | 2 +- src/Nazara/Utility/Animation.cpp | 4 +- src/Nazara/Utility/AxisAlignedBox.cpp | 12 +-- src/Nazara/Utility/Buffer.cpp | 8 +- src/Nazara/Utility/BufferImpl.cpp | 4 +- src/Nazara/Utility/Cursor.cpp | 4 +- src/Nazara/Utility/Debug/Leaks.cpp | 4 +- src/Nazara/Utility/Icon.cpp | 4 +- src/Nazara/Utility/Image.cpp | 20 ++--- src/Nazara/Utility/IndexBuffer.cpp | 4 +- src/Nazara/Utility/Keyboard.cpp | 4 +- src/Nazara/Utility/KeyframeMesh.cpp | 4 +- src/Nazara/Utility/Loaders/MD2.hpp | 4 +- src/Nazara/Utility/Loaders/MD2/Constants.cpp | 6 +- src/Nazara/Utility/Loaders/MD2/Constants.hpp | 18 ++--- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 24 +++--- src/Nazara/Utility/Loaders/MD2/Mesh.cpp | 14 ++-- src/Nazara/Utility/Loaders/MD2/Mesh.hpp | 4 +- src/Nazara/Utility/Loaders/PCX.hpp | 4 +- src/Nazara/Utility/Loaders/PCX/Loader.cpp | 8 +- src/Nazara/Utility/Loaders/STB.hpp | 4 +- src/Nazara/Utility/Loaders/STB/Loader.cpp | 6 +- src/Nazara/Utility/Mesh.cpp | 4 +- src/Nazara/Utility/Mouse.cpp | 4 +- src/Nazara/Utility/PixelFormat.cpp | 10 +-- src/Nazara/Utility/SoftwareBuffer.cpp | 6 +- src/Nazara/Utility/SoftwareBuffer.hpp | 4 +- src/Nazara/Utility/StaticMesh.cpp | 8 +- src/Nazara/Utility/SubMesh.cpp | 6 +- src/Nazara/Utility/Utility.cpp | 20 ++--- src/Nazara/Utility/VertexBuffer.cpp | 4 +- src/Nazara/Utility/VertexDeclaration.cpp | 14 ++-- src/Nazara/Utility/VideoMode.cpp | 4 +- src/Nazara/Utility/VideoModeImpl.hpp | 4 +- src/Nazara/Utility/Win32/CursorImpl.cpp | 4 +- src/Nazara/Utility/Win32/CursorImpl.hpp | 4 +- src/Nazara/Utility/Win32/IconImpl.cpp | 4 +- src/Nazara/Utility/Win32/IconImpl.hpp | 4 +- src/Nazara/Utility/Win32/InputImpl.cpp | 14 ++-- src/Nazara/Utility/Win32/InputImpl.hpp | 4 +- src/Nazara/Utility/Win32/VideoModeImpl.cpp | 6 +- src/Nazara/Utility/Win32/WindowImpl.cpp | 48 +++++------ src/Nazara/Utility/Win32/WindowImpl.hpp | 8 +- src/Nazara/Utility/Window.cpp | 14 ++-- 269 files changed, 888 insertions(+), 890 deletions(-) delete mode 100644 include/Nazara/Math/Math.hpp diff --git a/NazaraModuleTemplate/include/Nazara/ModuleName/ClassName.hpp b/NazaraModuleTemplate/include/Nazara/ModuleName/ClassName.hpp index 5f7d10f41..453b1fd62 100644 --- a/NazaraModuleTemplate/include/Nazara/ModuleName/ClassName.hpp +++ b/NazaraModuleTemplate/include/Nazara/ModuleName/ClassName.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/NazaraModuleTemplate/include/Nazara/ModuleName/Config.hpp b/NazaraModuleTemplate/include/Nazara/ModuleName/Config.hpp index 9527720de..c54134ee2 100644 --- a/NazaraModuleTemplate/include/Nazara/ModuleName/Config.hpp +++ b/NazaraModuleTemplate/include/Nazara/ModuleName/Config.hpp @@ -1,5 +1,5 @@ /* - Nazara Engine + Nazara Engine - Module name Copyright (C) 2012 AUTHORS (EMAIL) @@ -27,12 +27,12 @@ #ifndef NAZARA_CONFIG_MODULENAME_HPP #define NAZARA_CONFIG_MODULENAME_HPP -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_MODULENAME_MEMORYLEAKTRACKER 0 -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_MODULENAME_SAFE 1 #endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/NazaraModuleTemplate/include/Nazara/ModuleName/Debug.hpp b/NazaraModuleTemplate/include/Nazara/ModuleName/Debug.hpp index fa2f9482e..7d29c4775 100644 --- a/NazaraModuleTemplate/include/Nazara/ModuleName/Debug.hpp +++ b/NazaraModuleTemplate/include/Nazara/ModuleName/Debug.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/NazaraModuleTemplate/include/Nazara/ModuleName/DebugOff.hpp b/NazaraModuleTemplate/include/Nazara/ModuleName/DebugOff.hpp index 0a21b742d..c989b8856 100644 --- a/NazaraModuleTemplate/include/Nazara/ModuleName/DebugOff.hpp +++ b/NazaraModuleTemplate/include/Nazara/ModuleName/DebugOff.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) diff --git a/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp b/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp index 54bc0f3b8..106ff9924 100644 --- a/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp +++ b/NazaraModuleTemplate/include/Nazara/ModuleName/ModuleName.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/NazaraModuleTemplate/src/Nazara/ModuleName/ClassName.cpp b/NazaraModuleTemplate/src/Nazara/ModuleName/ClassName.cpp index f57baac14..dc4e93f80 100644 --- a/NazaraModuleTemplate/src/Nazara/ModuleName/ClassName.cpp +++ b/NazaraModuleTemplate/src/Nazara/ModuleName/ClassName.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/NazaraModuleTemplate/src/Nazara/ModuleName/Debug/Leaks.cpp b/NazaraModuleTemplate/src/Nazara/ModuleName/Debug/Leaks.cpp index 6c4fc1d7d..f9832e155 100644 --- a/NazaraModuleTemplate/src/Nazara/ModuleName/Debug/Leaks.cpp +++ b/NazaraModuleTemplate/src/Nazara/ModuleName/Debug/Leaks.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp b/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp index 7c600b5de..e38656552 100644 --- a/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp +++ b/NazaraModuleTemplate/src/Nazara/ModuleName/ModuleName.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Module name" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -12,9 +12,9 @@ bool NzModuleName::Initialize() { if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé + return true; // Déjà initialisé - // Initialisation des dépendances + // Initialisation des dépendances if (!NzCore::Initialize()) { NazaraError("Failed to initialize core module"); @@ -36,13 +36,13 @@ bool NzModuleName::IsInitialized() void NzModuleName::Uninitialize() { if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé + return; // Encore utilisé - // Libération du module + // Libération du module NazaraNotice("Uninitialized: ModuleName module"); - // Libération des dépendances + // Libération des dépendances NzCore::Uninitialize(); } diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index 2fdf36497..a1f9500d0 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -1,7 +1,7 @@ // This file was automatically generated by Nazara /* - Nazara Engine + Nazara Engine - Core module Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) diff --git a/include/Nazara/Core/ByteArray.hpp b/include/Nazara/Core/ByteArray.hpp index 94b64654e..d4014ec3d 100644 --- a/include/Nazara/Core/ByteArray.hpp +++ b/include/Nazara/Core/ByteArray.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -58,7 +58,7 @@ class NAZARA_API NzByteArray : public NzHashable NzByteArray& Trim(nzUInt8 byte = '\0'); NzByteArray Trimmed(nzUInt8 byte = '\0') const; - // Méthodes compatibles STD + // Méthodes compatibles STD nzUInt8* begin(); const nzUInt8* begin() const; nzUInt8* end(); @@ -74,7 +74,7 @@ class NAZARA_API NzByteArray : public NzHashable typedef nzUInt8* iterator; //typedef nzUInt8* reverse_iterator; typedef nzUInt8 value_type; - // Méthodes compatibles STD + // Méthodes compatibles STD nzUInt8& operator[](unsigned int pos); nzUInt8 operator[](unsigned int pos) const; diff --git a/include/Nazara/Core/Clock.hpp b/include/Nazara/Core/Clock.hpp index 6ade015b7..7d1dd111e 100644 --- a/include/Nazara/Core/Clock.hpp +++ b/include/Nazara/Core/Clock.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Color.hpp b/include/Nazara/Core/Color.hpp index 96bebca0d..a63467ca5 100644 --- a/include/Nazara/Core/Color.hpp +++ b/include/Nazara/Core/Color.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Color.inl b/include/Nazara/Core/Color.inl index 13fb3fe11..c7651e24b 100644 --- a/include/Nazara/Core/Color.inl +++ b/include/Nazara/Core/Color.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // http://www.easyrgb.com/index.php?X=MATH @@ -378,7 +378,7 @@ inline void NzColor::ToXYZ(const NzColor& color, float* x, float* y, float* z) g *= 100.0; b *= 100.0; - //Observer. = 2°, Illuminant = D65 + //Observer. = 2°, Illuminant = D65 *x = r*0.4124 + g*0.3576 + b*0.1805; *y = r*0.2126 + g*0.7152 + b*0.0722; *z = r*0.0193 + g*0.1192 + b*0.9505; diff --git a/include/Nazara/Core/ConditionVariable.hpp b/include/Nazara/Core/ConditionVariable.hpp index f031a7e57..137047fef 100644 --- a/include/Nazara/Core/ConditionVariable.hpp +++ b/include/Nazara/Core/ConditionVariable.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Config.hpp b/include/Nazara/Core/Config.hpp index 7cfef54af..ddb8efb5b 100644 --- a/include/Nazara/Core/Config.hpp +++ b/include/Nazara/Core/Config.hpp @@ -1,5 +1,5 @@ /* - Nazara Engine + Nazara Engine - Core module Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) diff --git a/include/Nazara/Core/Core.hpp b/include/Nazara/Core/Core.hpp index 9cf3bd232..14efc40e7 100644 --- a/include/Nazara/Core/Core.hpp +++ b/include/Nazara/Core/Core.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Debug.hpp b/include/Nazara/Core/Debug.hpp index c4a1f45e5..9d081b6eb 100644 --- a/include/Nazara/Core/Debug.hpp +++ b/include/Nazara/Core/Debug.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Core/Debug/MemoryLeakTracker.hpp b/include/Nazara/Core/Debug/MemoryLeakTracker.hpp index 6e0cc072d..17de7104f 100644 --- a/include/Nazara/Core/Debug/MemoryLeakTracker.hpp +++ b/include/Nazara/Core/Debug/MemoryLeakTracker.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/DebugOff.hpp b/include/Nazara/Core/DebugOff.hpp index 46023d974..7dfabd341 100644 --- a/include/Nazara/Core/DebugOff.hpp +++ b/include/Nazara/Core/DebugOff.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #if NAZARA_CORE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) diff --git a/include/Nazara/Core/Directory.hpp b/include/Nazara/Core/Directory.hpp index d39f8d00a..319066c8d 100644 --- a/include/Nazara/Core/Directory.hpp +++ b/include/Nazara/Core/Directory.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/DynLib.hpp b/include/Nazara/Core/DynLib.hpp index 2c05a0eea..dc95e616a 100644 --- a/include/Nazara/Core/DynLib.hpp +++ b/include/Nazara/Core/DynLib.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -18,7 +18,7 @@ #endif class NzDynLibImpl; -typedef int (*NzDynLibFunc)(); // Type "générique" de pointeur sur fonction +typedef int (*NzDynLibFunc)(); // Type "générique" de pointeur sur fonction class NzDynLib : NzNonCopyable { diff --git a/include/Nazara/Core/Endianness.hpp b/include/Nazara/Core/Endianness.hpp index 1f079a70f..8c43064de 100644 --- a/include/Nazara/Core/Endianness.hpp +++ b/include/Nazara/Core/Endianness.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -11,7 +11,7 @@ #include #if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN) - // Détection automatique selon les macros du compilateur + // Détection automatique selon les macros du compilateur #if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__) #define NAZARA_BIG_ENDIAN diff --git a/include/Nazara/Core/Endianness.inl b/include/Nazara/Core/Endianness.inl index 20edee20f..930b600d7 100644 --- a/include/Nazara/Core/Endianness.inl +++ b/include/Nazara/Core/Endianness.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 79d7e09ad..f97348afc 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Error.hpp b/include/Nazara/Core/Error.hpp index 9c95ade9b..e59b76a38 100644 --- a/include/Nazara/Core/Error.hpp +++ b/include/Nazara/Core/Error.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index dc28ff401..aa84ec68e 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -29,7 +29,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable public: enum CursorPosition { - AtBegin, // Début du fichier + AtBegin, // Début du fichier AtCurrent, // Position du pointeur AtEnd // Fin du fichier }; @@ -38,13 +38,13 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable { Current = 0x00, // Utilise le mode d'ouverture actuel - Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin - Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert + Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin + Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert ReadOnly = 0x04, // Ouvre uniquement en lecture - ReadWrite = 0x08, // Ouvre en lecture/écriture + ReadWrite = 0x08, // Ouvre en lecture/écriture Text = 0x10, // Ouvre en mode texte - Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe - WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas + Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe + WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas }; NzFile(); diff --git a/include/Nazara/Core/Format.hpp b/include/Nazara/Core/Format.hpp index 54c553bf2..ae8e461b8 100644 --- a/include/Nazara/Core/Format.hpp +++ b/include/Nazara/Core/Format.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Functor.hpp b/include/Nazara/Core/Functor.hpp index 620423d70..656b6a866 100644 --- a/include/Nazara/Core/Functor.hpp +++ b/include/Nazara/Core/Functor.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -9,7 +9,7 @@ #include -// Inspiré du code de la SFML par Laurent Gomila +// Inspiré du code de la SFML par Laurent Gomila struct NzFunctor { diff --git a/include/Nazara/Core/Functor.inl b/include/Nazara/Core/Functor.inl index 834f4687e..e867f79ef 100644 --- a/include/Nazara/Core/Functor.inl +++ b/include/Nazara/Core/Functor.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp template NzFunctorWithoutArgs::NzFunctorWithoutArgs(F func) : diff --git a/include/Nazara/Core/Hash.hpp b/include/Nazara/Core/Hash.hpp index 2243326b4..2e2f59cf8 100644 --- a/include/Nazara/Core/Hash.hpp +++ b/include/Nazara/Core/Hash.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Hash/CRC32.hpp b/include/Nazara/Core/Hash/CRC32.hpp index 3ca48046d..3e17dfd01 100644 --- a/include/Nazara/Core/Hash/CRC32.hpp +++ b/include/Nazara/Core/Hash/CRC32.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Hash/Fletcher16.hpp b/include/Nazara/Core/Hash/Fletcher16.hpp index ea61ce4e0..6fc43fb41 100644 --- a/include/Nazara/Core/Hash/Fletcher16.hpp +++ b/include/Nazara/Core/Hash/Fletcher16.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/Hash/MD5.hpp b/include/Nazara/Core/Hash/MD5.hpp index 30dbdedc6..4c33acb0f 100644 --- a/include/Nazara/Core/Hash/MD5.hpp +++ b/include/Nazara/Core/Hash/MD5.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/Hash/SHA224.hpp b/include/Nazara/Core/Hash/SHA224.hpp index 6495180b9..63c62de16 100644 --- a/include/Nazara/Core/Hash/SHA224.hpp +++ b/include/Nazara/Core/Hash/SHA224.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/Hash/SHA256.hpp b/include/Nazara/Core/Hash/SHA256.hpp index 3a72f41e2..68f09c2bc 100644 --- a/include/Nazara/Core/Hash/SHA256.hpp +++ b/include/Nazara/Core/Hash/SHA256.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/Hash/SHA384.hpp b/include/Nazara/Core/Hash/SHA384.hpp index 08b8a2318..0a68d49e3 100644 --- a/include/Nazara/Core/Hash/SHA384.hpp +++ b/include/Nazara/Core/Hash/SHA384.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/Hash/SHA512.hpp b/include/Nazara/Core/Hash/SHA512.hpp index 0b9a58af0..52bb47916 100644 --- a/include/Nazara/Core/Hash/SHA512.hpp +++ b/include/Nazara/Core/Hash/SHA512.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/Hash/Whirlpool.hpp b/include/Nazara/Core/Hash/Whirlpool.hpp index b26cfc504..412b757aa 100644 --- a/include/Nazara/Core/Hash/Whirlpool.hpp +++ b/include/Nazara/Core/Hash/Whirlpool.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Core/HashDigest.hpp b/include/Nazara/Core/HashDigest.hpp index 0359318b1..bac09615b 100644 --- a/include/Nazara/Core/HashDigest.hpp +++ b/include/Nazara/Core/HashDigest.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/HashImpl.hpp b/include/Nazara/Core/HashImpl.hpp index 83f087bd6..a871c0f8f 100644 --- a/include/Nazara/Core/HashImpl.hpp +++ b/include/Nazara/Core/HashImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Hashable.hpp b/include/Nazara/Core/Hashable.hpp index bb8367477..4b9395bb3 100644 --- a/include/Nazara/Core/Hashable.hpp +++ b/include/Nazara/Core/Hashable.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Initializer.hpp b/include/Nazara/Core/Initializer.hpp index 592ffb506..66108a7a9 100644 --- a/include/Nazara/Core/Initializer.hpp +++ b/include/Nazara/Core/Initializer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Initializer.inl b/include/Nazara/Core/Initializer.inl index 83cc85612..2f814517d 100644 --- a/include/Nazara/Core/Initializer.inl +++ b/include/Nazara/Core/Initializer.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // http://www.easyrgb.com/index.php?X=MATH diff --git a/include/Nazara/Core/InputStream.hpp b/include/Nazara/Core/InputStream.hpp index efedc20bc..28b951b85 100644 --- a/include/Nazara/Core/InputStream.hpp +++ b/include/Nazara/Core/InputStream.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/LockGuard.hpp b/include/Nazara/Core/LockGuard.hpp index c9397bc2d..698048b51 100644 --- a/include/Nazara/Core/LockGuard.hpp +++ b/include/Nazara/Core/LockGuard.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Log.hpp b/include/Nazara/Core/Log.hpp index 76d6b8776..8af87b182 100644 --- a/include/Nazara/Core/Log.hpp +++ b/include/Nazara/Core/Log.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/MemoryStream.hpp b/include/Nazara/Core/MemoryStream.hpp index 12e3d5996..ae6025e2b 100644 --- a/include/Nazara/Core/MemoryStream.hpp +++ b/include/Nazara/Core/MemoryStream.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Mutex.hpp b/include/Nazara/Core/Mutex.hpp index fe4821f00..6ca9d91d4 100644 --- a/include/Nazara/Core/Mutex.hpp +++ b/include/Nazara/Core/Mutex.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/NonCopyable.hpp b/include/Nazara/Core/NonCopyable.hpp index 5623026de..8f08623bd 100644 --- a/include/Nazara/Core/NonCopyable.hpp +++ b/include/Nazara/Core/NonCopyable.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Resource.hpp b/include/Nazara/Core/Resource.hpp index 090de9146..920c4aceb 100644 --- a/include/Nazara/Core/Resource.hpp +++ b/include/Nazara/Core/Resource.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -22,7 +22,7 @@ class NAZARA_API NzResource void SetPersistent(bool persistent = true); private: - // Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms + // Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms mutable bool m_resourcePersistent; mutable unsigned int m_resourceReferenceCount; }; diff --git a/include/Nazara/Core/Semaphore.hpp b/include/Nazara/Core/Semaphore.hpp index 53e7ae509..711b34acd 100644 --- a/include/Nazara/Core/Semaphore.hpp +++ b/include/Nazara/Core/Semaphore.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp index 34bee2504..33b323d01 100644 --- a/include/Nazara/Core/String.hpp +++ b/include/Nazara/Core/String.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -27,11 +27,11 @@ class NAZARA_API NzString : public NzHashable public: enum Flags { - None = 0x00, // Mode par défaut - CaseInsensitive = 0x01, // Insensible à la casse - HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 - TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne - TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne + None = 0x00, // Mode par défaut + CaseInsensitive = 0x01, // Insensible à la casse + HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 + TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne + TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne }; struct SharedString; @@ -157,7 +157,7 @@ class NAZARA_API NzString : public NzHashable NzString Trimmed(nzUInt32 flags = None) const; NzString Trimmed(char character, nzUInt32 flags = None) const; - // Méthodes STD + // Méthodes STD char* begin(); const char* begin() const; char* end(); @@ -173,7 +173,7 @@ class NAZARA_API NzString : public NzHashable typedef char* iterator; //typedef char* reverse_iterator; typedef char value_type; - // Méthodes STD + // Méthodes STD operator std::string() const; diff --git a/include/Nazara/Core/StringStream.hpp b/include/Nazara/Core/StringStream.hpp index 63b975772..719adb7b5 100644 --- a/include/Nazara/Core/StringStream.hpp +++ b/include/Nazara/Core/StringStream.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Thread.hpp b/include/Nazara/Core/Thread.hpp index 5895040b8..aa67e0beb 100644 --- a/include/Nazara/Core/Thread.hpp +++ b/include/Nazara/Core/Thread.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Inspiré du code de la SFML par Laurent Gomila +// Inspiré du code de la SFML par Laurent Gomila #pragma once diff --git a/include/Nazara/Core/Thread.inl b/include/Nazara/Core/Thread.inl index ddf73ca3d..301a32240 100644 --- a/include/Nazara/Core/Thread.inl +++ b/include/Nazara/Core/Thread.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Core/ThreadSafety.hpp b/include/Nazara/Core/ThreadSafety.hpp index ff6ee4907..be9d5d103 100644 --- a/include/Nazara/Core/ThreadSafety.hpp +++ b/include/Nazara/Core/ThreadSafety.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // Pas de header guard @@ -7,7 +7,7 @@ #include #include -// Ces macros peuvent changer pour n'importe quel fichier qui l'utilise dans une même unité de compilation +// Ces macros peuvent changer pour n'importe quel fichier qui l'utilise dans une même unité de compilation #undef NazaraLock #undef NazaraMutex #undef NazaraMutexAttrib diff --git a/include/Nazara/Core/ThreadSafetyOff.hpp b/include/Nazara/Core/ThreadSafetyOff.hpp index 86c84e938..88c9fc7c0 100644 --- a/include/Nazara/Core/ThreadSafetyOff.hpp +++ b/include/Nazara/Core/ThreadSafetyOff.hpp @@ -1,10 +1,10 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // Pas de header guard -// Ces macros peuvent changer pour n'importe quel fichier qui l'utilise dans une même unité de compilation +// Ces macros peuvent changer pour n'importe quel fichier qui l'utilise dans une même unité de compilation #undef NazaraLock #undef NazaraMutex #undef NazaraMutexAttrib diff --git a/include/Nazara/Core/Tuple.hpp b/include/Nazara/Core/Tuple.hpp index 94d0b77da..ffe5068ed 100644 --- a/include/Nazara/Core/Tuple.hpp +++ b/include/Nazara/Core/Tuple.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Core/Tuple.inl b/include/Nazara/Core/Tuple.inl index bd662256f..326ca5d97 100644 --- a/include/Nazara/Core/Tuple.inl +++ b/include/Nazara/Core/Tuple.inl @@ -1,10 +1,10 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // http://stackoverflow.com/questions/687490/c0x-how-do-i-expand-a-tuple-into-variadic-template-function-arguments -// Merci à Ryan "FullMetal Alchemist" Lahfa -// Merci aussi à Freedom de siteduzero.com +// Merci à Ryan "FullMetal Alchemist" Lahfa +// Merci aussi à Freedom de siteduzero.com #include diff --git a/include/Nazara/Core/Unicode.hpp b/include/Nazara/Core/Unicode.hpp index f9b05d6fd..e9bccad03 100644 --- a/include/Nazara/Core/Unicode.hpp +++ b/include/Nazara/Core/Unicode.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -13,13 +13,13 @@ class NzUnicode { public: /* - Catégorie Unicode: - -Les valeurs de 0x01 à 0x80 indiquent la catégorie. - -Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie. + Catégorie Unicode: + -Les valeurs de 0x01 à 0x80 indiquent la catégorie. + -Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie. */ enum Category : nzUInt16 { - // Catégorie non-reconnue par Nazara + // Catégorie non-reconnue par Nazara Category_NoCategory = 0, // Lettres diff --git a/include/Nazara/Debug.hpp b/include/Nazara/Debug.hpp index 22ca244ef..9ca669bb7 100644 --- a/include/Nazara/Debug.hpp +++ b/include/Nazara/Debug.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/DebugOff.hpp b/include/Nazara/DebugOff.hpp index e32f36866..d76ff1bb8 100644 --- a/include/Nazara/DebugOff.hpp +++ b/include/Nazara/DebugOff.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine" // For conditions of distribution and use, see copyright notice in Config.hpp #undef delete diff --git a/include/Nazara/Math.hpp b/include/Nazara/Math.hpp index e26587f36..33747808b 100644 --- a/include/Nazara/Math.hpp +++ b/include/Nazara/Math.hpp @@ -1,10 +1,10 @@ // This file was automatically generated by Nazara /* - Nazara Engine + Nazara Engine - Mathematics module - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - Rémi "overdrivr" Bèges (remi.beges@laposte.net) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Rémi "overdrivr" Bèges (remi.beges@laposte.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/include/Nazara/Math/Basic.hpp b/include/Nazara/Math/Basic.hpp index ec374efe2..572afa5e3 100644 --- a/include/Nazara/Math/Basic.hpp +++ b/include/Nazara/Math/Basic.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Basic.inl b/include/Nazara/Math/Basic.inl index 867002a92..92f17ddd2 100644 --- a/include/Nazara/Math/Basic.inl +++ b/include/Nazara/Math/Basic.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -55,7 +55,7 @@ unsigned int NzGetNumberLength(signed char number) if (number == 0) return 1; - // Le standard définit le char comme étant codé sur un octet + // Le standard définit le char comme étant codé sur un octet static_assert(sizeof(number) == 1, "Signed char must be one byte-sized"); if (number >= 100) @@ -71,7 +71,7 @@ unsigned int NzGetNumberLength(unsigned char number) if (number == 0) return 1; - // Le standard définit le char comme étant codé sur un octet + // Le standard définit le char comme étant codé sur un octet static_assert(sizeof(number) == 1, "Signed char must be one byte-sized"); if (number >= 100) @@ -148,19 +148,19 @@ unsigned int NzGetNumberLength(unsigned long long number) unsigned int NzGetNumberLength(float number, nzUInt8 precision) { - // L'imprécision des flottants nécessite un cast (log10(9.99999) = 1) + // L'imprécision des flottants nécessite un cast (log10(9.99999) = 1) return NzGetNumberLength(static_cast(number)) + precision + 1; // Plus un pour le point } unsigned int NzGetNumberLength(double number, nzUInt8 precision) { - // L'imprécision des flottants nécessite un cast (log10(9.99999) = 1) + // L'imprécision des flottants nécessite un cast (log10(9.99999) = 1) return NzGetNumberLength(static_cast(number)) + precision + 1; // Plus un pour le point } unsigned int NzGetNumberLength(long double number, nzUInt8 precision) { - // L'imprécision des flottants nécessite un cast (log10(9.99999) = 1) + // L'imprécision des flottants nécessite un cast (log10(9.99999) = 1) return NzGetNumberLength(static_cast(number)) + precision + 1; // Plus un pour le point } diff --git a/include/Nazara/Math/Config.hpp b/include/Nazara/Math/Config.hpp index 1325d5ad0..6adf384cf 100644 --- a/include/Nazara/Math/Config.hpp +++ b/include/Nazara/Math/Config.hpp @@ -1,8 +1,8 @@ /* - Nazara Engine + Nazara Engine - Mathematics module - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - Rémi "overdrivr" Bèges (remi.beges@laposte.net) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Rémi "overdrivr" Bèges (remi.beges@laposte.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -28,24 +28,24 @@ #ifndef NAZARA_CONFIG_MATH_HPP #define NAZARA_CONFIG_MATH_HPP -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci -// Définit le radian comme l'unité utilisée pour les angles +// Définit le radian comme l'unité utilisée pour les angles #define NAZARA_MATH_ANGLE_RADIAN 0 -// Définit la disposition des matrices en colonnes (Façon OpenGL) +// Définit la disposition des matrices en colonnes (Façon OpenGL) #define NAZARA_MATH_MATRIX_COLUMN_MAJOR 1 -// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) +// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) #define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0 -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_MATH_SAFE 1 -// Protège les classes des accès concurrentiels +// Protège les classes des accès concurrentiels #define NAZARA_MATH_THREADSAFE 1 -// Les classes à protéger des accès concurrentiels +// Les classes à protéger des accès concurrentiels #define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) #define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) diff --git a/include/Nazara/Math/Cube.hpp b/include/Nazara/Math/Cube.hpp index 7230c1108..8fa678d38 100644 --- a/include/Nazara/Math/Cube.hpp +++ b/include/Nazara/Math/Cube.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Cube.inl b/include/Nazara/Math/Cube.inl index 64d69bf66..d96c2cfcd 100644 --- a/include/Nazara/Math/Cube.inl +++ b/include/Nazara/Math/Cube.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Math/EulerAngles.hpp b/include/Nazara/Math/EulerAngles.hpp index a9667186f..1fb14aa52 100644 --- a/include/Nazara/Math/EulerAngles.hpp +++ b/include/Nazara/Math/EulerAngles.hpp @@ -1,6 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/EulerAngles.inl b/include/Nazara/Math/EulerAngles.inl index 0752f2948..8797d3310 100644 --- a/include/Nazara/Math/EulerAngles.inl +++ b/include/Nazara/Math/EulerAngles.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Math/Math.hpp b/include/Nazara/Math/Math.hpp deleted file mode 100644 index f0212dde6..000000000 --- a/include/Nazara/Math/Math.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - Nazara Engine - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ \ No newline at end of file diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index f0c136207..076d1b373 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 051b10697..2f11f83dd 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -16,7 +16,7 @@ #include #include //#include -///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) +///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) #define F(a) static_cast(a) @@ -407,7 +407,7 @@ void NzMatrix4::Set(const T matrix[16]) { EnsureOwnership(); - // Ici nous sommes certains de la continuité des éléments en mémoire + // Ici nous sommes certains de la continuité des éléments en mémoire std::memcpy(&m_sharedMatrix->m11, matrix, 16*sizeof(T)); } diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index b09518b52..6b3c0e7b7 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -1,6 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index b03c588f2..c17e5b026 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -1,6 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -111,7 +110,7 @@ T NzQuaternion::Normalize() return magnitude; } else - return F(1.0); // Le quaternion est déjà normalisé + return F(1.0); // Le quaternion est déjà normalisé } template @@ -364,7 +363,7 @@ NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuater T k0, k1; if (cosOmega > F(0.9999)) { - // Interpolation linéaire pour éviter une division par zéro + // Interpolation linéaire pour éviter une division par zéro k0 = F(1.0) - interp; k1 = interp; } @@ -373,7 +372,7 @@ NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuater T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); T omega = std::atan2(sinOmega, cosOmega); - // Pour éviter deux divisions + // Pour éviter deux divisions sinOmega = F(1.0)/sinOmega; k0 = std::sin((F(1.0) - interp) * omega) * sinOmega; diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index 5c06e9140..938e9e1ea 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 97d1a6a69..3984593c0 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index b7fc3eff1..4f02ae77e 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 3ee71da3f..f1a716f7b 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index c8320b9f0..b501fee58 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 136fce90b..671b3898e 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 8faa3b94c..3987a6b76 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 99e868cf6..18e915e96 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -9,7 +9,7 @@ #include #include -///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D +///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D #define F(a) static_cast(a) diff --git a/include/Nazara/Noise.hpp b/include/Nazara/Noise.hpp index 6603cf442..4be156c28 100644 --- a/include/Nazara/Noise.hpp +++ b/include/Nazara/Noise.hpp @@ -1,9 +1,9 @@ // This file was automatically generated by Nazara /* - Nazara Engine - NzNoise Module + Nazara Engine - Noise module - Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) + Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/include/Nazara/Noise/ComplexNoiseBase.hpp b/include/Nazara/Noise/ComplexNoiseBase.hpp index a9db6870e..8e1591df0 100644 --- a/include/Nazara/Noise/ComplexNoiseBase.hpp +++ b/include/Nazara/Noise/ComplexNoiseBase.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Config.hpp b/include/Nazara/Noise/Config.hpp index dff3349d1..11b3ac5e1 100644 --- a/include/Nazara/Noise/Config.hpp +++ b/include/Nazara/Noise/Config.hpp @@ -1,7 +1,7 @@ /* - Nazara Engine - NzNoise Module + Nazara Engine - Noise module - Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) + Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -27,12 +27,12 @@ #ifndef NAZARA_CONFIG_NOISE_HPP #define NAZARA_CONFIG_NOISE_HPP -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_NOISE_MEMORYLEAKTRACKER 0 -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_NOISE_SAFE 1 #endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/Noise/Debug.hpp b/include/Nazara/Noise/Debug.hpp index 1f8a08966..7f5b31f2c 100644 --- a/include/Nazara/Noise/Debug.hpp +++ b/include/Nazara/Noise/Debug.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Noise/DebugOff.hpp b/include/Nazara/Noise/DebugOff.hpp index 1162e79c0..0230ec332 100644 --- a/include/Nazara/Noise/DebugOff.hpp +++ b/include/Nazara/Noise/DebugOff.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #if NAZARA_NOISE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp index 1b6206c84..464117ecc 100644 --- a/include/Nazara/Noise/Noise.hpp +++ b/include/Nazara/Noise/Noise.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp index 331d227df..6ec1d6f31 100644 --- a/include/Nazara/Noise/NoiseBase.hpp +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index 4c221628f..d5abad75b 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp index 18e7ae875..c9e4186e4 100644 --- a/include/Nazara/Noise/Perlin2D.hpp +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Perlin2D.inl b/include/Nazara/Noise/Perlin2D.inl index a823aba81..df1a383d8 100644 --- a/include/Nazara/Noise/Perlin2D.inl +++ b/include/Nazara/Noise/Perlin2D.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Noise/Perlin3D.hpp b/include/Nazara/Noise/Perlin3D.hpp index a425dc384..573dac6ae 100644 --- a/include/Nazara/Noise/Perlin3D.hpp +++ b/include/Nazara/Noise/Perlin3D.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Perlin3D.inl b/include/Nazara/Noise/Perlin3D.inl index 60231979a..b29a3adc0 100644 --- a/include/Nazara/Noise/Perlin3D.inl +++ b/include/Nazara/Noise/Perlin3D.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Noise/Perlin4D.hpp b/include/Nazara/Noise/Perlin4D.hpp index b5a25ee4d..e73e7cf72 100644 --- a/include/Nazara/Noise/Perlin4D.hpp +++ b/include/Nazara/Noise/Perlin4D.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Perlin4D.inl b/include/Nazara/Noise/Perlin4D.inl index b009098f8..c21c7e97d 100644 --- a/include/Nazara/Noise/Perlin4D.inl +++ b/include/Nazara/Noise/Perlin4D.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index 78d896f7d..9dfa542be 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Simplex2D.inl b/include/Nazara/Noise/Simplex2D.inl index 3d019fd54..c86a8408b 100644 --- a/include/Nazara/Noise/Simplex2D.inl +++ b/include/Nazara/Noise/Simplex2D.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Noise/Simplex3D.hpp b/include/Nazara/Noise/Simplex3D.hpp index 399705072..13ced155b 100644 --- a/include/Nazara/Noise/Simplex3D.hpp +++ b/include/Nazara/Noise/Simplex3D.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Simplex3D.inl b/include/Nazara/Noise/Simplex3D.inl index d0bd3bf0d..779ba5cb1 100644 --- a/include/Nazara/Noise/Simplex3D.inl +++ b/include/Nazara/Noise/Simplex3D.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Noise/Simplex4D.hpp b/include/Nazara/Noise/Simplex4D.hpp index f932d212b..8c7bb31e5 100644 --- a/include/Nazara/Noise/Simplex4D.hpp +++ b/include/Nazara/Noise/Simplex4D.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Noise/Simplex4D.inl b/include/Nazara/Noise/Simplex4D.inl index 413467b85..f49235479 100644 --- a/include/Nazara/Noise/Simplex4D.inl +++ b/include/Nazara/Noise/Simplex4D.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Prerequesites.hpp b/include/Nazara/Prerequesites.hpp index 4593dce62..af3ec7707 100644 --- a/include/Nazara/Prerequesites.hpp +++ b/include/Nazara/Prerequesites.hpp @@ -1,6 +1,26 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp +/* + Nazara Engine + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ #ifndef NAZARA_PREREQUESITES_HPP #define NAZARA_PREREQUESITES_HPP @@ -55,7 +75,7 @@ #define NAZARA_PLATFORM_WINDOWS // Des defines pour le header Windows - #if defined(NAZARA_BUILD) // Pour ne pas entrer en conflit avec les defines de l'application ou d'une autre bibliothèque + #if defined(NAZARA_BUILD) // Pour ne pas entrer en conflit avec les defines de l'application ou d'une autre bibliothèque #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -71,7 +91,7 @@ #define NAZARA_WINNT 0x0501 #endif - // Pour ne pas casser le define déjà en place s'il est applicable + // Pour ne pas casser le define déjà en place s'il est applicable #if defined(_WIN32_WINNT) #if _WIN32_WINNT < NAZARA_WINNT #undef _WIN32_WINNT @@ -98,7 +118,7 @@ #define NAZARA_PLATFORM_FREEBSD #define NAZARA_PLATFORM_POSIX*/ #else - // À commenter pour tenter quand même une compilation + // À commenter pour tenter quand même une compilation #error This operating system is not fully supported by the Nazara Engine #define NAZARA_PLATFORM_UNKNOWN diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index 98d61077e..f4c24dbfb 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -1,9 +1,9 @@ // This file was automatically generated by Nazara /* - Nazara Engine + Nazara Engine - Renderer module - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/include/Nazara/Renderer/Config.hpp b/include/Nazara/Renderer/Config.hpp index ae970da77..5fa27a4f0 100644 --- a/include/Nazara/Renderer/Config.hpp +++ b/include/Nazara/Renderer/Config.hpp @@ -1,7 +1,7 @@ /* - Nazara Engine + Nazara Engine - Renderer module - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -27,18 +27,18 @@ #ifndef NAZARA_CONFIG_RENDERER_HPP #define NAZARA_CONFIG_RENDERER_HPP -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci -// Active une fenêtre de rendu (NzRenderWindow) lors de sa création +// Active une fenêtre de rendu (NzRenderWindow) lors de sa création #define NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION 1 -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 -// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL) +// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL) #define NAZARA_RENDERER_OPENGL_DEBUG 0 -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_RENDERER_SAFE 1 #endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/Renderer/Context.hpp b/include/Nazara/Renderer/Context.hpp index 08da75937..9aaf37304 100644 --- a/include/Nazara/Renderer/Context.hpp +++ b/include/Nazara/Renderer/Context.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #ifdef NAZARA_RENDERER_COMMON diff --git a/include/Nazara/Renderer/ContextParameters.hpp b/include/Nazara/Renderer/ContextParameters.hpp index 93b731e04..e11f033c9 100644 --- a/include/Nazara/Renderer/ContextParameters.hpp +++ b/include/Nazara/Renderer/ContextParameters.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/Debug.hpp b/include/Nazara/Renderer/Debug.hpp index 0ed2db662..64527355e 100644 --- a/include/Nazara/Renderer/Debug.hpp +++ b/include/Nazara/Renderer/Debug.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Renderer/DebugOff.hpp b/include/Nazara/Renderer/DebugOff.hpp index 52edf35d4..724669a51 100644 --- a/include/Nazara/Renderer/DebugOff.hpp +++ b/include/Nazara/Renderer/DebugOff.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #if NAZARA_RENDERER_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) diff --git a/include/Nazara/Renderer/Enums.hpp b/include/Nazara/Renderer/Enums.hpp index 47678946e..459ea4d4a 100644 --- a/include/Nazara/Renderer/Enums.hpp +++ b/include/Nazara/Renderer/Enums.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/OcclusionQuery.hpp b/include/Nazara/Renderer/OcclusionQuery.hpp index e6ea73e3a..aa48cabfa 100644 --- a/include/Nazara/Renderer/OcclusionQuery.hpp +++ b/include/Nazara/Renderer/OcclusionQuery.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 9adee291f..72bd906a4 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #ifdef NAZARA_RENDERER_COMMON @@ -11,7 +11,7 @@ #ifndef NAZARA_OPENGL_HPP #define NAZARA_OPENGL_HPP -// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier +// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier #include #include #include diff --git a/include/Nazara/Renderer/RenderTarget.hpp b/include/Nazara/Renderer/RenderTarget.hpp index 8a065a31c..347bf90fb 100644 --- a/include/Nazara/Renderer/RenderTarget.hpp +++ b/include/Nazara/Renderer/RenderTarget.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/RenderTargetParameters.hpp b/include/Nazara/Renderer/RenderTargetParameters.hpp index bd823e021..5a54d59ab 100644 --- a/include/Nazara/Renderer/RenderTargetParameters.hpp +++ b/include/Nazara/Renderer/RenderTargetParameters.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index 391314c31..d9b932d09 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index b73fb07a5..b34b16965 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index f1ebb9ed2..bf270b63c 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index af056c0db..d0e1b8856 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp index 449b99967..c578347d9 100644 --- a/include/Nazara/Utility.hpp +++ b/include/Nazara/Utility.hpp @@ -1,9 +1,9 @@ // This file was automatically generated by Nazara /* - Nazara Engine + Nazara Engine - Window module - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index 11b2c08bb..15ecd6b78 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/AxisAlignedBox.hpp b/include/Nazara/Utility/AxisAlignedBox.hpp index a12658c30..174ff5fc8 100644 --- a/include/Nazara/Utility/AxisAlignedBox.hpp +++ b/include/Nazara/Utility/AxisAlignedBox.hpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2011 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #ifndef NAZARA_AXISALIGNEDBOX_HPP #define NAZARA_AXISALIGNEDBOX_HPP diff --git a/include/Nazara/Utility/Buffer.hpp b/include/Nazara/Utility/Buffer.hpp index 5c728473a..db03d85f6 100644 --- a/include/Nazara/Utility/Buffer.hpp +++ b/include/Nazara/Utility/Buffer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/BufferImpl.hpp b/include/Nazara/Utility/BufferImpl.hpp index 7821c3c76..f1015d75d 100644 --- a/include/Nazara/Utility/BufferImpl.hpp +++ b/include/Nazara/Utility/BufferImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Config.hpp b/include/Nazara/Utility/Config.hpp index f18cea996..2f9e23ffc 100644 --- a/include/Nazara/Utility/Config.hpp +++ b/include/Nazara/Utility/Config.hpp @@ -1,7 +1,7 @@ /* - Nazara Engine + Nazara Engine - Window module - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -27,24 +27,24 @@ #ifndef NAZARA_CONFIG_UTILITY_HPP #define NAZARA_CONFIG_UTILITY_HPP -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci -// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire) +// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire) #define NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0 -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) #define NAZARA_UTILITY_MEMORYLEAKTRACKER 0 -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) #define NAZARA_UTILITY_SAFE 1 -// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte -#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7 +// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte +#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7 -// Protège les classes des accès concurrentiels +// Protège les classes des accès concurrentiels #define NAZARA_UTILITY_THREADSAFE 1 -// Les classes à protéger des accès concurrentiels +// Les classes à protéger des accès concurrentiels #define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW) #define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW) diff --git a/include/Nazara/Utility/Cursor.hpp b/include/Nazara/Utility/Cursor.hpp index 56156346f..46ba6a940 100644 --- a/include/Nazara/Utility/Cursor.hpp +++ b/include/Nazara/Utility/Cursor.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Debug.hpp b/include/Nazara/Utility/Debug.hpp index 31cc4d329..b41890db5 100644 --- a/include/Nazara/Utility/Debug.hpp +++ b/include/Nazara/Utility/Debug.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/include/Nazara/Utility/DebugOff.hpp b/include/Nazara/Utility/DebugOff.hpp index e6305ae55..04a295c3f 100644 --- a/include/Nazara/Utility/DebugOff.hpp +++ b/include/Nazara/Utility/DebugOff.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #if NAZARA_UTILITY_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 5758f14ea..71e5418c0 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once @@ -45,7 +45,7 @@ enum nzBufferUsage enum nzCubemapFace { - // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap + // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap // L'ordre est X, -X, Y, -Y, Z, -Z nzCubemapFace_PositiveX = 0, nzCubemapFace_PositiveY = 2, diff --git a/include/Nazara/Utility/Event.hpp b/include/Nazara/Utility/Event.hpp index 6f8d28dee..88b984c5c 100644 --- a/include/Nazara/Utility/Event.hpp +++ b/include/Nazara/Utility/Event.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once @@ -14,7 +14,7 @@ struct NzEvent { - // Utilisé par: + // Utilisé par: // -nzEventType_KeyPressed // -nzEventType_KeyReleased struct KeyEvent @@ -27,7 +27,7 @@ struct NzEvent bool system; }; - // Utilisé par: + // Utilisé par: // -nzEventType_MouseButtonDoubleClicked // -nzEventType_MouseButtonPressed struct MouseButtonEvent @@ -37,7 +37,7 @@ struct NzEvent unsigned int y; }; - // Utilisé par: + // Utilisé par: // -nzEventType_MouseMoved struct MouseMoveEvent { @@ -47,14 +47,14 @@ struct NzEvent unsigned int y; }; - // Utilisé par: + // Utilisé par: // -nzEventType_MouseWheelMoved struct MouseWheelEvent { float delta; }; - // Utilisé par: + // Utilisé par: // -nzEventType_Moved struct PositionEvent { @@ -62,7 +62,7 @@ struct NzEvent int y; }; - // Utilisé par: + // Utilisé par: // -nzEventType_Resized struct SizeEvent { @@ -70,7 +70,7 @@ struct NzEvent unsigned int width; }; - // Utilisé par: + // Utilisé par: // -nzEventType_TextEntered struct TextEvent { @@ -82,33 +82,33 @@ struct NzEvent union { - // Utilisé par: + // Utilisé par: // -nzEventType_KeyPressed // -nzEventType_KeyReleased KeyEvent key; - // Utilisé par: + // Utilisé par: // -nzEventType_MouseButtonDoubleClicked // -nzEventType_MouseButtonPressed MouseButtonEvent mouseButton; - // Utilisé par: + // Utilisé par: // -nzEventType_MouseMoved MouseMoveEvent mouseMove; - // Utilisé par: + // Utilisé par: // -nzEventType_MouseWheelMoved MouseWheelEvent mouseWheel; - // Utilisé par: + // Utilisé par: // -nzEventType_Moved PositionEvent position; - // Utilisé par: + // Utilisé par: // -nzEventType_Resized SizeEvent size; - // Utilisé par: + // Utilisé par: // -nzEventType_TextEntered TextEvent text; }; diff --git a/include/Nazara/Utility/Icon.hpp b/include/Nazara/Utility/Icon.hpp index fa724a62c..d2797517a 100644 --- a/include/Nazara/Utility/Icon.hpp +++ b/include/Nazara/Utility/Icon.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 3a98656e1..7c682b7cb 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/IndexBuffer.hpp b/include/Nazara/Utility/IndexBuffer.hpp index dd6f99fd0..8dcb10a0b 100644 --- a/include/Nazara/Utility/IndexBuffer.hpp +++ b/include/Nazara/Utility/IndexBuffer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Keyboard.hpp b/include/Nazara/Utility/Keyboard.hpp index d9f35921b..a7bb39f3a 100644 --- a/include/Nazara/Utility/Keyboard.hpp +++ b/include/Nazara/Utility/Keyboard.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once @@ -63,13 +63,13 @@ class NAZARA_API NzKeyboard F14, F15, - // Flèches directionnelles + // Flèches directionnelles Down, Left, Right, Up, - // Pavé numérique + // Pavé numérique Add, Divide, Multiply, @@ -140,18 +140,18 @@ class NAZARA_API NzKeyboard Browser_Search, Browser_Stop, - // Touches de contrôle de lecture + // Touches de contrôle de lecture Media_Next, Media_Play, Media_Previous, Media_Stop, - // Touches de contrôle du volume + // Touches de contrôle du volume Volume_Down, Volume_Mute, Volume_Up, - // Touches à verrouillage + // Touches à verrouillage CapsLock, NumLock, ScrollLock, diff --git a/include/Nazara/Utility/KeyframeMesh.hpp b/include/Nazara/Utility/KeyframeMesh.hpp index d2e894c51..eec42bbb9 100644 --- a/include/Nazara/Utility/KeyframeMesh.hpp +++ b/include/Nazara/Utility/KeyframeMesh.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 7b4072035..8fb29dbd5 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Mouse.hpp b/include/Nazara/Utility/Mouse.hpp index 37befe3ca..cad6046f0 100644 --- a/include/Nazara/Utility/Mouse.hpp +++ b/include/Nazara/Utility/Mouse.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 2f71927b7..611819d27 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index bac3ff377..9660a3d63 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -83,7 +83,7 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, it->second(width, height, depth, reinterpret_cast(src), reinterpret_cast(dst)); else { - // Flipping générique + // Flipping générique #if NAZARA_UTILITY_SAFE if (IsCompressed(format)) diff --git a/include/Nazara/Utility/ResourceLoader.hpp b/include/Nazara/Utility/ResourceLoader.hpp index 732d6de98..6cc1a08e1 100644 --- a/include/Nazara/Utility/ResourceLoader.hpp +++ b/include/Nazara/Utility/ResourceLoader.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/ResourceLoader.inl b/include/Nazara/Utility/ResourceLoader.inl index 9833cf40b..ee004d32e 100644 --- a/include/Nazara/Utility/ResourceLoader.inl +++ b/include/Nazara/Utility/ResourceLoader.inl @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -27,7 +27,7 @@ bool NzResourceLoader::LoadFromFile(Type* resource, const NzSt return false; } - // Récupération de tous les loaders de cette extension + // Récupération de tous les loaders de cette extension auto range = Type::s_fileLoaders.equal_range(ext); if (range.first == range.second) { @@ -35,7 +35,7 @@ bool NzResourceLoader::LoadFromFile(Type* resource, const NzSt return false; } - // range.second est un itérateur vers l'élément après le dernier élémént du range + // range.second est un itérateur vers l'élément après le dernier élémént du range auto it = range.second; do @@ -74,7 +74,7 @@ bool NzResourceLoader::LoadFromMemory(Type* resource, const vo for (auto loader = Type::s_memoryLoaders.rbegin(); loader != Type::s_memoryLoaders.rend(); ++loader) { - // Le loader supporte-t-il les données ? + // Le loader supporte-t-il les données ? if (!loader->first(data, size, parameters)) continue; @@ -111,7 +111,7 @@ bool NzResourceLoader::LoadFromStream(Type* resource, NzInputS { stream.SetCursorPos(streamPos); - // Le loader supporte-t-il les données ? + // Le loader supporte-t-il les données ? if (!loader->first(stream, parameters)) continue; @@ -158,7 +158,7 @@ void NzResourceLoader::UnregisterFileLoader(const NzString& ex for (const NzString& ext : exts) { - // Récupération de tous les loaders de cette extension + // Récupération de tous les loaders de cette extension auto range = Type::s_fileLoaders.equal_range(ext); for (auto it = range.first; it != range.second; ++it) diff --git a/include/Nazara/Utility/StaticMesh.hpp b/include/Nazara/Utility/StaticMesh.hpp index dbdbf2cc1..2d8ae3ec1 100644 --- a/include/Nazara/Utility/StaticMesh.hpp +++ b/include/Nazara/Utility/StaticMesh.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/SubMesh.hpp b/include/Nazara/Utility/SubMesh.hpp index ee4c6bd5a..f1acc4687 100644 --- a/include/Nazara/Utility/SubMesh.hpp +++ b/include/Nazara/Utility/SubMesh.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/Utility.hpp b/include/Nazara/Utility/Utility.hpp index 1133f0210..e7ce5fd90 100644 --- a/include/Nazara/Utility/Utility.hpp +++ b/include/Nazara/Utility/Utility.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/VertexBuffer.hpp b/include/Nazara/Utility/VertexBuffer.hpp index 51c5f154d..600152f7d 100644 --- a/include/Nazara/Utility/VertexBuffer.hpp +++ b/include/Nazara/Utility/VertexBuffer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 049fb43f7..09977ebe9 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #ifndef NAZARA_VERTEXDECLARATION_HPP diff --git a/include/Nazara/Utility/VideoMode.hpp b/include/Nazara/Utility/VideoMode.hpp index 248010977..f4a77815f 100644 --- a/include/Nazara/Utility/VideoMode.hpp +++ b/include/Nazara/Utility/VideoMode.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index ab803d30b..e7f070300 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once diff --git a/include/Nazara/Utility/WindowHandle.hpp b/include/Nazara/Utility/WindowHandle.hpp index 72cefce63..debf9ae4b 100644 --- a/include/Nazara/Utility/WindowHandle.hpp +++ b/include/Nazara/Utility/WindowHandle.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/ByteArray.cpp b/src/Nazara/Core/ByteArray.cpp index dcd688d24..d390d6611 100644 --- a/src/Nazara/Core/ByteArray.cpp +++ b/src/Nazara/Core/ByteArray.cpp @@ -1,4 +1,9 @@ -/*#include +/* +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include #include #include #include @@ -12,7 +17,7 @@ inline unsigned int nzPow2(unsigned int n) return x; } -// Cet algorithme est inspiré de la documentation de Qt +// Cet algorithme est inspiré de la documentation de Qt inline unsigned int nzGetNewSize(unsigned int newSize) { if (newSize < 20) @@ -146,7 +151,7 @@ NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bu unsigned int start = std::min(static_cast(pos), m_sharedArray->size); - // Si le buffer est déjà suffisamment grand + // Si le buffer est déjà suffisamment grand if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength) { EnsureOwnership(); @@ -195,7 +200,7 @@ NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray) unsigned int start = std::min(static_cast(pos), m_sharedArray->size); - // Si le buffer est déjà suffisamment grand + // Si le buffer est déjà suffisamment grand if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size) { EnsureOwnership(); diff --git a/src/Nazara/Core/Clock.cpp b/src/Nazara/Core/Clock.cpp index 5f685b3dc..a0a389a1e 100644 --- a/src/Nazara/Core/Clock.cpp +++ b/src/Nazara/Core/Clock.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Color.cpp b/src/Nazara/Core/Color.cpp index e7e583f2d..12144f0d5 100644 --- a/src/Nazara/Core/Color.cpp +++ b/src/Nazara/Core/Color.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/ConditionVariable.cpp b/src/Nazara/Core/ConditionVariable.cpp index 88337bb64..46900f1a8 100644 --- a/src/Nazara/Core/ConditionVariable.cpp +++ b/src/Nazara/Core/ConditionVariable.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Core.cpp b/src/Nazara/Core/Core.cpp index 0bd2ff041..bbe3d8950 100644 --- a/src/Nazara/Core/Core.cpp +++ b/src/Nazara/Core/Core.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -11,11 +11,11 @@ bool NzCore::Initialize() { if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé + return true; // Déjà initialisé // Initialisation du module - // Le noyau de Nazara n'a pour l'instant aucun besoin d'initialisation, mais dans le futur il est très probable que ce soit le cas. - // Donc en prévision, tous les modules initialisent le noyau + // Le noyau de Nazara n'a pour l'instant aucun besoin d'initialisation, mais dans le futur il est très probable que ce soit le cas. + // Donc en prévision, tous les modules initialisent le noyau NazaraNotice("Initialized: Core"); @@ -30,9 +30,9 @@ bool NzCore::IsInitialized() void NzCore::Uninitialize() { if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé + return; // Encore utilisé - // Libération du module + // Libération du module NazaraNotice("Uninitialized: Core"); } diff --git a/src/Nazara/Core/Debug/Leaks.cpp b/src/Nazara/Core/Debug/Leaks.cpp index 732b99a20..3fc4d3417 100644 --- a/src/Nazara/Core/Debug/Leaks.cpp +++ b/src/Nazara/Core/Debug/Leaks.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp index 35e96a967..b88073725 100644 --- a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp +++ b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Directory.cpp b/src/Nazara/Core/Directory.cpp index a614ba695..95bfe7a82 100644 --- a/src/Nazara/Core/Directory.cpp +++ b/src/Nazara/Core/Directory.cpp @@ -1,12 +1,12 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include -//#include +//#include #if defined(NAZARA_PLATFORM_WINDOWS) #include @@ -21,7 +21,7 @@ namespace { NzString currentPath(NzDirectoryImpl::GetCurrent()); - //static ThreadLocalVar currentPath(NzDirectoryImpl::GetCurrent()); + //static ThreadLocal currentPath(NzDirectoryImpl::GetCurrent()); } NzDirectory::NzDirectory() : @@ -247,7 +247,7 @@ bool NzDirectory::Create(const NzString& dirPath, bool recursive) return false; #ifdef NAZARA_PLATFORM_WINDOWS - // Contrairement au disque (Ex: "C:"), le chemin réseau n'est pas considéré comme un dossier (Ex: "\\Laptop") + // Contrairement au disque (Ex: "C:"), le chemin réseau n'est pas considéré comme un dossier (Ex: "\\Laptop") if (path.Match("\\\\*")) { foundPos = path.Find('\\', 2); @@ -304,7 +304,7 @@ bool NzDirectory::Remove(const NzString& dirPath, bool emptyDirectory) { NzDirectory dir(dirPath); if (!dir.Open()) - return NzDirectoryImpl::Remove(dirPath); // Si on n'arrive pas à ouvrir le dossier, on tente de le supprimer + return NzDirectoryImpl::Remove(dirPath); // Si on n'arrive pas à ouvrir le dossier, on tente de le supprimer while (dir.NextResult(true)) { diff --git a/src/Nazara/Core/DynLib.cpp b/src/Nazara/Core/DynLib.cpp index 4877698df..92e6d555a 100644 --- a/src/Nazara/Core/DynLib.cpp +++ b/src/Nazara/Core/DynLib.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index a81012b2e..302b12e88 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -52,7 +52,7 @@ NzString NzGetLastSystemError(unsigned int code) NzString error(NzString::Unicode(buffer)); LocalFree(buffer); - error.Trim(); // Pour une raison inconnue, Windows met deux-trois retours à la ligne après le message + error.Trim(); // Pour une raison inconnue, Windows met deux-trois retours à la ligne après le message return error; #elif defined(NAZARA_PLATFORM_POSIX) diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 6a4d8ae20..55cba809e 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -207,7 +207,7 @@ NzString NzFile::GetLine(unsigned int lineSize) #endif NzString line; - if (lineSize == 0) // Taille maximale indéterminée + if (lineSize == 0) // Taille maximale indéterminée { while (!m_impl->EndOfFile()) { @@ -293,7 +293,7 @@ std::size_t NzFile::Read(void* buffer, std::size_t size) return m_impl->Read(buffer, size); else { - // Si nous ne devons rien lire, nous avançons simplement + // Si nous ne devons rien lire, nous avançons simplement nzUInt64 currentPos = m_impl->GetCursorPos(); m_impl->SetCursorPos(NzFile::AtCurrent, size); @@ -464,7 +464,7 @@ bool NzFile::Write(const NzString& string) #if defined(NAZARA_PLATFORM_WINDOWS) temp.Replace("\n", "\r\n"); #elif defined(NAZARA_PLATFORM_LINUX) - // Rien à faire + // Rien à faire #elif defined(NAZARA_PLATFORM_MACOS) temp.Replace('\n', '\r'); #else @@ -554,7 +554,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath) base = "\\\\"; start = 2; } - else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine { NzString drive = NzDirectory::GetCurrent().SubstrTo('\\'); NzString end = path.Substr(1, -1); @@ -594,7 +594,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath) sep.erase(sep.begin() + i--); else if (sep[i] == "..") { - if (i > start) // Si nous ne sommes pas dans la partie protégée + if (i > start) // Si nous ne sommes pas dans la partie protégée sep.erase(sep.begin() + i--); sep.erase(sep.begin() + i--); @@ -605,7 +605,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath) pathLen += sep.size()-1; - ///FIXME: Le destructeur de NzStringStream provoque un bug lors de la libération de son vector + ///FIXME: Le destructeur de NzStringStream provoque un bug lors de la libération de son vector //NzStringStream stream(base); NzString stream; @@ -714,7 +714,7 @@ bool NzFile::IsAbsolute(const NzString& path) return true; else if (path.Match("\\\\*")) return true; - else if (wpath.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + else if (wpath.StartsWith('\\')) // Spécial : '\' fait référence au disque racine return true; else return false; diff --git a/src/Nazara/Core/Hash.cpp b/src/Nazara/Core/Hash.cpp index c3d48b39a..10c7a5685 100644 --- a/src/Nazara/Core/Hash.cpp +++ b/src/Nazara/Core/Hash.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/CRC32.cpp b/src/Nazara/Core/Hash/CRC32.cpp index 6a481e1c4..72c1ba982 100644 --- a/src/Nazara/Core/Hash/CRC32.cpp +++ b/src/Nazara/Core/Hash/CRC32.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -70,7 +70,7 @@ NzHashCRC32::NzHashCRC32(nzUInt32 polynomial) m_state = new NzHashCRC32_state; if (polynomial == 0x04c11db7) - m_state->table = crc32_table; // Table précalculée (Bien plus rapide) + m_state->table = crc32_table; // Table précalculée (Bien plus rapide) else { nzUInt32* table = new nzUInt32[256]; diff --git a/src/Nazara/Core/Hash/Fletcher16.cpp b/src/Nazara/Core/Hash/Fletcher16.cpp index e3c20b32d..d8e3cef40 100644 --- a/src/Nazara/Core/Hash/Fletcher16.cpp +++ b/src/Nazara/Core/Hash/Fletcher16.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/MD5.cpp b/src/Nazara/Core/Hash/MD5.cpp index 3095746e0..8ed3a724e 100644 --- a/src/Nazara/Core/Hash/MD5.cpp +++ b/src/Nazara/Core/Hash/MD5.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp /* diff --git a/src/Nazara/Core/Hash/SHA/Internal.cpp b/src/Nazara/Core/Hash/SHA/Internal.cpp index 40f9fcd68..d03ad9b9c 100644 --- a/src/Nazara/Core/Hash/SHA/Internal.cpp +++ b/src/Nazara/Core/Hash/SHA/Internal.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp /* diff --git a/src/Nazara/Core/Hash/SHA/Internal.hpp b/src/Nazara/Core/Hash/SHA/Internal.hpp index 8230964b0..57e733618 100644 --- a/src/Nazara/Core/Hash/SHA/Internal.hpp +++ b/src/Nazara/Core/Hash/SHA/Internal.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp /* diff --git a/src/Nazara/Core/Hash/SHA1.cpp b/src/Nazara/Core/Hash/SHA1.cpp index dd34c5b40..54b03169f 100644 --- a/src/Nazara/Core/Hash/SHA1.cpp +++ b/src/Nazara/Core/Hash/SHA1.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/SHA224.cpp b/src/Nazara/Core/Hash/SHA224.cpp index 499a8637b..b9cf3fd8e 100644 --- a/src/Nazara/Core/Hash/SHA224.cpp +++ b/src/Nazara/Core/Hash/SHA224.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/SHA256.cpp b/src/Nazara/Core/Hash/SHA256.cpp index 8f815f0b5..d99fdebf0 100644 --- a/src/Nazara/Core/Hash/SHA256.cpp +++ b/src/Nazara/Core/Hash/SHA256.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/SHA384.cpp b/src/Nazara/Core/Hash/SHA384.cpp index 33a2efccc..8252b5a1e 100644 --- a/src/Nazara/Core/Hash/SHA384.cpp +++ b/src/Nazara/Core/Hash/SHA384.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/SHA512.cpp b/src/Nazara/Core/Hash/SHA512.cpp index 5978e2718..2614b7d03 100644 --- a/src/Nazara/Core/Hash/SHA512.cpp +++ b/src/Nazara/Core/Hash/SHA512.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hash/Whirlpool.cpp b/src/Nazara/Core/Hash/Whirlpool.cpp index 337f41b58..907de024a 100644 --- a/src/Nazara/Core/Hash/Whirlpool.cpp +++ b/src/Nazara/Core/Hash/Whirlpool.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp /** diff --git a/src/Nazara/Core/HashDigest.cpp b/src/Nazara/Core/HashDigest.cpp index d86a0e53f..5b9802b80 100644 --- a/src/Nazara/Core/HashDigest.cpp +++ b/src/Nazara/Core/HashDigest.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Hashable.cpp b/src/Nazara/Core/Hashable.cpp index aa017f89c..65d0db8e6 100644 --- a/src/Nazara/Core/Hashable.cpp +++ b/src/Nazara/Core/Hashable.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/InputStream.cpp b/src/Nazara/Core/InputStream.cpp index d4705061d..2759f4d83 100644 --- a/src/Nazara/Core/InputStream.cpp +++ b/src/Nazara/Core/InputStream.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/LockGuard.cpp b/src/Nazara/Core/LockGuard.cpp index 34f04fd16..d2c3144f9 100644 --- a/src/Nazara/Core/LockGuard.cpp +++ b/src/Nazara/Core/LockGuard.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Log.cpp b/src/Nazara/Core/Log.cpp index 946182d62..7705651ee 100644 --- a/src/Nazara/Core/Log.cpp +++ b/src/Nazara/Core/Log.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/MemoryStream.cpp b/src/Nazara/Core/MemoryStream.cpp index 182d7f12e..03196651e 100644 --- a/src/Nazara/Core/MemoryStream.cpp +++ b/src/Nazara/Core/MemoryStream.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Mutex.cpp b/src/Nazara/Core/Mutex.cpp index 18df21009..67feba11c 100644 --- a/src/Nazara/Core/Mutex.cpp +++ b/src/Nazara/Core/Mutex.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Resource.cpp b/src/Nazara/Core/Resource.cpp index 810d02e0a..c83346d78 100644 --- a/src/Nazara/Core/Resource.cpp +++ b/src/Nazara/Core/Resource.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Semaphore.cpp b/src/Nazara/Core/Semaphore.cpp index 809af5b8d..d43c524a9 100644 --- a/src/Nazara/Core/Semaphore.cpp +++ b/src/Nazara/Core/Semaphore.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index 40642cb4e..419e748de 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -19,13 +19,13 @@ inline unsigned int nzPow2(unsigned int n) { unsigned int x = 1; - // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux + // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux while(x <= n) x <<= 1; return x; } -// Cet algorithme est inspiré de la documentation de Qt +// Cet algorithme est inspiré de la documentation de Qt inline unsigned int nzGetNewSize(unsigned int newSize) { if (newSize < 20) @@ -1174,7 +1174,7 @@ unsigned int NzString::FindLast(const char* string, int start, nzUInt32 flags) c if (flags & HandleUtf8) { if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère utf8::unchecked::iterator it(ptr); const char* t = string; @@ -1282,9 +1282,9 @@ unsigned int NzString::FindLast(const NzString& string, int start, nzUInt32 flag { if (flags & HandleUtf8) { - ///Algo 1.FindLast#3 (Itérateur non-adapté) + ///Algo 1.FindLast#3 (Itérateur non-adapté) if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère utf8::unchecked::iterator it(ptr); const char* t = string.m_sharedString->string; @@ -1559,13 +1559,13 @@ unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flag if (flags & HandleUtf8) { if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère utf8::unchecked::iterator it(ptr); if (flags & CaseInsensitive) { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); do { @@ -1607,7 +1607,7 @@ unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flag } else { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = utf8::unchecked::next(t); do { @@ -1742,13 +1742,13 @@ unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 if (flags & HandleUtf8) { if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère utf8::unchecked::iterator it(ptr); if (flags & CaseInsensitive) { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); do { @@ -1790,7 +1790,7 @@ unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 } else { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = utf8::unchecked::next(t); do { @@ -1917,13 +1917,13 @@ unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) c if (flags & HandleUtf8) { if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère utf8::unchecked::iterator it(ptr); if (flags & CaseInsensitive) { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); do @@ -1963,7 +1963,7 @@ unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) c } else { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); do @@ -2087,15 +2087,15 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag char* ptr = m_sharedString->string; if (flags & HandleUtf8) { - ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) + ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère utf8::unchecked::iterator it(ptr); if (flags & CaseInsensitive) { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); do @@ -2135,7 +2135,7 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag } else { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); do @@ -2213,7 +2213,7 @@ unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flag { while ((ptr = std::strstr(ptr, string.m_sharedString->string))) { - // Si le mot est bien isolé + // Si le mot est bien isolé if ((ptr == m_sharedString->string || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) return ptr - m_sharedString->string; @@ -2396,11 +2396,11 @@ NzString NzString::GetWord(unsigned int index, nzUInt32 flags) const if (m_sharedString->size == 0) return NzString(); - NzString temp = Simplified(flags); // Évitons les mauvaises surprises + NzString temp = Simplified(flags); // Évitons les mauvaises surprises if (temp.IsEmpty()) return NzString(); - unsigned int foundPos = temp.Find(' '); // Simplified nous assure que nous n'avons plus que des espaces comme séparation + unsigned int foundPos = temp.Find(' '); // Simplified nous assure que nous n'avons plus que des espaces comme séparation unsigned int lastPos = 0; for (; index > 0; --index) { @@ -2475,7 +2475,7 @@ NzString& NzString::Insert(int pos, char character) unsigned int start = std::min(static_cast(pos), m_sharedString->size); - // Si le buffer est déjà suffisamment grand + // Si le buffer est déjà suffisamment grand if (m_sharedString->capacity >= m_sharedString->size+1) { EnsureOwnership(); @@ -2520,7 +2520,7 @@ NzString& NzString::Insert(int pos, const char* string) unsigned int start = std::min(static_cast(pos), m_sharedString->size); - // Si le buffer est déjà suffisamment grand + // Si le buffer est déjà suffisamment grand unsigned int len = std::strlen(string); if (m_sharedString->capacity >= m_sharedString->size+len) { @@ -2571,7 +2571,7 @@ NzString& NzString::Insert(int pos, const NzString& string) unsigned int start = std::min(static_cast(pos), m_sharedString->size); - // Si le buffer est déjà suffisamment grand + // Si le buffer est déjà suffisamment grand if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) { EnsureOwnership(); @@ -2828,7 +2828,7 @@ unsigned int NzString::Replace(const char* oldString, const char* replaceString, { bool found = false; - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide while ((pos = Find(oldString, pos, flags)) != npos) { if (!found) @@ -2869,7 +2869,7 @@ unsigned int NzString::Replace(const char* oldString, const char* replaceString, count++; } - std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion + std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion ReleaseString(); m_sharedString = new SharedString; @@ -2898,7 +2898,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac { bool found = false; - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide while ((pos = Find(oldString, pos, flags)) != npos) { if (!found) @@ -2939,7 +2939,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac count++; } - std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion + std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion ReleaseString(); m_sharedString = new SharedString; @@ -2953,7 +2953,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags) { - ///FIXME: Ne gère pas l'UTF-8 + ///FIXME: Ne gère pas l'UTF-8 if (!oldCharacters || !oldCharacters[0]) return 0; @@ -3040,7 +3040,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact unsigned int count = 0; - if (rSize == 1) // On utilise un algorithme optimisé + if (rSize == 1) // On utilise un algorithme optimisé { EnsureOwnership(); @@ -3070,7 +3070,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact unsigned int j = 0; for (unsigned int i = 0; i < m_sharedString->size; ++i) { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier + if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier newString[j++] = m_sharedString->string[i]; else { @@ -3084,7 +3084,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact ++count; found = true; - break; // Simple façon d'éviter la ligne après la boucle + break; // Simple façon d'éviter la ligne après la boucle } } @@ -3119,7 +3119,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact unsigned int count = 0; - if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé + if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé { EnsureOwnership(); @@ -3149,7 +3149,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact unsigned int j = 0; for (unsigned int i = 0; i < m_sharedString->size; ++i) { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier + if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier newString[j++] = m_sharedString->string[i]; else { @@ -3163,7 +3163,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact ++count; found = true; - break; // Simple façon d'éviter la ligne après la boucle + break; // Simple façon d'éviter la ligne après la boucle } } @@ -3217,7 +3217,7 @@ NzString& NzString::Resize(int size, char character) { EnsureOwnership(); - // Nous avons déjà la place requise, contentons-nous de remplir le buffer + // Nous avons déjà la place requise, contentons-nous de remplir le buffer if (character != '\0' && newSize > m_sharedString->size) { char* ptr = &m_sharedString->string[m_sharedString->size]; @@ -3229,7 +3229,7 @@ NzString& NzString::Resize(int size, char character) m_sharedString->size = newSize; m_sharedString->string[newSize] = '\0'; } - else // On veut forcément agrandir la chaine + else // On veut forcément agrandir la chaine { char* newString = new char[newSize+1]; if (m_sharedString->size != 0) @@ -3832,7 +3832,7 @@ bool NzString::ToBool(bool* value, nzUInt32 flags) const else { if (flags & CaseInsensitive) - word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode + word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode if (word == "true") { diff --git a/src/Nazara/Core/StringStream.cpp b/src/Nazara/Core/StringStream.cpp index 600537fdf..04e2a281f 100644 --- a/src/Nazara/Core/StringStream.cpp +++ b/src/Nazara/Core/StringStream.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Thread.cpp b/src/Nazara/Core/Thread.cpp index 5938fe305..78fc2053b 100644 --- a/src/Nazara/Core/Thread.cpp +++ b/src/Nazara/Core/Thread.cpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Inspiré du code de la SFML par Laurent Gomila +// Inspiré du code de la SFML par Laurent Gomila #include #include diff --git a/src/Nazara/Core/Unicode.cpp b/src/Nazara/Core/Unicode.cpp index 95828049b..1cf9020aa 100644 --- a/src/Nazara/Core/Unicode.cpp +++ b/src/Nazara/Core/Unicode.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -9,16 +9,16 @@ #if NAZARA_CORE_INCLUDE_UNICODEDATA struct Character { - nzUInt16 category; // Le type du caractère - nzUInt8 direction; // Le sens de lecure du caractère - nzUInt32 lowerCase; // Le caractère correspondant en minuscule - nzUInt32 titleCase; // Le caractère correspondant en titre - nzUInt32 upperCase; // Le caractère correspondant en majuscule + nzUInt16 category; // Le type du caractère + nzUInt8 direction; // Le sens de lecure du caractère + nzUInt32 lowerCase; // Le caractère correspondant en minuscule + nzUInt32 titleCase; // Le caractère correspondant en titre + nzUInt32 upperCase; // Le caractère correspondant en majuscule }; #include -#else // Implémentation bidon +#else // Implémentation bidon NzUnicode::Category NzUnicode::GetCategory(char32_t character) { diff --git a/src/Nazara/Core/Win32/ClockImpl.cpp b/src/Nazara/Core/Win32/ClockImpl.cpp index 440d521c9..91772e3ea 100644 --- a/src/Nazara/Core/Win32/ClockImpl.cpp +++ b/src/Nazara/Core/Win32/ClockImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/ClockImpl.hpp b/src/Nazara/Core/Win32/ClockImpl.hpp index 6267951f2..83e54bb05 100644 --- a/src/Nazara/Core/Win32/ClockImpl.hpp +++ b/src/Nazara/Core/Win32/ClockImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/Win32/ConditionVariableImpl.cpp b/src/Nazara/Core/Win32/ConditionVariableImpl.cpp index 76cdf8cd9..1ddb7b9a9 100644 --- a/src/Nazara/Core/Win32/ConditionVariableImpl.cpp +++ b/src/Nazara/Core/Win32/ConditionVariableImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // Source: http://www.cs.wustl.edu/~schmidt/win32-cv-1.html diff --git a/src/Nazara/Core/Win32/ConditionVariableImpl.hpp b/src/Nazara/Core/Win32/ConditionVariableImpl.hpp index f4afa4545..11c700ff2 100644 --- a/src/Nazara/Core/Win32/ConditionVariableImpl.hpp +++ b/src/Nazara/Core/Win32/ConditionVariableImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // http://www.cs.wustl.edu/~schmidt/win32-cv-1.html diff --git a/src/Nazara/Core/Win32/DirectoryImpl.cpp b/src/Nazara/Core/Win32/DirectoryImpl.cpp index 59258cc27..03dce2f2c 100644 --- a/src/Nazara/Core/Win32/DirectoryImpl.cpp +++ b/src/Nazara/Core/Win32/DirectoryImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/DirectoryImpl.hpp b/src/Nazara/Core/Win32/DirectoryImpl.hpp index 799cee9c6..6b6e25d94 100644 --- a/src/Nazara/Core/Win32/DirectoryImpl.hpp +++ b/src/Nazara/Core/Win32/DirectoryImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/Win32/DynLibImpl.cpp b/src/Nazara/Core/Win32/DynLibImpl.cpp index 1cd9fa4a2..bfe2d9d87 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.cpp +++ b/src/Nazara/Core/Win32/DynLibImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/DynLibImpl.hpp b/src/Nazara/Core/Win32/DynLibImpl.hpp index 6688a98fd..7d742d32f 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.hpp +++ b/src/Nazara/Core/Win32/DynLibImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index 6154b1b65..56ad64855 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/FileImpl.hpp b/src/Nazara/Core/Win32/FileImpl.hpp index 8f3cf3ad0..37d66219c 100644 --- a/src/Nazara/Core/Win32/FileImpl.hpp +++ b/src/Nazara/Core/Win32/FileImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/Win32/MutexImpl.cpp b/src/Nazara/Core/Win32/MutexImpl.cpp index 9bebb187c..a8b735d3c 100644 --- a/src/Nazara/Core/Win32/MutexImpl.cpp +++ b/src/Nazara/Core/Win32/MutexImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/MutexImpl.hpp b/src/Nazara/Core/Win32/MutexImpl.hpp index 6356f9e9e..cb02f4e07 100644 --- a/src/Nazara/Core/Win32/MutexImpl.hpp +++ b/src/Nazara/Core/Win32/MutexImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/Win32/SemaphoreImpl.cpp b/src/Nazara/Core/Win32/SemaphoreImpl.cpp index c9df1ad4f..30af1edb4 100644 --- a/src/Nazara/Core/Win32/SemaphoreImpl.cpp +++ b/src/Nazara/Core/Win32/SemaphoreImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/SemaphoreImpl.hpp b/src/Nazara/Core/Win32/SemaphoreImpl.hpp index 637cc3664..49ef54843 100644 --- a/src/Nazara/Core/Win32/SemaphoreImpl.hpp +++ b/src/Nazara/Core/Win32/SemaphoreImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Core/Win32/ThreadImpl.cpp b/src/Nazara/Core/Win32/ThreadImpl.cpp index b38b6304f..e2d69bc84 100644 --- a/src/Nazara/Core/Win32/ThreadImpl.cpp +++ b/src/Nazara/Core/Win32/ThreadImpl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // Inspiré du code de la SFML par Laurent Gomila diff --git a/src/Nazara/Core/Win32/ThreadImpl.hpp b/src/Nazara/Core/Win32/ThreadImpl.hpp index 2e7cbd8ce..31b544869 100644 --- a/src/Nazara/Core/Win32/ThreadImpl.hpp +++ b/src/Nazara/Core/Win32/ThreadImpl.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp // Inspiré du code de la SFML par Laurent Gomila diff --git a/src/Nazara/Core/Win32/Time.cpp b/src/Nazara/Core/Win32/Time.cpp index 23643d39e..a7da94cb1 100644 --- a/src/Nazara/Core/Win32/Time.cpp +++ b/src/Nazara/Core/Win32/Time.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Core/Win32/Time.hpp b/src/Nazara/Core/Win32/Time.hpp index 952c2f240..0353c73ce 100644 --- a/src/Nazara/Core/Win32/Time.hpp +++ b/src/Nazara/Core/Win32/Time.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Noise/ComplexNoiseBase.cpp b/src/Nazara/Noise/ComplexNoiseBase.cpp index 0388a7786..dab569db5 100644 --- a/src/Nazara/Noise/ComplexNoiseBase.cpp +++ b/src/Nazara/Noise/ComplexNoiseBase.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Noise/Debug/Leaks.cpp b/src/Nazara/Noise/Debug/Leaks.cpp index aaba6c452..76e45432d 100644 --- a/src/Nazara/Noise/Debug/Leaks.cpp +++ b/src/Nazara/Noise/Debug/Leaks.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index a5d1b00ed..a38a8346d 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -12,9 +12,9 @@ bool NzNoise::Initialize() { if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé + return true; // Déjà initialisé - // Initialisation des dépendances + // Initialisation des dépendances if (!NzCore::Initialize()) { NazaraError("Failed to initialize core module"); @@ -36,11 +36,11 @@ bool NzNoise::IsInitialized() void NzNoise::Uninitialize() { if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé + return; // Encore utilisé - // Libération du module + // Libération du module - // Libération des dépendances + // Libération des dépendances NzCore::Uninitialize(); NazaraNotice("Uninitialized: Noise module"); diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp index 410e2b95d..f08546a02 100644 --- a/src/Nazara/Noise/NoiseBase.cpp +++ b/src/Nazara/Noise/NoiseBase.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index e695d46fe..e053eeff1 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine - Noise module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index 29d69ce0e..1dfc9787e 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -62,7 +62,7 @@ namespace break; default: - // Peut être rajouté par une extension + // Peut être rajouté par une extension ss << "Unknown"; break; } @@ -96,7 +96,7 @@ namespace break; default: - // Peut être rajouté par une extension + // Peut être rajouté par une extension ss << "Unknown"; break; } @@ -118,7 +118,7 @@ namespace break; default: - // Peut être rajouté par une extension + // Peut être rajouté par une extension ss << "Unknown"; break; } @@ -230,7 +230,7 @@ bool NzContext::SetActive(bool active) } #endif - // Si le contexte est déjà activé/désactivé + // Si le contexte est déjà activé/désactivé if ((currentContext == this) == active) return true; @@ -322,7 +322,7 @@ bool NzContext::Initialize() { NzContextParameters parameters; // parameters.compatibilityProfile = true; - parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même + parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même s_reference = new NzContext; if (!s_reference->Create(parameters)) @@ -333,7 +333,7 @@ bool NzContext::Initialize() return false; } - // Le contexte de référence doit rester désactivé pour le partage + // Le contexte de référence doit rester désactivé pour le partage s_reference->SetActive(false); NzContextParameters::defaultShareContext = s_reference; @@ -346,7 +346,7 @@ void NzContext::Uninitialize() for (NzContext* context : contexts) delete context; - contexts.clear(); // On supprime tous les contextes créés + contexts.clear(); // On supprime tous les contextes créés delete s_reference; s_reference = nullptr; diff --git a/src/Nazara/Renderer/ContextParameters.cpp b/src/Nazara/Renderer/ContextParameters.cpp index 04ecffee8..4f3914f7f 100644 --- a/src/Nazara/Renderer/ContextParameters.cpp +++ b/src/Nazara/Renderer/ContextParameters.cpp @@ -1,24 +1,24 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include -// Version majeure d'OpenGL, initialisé par NzOpenGL::Initialize() +// Version majeure d'OpenGL, initialisé par NzOpenGL::Initialize() nzUInt8 NzContextParameters::defaultMajorVersion; - // Version majeure d'OpenGL, initialisé par NzOpenGL::Initialize() + // Version majeure d'OpenGL, initialisé par NzOpenGL::Initialize() nzUInt8 NzContextParameters::defaultMinorVersion; -// Contexte de partage par défaut, initialisé par NzOpenGL::Initialize() +// Contexte de partage par défaut, initialisé par NzOpenGL::Initialize() const NzContext* NzContextParameters::defaultShareContext = nullptr; -// Si possible, garder la compatibilité avec les fonctionnalités dépréciées +// Si possible, garder la compatibilité avec les fonctionnalités dépréciées bool NzContextParameters::defaultCompatibilityProfile = false; -// Mode debug d'OpenGL par défaut +// Mode debug d'OpenGL par défaut #if NAZARA_RENDERER_OPENGL_DEBUG || defined(NAZARA_DEBUG) bool NzContextParameters::defaultDebugMode = true; #else diff --git a/src/Nazara/Renderer/Debug/Leaks.cpp b/src/Nazara/Renderer/Debug/Leaks.cpp index ee8f4be88..0d6c99ccd 100644 --- a/src/Nazara/Renderer/Debug/Leaks.cpp +++ b/src/Nazara/Renderer/Debug/Leaks.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLShader.cpp index aa17c7ede..22ebcc6fe 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLShader.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -14,7 +14,7 @@ namespace { - ///FIXME: Déclaré deux fois (ici et dans Renderer.cpp) + ///FIXME: Déclaré deux fois (ici et dans Renderer.cpp) const nzUInt8 attribIndex[] = { 2, // nzElementUsage_Diffuse @@ -111,9 +111,9 @@ bool NzGLSLShader::Compile() if (length > 1) { m_log.Clear(true); - m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) + m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) m_log.Prepend("Linkage error: "); - m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log + m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]); } @@ -191,7 +191,7 @@ NzString NzGLSLShader::GetSourceCode(nzShaderType type) const glGetShaderiv(m_shaders[type], GL_SHADER_SOURCE_LENGTH, &length); if (length > 1) { - source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin) + source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin) glGetShaderSource(m_shaders[type], length, nullptr, &source[0]); } @@ -260,9 +260,9 @@ bool NzGLSLShader::Load(nzShaderType type, const NzString& source) if (length > 1) { m_log.Clear(true); - m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) + m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) m_log.Prepend("Compilation error: "); - m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log + m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]); } @@ -384,7 +384,7 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) auto it = m_textures.find(location); if (it != m_textures.end()) { - // Slot déjà utilisé + // Slot déjà utilisé TextureSlot& slot = it->second; if (slot.texture != texture) { @@ -412,21 +412,21 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) return false; } - // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre + // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre nzUInt8 unit; if (unitUsed == 0) - // Pas d'unité utilisée, la tâche est simple + // Pas d'unité utilisée, la tâche est simple unit = 0; else { - auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map + auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map unit = it2->second.unit; if (unit == maxUnits-1) { - // Il y a une place libre, mais pas à la fin + // Il y a une place libre, mais pas à la fin for (; it2 != m_textures.rend(); ++it2) { - if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre + if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre { unit--; break; @@ -434,7 +434,7 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) } } else - // Il y a une place libre à la fin + // Il y a une place libre à la fin unit++; } diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLShader.hpp index b429daced..4cfb4d269 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLShader.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index a56223103..4549a46c8 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -37,8 +37,8 @@ namespace }; GLenum bufferUsage[] = { - // J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus" - // Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?) + // J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus" + // Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?) // Source: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=160839 GL_DYNAMIC_DRAW, // nzBufferUsage_Dynamic GL_STATIC_DRAW // nzBufferUsage_Static @@ -125,7 +125,7 @@ bool NzHardwareBuffer::Create(unsigned int size, nzBufferUsage usage) glBindBuffer(bufferTarget[m_type], m_buffer); glBufferData(bufferTarget[m_type], size, nullptr, bufferUsage[usage]); - // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent + // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent if (previous != 0) glBindBuffer(bufferTarget[m_type], previous); @@ -172,7 +172,7 @@ bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int if (glUnmapBuffer(bufferTarget[m_type]) != GL_TRUE) { - // Une erreur rare est survenue, nous devons réinitialiser le buffer + // Une erreur rare est survenue, nous devons réinitialiser le buffer NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetStorage()]); @@ -181,7 +181,7 @@ bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int } } - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) if (previous != m_buffer && previous != 0) glBindBuffer(bufferTarget[m_type], previous); @@ -202,7 +202,7 @@ void* NzHardwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned { NzContext::EnsureContext(); - // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent + // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent GLuint previous; glGetIntegerv(bufferTargetBinding[m_type], reinterpret_cast(&previous)); @@ -211,7 +211,7 @@ void* NzHardwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned void* ptr = mapBuffer(m_type, access, offset, size); - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérrations chaînées) + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérrations chaînées) if (previous != m_buffer && previous != 0) glBindBuffer(bufferTarget[m_type], previous); @@ -230,19 +230,19 @@ bool NzHardwareBuffer::Unmap() if (glUnmapBuffer(bufferTarget[m_type]) != GL_TRUE) { - // Une erreur rare est survenue, nous devons réinitialiser le buffer + // Une erreur rare est survenue, nous devons réinitialiser le buffer NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetStorage()]); - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) if (previous != m_buffer && previous != 0) glBindBuffer(bufferTarget[m_type], previous); return false; } - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) if (previous != m_buffer && previous != 0) glBindBuffer(bufferTarget[m_type], previous); diff --git a/src/Nazara/Renderer/HardwareBuffer.hpp b/src/Nazara/Renderer/HardwareBuffer.hpp index c2451adc2..d13d7ec1d 100644 --- a/src/Nazara/Renderer/HardwareBuffer.hpp +++ b/src/Nazara/Renderer/HardwareBuffer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Renderer/OcclusionQuery.cpp b/src/Nazara/Renderer/OcclusionQuery.cpp index 2b2d062cd..de2c7a660 100644 --- a/src/Nazara/Renderer/OcclusionQuery.cpp +++ b/src/Nazara/Renderer/OcclusionQuery.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index a8dfda1ea..992c58d05 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -69,7 +69,7 @@ namespace return false; } - // On peut sûrement faire plus rapide mais comme ça ne se fait qu'une fois et que NzString implémente le COW... + // On peut sûrement faire plus rapide mais comme ça ne se fait qu'une fois et que NzString implémente le COW... std::vector ext; extensionString.Split(ext); @@ -124,18 +124,18 @@ bool NzOpenGL::Initialize() return false; } - // Le chargement des fonctions OpenGL nécessite un contexte OpenGL + // Le chargement des fonctions OpenGL nécessite un contexte OpenGL NzContextParameters parameters; parameters.majorVersion = 2; parameters.minorVersion = 0; parameters.shared = false; /* - Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser - Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant - de créer le second avec les bons paramètres. + Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser + Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant + de créer le second avec les bons paramètres. - Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise + Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise */ /****************************************Initialisation****************************************/ @@ -158,9 +158,9 @@ bool NzOpenGL::Initialize() glXCreateContextAttribs = reinterpret_cast(LoadEntry("glXCreateContextAttribsARB", false)); #endif - // Récupération de la version d'OpenGL - // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée - // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... + // Récupération de la version d'OpenGL + // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée + // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... glGetString = reinterpret_cast(LoadEntry("glGetString", false)); if (!glGetString) { @@ -440,7 +440,7 @@ bool NzOpenGL::Initialize() glProgramUniform4fv = reinterpret_cast(LoadEntry("glProgramUniform4fv")); glProgramUniformMatrix4fv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4fv")); - // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double + // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double if (openGLextensions[NzOpenGL::FP64]) { glProgramUniform1d = reinterpret_cast(LoadEntry("glProgramUniform1d")); @@ -469,9 +469,9 @@ bool NzOpenGL::Initialize() { try { - // Hacky: Normalement incompatible à cause du internalFormat, GLenum pour l'extension et GLint pour le noyau - // Mais la taille du type étant la même (GLenum est un typedef équivalent à GLint) et Nazara n'utilisant pas - // Ce qui cause l'incompatibilité (les paramètres 1,2,3,4), je prends cette liberté + // Hacky: Normalement incompatible à cause du internalFormat, GLenum pour l'extension et GLint pour le noyau + // Mais la taille du type étant la même (GLenum est un typedef équivalent à GLint) et Nazara n'utilisant pas + // Ce qui cause l'incompatibilité (les paramètres 1,2,3,4), je prends cette liberté glTexImage3D = reinterpret_cast(LoadEntry("glTexImage3DEXT")); glTexSubImage3D = reinterpret_cast(LoadEntry("glTexSubImage3DEXT")); @@ -528,9 +528,9 @@ bool NzOpenGL::Initialize() if (!glGenerateMipmap) glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmapEXT", false)); - /****************************************Contexte de référence****************************************/ + /****************************************Contexte de référence****************************************/ - ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) + ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) if (!NzContext::Initialize()) { NazaraError("Failed to initialize contexts"); diff --git a/src/Nazara/Renderer/RenderTarget.cpp b/src/Nazara/Renderer/RenderTarget.cpp index 9a9be298d..e68761722 100644 --- a/src/Nazara/Renderer/RenderTarget.cpp +++ b/src/Nazara/Renderer/RenderTarget.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -25,5 +25,5 @@ bool NzRenderTarget::SetActive(bool active) void NzRenderTarget::Desactivate() { - // Seuls les target sans contextes (ex: NzRenderTexture) nécessitent une désactivation + // Seuls les target sans contextes (ex: NzRenderTexture) nécessitent une désactivation } diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index 46861f4eb..ffdbc21cc 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -39,7 +39,7 @@ NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& NzRenderWindow::~NzRenderWindow() { - // Nécessaire si NzWindow::Destroy est appelé par son destructeur + // Nécessaire si NzWindow::Destroy est appelé par son destructeur OnWindowDestroying(); } @@ -268,7 +268,7 @@ bool NzRenderWindow::OnWindowCreated() EnableVerticalSync(false); #if NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION - if (!SetActive(true)) // Les fenêtres s'activent à la création + if (!SetActive(true)) // Les fenêtres s'activent à la création NazaraWarning("Failed to activate window"); #endif diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 65e1aceee..01ec4afca 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include // Pour éviter une redéfinition de WIN32_LEAN_AND_MEAN +#include // Pour éviter une redéfinition de WIN32_LEAN_AND_MEAN #include #include #include @@ -31,7 +31,7 @@ namespace 0, // nzElementUsage_Position 3, // nzElementUsage_Tangent - 4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible) + 4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible) }; @@ -132,7 +132,7 @@ namespace GL_ZERO // nzStencilOperation_Zero }; - ///FIXME: Solution temporaire pour plus de facilité + ///FIXME: Solution temporaire pour plus de facilité enum nzMatrixCombination { nzMatrixCombination_ViewProj = nzMatrixType_Max+1, @@ -391,9 +391,9 @@ bool NzRenderer::HasCapability(nzRendererCap capability) bool NzRenderer::Initialize() { if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé + return true; // Déjà initialisé - // Initialisation des dépendances + // Initialisation des dépendances if (!NzUtility::Initialize()) { NazaraError("Failed to initialize utility module"); @@ -431,7 +431,7 @@ bool NzRenderer::Initialize() s_vertexBuffer = nullptr; s_vertexDeclaration = nullptr; - // Récupération des capacités + // Récupération des capacités s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter); s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64); s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 @@ -471,7 +471,7 @@ bool NzRenderer::Initialize() GLint maxVertexAttribs; glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); - // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) + // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) s_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord])); } else @@ -603,7 +603,7 @@ void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix) { s_matrix[type] = matrix; - // Cas particulier, la matrice projection doit être inversée sur l'axe Y à cause des conventions d'OpenGL + // Cas particulier, la matrice projection doit être inversée sur l'axe Y à cause des conventions d'OpenGL if (type == nzMatrixType_Projection) s_matrix[type] *= NzMatrix4f::Scale(NzVector3f(1.f, -1.f, 1.f)); @@ -648,7 +648,7 @@ bool NzRenderer::SetShader(NzShader* shader) return false; } - // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) + // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix"); s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix"); s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix"); @@ -815,12 +815,12 @@ void NzRenderer::SetViewport(const NzRectui& viewport) void NzRenderer::Uninitialize() { if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé + return; // Encore utilisé - // Libération du module + // Libération du module NzContext::EnsureContext(); - // Libération des VAOs + // Libération des VAOs for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it) { GLuint vao = static_cast(it->second); @@ -831,7 +831,7 @@ void NzRenderer::Uninitialize() NazaraNotice("Uninitialized: Renderer module"); - // Libération des dépendances + // Libération des dépendances NzUtility::Uninitialize(); } @@ -853,7 +853,7 @@ bool NzRenderer::EnsureStateUpdate() } #endif - // Il est plus rapide d'opérer sur l'implémentation du shader directement + // Il est plus rapide d'opérer sur l'implémentation du shader directement NzShaderImpl* shaderImpl = s_shader->m_impl; if (!shaderImpl->BindTextures()) @@ -868,7 +868,7 @@ bool NzRenderer::EnsureStateUpdate() } } - // Cas spéciaux car il faut recalculer la matrice + // Cas spéciaux car il faut recalculer la matrice if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) { s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; @@ -925,21 +925,21 @@ bool NzRenderer::EnsureStateUpdate() bool update; GLuint vao; - // Si les VAOs sont supportés, on entoure nos appels par ceux-ci + // Si les VAOs sont supportés, on entoure nos appels par ceux-ci if (vaoSupported) { - // On recherche si un VAO existe déjà avec notre configuration - // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration + // On recherche si un VAO existe déjà avec notre configuration + // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration); auto it = s_vaos.find(key); if (it == s_vaos.end()) { - // On créé notre VAO + // On créé notre VAO glGenVertexArrays(1, &vao); glBindVertexArray(vao); - // On l'ajoute à notre liste + // On l'ajoute à notre liste s_vaos.insert(std::make_pair(key, static_cast(vao))); // Et on indique qu'on veut le programmer @@ -947,14 +947,14 @@ bool NzRenderer::EnsureStateUpdate() } else { - // Notre VAO existe déjà, il est donc inutile de le reprogrammer + // Notre VAO existe déjà, il est donc inutile de le reprogrammer vao = it->second; update = false; } } else - update = true; // Fallback si les VAOs ne sont pas supportés + update = true; // Fallback si les VAOs ne sont pas supportés if (update) { @@ -991,11 +991,11 @@ bool NzRenderer::EnsureStateUpdate() if (vaoSupported) { - // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction + // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction if (update) glBindVertexArray(0); - // Nous (re)bindons le VAO pour définir les attributs de vertice + // Nous (re)bindons le VAO pour définir les attributs de vertice glBindVertexArray(vao); } diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index ec12ee1d1..51f0f89db 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Renderer/ShaderImpl.cpp b/src/Nazara/Renderer/ShaderImpl.cpp index 5f2b2976b..a05df390c 100644 --- a/src/Nazara/Renderer/ShaderImpl.cpp +++ b/src/Nazara/Renderer/ShaderImpl.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Renderer/ShaderImpl.hpp b/src/Nazara/Renderer/ShaderImpl.hpp index 94916904f..c47e526c8 100644 --- a/src/Nazara/Renderer/ShaderImpl.hpp +++ b/src/Nazara/Renderer/ShaderImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index cfe154a33..9c362d2f6 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -456,7 +456,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt LockTexture(impl); - // Vérification du support par la carte graphique + // Vérification du support par la carte graphique /*if (!CreateTexture(impl, true)) { NazaraError("Texture's parameters not supported by driver"); @@ -467,7 +467,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt return false; }*/ - // Création de la texture + // Création de la texture if (!CreateTexture(impl, false)) { NazaraError("Failed to create texture"); @@ -480,7 +480,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt m_impl = impl; - // Paramètres par défaut + // Paramètres par défaut SetFilterMode(nzTextureFilter_Nearest); SetMipmapRange(0, m_impl->levelCount); SetWrapMode(nzTextureWrap_Repeat); @@ -549,7 +549,7 @@ bool NzTexture::Download(NzImage* image) const unsigned int height = m_impl->height; unsigned int depth = m_impl->depth; - // Téléchargement... + // Téléchargement... for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) { glGetTexImage(openglTarget[m_impl->type], level, format.dataFormat, format.dataType, image->GetPixels(level)); @@ -566,7 +566,7 @@ bool NzTexture::Download(NzImage* image) const UnlockTexture(m_impl); - // Inversion de la texture pour le repère d'OpenGL + // Inversion de la texture pour le repère d'OpenGL if (!image->FlipVertically()) NazaraWarning("Failed to flip image"); @@ -1253,7 +1253,7 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - // Inversion de la texture pour le repère d'OpenGL + // Inversion de la texture pour le repère d'OpenGL NzImage mirrored; mirrored.Create(m_impl->type, m_impl->format, rect.width, rect.height); mirrored.Update(pixels); @@ -1350,7 +1350,7 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 leve nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - // Inversion de la texture pour le repère d'OpenGL + // Inversion de la texture pour le repère d'OpenGL unsigned int size = cube.width*cube.height*cube.depth*bpp; nzUInt8* mirrored = new nzUInt8[size]; if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, cube.width, cube.height, cube.depth, pixels, mirrored)) @@ -1505,7 +1505,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - // Inversion de la texture pour le repère d'OpenGL + // Inversion de la texture pour le repère d'OpenGL unsigned int size = rect.width*rect.height*bpp; nzUInt8* mirrored = new nzUInt8[size]; if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, rect.width, rect.height, 1, pixels, mirrored)) @@ -1562,12 +1562,12 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format) case nzPixelFormat_RGBA8: return true; - // Packed formats supportés depuis OpenGL 1.2 + // Packed formats supportés depuis OpenGL 1.2 case nzPixelFormat_RGB5A1: case nzPixelFormat_RGBA4: return true; - // Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..) + // Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..) case nzPixelFormat_L8: case nzPixelFormat_LA8: return false; @@ -1602,7 +1602,7 @@ bool NzTexture::IsTypeSupported(nzImageType type) case nzImageType_2D: case nzImageType_3D: case nzImageType_Cubemap: - return true; // Tous supportés nativement dans OpenGL 2 + return true; // Tous supportés nativement dans OpenGL 2 case nzImageType_1D_Array: case nzImageType_2D_Array: diff --git a/src/Nazara/Renderer/Win32/ContextImpl.cpp b/src/Nazara/Renderer/Win32/ContextImpl.cpp index 61fdb8388..5cb657f48 100644 --- a/src/Nazara/Renderer/Win32/ContextImpl.cpp +++ b/src/Nazara/Renderer/Win32/ContextImpl.cpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila +// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila #include #include @@ -129,7 +129,7 @@ bool NzContextImpl::Create(NzContextParameters& parameters) return false; } - // Arrivé ici, le format de pixel est choisi, nous récupérons donc les paramètres réels du futur contexte + // Arrivé ici, le format de pixel est choisi, nous récupérons donc les paramètres réels du futur contexte if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0) { parameters.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits; diff --git a/src/Nazara/Renderer/Win32/ContextImpl.hpp b/src/Nazara/Renderer/Win32/ContextImpl.hpp index 218829fb1..f640da789 100644 --- a/src/Nazara/Renderer/Win32/ContextImpl.hpp +++ b/src/Nazara/Renderer/Win32/ContextImpl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index 92e815f9c..eb4dcf3ca 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/AxisAlignedBox.cpp b/src/Nazara/Utility/AxisAlignedBox.cpp index 81b76cbb6..67a9fe15e 100644 --- a/src/Nazara/Utility/AxisAlignedBox.cpp +++ b/src/Nazara/Utility/AxisAlignedBox.cpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include #include @@ -55,7 +55,7 @@ void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box) } case nzExtend_Infinite: - // Rien à faire + // Rien à faire break; case nzExtend_Null: @@ -74,11 +74,11 @@ void NzAxisAlignedBox::ExtendTo(const NzVector3f& vector) break; case nzExtend_Infinite: - // Rien à faire + // Rien à faire break; case nzExtend_Null: - // Nous étendons l'AABB en la construisant de l'origine jusqu'au vecteur + // Nous étendons l'AABB en la construisant de l'origine jusqu'au vecteur m_cube.x = 0.f; m_cube.y = 0.f; m_cube.z = 0.f; diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index c537aeb03..cebc3e28a 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -88,7 +88,7 @@ bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage sto { Destroy(); - // On tente d'abord de faire un buffer hardware, si supporté + // On tente d'abord de faire un buffer hardware, si supporté if (s_bufferFunctions[storage]) { NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); @@ -113,7 +113,7 @@ bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage sto m_storage = storage; m_usage = usage; - // Si on arrive ici c'est que tout s'est bien passé. + // Si on arrive ici c'est que tout s'est bien passé. return true; } diff --git a/src/Nazara/Utility/BufferImpl.cpp b/src/Nazara/Utility/BufferImpl.cpp index 93ad045c4..16a037a87 100644 --- a/src/Nazara/Utility/BufferImpl.cpp +++ b/src/Nazara/Utility/BufferImpl.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Cursor.cpp b/src/Nazara/Utility/Cursor.cpp index f19b61cae..3f8e17873 100644 --- a/src/Nazara/Utility/Cursor.cpp +++ b/src/Nazara/Utility/Cursor.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Debug/Leaks.cpp b/src/Nazara/Utility/Debug/Leaks.cpp index 46b4e1abf..6089daa46 100644 --- a/src/Nazara/Utility/Debug/Leaks.cpp +++ b/src/Nazara/Utility/Debug/Leaks.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Icon.cpp b/src/Nazara/Utility/Icon.cpp index e2b8db5ce..f16506467 100644 --- a/src/Nazara/Utility/Icon.cpp +++ b/src/Nazara/Utility/Icon.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 79d4d16d9..3e6986677 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -84,7 +84,7 @@ bool NzImage::Convert(nzPixelFormat format) unsigned int width = m_sharedImage->width; unsigned int height = m_sharedImage->height; - // Les images 3D et cubemaps sont stockés de la même façon + // Les images 3D et cubemaps sont stockés de la même façon unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) @@ -101,7 +101,7 @@ bool NzImage::Convert(nzPixelFormat format) { NazaraError("Failed to convert image"); - // Nettoyage de la mémoire + // Nettoyage de la mémoire delete[] ptr; // Permet une optimisation de boucle (GCC) for (unsigned int j = 0; j < i; ++j) delete[] levels[j]; @@ -159,11 +159,11 @@ bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto } /* - Correctif temporaire : Update veut de la mémoire contigüe - Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour + Correctif temporaire : Update veut de la mémoire contigüe + Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour - FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) - (Appliquer l'interface à NzTexture également) + FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) + (Appliquer l'interface à NzTexture également) */ nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); unsigned int dstLineStride = srcCube.width*bpp; @@ -269,7 +269,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, for (unsigned int i = 0; i < levelCount; ++i) { - // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs + // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs try { levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBPP(format)]; @@ -1013,7 +1013,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) { - ///FIXME: Vérifier que ça fonctionne correctement + ///FIXME: Vérifier que ça fonctionne correctement #if NAZARA_UTILITY_SAFE if (!IsValid()) { diff --git a/src/Nazara/Utility/IndexBuffer.cpp b/src/Nazara/Utility/IndexBuffer.cpp index e14f30424..e6d7d3889 100644 --- a/src/Nazara/Utility/IndexBuffer.cpp +++ b/src/Nazara/Utility/IndexBuffer.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Keyboard.cpp b/src/Nazara/Utility/Keyboard.cpp index 236a04b2a..d463c6cb2 100644 --- a/src/Nazara/Utility/Keyboard.cpp +++ b/src/Nazara/Utility/Keyboard.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/KeyframeMesh.cpp b/src/Nazara/Utility/KeyframeMesh.cpp index c9d5fe0ff..fa9ee4e04 100644 --- a/src/Nazara/Utility/KeyframeMesh.cpp +++ b/src/Nazara/Utility/KeyframeMesh.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Loaders/MD2.hpp b/src/Nazara/Utility/Loaders/MD2.hpp index a0be386e6..16ad00424 100644 --- a/src/Nazara/Utility/Loaders/MD2.hpp +++ b/src/Nazara/Utility/Loaders/MD2.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Loaders/MD2/Constants.cpp b/src/Nazara/Utility/Loaders/MD2/Constants.cpp index 872e5c7dd..be963a524 100644 --- a/src/Nazara/Utility/Loaders/MD2/Constants.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Constants.cpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Loaders/MD2/Constants.hpp b/src/Nazara/Utility/Loaders/MD2/Constants.hpp index ae4263a98..9e9d9062b 100644 --- a/src/Nazara/Utility/Loaders/MD2/Constants.hpp +++ b/src/Nazara/Utility/Loaders/MD2/Constants.hpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #ifndef NAZARA_LOADERS_MD2_CONSTANTS_HPP #define NAZARA_LOADERS_MD2_CONSTANTS_HPP @@ -21,16 +21,16 @@ struct md2_header nzUInt32 num_skins; // nombre de skins nzUInt32 num_vertices; // nombre de vertices par frame - nzUInt32 num_st; // nombre de coordonnées de texture + nzUInt32 num_st; // nombre de coordonnées de texture nzUInt32 num_tris; // nombre de triangles nzUInt32 num_glcmds; // nombre de commandes opengl nzUInt32 num_frames; // nombre de frames - nzUInt32 offset_skins; // offset données skins - nzUInt32 offset_st; // offset données coordonnées de texture - nzUInt32 offset_tris; // offset données triangles - nzUInt32 offset_frames; // offset données frames - nzUInt32 offset_glcmds; // offset données commandes OpenGL + nzUInt32 offset_skins; // offset données skins + nzUInt32 offset_st; // offset données coordonnées de texture + nzUInt32 offset_tris; // offset données triangles + nzUInt32 offset_frames; // offset données frames + nzUInt32 offset_glcmds; // offset données commandes OpenGL nzUInt32 offset_end; // offset fin de fichier }; diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index cd9fc862b..d2fa86371 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2011 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include #include @@ -92,8 +92,8 @@ namespace return false; } - /// Création du mesh - // Animé ou statique, c'est la question + /// Création du mesh + // Animé ou statique, c'est la question bool animated; unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); @@ -103,7 +103,7 @@ namespace else animated = false; - if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait pas échouer + if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait pas échouer { NazaraInternalError("Failed to create mesh"); return false; @@ -129,11 +129,11 @@ namespace NzAnimation* animation = new NzAnimation; if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1)) { - // Décodage des séquences + // Décodage des séquences NzString frameName; NzSequence sequence; - sequence.framePerSecond = 10; // Par défaut pour les animations MD2 + sequence.framePerSecond = 10; // Par défaut pour les animations MD2 char name[16], last[16]; stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + offsetof(md2_frame, name)); @@ -165,9 +165,9 @@ namespace } name[pos+1] = '\0'; - if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom + if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom { - // Alors on enregistre la séquence + // Alors on enregistre la séquence sequence.firstFrame = i-numFrames; sequence.lastFrame = i-1; sequence.name = last; @@ -181,7 +181,7 @@ namespace numFrames++; } - // On ajoute la dernière frame (Qui n'a pas été traitée par la boucle) + // On ajoute la dernière frame (Qui n'a pas été traitée par la boucle) sequence.firstFrame = endFrame-numFrames; sequence.lastFrame = endFrame; sequence.name = last; @@ -196,7 +196,7 @@ namespace /// Chargement des submesh // Actuellement le loader ne charge qu'un submesh - // TODO: Utiliser les commandes OpenGL pour accélérer le rendu + // TODO: Utiliser les commandes OpenGL pour accélérer le rendu NzMD2Mesh* subMesh = new NzMD2Mesh(mesh); if (!subMesh->Create(header, stream, parameters)) { diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp index 1accab406..63db23e6b 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2011 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include #include @@ -37,7 +37,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz std::vector texCoords(header.num_st); std::vector triangles(header.num_tris); - // Lecture des coordonnées de texture + // Lecture des coordonnées de texture stream.SetCursorPos(header.offset_st); stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord)); @@ -71,7 +71,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz md2_frame frame; frame.vertices.resize(header.num_vertices); - // Pour que le modèle soit correctement aligné, on génère une matrice de rotation que nous appliquerons à chacune des vertices + // Pour que le modèle soit correctement aligné, on génère une matrice de rotation que nous appliquerons à chacune des vertices NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(90.f, -90.f, 0.f)); unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); @@ -94,7 +94,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz NzByteSwap(&frame.translate.z, sizeof(float)); #endif - m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice de la normale plutôt que la normale (gain d'espace) + m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice de la normale plutôt que la normale (gain d'espace) m_frames[i].vertices = new NzVector3f[m_vertexCount]; NzVector3f max, min; @@ -128,7 +128,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz return false; } - // On avance jusqu'aux premières coordonnées de texture + // On avance jusqu'aux premières coordonnées de texture ptr += s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_TexCoord)->offset; for (unsigned int t = 0; t < header.num_tris; ++t) { diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.hpp b/src/Nazara/Utility/Loaders/MD2/Mesh.hpp index baa5cc9a8..7135cd106 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.hpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Loaders/PCX.hpp b/src/Nazara/Utility/Loaders/PCX.hpp index 40bd5d3c2..efcfcd29a 100644 --- a/src/Nazara/Utility/Loaders/PCX.hpp +++ b/src/Nazara/Utility/Loaders/PCX.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Loaders/PCX/Loader.cpp b/src/Nazara/Utility/Loaders/PCX/Loader.cpp index abf21a8a7..6240461e3 100644 --- a/src/Nazara/Utility/Loaders/PCX/Loader.cpp +++ b/src/Nazara/Utility/Loaders/PCX/Loader.cpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include #include @@ -339,7 +339,7 @@ namespace } default: - NazaraError("Unable to load " + NzString::Number(bitCount) + " bitcount pcx files"); + NazaraError("Failed to load " + NzString::Number(bitCount) + " bitcount pcx files"); return false; } diff --git a/src/Nazara/Utility/Loaders/STB.hpp b/src/Nazara/Utility/Loaders/STB.hpp index 97886d7f3..9ea7d05c4 100644 --- a/src/Nazara/Utility/Loaders/STB.hpp +++ b/src/Nazara/Utility/Loaders/STB.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Loaders/STB/Loader.cpp b/src/Nazara/Utility/Loaders/STB/Loader.cpp index d5b260de0..ebdbac78f 100644 --- a/src/Nazara/Utility/Loaders/STB/Loader.cpp +++ b/src/Nazara/Utility/Loaders/STB/Loader.cpp @@ -1,6 +1,6 @@ -// Copyright (C) 2011 Jérôme Leclercq -// This file is part of the "Ungine". -// For conditions of distribution and use, see copyright notice in Core.h +// Copyright (C) 2011 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp #include #include diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index db61476ce..f082517da 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Mouse.cpp b/src/Nazara/Utility/Mouse.cpp index 206ea6c1d..17f44f992 100644 --- a/src/Nazara/Utility/Mouse.cpp +++ b/src/Nazara/Utility/Mouse.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index ee440c489..7c812f030 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -1139,7 +1139,7 @@ bool NzPixelFormat::Initialize() RegisterConverter(); /**********************************DXT1***********************************/ - ///TODO: Décompresseur DXT1 + ///TODO: Décompresseur DXT1 /* RegisterConverter(); RegisterConverter(); @@ -1162,7 +1162,7 @@ bool NzPixelFormat::Initialize() */ /**********************************DXT3***********************************/ - ///TODO: Décompresseur DXT3 + ///TODO: Décompresseur DXT3 /* RegisterConverter(); RegisterConverter(); @@ -1185,7 +1185,7 @@ bool NzPixelFormat::Initialize() */ /**********************************DXT5***********************************/ - ///TODO: Décompresseur DXT5 + ///TODO: Décompresseur DXT5 /* RegisterConverter(); RegisterConverter(); diff --git a/src/Nazara/Utility/SoftwareBuffer.cpp b/src/Nazara/Utility/SoftwareBuffer.cpp index 0fb3537c9..f2a7e8b13 100644 --- a/src/Nazara/Utility/SoftwareBuffer.cpp +++ b/src/Nazara/Utility/SoftwareBuffer.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -23,7 +23,7 @@ bool NzSoftwareBuffer::Create(unsigned int size, nzBufferUsage usage) { NazaraUnused(usage); - // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs + // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs try { m_buffer = new nzUInt8[size]; diff --git a/src/Nazara/Utility/SoftwareBuffer.hpp b/src/Nazara/Utility/SoftwareBuffer.hpp index 8df91b919..9c07b9e2d 100644 --- a/src/Nazara/Utility/SoftwareBuffer.hpp +++ b/src/Nazara/Utility/SoftwareBuffer.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index 7d72e29c6..a85273327 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -95,7 +95,7 @@ bool NzStaticMesh::GenerateAABB() const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position); if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3 { - // On lock le buffer pour itérer sur toutes les positions et composer notre AABB + // On lock le buffer pour itérer sur toutes les positions et composer notre AABB nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_ReadOnly)); if (!buffer) { @@ -181,6 +181,6 @@ void NzStaticMesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float i NazaraUnused(frameB); NazaraUnused(interpolation); - // Le safe mode est censé nous protéger de cet appel + // Le safe mode est censé nous protéger de cet appel NazaraError("Static mesh have no animation, please enable safe mode"); } diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index a44420423..fb382d97a 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -11,7 +11,7 @@ #include NzSubMesh::NzSubMesh(const NzMesh* parent) : -NzResource(false), // Un SubMesh n'est pas persistant par défaut +NzResource(false), // Un SubMesh n'est pas persistant par défaut m_parent(parent) { #ifdef NAZARA_DEBUG diff --git a/src/Nazara/Utility/Utility.cpp b/src/Nazara/Utility/Utility.cpp index 755b05120..095161214 100644 --- a/src/Nazara/Utility/Utility.cpp +++ b/src/Nazara/Utility/Utility.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -18,9 +18,9 @@ bool NzUtility::Initialize() { if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé + return true; // Déjà initialisé - // Initialisation des dépendances + // Initialisation des dépendances if (!NzCore::Initialize()) { NazaraError("Failed to initialize core module"); @@ -48,16 +48,16 @@ bool NzUtility::Initialize() return false; } - /// Loaders spécialisés + /// Loaders spécialisés // Mesh NzLoaders_MD2_Register(); // Loader de fichiers .MD2 (v8) // Image NzLoaders_PCX_Register(); // Loader de fichiers .PCX (1, 4, 8, 24) - /// Loaders génériques (En dernier pour donner la priorité aux loaders spécialisés) + /// Loaders génériques (En dernier pour donner la priorité aux loaders spécialisés) // Image - NzLoaders_STB_Register(); // Loader générique (STB) + NzLoaders_STB_Register(); // Loader générique (STB) NazaraNotice("Initialized: Utility module"); @@ -72,9 +72,9 @@ bool NzUtility::IsInitialized() void NzUtility::Uninitialize() { if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé + return; // Encore utilisé - // Libération du module + // Libération du module NzLoaders_MD2_Unregister(); NzLoaders_PCX_Unregister(); NzLoaders_STB_Unregister(); @@ -85,7 +85,7 @@ void NzUtility::Uninitialize() NazaraNotice("Uninitialized: Utility module"); - // Libération des dépendances + // Libération des dépendances NzCore::Uninitialize(); } diff --git a/src/Nazara/Utility/VertexBuffer.cpp b/src/Nazara/Utility/VertexBuffer.cpp index 639355e49..5062ee830 100644 --- a/src/Nazara/Utility/VertexBuffer.cpp +++ b/src/Nazara/Utility/VertexBuffer.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index 1d8f546f7..f6be21c60 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -113,7 +113,7 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e std::memset(&impl->elementPos, -1, (nzElementStream_Max+1)*(nzElementUsage_Max+1)*sizeof(int)); std::memset(&impl->streamPos, -1, (nzElementStream_Max+1)*sizeof(int)); - // On copie et trie les éléments + // On copie et trie les éléments impl->elements.resize(elementCount); std::memcpy(&impl->elements[0], elements, elementCount*sizeof(NzVertexElement)); std::sort(impl->elements.begin(), impl->elements.end(), VertexElementCompare); @@ -122,13 +122,13 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e { NzVertexElement& current = impl->elements[i]; #if NAZARA_UTILITY_SAFE - // Notre tableau étant trié, s'il y a collision, les deux éléments identiques se suivent... + // Notre tableau étant trié, s'il y a collision, les deux éléments identiques se suivent... if (i > 0) { - NzVertexElement& previous = impl->elements[i-1]; // On accède à l'élément précédent + NzVertexElement& previous = impl->elements[i-1]; // On accède à l'élément précédent if (previous.usage == current.usage && previous.usageIndex == current.usageIndex && previous.stream == current.stream) { - // Les deux éléments sont identiques là où ils ne devraient pas, nous avons une collision... + // Les deux éléments sont identiques là où ils ne devraient pas, nous avons une collision... NazaraError("Element usage 0x" + NzString::Number(current.usage, 16) + " collision with usage index " + NzString::Number(current.usageIndex) + " on stream 0x" + NzString::Number(current.stream, 16)); delete impl; @@ -141,7 +141,7 @@ bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int e impl->elementPos[current.stream][current.usage] = i; if (impl->streamPos[current.stream] == -1) - impl->streamPos[current.stream] = i; // Premier élément du stream (via le triage) + impl->streamPos[current.stream] = i; // Premier élément du stream (via le triage) impl->stride[current.stream] += size[current.type]; } diff --git a/src/Nazara/Utility/VideoMode.cpp b/src/Nazara/Utility/VideoMode.cpp index 85488b865..3beb43743 100644 --- a/src/Nazara/Utility/VideoMode.cpp +++ b/src/Nazara/Utility/VideoMode.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/VideoModeImpl.hpp b/src/Nazara/Utility/VideoModeImpl.hpp index 510d491fd..ee6bbddfa 100644 --- a/src/Nazara/Utility/VideoModeImpl.hpp +++ b/src/Nazara/Utility/VideoModeImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Win32/CursorImpl.cpp b/src/Nazara/Utility/Win32/CursorImpl.cpp index 10010535f..165e008d5 100644 --- a/src/Nazara/Utility/Win32/CursorImpl.cpp +++ b/src/Nazara/Utility/Win32/CursorImpl.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Win32/CursorImpl.hpp b/src/Nazara/Utility/Win32/CursorImpl.hpp index ba9fa63b7..b6cb61851 100644 --- a/src/Nazara/Utility/Win32/CursorImpl.hpp +++ b/src/Nazara/Utility/Win32/CursorImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Win32/IconImpl.cpp b/src/Nazara/Utility/Win32/IconImpl.cpp index 730017241..455b6a410 100644 --- a/src/Nazara/Utility/Win32/IconImpl.cpp +++ b/src/Nazara/Utility/Win32/IconImpl.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include diff --git a/src/Nazara/Utility/Win32/IconImpl.hpp b/src/Nazara/Utility/Win32/IconImpl.hpp index 9747283c3..2c9cc71be 100644 --- a/src/Nazara/Utility/Win32/IconImpl.hpp +++ b/src/Nazara/Utility/Win32/IconImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Win32/InputImpl.cpp b/src/Nazara/Utility/Win32/InputImpl.cpp index a91c92cce..0bc96168d 100644 --- a/src/Nazara/Utility/Win32/InputImpl.cpp +++ b/src/Nazara/Utility/Win32/InputImpl.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -31,7 +31,7 @@ NzVector2i NzEventImpl::GetMousePosition(const NzWindow& relativeTo) { NazaraError("Window's handle is invalid"); - // Attention que (-1, -1) est une position tout à fait valide et ne doit pas être utilisée pour tester l'erreur + // Attention que (-1, -1) est une position tout à fait valide et ne doit pas être utilisée pour tester l'erreur return NzVector2i(-1, -1); } } @@ -84,13 +84,13 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key) VK_F14, // Key::F14 VK_F15, // Key::F15 - // Flèches directionnelles + // Flèches directionnelles VK_DOWN, // Key::Down VK_LEFT, // Key::Left VK_RIGHT, // Key::Right VK_UP, // Key::Up - // Pavé numérique + // Pavé numérique VK_ADD, // Key::Add VK_DIVIDE, // Key::Divide VK_MULTIPLY, // Key::Multiply @@ -167,12 +167,12 @@ bool NzEventImpl::IsKeyPressed(NzKeyboard::Key key) VK_MEDIA_PREV_TRACK, // Key::Media_Previous, VK_MEDIA_STOP, // Key::Media_Stop, - // Touches de contrôle du volume + // Touches de contrôle du volume VK_VOLUME_DOWN, // Key::Volume_Down VK_VOLUME_MUTE, // Key::Volume_Mute VK_VOLUME_UP, // Key::Volume_Up - // Touches à verrouillage + // Touches à verrouillage VK_CAPITAL, // Key::CapsLock VK_NUMLOCK, // Key::NumLock VK_SCROLL // Key::ScrollLock diff --git a/src/Nazara/Utility/Win32/InputImpl.hpp b/src/Nazara/Utility/Win32/InputImpl.hpp index e140d21c8..41961312e 100644 --- a/src/Nazara/Utility/Win32/InputImpl.hpp +++ b/src/Nazara/Utility/Win32/InputImpl.hpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once diff --git a/src/Nazara/Utility/Win32/VideoModeImpl.cpp b/src/Nazara/Utility/Win32/VideoModeImpl.cpp index 73411cb63..147673979 100644 --- a/src/Nazara/Utility/Win32/VideoModeImpl.cpp +++ b/src/Nazara/Utility/Win32/VideoModeImpl.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -25,7 +25,7 @@ void NzVideoModeImpl::GetFullscreenModes(std::vector& modes) { NzVideoMode mode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); - // Il existe plusieurs modes avec ces trois caractéristques identiques + // Il existe plusieurs modes avec ces trois caractéristques identiques if (std::find(modes.begin(), modes.end(), mode) == modes.end()) modes.push_back(mode); } diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index ec8dd7b96..b44e6b9ee 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation +// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation #define OEMRESOURCE @@ -26,12 +26,12 @@ #define GWL_USERDATA GWLP_USERDATA #endif -// N'est pas définit avec MinGW apparemment +// N'est pas définit avec MinGW apparemment #ifndef MAPVK_VK_TO_VSC #define MAPVK_VK_TO_VSC 0 #endif -#undef IsMinimized // Conflit avec la méthode du même nom +#undef IsMinimized // Conflit avec la méthode du même nom namespace { @@ -71,20 +71,20 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl if (ChangeDisplaySettings(&win32Mode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { - // Situation extrêmement rare grâce à NzVideoMode::IsValid appelé par NzWindow + // Situation extrêmement rare grâce à NzVideoMode::IsValid appelé par NzWindow NazaraError("Failed to change display settings for fullscreen, this video mode is not supported by your computer"); fullscreen = false; } } - // Testé une seconde fois car sa valeur peut changer + // Testé une seconde fois car sa valeur peut changer if (fullscreen) { x = 0; y = 0; win32Style = WS_CLIPCHILDREN | WS_POPUP; - // Pour cacher la barre des tâches + // Pour cacher la barre des tâches // http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx win32StyleEx = WS_EX_APPWINDOW; @@ -126,7 +126,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl m_thread = new NzThread(WindowThread, &m_handle, win32StyleEx, wtitle, win32Style, x, y, width, height, this, &mutex, &condition); m_threadActive = true; - // On attend que la fenêtre soit créée + // On attend que la fenêtre soit créée mutex.Lock(); m_thread->Launch(); condition.Wait(&mutex); @@ -178,7 +178,7 @@ void NzWindowImpl::Destroy() if (m_thread) { m_threadActive = false; - PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread + PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread m_thread->Join(); delete m_thread; @@ -234,7 +234,7 @@ NzString NzWindowImpl::GetTitle() const if (titleSize == 0) return NzString(); - titleSize++; // Caractère nul + titleSize++; // Caractère nul wchar_t* wTitle = new wchar_t[titleSize]; GetWindowTextW(m_handle, wTitle, titleSize); @@ -353,7 +353,7 @@ void NzWindowImpl::SetCursor(nzWindowCursor cursor) break; } - // Pas besoin de libérer le curseur par la suite s'il est partagé + // Pas besoin de libérer le curseur par la suite s'il est partagé // http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx ::SetCursor(m_cursor); } @@ -437,7 +437,7 @@ void NzWindowImpl::SetPosition(int x, int y) void NzWindowImpl::SetSize(unsigned int width, unsigned int height) { - // SetWindowPos demande la taille totale de la fenêtre + // SetWindowPos demande la taille totale de la fenêtre RECT rect = {0, 0, static_cast(width), static_cast(height)}; AdjustWindowRect(&rect, GetWindowLongPtr(m_handle, GWL_STYLE), false); @@ -466,7 +466,7 @@ void NzWindowImpl::SetVisible(bool visible) bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam) { - // Inutile de récupérer des évènements ne venant pas de notre fenêtre + // Inutile de récupérer des évènements ne venant pas de notre fenêtre if (m_handle != window) return false; @@ -531,7 +531,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA event.type = nzEventType_Quit; m_parent->PushEvent(event); - return true; // Afin que Windows ne ferme pas la fenêtre automatiquement + return true; // Afin que Windows ne ferme pas la fenêtre automatiquement } #if !NAZARA_UTILITY_THREADED_WINDOW @@ -545,7 +545,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA { m_sizemove = false; - // On vérifie ce qui a changé + // On vérifie ce qui a changé NzVector2i position = GetPosition(); if (m_position != position) { @@ -621,8 +621,8 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA case WM_LBUTTONDBLCLK: { - // Cet évènement est généré à la place d'un WM_LBUTTONDOWN lors d'un double-clic. - // Comme nous désirons quand même notifier chaque clic, nous envoyons les deux évènements. + // Cet évènement est généré à la place d'un WM_LBUTTONDOWN lors d'un double-clic. + // Comme nous désirons quand même notifier chaque clic, nous envoyons les deux évènements. NzEvent event; event.mouseButton.button = NzMouse::Left; event.mouseButton.x = GET_X_LPARAM(lParam); @@ -701,7 +701,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA break; } - // Nécessite un appel précédent à TrackMouseEvent (Fait dans WM_MOUSEMOVE) + // Nécessite un appel précédent à TrackMouseEvent (Fait dans WM_MOUSEMOVE) // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645615(v=vs.85).aspx case WM_MOUSELEAVE: { @@ -860,7 +860,7 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA if (!m_sizemove && wParam != SIZE_MINIMIZED) #endif { - NzVector2ui size = GetSize(); // On récupère uniquement la taille de la zone client + NzVector2ui size = GetSize(); // On récupère uniquement la taille de la zone client #if !NAZARA_UTILITY_THREADED_WINDOW if (m_size == size) break; @@ -941,14 +941,14 @@ bool NzWindowImpl::HandleMessage(HWND window, UINT message, WPARAM wParam, LPARA bool NzWindowImpl::Initialize() { - // Nous devons faire un type Unicode pour que la fenêtre le soit également + // Nous devons faire un type Unicode pour que la fenêtre le soit également // http://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx WNDCLASSW windowClass; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hbrBackground = nullptr; - windowClass.hCursor = nullptr; // Le curseur est définit dynamiquement - windowClass.hIcon = nullptr; // L'icône est définie dynamiquement + windowClass.hCursor = nullptr; // Le curseur est définit dynamiquement + windowClass.hIcon = nullptr; // L'icône est définie dynamiquement windowClass.hInstance = GetModuleHandle(nullptr); windowClass.lpfnWndProc = MessageHandler; windowClass.lpszClassName = className; @@ -1125,7 +1125,7 @@ void NzWindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* titl mutex->Lock(); condition->Signal(); mutex->Unlock(); - // mutex et condition sont considérés invalides à partir d'ici + // mutex et condition sont considérés invalides à partir d'ici while (window->m_threadActive) window->ProcessEvents(true); diff --git a/src/Nazara/Utility/Win32/WindowImpl.hpp b/src/Nazara/Utility/Win32/WindowImpl.hpp index bb566ebda..5dc4cd458 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.hpp +++ b/src/Nazara/Utility/Win32/WindowImpl.hpp @@ -1,8 +1,8 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -// Interface inspirée de la SFML par Laurent Gomila +// Interface inspirée de la SFML par Laurent Gomila #pragma once @@ -26,7 +26,7 @@ class NzThread; #endif class NzWindow; -#undef IsMinimized // Conflit avec la méthode du même nom +#undef IsMinimized // Conflit avec la méthode du même nom class NzWindowImpl : NzNonCopyable { diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index 5e476dbaf..a9d3e1ed2 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -1,5 +1,5 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine". +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include @@ -87,7 +87,7 @@ NzWindow::~NzWindow() bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) { - // Si la fenêtre est déjà ouverte, nous conservons sa position + // Si la fenêtre est déjà ouverte, nous conservons sa position bool opened = IsOpen(); NzVector2i position; if (opened) @@ -95,7 +95,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) Destroy(); - // Inspiré du code de la SFML par Laurent Gomila + // Inspiré du code de la SFML par Laurent Gomila if (style & nzWindowStyle_Fullscreen) { if (fullscreenWindow) @@ -138,7 +138,7 @@ bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) return false; } - // Paramètres par défaut + // Paramètres par défaut m_impl->EnableKeyRepeat(true); m_impl->EnableSmoothScrolling(false); m_impl->SetCursor(nzWindowCursor_Default); @@ -337,7 +337,7 @@ void NzWindow::SetEventListener(bool listener) m_impl->SetEventListener(listener); if (!listener) { - // On vide la pile des évènements + // On vide la pile des évènements NzLockGuard lock(m_eventMutex); while (!m_events.empty()) m_events.pop(); @@ -345,7 +345,7 @@ void NzWindow::SetEventListener(bool listener) #else if (m_ownsWindow) { - // Inutile de transmettre l'ordre dans ce cas-là + // Inutile de transmettre l'ordre dans ce cas-là if (!listener) NazaraError("A non-threaded window needs to listen to events"); } From 15afde86c84f65f543d202f0e7f8ba161273b092 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 18 Aug 2012 01:46:01 +0200 Subject: [PATCH 05/31] Rewritted ResourceLoader and moved it to core Added creation constructor to NzImage Added member function functor Added option to build Nazara as one library (instead of many) Fixed some 2011 copyrights Made use of "using def = T" C++11 feature instead of some illigible typedefs Removed unused premake file --- .../build/scripts/module/modulename.lua | 32 +-- build/scripts/common.lua | 7 + build/scripts/common_examples.lua | 5 +- build/scripts/module/core.lua | 14 +- build/scripts/module/noise.lua | 40 ++-- build/scripts/module/renderer.lua | 40 ++-- build/scripts/module/utility.lua | 32 +-- examples/AnimatedMesh/build.lua | 46 +++-- examples/ListSequences/build.lua | 38 ++-- include/Nazara/Core/DynLib.hpp | 2 +- include/Nazara/Core/Enums.hpp | 5 +- include/Nazara/Core/File.hpp | 6 +- include/Nazara/Core/Functor.hpp | 27 ++- include/Nazara/Core/Functor.inl | 36 +++- include/Nazara/Core/Hashable.hpp | 1 - include/Nazara/Core/Mutex.hpp | 1 - include/Nazara/Core/ResourceLoader.hpp | 36 ++++ include/Nazara/Core/ResourceLoader.inl | 142 +++++++++++++ include/Nazara/Core/Thread.hpp | 9 +- include/Nazara/Core/Thread.inl | 18 +- include/Nazara/Core/Tuple.inl | 8 +- include/Nazara/Renderer/Context.hpp | 2 +- include/Nazara/Renderer/OpenGL.hpp | 4 +- include/Nazara/Renderer/Shader.hpp | 7 +- include/Nazara/Renderer/Texture.hpp | 1 - include/Nazara/Utility/Animation.hpp | 12 +- include/Nazara/Utility/AxisAlignedBox.hpp | 2 +- include/Nazara/Utility/Buffer.hpp | 5 +- include/Nazara/Utility/Cursor.hpp | 1 - include/Nazara/Utility/Enums.hpp | 2 +- include/Nazara/Utility/Icon.hpp | 1 - include/Nazara/Utility/Image.hpp | 17 +- include/Nazara/Utility/Mesh.hpp | 12 +- include/Nazara/Utility/PixelFormat.hpp | 4 +- include/Nazara/Utility/ResourceLoader.hpp | 43 ---- include/Nazara/Utility/ResourceLoader.inl | 187 ------------------ include/Nazara/Utility/Window.hpp | 4 +- src/Nazara/Core/Win32/MutexImpl.hpp | 2 - src/Nazara/Renderer/HardwareBuffer.cpp | 2 +- src/Nazara/Renderer/OpenGL.cpp | 6 +- src/Nazara/Renderer/Renderer.cpp | 4 +- src/Nazara/Renderer/Shader.cpp | 10 +- src/Nazara/Renderer/ShaderImpl.hpp | 1 - src/Nazara/Renderer/Texture.cpp | 52 ++--- src/Nazara/Utility/Animation.cpp | 5 +- src/Nazara/Utility/Image.cpp | 51 +++-- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 76 ++----- src/Nazara/Utility/Loaders/MD2/Mesh.cpp | 2 +- src/Nazara/Utility/Loaders/PCX/Loader.cpp | 52 +---- src/Nazara/Utility/Loaders/STB/Loader.cpp | 54 +---- src/Nazara/Utility/Mesh.cpp | 5 +- 51 files changed, 542 insertions(+), 629 deletions(-) create mode 100644 include/Nazara/Core/ResourceLoader.hpp create mode 100644 include/Nazara/Core/ResourceLoader.inl delete mode 100644 include/Nazara/Utility/ResourceLoader.hpp delete mode 100644 include/Nazara/Utility/ResourceLoader.inl diff --git a/NazaraModuleTemplate/build/scripts/module/modulename.lua b/NazaraModuleTemplate/build/scripts/module/modulename.lua index 31847eb8c..c1d8d7d12 100644 --- a/NazaraModuleTemplate/build/scripts/module/modulename.lua +++ b/NazaraModuleTemplate/build/scripts/module/modulename.lua @@ -1,4 +1,6 @@ -project "NazaraModuleName" +if (not _OPTIONS["one-library"]) then + project "NazaraModuleName" +end files { @@ -14,18 +16,22 @@ else excludes { "../src/Nazara/ModuleName/Win32/*.hpp", "../src/Nazara/ModuleName/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraModuleNamed" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Audio/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraModuleNamed" -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraModuleName" + configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraModuleName" -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraModuleNamed" + configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraModuleNamed" -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraModuleName" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraModuleName" +end \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index c531d7c52..797db69d4 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -19,6 +19,13 @@ includedirs } libdirs "../lib" + +if (_OPTIONS["x64"]) then + libdirs "../extlibs/lib/x64" +end + +libdirs "../extlibs/lib/x86" + targetdir "../lib" configuration "Debug*" diff --git a/build/scripts/common_examples.lua b/build/scripts/common_examples.lua index 0ef097298..03b087a3d 100644 --- a/build/scripts/common_examples.lua +++ b/build/scripts/common_examples.lua @@ -10,10 +10,7 @@ configurations language "C++" location("../examples/build/" .. _ACTION) -includedirs -{ - "../include" -} +includedirs "../include" debugdir "../examples/bin" libdirs "../lib" diff --git a/build/scripts/module/core.lua b/build/scripts/module/core.lua index 4efb6b578..fcd8efb4d 100644 --- a/build/scripts/module/core.lua +++ b/build/scripts/module/core.lua @@ -1,4 +1,6 @@ -project "NazaraCore" +if (not _OPTIONS["one-library"]) then + project "NazaraCore" +end files { @@ -17,8 +19,10 @@ else excludes { "../src/Nazara/Core/Win32/**.hpp", "../src/Nazara/Core/Win32/**.cpp" } end -configuration "Debug*" - targetname "NazaraCored" +if (not _OPTIONS["one-library"]) then + configuration "Debug*" + targetname "NazaraCored" -configuration "Release*" - targetname "NazaraCore" + configuration "Release*" + targetname "NazaraCore" +end \ No newline at end of file diff --git a/build/scripts/module/noise.lua b/build/scripts/module/noise.lua index 55f21fc76..0d9cc325e 100644 --- a/build/scripts/module/noise.lua +++ b/build/scripts/module/noise.lua @@ -1,11 +1,13 @@ -project "NazaraNoise" +if (not _OPTIONS["one-library"]) then + project "NazaraNoise" +end files { - "../include/Nazara/Noise/**.hpp", - "../include/Nazara/Noise/**.inl", - "../src/Nazara/Noise/**.hpp", - "../src/Nazara/Noise/**.cpp" + "../include/Nazara/Noise/**.hpp", + "../include/Nazara/Noise/**.inl", + "../src/Nazara/Noise/**.hpp", + "../src/Nazara/Noise/**.cpp" } if (os.is("windows")) then @@ -14,18 +16,22 @@ else excludes { "../src/Nazara/Noise/Win32/*.hpp", "../src/Nazara/Noise/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraNoised" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Noise/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraNoised" -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraNoise" + configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraNoise" -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraNoised" + configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraNoised" -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraNoise" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraNoise" +end \ No newline at end of file diff --git a/build/scripts/module/renderer.lua b/build/scripts/module/renderer.lua index 9529919f7..7419c05b0 100644 --- a/build/scripts/module/renderer.lua +++ b/build/scripts/module/renderer.lua @@ -1,4 +1,6 @@ -project "NazaraRenderer" +if (not _OPTIONS["one-library"]) then + project "NazaraRenderer" +end files { @@ -17,22 +19,26 @@ else excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraUtilityd-s" - targetname "NazaraRendererd" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + links "NazaraUtilityd-s" + targetname "NazaraRendererd" -configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraUtility-s" - targetname "NazaraRenderer" + configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraUtility-s" + targetname "NazaraRenderer" -configuration "DebugDLL" - links "NazaraCored" - links "NazaraUtilityd" - targetname "NazaraRendererd" + configuration "DebugDLL" + links "NazaraCored" + links "NazaraUtilityd" + targetname "NazaraRendererd" -configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraUtility" - targetname "NazaraRenderer" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraUtility" + targetname "NazaraRenderer" +end \ No newline at end of file diff --git a/build/scripts/module/utility.lua b/build/scripts/module/utility.lua index 183abe974..81091bcef 100644 --- a/build/scripts/module/utility.lua +++ b/build/scripts/module/utility.lua @@ -1,4 +1,6 @@ -project "NazaraUtility" +if (not _OPTIONS["one-library"]) then + project "NazaraUtility" +end defines "STBI_NO_STDIO" @@ -18,18 +20,22 @@ else excludes { "../src/Nazara/Utility/Win32/*.hpp", "../src/Nazara/Utility/Win32/*.cpp" } end -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraUtilityd" +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Utility/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraUtilityd" -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraUtility" + configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraUtility" -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraUtilityd" + configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraUtilityd" -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraUtility" \ No newline at end of file + configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraUtility" +end \ No newline at end of file diff --git a/examples/AnimatedMesh/build.lua b/examples/AnimatedMesh/build.lua index 4d93b53c9..d45cb5983 100644 --- a/examples/AnimatedMesh/build.lua +++ b/examples/AnimatedMesh/build.lua @@ -2,22 +2,36 @@ kind "ConsoleApp" files "main.cpp" -configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraRendererd-s" - links "NazaraUtilityd-s" +if (_OPTIONS["one-library"]) then + configuration "DebugStatic" + links "Nazarad-s" -configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraRenderer-s" - links "NazaraUtility-s" + configuration "ReleaseStatic" + links "Nazara-s" -configuration "DebugDLL" - links "NazaraCored" - links "NazaraRendererd" - links "NazaraUtilityd" + configuration "DebugDLL" + links "Nazarad" -configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraRenderer" - links "NazaraUtility" \ No newline at end of file + configuration "ReleaseDLL" + links "Nazara" +else + configuration "DebugStatic" + links "NazaraRendererd-s" + links "NazaraUtilityd-s" + links "NazaraCored-s" + + configuration "ReleaseStatic" + links "NazaraRenderer-s" + links "NazaraUtility-s" + links "NazaraCore-s" + + configuration "DebugDLL" + links "NazaraRendererd" + links "NazaraCored" + links "NazaraUtilityd" + + configuration "ReleaseDLL" + links "NazaraRenderer" + links "NazaraUtility" + links "NazaraCore" +end diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua index 022a86bc8..a522b53f6 100644 --- a/examples/ListSequences/build.lua +++ b/examples/ListSequences/build.lua @@ -2,18 +2,32 @@ kind "ConsoleApp" files "main.cpp" -configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraUtilityd-s" +if (_OPTIONS["one-library"]) then + configuration "DebugStatic" + links "Nazarad-s" -configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraUtility-s" + configuration "ReleaseStatic" + links "Nazara-s" -configuration "DebugDLL" - links "NazaraCored" - links "NazaraUtilityd" + configuration "DebugDLL" + links "Nazarad" -configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraUtility" \ No newline at end of file + configuration "ReleaseDLL" + links "Nazara" +else + configuration "DebugStatic" + links "NazaraCored-s" + links "NazaraUtilityd-s" + + configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraUtility-s" + + configuration "DebugDLL" + links "NazaraCored" + links "NazaraUtilityd" + + configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraUtility" +end diff --git a/include/Nazara/Core/DynLib.hpp b/include/Nazara/Core/DynLib.hpp index dc95e616a..7359bca5f 100644 --- a/include/Nazara/Core/DynLib.hpp +++ b/include/Nazara/Core/DynLib.hpp @@ -22,7 +22,7 @@ typedef int (*NzDynLibFunc)(); // Type "générique" de pointeur sur fonction class NzDynLib : NzNonCopyable { - friend class NzDynLibImpl; + friend NzDynLibImpl; public: NzDynLib(const NzString& libraryPath); diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index f97348afc..38f06d8de 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -9,9 +9,10 @@ enum nzEndianness { + nzEndianness_Unknown = -1, + nzEndianness_BigEndian, - nzEndianness_LittleEndian, - nzEndianness_Unknown + nzEndianness_LittleEndian }; enum nzErrorType diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index aa84ec68e..3bb64342e 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -38,11 +38,11 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable { Current = 0x00, // Utilise le mode d'ouverture actuel - Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin - Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert + Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin + Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert ReadOnly = 0x04, // Ouvre uniquement en lecture ReadWrite = 0x08, // Ouvre en lecture/écriture - Text = 0x10, // Ouvre en mode texte + Text = 0x10, // Ouvre en mode texte Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas }; diff --git a/include/Nazara/Core/Functor.hpp b/include/Nazara/Core/Functor.hpp index 656b6a866..6429452f8 100644 --- a/include/Nazara/Core/Functor.hpp +++ b/include/Nazara/Core/Functor.hpp @@ -18,27 +18,40 @@ struct NzFunctor virtual void Run() = 0; }; -template struct NzFunctorWithoutArgs : NzFunctor +template +struct NzFunctorWithoutArgs : NzFunctor { NzFunctorWithoutArgs(F func); void Run(); - F function; + private: + F m_func; }; -template struct NzFunctorWithArgs : NzFunctor +template +struct NzFunctorWithArgs : NzFunctor { NzFunctorWithArgs(F func, Args&... args); void Run(); - F function; - std::tuple arguments; + private: + F m_func; + std::tuple m_args; }; -template struct NzFunctorWithoutArgs; -template struct NzFunctorWithArgs; +template +struct NzMemberWithoutArgs : NzFunctor +{ + NzMemberWithoutArgs(void (C::*func)(), C* object); + + void Run(); + + private: + void (C::*m_func)(); + C* m_object; +}; #include diff --git a/include/Nazara/Core/Functor.inl b/include/Nazara/Core/Functor.inl index e867f79ef..38f0a4fc5 100644 --- a/include/Nazara/Core/Functor.inl +++ b/include/Nazara/Core/Functor.inl @@ -2,23 +2,41 @@ // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp -template NzFunctorWithoutArgs::NzFunctorWithoutArgs(F func) : -function(func) +template +NzFunctorWithoutArgs::NzFunctorWithoutArgs(F func) : +m_func(func) { } -template void NzFunctorWithoutArgs::Run() +template +void NzFunctorWithoutArgs::Run() { - function(); + m_func(); } -template NzFunctorWithArgs::NzFunctorWithArgs(F func, Args&... args) : -function(func), -arguments(args...) +template +NzFunctorWithArgs::NzFunctorWithArgs(F func, Args&... args) : +m_func(func), +m_args(args...) { } -template void NzFunctorWithArgs::Run() +template +void NzFunctorWithArgs::Run() { - NzUnpackTuple(function, arguments); + NzUnpackTuple(m_func, m_args); +} + + +template +NzMemberWithoutArgs::NzMemberWithoutArgs(void (C::*func)(), C* object) : +m_func(func), +m_object(object) +{ +} + +template +void NzMemberWithoutArgs::Run() +{ + (m_object->*m_func)(); } diff --git a/include/Nazara/Core/Hashable.hpp b/include/Nazara/Core/Hashable.hpp index 4b9395bb3..9dad8a771 100644 --- a/include/Nazara/Core/Hashable.hpp +++ b/include/Nazara/Core/Hashable.hpp @@ -22,7 +22,6 @@ enum nzHash nzHash_Whirlpool }; -class NzHash; class NzHashDigest; class NzHashImpl; diff --git a/include/Nazara/Core/Mutex.hpp b/include/Nazara/Core/Mutex.hpp index 6ca9d91d4..9e5fb3147 100644 --- a/include/Nazara/Core/Mutex.hpp +++ b/include/Nazara/Core/Mutex.hpp @@ -11,7 +11,6 @@ #include class NzMutexImpl; -class NzConditionVariable; class NAZARA_API NzMutex : NzNonCopyable { diff --git a/include/Nazara/Core/ResourceLoader.hpp b/include/Nazara/Core/ResourceLoader.hpp new file mode 100644 index 000000000..3d2d23117 --- /dev/null +++ b/include/Nazara/Core/ResourceLoader.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RESOURCELOADER_HPP +#define NAZARA_RESOURCELOADER_HPP + +#include +#include +#include + +class NzInputStream; + +template +class NzResourceLoader +{ + public: + using CheckFunction = bool (*)(NzInputStream& stream, const Parameters& parameters); + using LoadFunction = bool (*)(Type* resource, NzInputStream& stream, const Parameters& parameters); + + static bool LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters = Parameters()); + static bool LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters = Parameters()); + static bool LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters = Parameters()); + + static void RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadfunc); + static void UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadfunc); + + using Loader = std::tuple, CheckFunction, LoadFunction>; + using LoaderList = std::set; +}; + +#include + +#endif // NAZARA_RESOURCELOADER_HPP diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl new file mode 100644 index 000000000..321279ed6 --- /dev/null +++ b/include/Nazara/Core/ResourceLoader.inl @@ -0,0 +1,142 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +template +bool NzResourceLoader::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters) +{ + #if NAZARA_CORE_SAFE + if (!parameters.IsValid()) + { + NazaraError("Invalid Parameters"); + return false; + } + #endif + + NzString path = NzFile::NormalizePath(filePath); + NzString ext = path.SubstrFrom('.', -1, true); + if (ext.IsEmpty()) + { + NazaraError("Failed to get file extension"); + return false; + } + + NzFile file(path, NzFile::ReadOnly); + if (!file.IsOpen()) + { + NazaraError("Failed to open file"); + return false; + } + + for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) + { + for (const NzString& loaderExt : std::get<0>(*loader)) + { + int cmp = NzString::Compare(loaderExt, ext); + if (cmp == 0) + { + if (!std::get<1>(*loader)(file, parameters)) + continue; + + file.SetCursorPos(0); + + // Chargement de la ressource + if (std::get<2>(*loader)(resource, file, parameters)) + return true; + + NazaraWarning("Loader failed"); + + file.SetCursorPos(0); + } + else if (cmp < 0) // S'il est encore possible que l'extension se situe après + continue; + + break; + } + } + + NazaraError("Failed to load file: no loader"); + + return false; +} + +template +bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) +{ + NzMemoryStream stream(data, size); + + return LoadFromStream(resource, stream, parameters); +} + +template +bool NzResourceLoader::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters) +{ + #if NAZARA_CORE_SAFE + if (!parameters.IsValid()) + { + NazaraError("Invalid Parameters"); + return false; + } + + if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize()) + { + NazaraError("No data to load"); + return false; + } + #endif + + nzUInt64 streamPos = stream.GetCursorPos(); + for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) + { + // Le loader supporte-t-il les données ? + if (!std::get<1>(*loader)(stream, parameters)) + continue; + + // On repositionne le stream au début + stream.SetCursorPos(streamPos); + + // Chargement de la ressource + if (std::get<2>(*loader)(resource, stream, parameters)) + return true; + + NazaraWarning("Loader failed"); + stream.SetCursorPos(streamPos); // On repositionne au début + } + + NazaraError("Failed to load file: no loader"); + return false; +} + +template +void NzResourceLoader::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + /// Trouver une alternative à ce code monstrueux + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set extensions; + std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); + + Type::s_loaders.insert(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); +} + +template +void NzResourceLoader::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set extensions; + std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); + + Type::s_loaders.erase(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); +} + +#include diff --git a/include/Nazara/Core/Thread.hpp b/include/Nazara/Core/Thread.hpp index aa67e0beb..0b2744533 100644 --- a/include/Nazara/Core/Thread.hpp +++ b/include/Nazara/Core/Thread.hpp @@ -17,13 +17,13 @@ class NzThreadImpl; class NAZARA_API NzThread : NzNonCopyable { - friend class NzThreadImpl; + friend NzThreadImpl; public: class NAZARA_API Id { - friend class NzThread; - friend class NzThreadImpl; + friend NzThread; + friend NzThreadImpl; public: Id() = default; @@ -43,6 +43,7 @@ class NAZARA_API NzThread : NzNonCopyable template NzThread(F function); template NzThread(F function, Args... args); + template NzThread(void (C::*function)(), C* object); ~NzThread(); Id GetId() const; @@ -56,7 +57,7 @@ class NAZARA_API NzThread : NzNonCopyable private: NzFunctor* m_func; - NzThreadImpl* m_impl; + NzThreadImpl* m_impl = nullptr; bool m_independent; }; diff --git a/include/Nazara/Core/Thread.inl b/include/Nazara/Core/Thread.inl index 301a32240..80b1ead60 100644 --- a/include/Nazara/Core/Thread.inl +++ b/include/Nazara/Core/Thread.inl @@ -4,15 +4,21 @@ #include -template NzThread::NzThread(F function) : -m_func(new NzFunctorWithoutArgs(function)), -m_impl(nullptr) +template +NzThread::NzThread(F function) : +m_func(new NzFunctorWithoutArgs(function)) { } -template NzThread::NzThread(F function, Args... args) : -m_func(new NzFunctorWithArgs(function, args...)), -m_impl(nullptr) +template +NzThread::NzThread(F function, Args... args) : +m_func(new NzFunctorWithArgs(function, args...)) +{ +} + +template +NzThread::NzThread(void (C::*function)(), C* object) : +m_func(new NzMemberWithoutArgs(function, object)) { } diff --git a/include/Nazara/Core/Tuple.inl b/include/Nazara/Core/Tuple.inl index 326ca5d97..b4d4e801c 100644 --- a/include/Nazara/Core/Tuple.inl +++ b/include/Nazara/Core/Tuple.inl @@ -8,7 +8,8 @@ #include -template struct NzTupleUnpack +template +struct NzTupleUnpack { template void operator()(F func, const std::tuple& t, Args&... args) @@ -17,7 +18,8 @@ template struct NzTupleUnpack } }; -template<> struct NzTupleUnpack<0> +template<> +struct NzTupleUnpack<0> { template void operator()(F func, const std::tuple&, Args&... args) @@ -27,7 +29,7 @@ template<> struct NzTupleUnpack<0> }; template -void NzUnpackTuple(F func, const std::tuple& t ) +void NzUnpackTuple(F func, const std::tuple& t) { NzTupleUnpack()(func, t); } diff --git a/include/Nazara/Renderer/Context.hpp b/include/Nazara/Renderer/Context.hpp index 9aaf37304..b24f1e106 100644 --- a/include/Nazara/Renderer/Context.hpp +++ b/include/Nazara/Renderer/Context.hpp @@ -17,7 +17,7 @@ class NzContextImpl; class NAZARA_API NzContext { - friend class NzContextImpl; + friend NzContextImpl; public: NzContext(); diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 72bd906a4..1944054e6 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -24,7 +24,7 @@ #include #endif -typedef void (*NzOpenGLFunc)(); +using NzOpenGLFunc = void (*)(); class NAZARA_API NzOpenGL { @@ -77,9 +77,9 @@ NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; NAZARA_API extern PFNGLCULLFACEPROC glCullFace; NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; +NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; -NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index bf270b63c..4b9e56454 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -17,7 +17,6 @@ #include #include -class NzRenderer; class NzShaderImpl; class NzTexture; @@ -26,7 +25,7 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable friend class NzRenderer; public: - NzShader(); + NzShader() = default; NzShader(nzShaderLanguage language); ~NzShader(); @@ -70,8 +69,8 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable static bool IsTypeSupported(nzShaderType type); private: - NzShaderImpl* m_impl; - bool m_compiled; + NzShaderImpl* m_impl = nullptr; + bool m_compiled = false; }; #endif // NAZARA_SHADER_HPP diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index d0e1b8856..0d9611865 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -13,7 +13,6 @@ #include #include -class NzShader; struct NzTextureImpl; class NAZARA_API NzTexture : public NzResource, NzNonCopyable diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index 15ecd6b78..cc13bc7b2 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -9,11 +9,9 @@ #include #include +#include #include #include -#include -#include -#include struct NzAnimationParams { @@ -33,13 +31,13 @@ struct NzSequence class NzAnimation; -typedef NzResourceLoader NzAnimationLoader; +using NzAnimationLoader = NzResourceLoader; struct NzAnimationImpl; class NAZARA_API NzAnimation : public NzResource { - friend class NzResourceLoader; + friend NzAnimationLoader; public: NzAnimation() = default; @@ -73,9 +71,7 @@ class NAZARA_API NzAnimation : public NzResource private: NzAnimationImpl* m_impl = nullptr; - static std::list s_memoryLoaders; - static std::list s_streamLoaders; - static std::multimap s_fileLoaders; + static NzAnimationLoader::LoaderList s_loaders; }; #endif // NAZARA_ANIMATION_HPP diff --git a/include/Nazara/Utility/AxisAlignedBox.hpp b/include/Nazara/Utility/AxisAlignedBox.hpp index 174ff5fc8..47934cda1 100644 --- a/include/Nazara/Utility/AxisAlignedBox.hpp +++ b/include/Nazara/Utility/AxisAlignedBox.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Utility/Buffer.hpp b/include/Nazara/Utility/Buffer.hpp index db03d85f6..96a47c522 100644 --- a/include/Nazara/Utility/Buffer.hpp +++ b/include/Nazara/Utility/Buffer.hpp @@ -13,16 +13,13 @@ #include class NzBufferImpl; -class NzRenderer; -class NzUtility; class NAZARA_API NzBuffer : public NzResource, NzNonCopyable { - friend class NzRenderer; friend class NzUtility; public: - typedef NzBufferImpl* (*BufferFunction)(NzBuffer* parent, nzBufferType type); + using BufferFunction = NzBufferImpl* (*)(NzBuffer* parent, nzBufferType type); NzBuffer(nzBufferType type); NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); diff --git a/include/Nazara/Utility/Cursor.hpp b/include/Nazara/Utility/Cursor.hpp index 46ba6a940..d95f34718 100644 --- a/include/Nazara/Utility/Cursor.hpp +++ b/include/Nazara/Utility/Cursor.hpp @@ -12,7 +12,6 @@ class NzCursorImpl; class NzImage; -class NzWindowImpl; class NAZARA_API NzCursor { diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 71e5418c0..9d044c7c1 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -127,7 +127,7 @@ enum nzImageType enum nzPixelFormat { - nzPixelFormat_Undefined, + nzPixelFormat_Undefined = -1, nzPixelFormat_BGR8, // 3*nzUInt8 nzPixelFormat_BGRA8, // 4*nzUInt8 diff --git a/include/Nazara/Utility/Icon.hpp b/include/Nazara/Utility/Icon.hpp index d2797517a..d734d6e85 100644 --- a/include/Nazara/Utility/Icon.hpp +++ b/include/Nazara/Utility/Icon.hpp @@ -12,7 +12,6 @@ class NzImage; class NzIconImpl; -class NzWindowImpl; class NAZARA_API NzIcon { diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 7c682b7cb..d58ff1736 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -11,14 +11,12 @@ #include #include #include +#include #include #include #include #include -#include #include -#include -#include #if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE #include @@ -26,6 +24,8 @@ #include #endif +///TODO: Filtres + struct NzImageParams { nzPixelFormat loadFormat = nzPixelFormat_Undefined; @@ -34,20 +34,19 @@ struct NzImageParams bool IsValid() const; }; -///TODO: Filtres - class NzImage; -typedef NzResourceLoader NzImageLoader; +using NzImageLoader = NzResourceLoader; class NAZARA_API NzImage : public NzResource { - friend class NzResourceLoader; + friend NzImageLoader; public: struct SharedImage; NzImage(); + NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1); NzImage(const NzImage& image); NzImage(NzImage&& image) noexcept; NzImage(SharedImage* sharedImage); @@ -135,9 +134,7 @@ class NAZARA_API NzImage : public NzResource SharedImage* m_sharedImage; - static std::list s_memoryLoaders; - static std::list s_streamLoaders; - static std::multimap s_fileLoaders; + static NzImageLoader::LoaderList s_loaders; }; #endif // NAZARA_IMAGE_HPP diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 8fb29dbd5..c8ca8b814 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -10,13 +10,11 @@ #include #include #include +#include #include #include #include -#include #include -#include -#include class NzVertexDeclaration; @@ -32,13 +30,13 @@ struct NzMeshParams class NzMesh; -typedef NzResourceLoader NzMeshLoader; +using NzMeshLoader = NzResourceLoader; struct NzMeshImpl; class NAZARA_API NzMesh : public NzResource { - friend class NzResourceLoader; + friend NzMeshLoader; public: NzMesh() = default; @@ -89,9 +87,7 @@ class NAZARA_API NzMesh : public NzResource private: NzMeshImpl* m_impl = nullptr; - static std::list s_memoryLoaders; - static std::list s_streamLoaders; - static std::multimap s_fileLoaders; + static NzMeshLoader::LoaderList s_loaders; }; #endif // NAZARA_MESH_HPP diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 611819d27..396fa8056 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -19,8 +19,8 @@ class NzPixelFormat friend class NzUtility; public: - typedef nzUInt8* (*ConvertFunction)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst); - typedef void (*FlipFunction)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst); + using ConvertFunction = nzUInt8* (*)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst); + using FlipFunction = void (*)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst); static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst); static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst); diff --git a/include/Nazara/Utility/ResourceLoader.hpp b/include/Nazara/Utility/ResourceLoader.hpp deleted file mode 100644 index 6cc1a08e1..000000000 --- a/include/Nazara/Utility/ResourceLoader.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RESOURCELOADER_HPP -#define NAZARA_RESOURCELOADER_HPP - -#include -#include - -class NzInputStream; - -template -class NzResourceLoader -{ - public: - using IdentifyMemoryFunction = bool (*)(const void* data, unsigned int size, const Parameters& parameters); - using IdentifyStreamFunction = bool (*)(NzInputStream& stream, const Parameters& parameters); - using LoadFileFunction = bool (*)(Type* resource, const NzString& filePath, const Parameters& parameters); - using LoadMemoryFunction = bool (*)(Type* resource, const void* data, unsigned int size, const Parameters& parameters); - using LoadStreamFunction = bool (*)(Type* resource, NzInputStream& stream, const Parameters& parameters); - - static bool LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters = Parameters()); - static bool LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters = Parameters()); - static bool LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters = Parameters()); - - static void RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile); - static void RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory); - static void RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream); - - static void UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile); - static void UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory); - static void UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream); - - typedef std::pair MemoryLoader; - typedef std::pair StreamLoader; -}; - -#include - -#endif // NAZARA_RESOURCELOADER_HPP diff --git a/include/Nazara/Utility/ResourceLoader.inl b/include/Nazara/Utility/ResourceLoader.inl deleted file mode 100644 index ee004d32e..000000000 --- a/include/Nazara/Utility/ResourceLoader.inl +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -template -bool NzResourceLoader::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters) -{ - #if NAZARA_UTILITY_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid Parameters"); - return false; - } - #endif - - NzString path = NzFile::NormalizePath(filePath); - NzString ext = path.SubstrFrom('.', -1, true); - if (ext.IsEmpty()) - { - NazaraError("Failed to get file extension"); - return false; - } - - // Récupération de tous les loaders de cette extension - auto range = Type::s_fileLoaders.equal_range(ext); - if (range.first == range.second) - { - NazaraError("No loader found for extension \"" + ext + '"'); - return false; - } - - // range.second est un itérateur vers l'élément après le dernier élémént du range - auto it = range.second; - - do - { - it--; - - // Chargement de la ressource - if (it->second(resource, filePath, parameters)) - return true; - - NazaraWarning("Loader failed"); - } - while (it != range.first); - - NazaraError("Failed to load file: all loaders failed"); - - return false; -} - -template -bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) -{ - #if NAZARA_UTILITY_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid Parameters"); - return false; - } - - if (!data || size == 0) - { - NazaraError("No data to load"); - return false; - } - #endif - - for (auto loader = Type::s_memoryLoaders.rbegin(); loader != Type::s_memoryLoaders.rend(); ++loader) - { - // Le loader supporte-t-il les données ? - if (!loader->first(data, size, parameters)) - continue; - - // Chargement de la ressource - if (loader->second(resource, data, size, parameters)) - return true; - - NazaraWarning("Loader failed"); - } - - NazaraError("Failed to load file: all loaders failed"); - return false; -} - -template -bool NzResourceLoader::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters) -{ - #if NAZARA_UTILITY_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid Parameters"); - return false; - } - - if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize()) - { - NazaraError("No data to load"); - return false; - } - #endif - - nzUInt64 streamPos = stream.GetCursorPos(); - for (auto loader = Type::s_streamLoaders.rbegin(); loader != Type::s_streamLoaders.rend(); ++loader) - { - stream.SetCursorPos(streamPos); - - // Le loader supporte-t-il les données ? - if (!loader->first(stream, parameters)) - continue; - - stream.SetCursorPos(streamPos); - - // Chargement de la ressource - if (loader->second(resource, stream, parameters)) - return true; - - NazaraWarning("Loader failed"); - } - - NazaraError("Failed to load file: all loaders failed"); - return false; -} - -template -void NzResourceLoader::RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile) -{ - std::vector exts; - extensions.SplitAny(exts, " /\\*.,;|-_"); - - for (const NzString& ext : exts) - Type::s_fileLoaders.insert(std::make_pair(ext, loadFile)); -} - -template -void NzResourceLoader::RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory) -{ - Type::s_memoryLoaders.push_back(std::make_pair(identifyMemory, loadMemory)); -} - -template -void NzResourceLoader::RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream) -{ - Type::s_streamLoaders.push_back(std::make_pair(identifyStream, loadStream)); -} - -template -void NzResourceLoader::UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile) -{ - std::vector exts; - extensions.SplitAny(exts, " /\\*.,;|-_"); - - for (const NzString& ext : exts) - { - // Récupération de tous les loaders de cette extension - auto range = Type::s_fileLoaders.equal_range(ext); - - for (auto it = range.first; it != range.second; ++it) - { - if (it->second == loadFile) - { - Type::s_fileLoaders.erase(it); - break; - } - } - } -} - -template -void NzResourceLoader::UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory) -{ - Type::s_memoryLoaders.remove(std::make_pair(identifyMemory, loadMemory)); -} - -template -void NzResourceLoader::UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream) -{ - Type::s_streamLoaders.remove(std::make_pair(identifyStream, loadStream)); -} - -#include diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index e7f070300..2e14e3913 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -28,15 +28,13 @@ class NzCursor; class NzImage; class NzIcon; -class NzMouse; -class NzUtility; class NzWindowImpl; class NAZARA_API NzWindow : NzNonCopyable { + friend NzWindowImpl; friend class NzMouse; friend class NzUtility; - friend class NzWindowImpl; public: NzWindow(); diff --git a/src/Nazara/Core/Win32/MutexImpl.hpp b/src/Nazara/Core/Win32/MutexImpl.hpp index cb02f4e07..d8f7ea461 100644 --- a/src/Nazara/Core/Win32/MutexImpl.hpp +++ b/src/Nazara/Core/Win32/MutexImpl.hpp @@ -9,8 +9,6 @@ #include -class NzConditionVariableImpl; - class NzMutexImpl { friend class NzConditionVariableImpl; diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index 4549a46c8..ce3f2c7e7 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -44,7 +44,7 @@ namespace GL_STATIC_DRAW // nzBufferUsage_Static }; - typedef nzUInt8* (*LockRoutine)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); + using LockRoutine = nzUInt8* (*)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); nzUInt8* LockBuffer(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) { diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 992c58d05..3871b7169 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -354,9 +354,9 @@ bool NzOpenGL::Initialize() { try { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); openGLextensions[NzOpenGL::DebugOutput] = true; @@ -371,9 +371,9 @@ bool NzOpenGL::Initialize() { try { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControlARB")); glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsertARB")); - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLogARB")); openGLextensions[NzOpenGL::DebugOutput] = true; @@ -590,9 +590,9 @@ PFNGLCOLORMASKPROC glColorMask = nullptr; PFNGLCULLFACEPROC glCullFace = nullptr; PFNGLCOMPILESHADERPROC glCompileShader = nullptr; PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; +PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; -PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 01ec4afca..a186fe518 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -147,10 +147,10 @@ namespace return new NzHardwareBuffer(parent, type); } - typedef std::tuple VAO_Key; - constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; + using VAO_Key = std::tuple; + std::map s_vaos; NzMatrix4f s_matrix[totalMatrixCount]; int s_matrixLocation[totalMatrixCount]; diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index 51f0f89db..fff9f9fd7 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -14,15 +14,7 @@ #include #include -NzShader::NzShader() : -m_impl(nullptr), -m_compiled(false) -{ -} - -NzShader::NzShader(nzShaderLanguage language) : -m_impl(nullptr), -m_compiled(false) +NzShader::NzShader(nzShaderLanguage language) { Create(language); diff --git a/src/Nazara/Renderer/ShaderImpl.hpp b/src/Nazara/Renderer/ShaderImpl.hpp index c47e526c8..cc826788e 100644 --- a/src/Nazara/Renderer/ShaderImpl.hpp +++ b/src/Nazara/Renderer/ShaderImpl.hpp @@ -9,7 +9,6 @@ #include -class NzRenderer; class NzTexture; class NzVertexBuffer; class NzVertexDeclaration; diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 9c362d2f6..7c829ff44 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -517,7 +517,7 @@ void NzTexture::Destroy() bool NzTexture::Download(NzImage* image) const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -576,7 +576,7 @@ bool NzTexture::Download(NzImage* image) const bool NzTexture::EnableMipmapping(bool enable) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -603,7 +603,7 @@ bool NzTexture::EnableMipmapping(bool enable) unsigned int NzTexture::GetAnisotropyLevel() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -626,7 +626,7 @@ unsigned int NzTexture::GetAnisotropyLevel() const nzUInt8 NzTexture::GetBPP() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -639,7 +639,7 @@ nzUInt8 NzTexture::GetBPP() const unsigned int NzTexture::GetDepth() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -652,7 +652,7 @@ unsigned int NzTexture::GetDepth() const nzTextureFilter NzTexture::GetFilterMode() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzTextureFilter_Unknown; @@ -689,7 +689,7 @@ nzTextureFilter NzTexture::GetFilterMode() const nzPixelFormat NzTexture::GetFormat() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzPixelFormat_Undefined; @@ -702,7 +702,7 @@ nzPixelFormat NzTexture::GetFormat() const unsigned int NzTexture::GetHeight() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -715,7 +715,7 @@ unsigned int NzTexture::GetHeight() const nzImageType NzTexture::GetType() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzImageType_2D; @@ -728,7 +728,7 @@ nzImageType NzTexture::GetType() const unsigned int NzTexture::GetWidth() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return 0; @@ -741,7 +741,7 @@ unsigned int NzTexture::GetWidth() const nzTextureWrap NzTexture::GetWrapMode() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return nzTextureWrap_Unknown; @@ -773,7 +773,7 @@ nzTextureWrap NzTexture::GetWrapMode() const bool NzTexture::IsCompressed() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -786,7 +786,7 @@ bool NzTexture::IsCompressed() const bool NzTexture::IsCubemap() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -799,7 +799,7 @@ bool NzTexture::IsCubemap() const bool NzTexture::IsTarget() const { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -915,7 +915,7 @@ bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& param bool NzTexture::Lock() { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -930,7 +930,7 @@ bool NzTexture::Lock() bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -955,7 +955,7 @@ bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) bool NzTexture::SetFilterMode(nzTextureFilter filter) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1008,7 +1008,7 @@ bool NzTexture::SetFilterMode(nzTextureFilter filter) bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1038,7 +1038,7 @@ bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) bool NzTexture::SetWrapMode(nzTextureWrap wrap) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1175,7 +1175,7 @@ bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1191,7 +1191,7 @@ bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1292,7 +1292,7 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1436,7 +1436,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, const NzRec bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1449,7 +1449,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 le bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return false; @@ -1527,7 +1527,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe void NzTexture::Unlock() { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraError("Texture must be valid"); return; @@ -1619,7 +1619,7 @@ bool NzTexture::IsTypeSupported(nzImageType type) void NzTexture::SetTarget(bool isTarget) { #if NAZARA_RENDERER_SAFE - if (!IsValid()) + if (!m_impl) { NazaraInternalError("Texture must be valid"); return; diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index eb4dcf3ca..48bad22f2 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -313,6 +314,4 @@ void NzAnimation::RemoveSequence(unsigned int index) m_impl->sequences.erase(it); } -std::list NzAnimation::s_memoryLoaders; -std::list NzAnimation::s_streamLoaders; -std::multimap NzAnimation::s_fileLoaders; +NzAnimationLoader::LoaderList NzAnimation::s_loaders; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 3e6986677..ebcfa716a 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace @@ -31,6 +32,20 @@ m_sharedImage(&emptyImage) { } +NzImage::NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) : +m_sharedImage(&emptyImage) +{ + Create(type, format, width, height, depth, levelCount); + + #ifdef NAZARA_DEBUG + if (!m_sharedImage) + { + NazaraError("Failed to create image"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + NzImage::NzImage(const NzImage& image) : NzResource(image), m_sharedImage(image.m_sharedImage) @@ -57,7 +72,7 @@ NzImage::~NzImage() bool NzImage::Convert(nzPixelFormat format) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -162,7 +177,7 @@ bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto Correctif temporaire : Update veut de la mémoire contigüe Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour - FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) + ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) (Appliquer l'interface à NzTexture également) */ nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); @@ -311,7 +326,7 @@ void NzImage::Destroy() bool NzImage::Fill(const NzColor& color) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -369,7 +384,7 @@ bool NzImage::Fill(const NzColor& color) bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -432,7 +447,7 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -495,7 +510,7 @@ bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) bool NzImage::FlipHorizontally() { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -534,7 +549,7 @@ bool NzImage::FlipHorizontally() bool NzImage::FlipVertically() { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -577,7 +592,7 @@ nzUInt8 NzImage::GetBPP() const const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return nullptr; @@ -656,7 +671,7 @@ nzUInt8 NzImage::GetMaxLevel() const NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return NzColor(); @@ -700,7 +715,7 @@ NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) c nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return nullptr; @@ -832,7 +847,7 @@ bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params) bool NzImage::SetLevelCount(nzUInt8 levelCount) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -877,7 +892,7 @@ bool NzImage::SetLevelCount(nzUInt8 levelCount) bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y, unsigned int z) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -923,7 +938,7 @@ bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -952,7 +967,7 @@ bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) { #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -990,7 +1005,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); if (z >= depth) { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= " + NzString::Number(depth) + ')'); return false; } #endif @@ -1015,7 +1030,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) { ///FIXME: Vérifier que ça fonctionne correctement #if NAZARA_UTILITY_SAFE - if (!IsValid()) + if (!m_sharedImage) { NazaraError("Image must be valid"); return false; @@ -1152,6 +1167,4 @@ void NzImage::ReleaseImage() } NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); -std::list NzImage::s_memoryLoaders; -std::list NzImage::s_streamLoaders; -std::multimap NzImage::s_fileLoaders; +NzImageLoader::LoaderList NzImage::s_loaders; diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index d2fa86371..bb30b5832 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -18,27 +18,23 @@ namespace { - bool NzLoader_MD2_LoadStream(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters); - - bool NzLoader_MD2_LoadFile(NzMesh* mesh, const NzString& filePath, const NzMeshParams& parameters) + bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters) { - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Failed to open file"); + NazaraUnused(parameters); + + nzUInt32 magic[2]; + if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) return false; - } - return NzLoader_MD2_LoadStream(mesh, file, parameters); + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&magic[0], sizeof(nzUInt32)); + NzByteSwap(&magic[1], sizeof(nzUInt32)); + #endif + + return magic[0] == md2Ident && magic[1] == 8; } - bool NzLoader_MD2_LoadMemory(NzMesh* mesh, const void* data, unsigned int size, const NzMeshParams& parameters) - { - NzMemoryStream stream(data, size); - return NzLoader_MD2_LoadStream(mesh, stream, parameters); - } - - bool NzLoader_MD2_LoadStream(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) + bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) { md2_header header; if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header)) @@ -208,60 +204,18 @@ namespace return true; } - - bool NzLoader_MD2_IdentifyMemory(const void* data, unsigned int size, const NzMeshParams& parameters) - { - NazaraUnused(parameters); - - if (size < sizeof(md2_header)) - return false; - - const md2_header* header = reinterpret_cast(data); - - #if defined(NAZARA_BIG_ENDIAN) - nzUInt32 ident = header->ident; - nzUInt32 version = header->version; - - NzByteSwap(&ident, sizeof(nzUInt32)); - NzByteSwap(&version, sizeof(nzUInt32)); - - return ident == md2Ident && version == 8; - #else - return header->ident == md2Ident && header->version == 8; - #endif - } - - bool NzLoader_MD2_IdentifyStream(NzInputStream& stream, const NzMeshParams& parameters) - { - NazaraUnused(parameters); - - nzUInt32 magic[2]; - if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) - return false; - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&magic[0], sizeof(nzUInt32)); - NzByteSwap(&magic[1], sizeof(nzUInt32)); - #endif - - return magic[0] == md2Ident && magic[1] == 8; - } } void NzLoaders_MD2_Register() { NzMD2Mesh::Initialize(); - NzMeshLoader::RegisterFileLoader("md2", NzLoader_MD2_LoadFile); - NzMeshLoader::RegisterMemoryLoader(NzLoader_MD2_IdentifyMemory, NzLoader_MD2_LoadMemory); - NzMeshLoader::RegisterStreamLoader(NzLoader_MD2_IdentifyStream, NzLoader_MD2_LoadStream); + NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); } void NzLoaders_MD2_Unregister() { - NzMeshLoader::UnregisterStreamLoader(NzLoader_MD2_IdentifyStream, NzLoader_MD2_LoadStream); - NzMeshLoader::UnregisterMemoryLoader(NzLoader_MD2_IdentifyMemory, NzLoader_MD2_LoadMemory); - NzMeshLoader::UnregisterFileLoader("md2", NzLoader_MD2_LoadFile); + NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); NzMD2Mesh::Uninitialize(); } diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp index 63db23e6b..2d25e0db7 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Utility/Loaders/PCX/Loader.cpp b/src/Nazara/Utility/Loaders/PCX/Loader.cpp index 6240461e3..74fc38725 100644 --- a/src/Nazara/Utility/Loaders/PCX/Loader.cpp +++ b/src/Nazara/Utility/Loaders/PCX/Loader.cpp @@ -37,27 +37,18 @@ namespace nzUInt8 padding[54]; }; - bool NzLoader_PCX_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters); - - bool NzLoader_PCX_LoadFile(NzImage* image, const NzString& filePath, const NzImageParams& parameters) + bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters) { - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Failed to open file"); + NazaraUnused(parameters); + + nzUInt8 manufacturer; + if (stream.Read(&manufacturer, 1) != 1) return false; - } - return NzLoader_PCX_LoadStream(image, file, parameters); + return manufacturer == 0x0a; } - bool NzLoader_PCX_LoadMemory(NzImage* image, const void* data, unsigned int size, const NzImageParams& parameters) - { - NzMemoryStream stream(data, size); - return NzLoader_PCX_LoadStream(image, stream, parameters); - } - - bool NzLoader_PCX_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) { NazaraUnused(parameters); @@ -348,39 +339,14 @@ namespace return true; } - - bool NzLoader_PCX_IdentifyMemory(const void* data, unsigned int size, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - if (size < sizeof(pcx_header)) - return false; - - return *reinterpret_cast(data) == 0x0a; - } - - bool NzLoader_PCX_IdentifyStream(NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - nzUInt8 manufacturer; - if (stream.Read(&manufacturer, 1) != 1) - return false; - - return manufacturer == 0x0a; - } } void NzLoaders_PCX_Register() { - NzImageLoader::RegisterFileLoader("pcx", NzLoader_PCX_LoadFile); - NzImageLoader::RegisterMemoryLoader(NzLoader_PCX_IdentifyMemory, NzLoader_PCX_LoadMemory); - NzImageLoader::RegisterStreamLoader(NzLoader_PCX_IdentifyStream, NzLoader_PCX_LoadStream); + NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); } void NzLoaders_PCX_Unregister() { - NzImageLoader::UnregisterStreamLoader(NzLoader_PCX_IdentifyStream, NzLoader_PCX_LoadStream); - NzImageLoader::UnregisterMemoryLoader(NzLoader_PCX_IdentifyMemory, NzLoader_PCX_LoadMemory); - NzImageLoader::UnregisterFileLoader("pcx", NzLoader_PCX_LoadFile); + NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); } diff --git a/src/Nazara/Utility/Loaders/STB/Loader.cpp b/src/Nazara/Utility/Loaders/STB/Loader.cpp index ebdbac78f..86047d350 100644 --- a/src/Nazara/Utility/Loaders/STB/Loader.cpp +++ b/src/Nazara/Utility/Loaders/STB/Loader.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -37,30 +37,16 @@ namespace static stbi_io_callbacks callbacks = {Read, Skip, Eof}; - bool NzLoader_STB_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters); - - bool NzLoader_STB_LoadFile(NzImage* image, const NzString& filePath, const NzImageParams& parameters) - { - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Failed to open file"); - return false; - } - - return NzLoader_STB_LoadStream(image, file, parameters); - } - - bool NzLoader_STB_LoadMemory(NzImage* image, const void* data, unsigned int size, const NzImageParams& parameters) - { - NzMemoryStream stream(data, size); - return NzLoader_STB_LoadStream(image, stream, parameters); - } - - bool NzLoader_STB_LoadStream(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + bool NzLoader_STB_Check(NzInputStream& stream, const NzImageParams& parameters) { NazaraUnused(parameters); + int width, height, bpp; + return stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp); + } + + bool NzLoader_STB_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + { static const nzPixelFormat formats[4] = { nzPixelFormat_L8, @@ -127,34 +113,14 @@ namespace return true; } - - bool NzLoader_STB_IdentifyMemory(const void* data, unsigned int size, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - int width, height, bpp; - return stbi_info_from_memory(reinterpret_cast(data), size, &width, &height, &bpp); - } - - bool NzLoader_STB_IdentifyStream(NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - int width, height, bpp; - return stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp); - } } void NzLoaders_STB_Register() { - NzImageLoader::RegisterFileLoader("bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga", NzLoader_STB_LoadFile); - NzImageLoader::RegisterMemoryLoader(NzLoader_STB_IdentifyMemory, NzLoader_STB_LoadMemory); - NzImageLoader::RegisterStreamLoader(NzLoader_STB_IdentifyStream, NzLoader_STB_LoadStream); + NzImageLoader::RegisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", NzLoader_STB_Check, NzLoader_STB_Load); } void NzLoaders_STB_Unregister() { - NzImageLoader::UnregisterStreamLoader(NzLoader_STB_IdentifyStream, NzLoader_STB_LoadStream); - NzImageLoader::UnregisterMemoryLoader(NzLoader_STB_IdentifyMemory, NzLoader_STB_LoadMemory); - NzImageLoader::UnregisterFileLoader("bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga", NzLoader_STB_LoadFile); + NzImageLoader::UnregisterLoader("bmp,gif,hdr,jpg,jpeg,pic,png,psd,tga", NzLoader_STB_Check, NzLoader_STB_Load); } diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index f082517da..797c0bcf9 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include bool NzMeshParams::IsValid() const @@ -619,6 +620,4 @@ bool NzMesh::SetAnimation(const NzAnimation* animation) return true; } -std::list NzMesh::s_memoryLoaders; -std::list NzMesh::s_streamLoaders; -std::multimap NzMesh::s_fileLoaders; +NzMeshLoader::LoaderList NzMesh::s_loaders; From d3951ddef646d2f01f8318df07abcf44b7afd823 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 18 Aug 2012 01:50:48 +0200 Subject: [PATCH 06/31] Regenerated (And fixed) global headers --- include/Nazara/Core.hpp | 1 + include/Nazara/Utility.hpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index a1f9500d0..17a1faa6b 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp index c578347d9..c1ee264ef 100644 --- a/include/Nazara/Utility.hpp +++ b/include/Nazara/Utility.hpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include From cd6b2c447a04829582c2e3eeea63d181baf0681f Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 18 Aug 2012 14:08:14 +0200 Subject: [PATCH 08/31] Fixed modules target names --- .../build/scripts/module/modulename.lua | 11 ++++------- build/scripts/common.lua | 10 +++++++++- build/scripts/module/core.lua | 8 -------- build/scripts/module/noise.lua | 8 ++------ build/scripts/module/renderer.lua | 12 ++++-------- build/scripts/module/utility.lua | 8 ++------ examples/AnimatedMesh/build.lua | 16 ++++++++-------- examples/ListSequences/build.lua | 12 ++++++------ 8 files changed, 35 insertions(+), 50 deletions(-) diff --git a/NazaraModuleTemplate/build/scripts/module/modulename.lua b/NazaraModuleTemplate/build/scripts/module/modulename.lua index c1d8d7d12..421c42306 100644 --- a/NazaraModuleTemplate/build/scripts/module/modulename.lua +++ b/NazaraModuleTemplate/build/scripts/module/modulename.lua @@ -17,21 +17,18 @@ else end if (_OPTIONS["one-library"]) then - excludes "../src/Nazara/Audio/Debug/Leaks.cpp" + excludes "../src/Nazara/ModuleName/Debug/Leaks.cpp" else configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraModuleNamed" + links "NazaraCore-s-d" configuration "ReleaseStatic" links "NazaraCore-s" - targetname "NazaraModuleName" configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraModuleNamed" + links "NazaraCore-d" configuration "ReleaseDLL" links "NazaraCore" - targetname "NazaraModuleName" +end end \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index 797db69d4..faaa95654 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -38,11 +38,19 @@ configuration "Release*" configuration "*Static" defines "NAZARA_STATIC" kind "StaticLib" - targetsuffix "-s" configuration "*DLL" kind "SharedLib" +configuration "DebugStatic" + targetsuffix "-s-d" + +configuration "ReleaseStatic" + targetsuffix "-s" + +configuration "DebugDLL" + targetsuffix "-d" + configuration "codeblocks or codelite or gmake or xcode3*" buildoptions "-std=c++11" diff --git a/build/scripts/module/core.lua b/build/scripts/module/core.lua index fcd8efb4d..df08604da 100644 --- a/build/scripts/module/core.lua +++ b/build/scripts/module/core.lua @@ -17,12 +17,4 @@ if (os.is("windows")) then excludes { "../src/Nazara/Core/Posix/**.hpp", "../src/Nazara/Core/Posix/**.cpp" } else excludes { "../src/Nazara/Core/Win32/**.hpp", "../src/Nazara/Core/Win32/**.cpp" } -end - -if (not _OPTIONS["one-library"]) then - configuration "Debug*" - targetname "NazaraCored" - - configuration "Release*" - targetname "NazaraCore" end \ No newline at end of file diff --git a/build/scripts/module/noise.lua b/build/scripts/module/noise.lua index 0d9cc325e..9fb0b9f71 100644 --- a/build/scripts/module/noise.lua +++ b/build/scripts/module/noise.lua @@ -20,18 +20,14 @@ if (_OPTIONS["one-library"]) then excludes "../src/Nazara/Noise/Debug/Leaks.cpp" else configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraNoised" + links "NazaraCore-s-d" configuration "ReleaseStatic" links "NazaraCore-s" - targetname "NazaraNoise" configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraNoised" + links "NazaraCore-d" configuration "ReleaseDLL" links "NazaraCore" - targetname "NazaraNoise" end \ No newline at end of file diff --git a/build/scripts/module/renderer.lua b/build/scripts/module/renderer.lua index 7419c05b0..391830ee2 100644 --- a/build/scripts/module/renderer.lua +++ b/build/scripts/module/renderer.lua @@ -23,22 +23,18 @@ if (_OPTIONS["one-library"]) then excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" else configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraUtilityd-s" - targetname "NazaraRendererd" + links "NazaraCore-s-d" + links "NazaraUtility-s-d" configuration "ReleaseStatic" links "NazaraCore-s" links "NazaraUtility-s" - targetname "NazaraRenderer" configuration "DebugDLL" - links "NazaraCored" - links "NazaraUtilityd" - targetname "NazaraRendererd" + links "NazaraCore-d" + links "NazaraUtility-d" configuration "ReleaseDLL" links "NazaraCore" links "NazaraUtility" - targetname "NazaraRenderer" end \ No newline at end of file diff --git a/build/scripts/module/utility.lua b/build/scripts/module/utility.lua index 81091bcef..097ed0915 100644 --- a/build/scripts/module/utility.lua +++ b/build/scripts/module/utility.lua @@ -24,18 +24,14 @@ if (_OPTIONS["one-library"]) then excludes "../src/Nazara/Utility/Debug/Leaks.cpp" else configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraUtilityd" + links "NazaraCore-s-d" configuration "ReleaseStatic" links "NazaraCore-s" - targetname "NazaraUtility" configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraUtilityd" + links "NazaraCore-d" configuration "ReleaseDLL" links "NazaraCore" - targetname "NazaraUtility" end \ No newline at end of file diff --git a/examples/AnimatedMesh/build.lua b/examples/AnimatedMesh/build.lua index d45cb5983..4704ecca7 100644 --- a/examples/AnimatedMesh/build.lua +++ b/examples/AnimatedMesh/build.lua @@ -4,21 +4,21 @@ files "main.cpp" if (_OPTIONS["one-library"]) then configuration "DebugStatic" - links "Nazarad-s" + links "Nazara-s-d" configuration "ReleaseStatic" links "Nazara-s" configuration "DebugDLL" - links "Nazarad" + links "Nazara-d" configuration "ReleaseDLL" links "Nazara" else configuration "DebugStatic" - links "NazaraRendererd-s" - links "NazaraUtilityd-s" - links "NazaraCored-s" + links "NazaraRenderer-s-d" + links "NazaraUtility-s-d" + links "NazaraCore-s-d" configuration "ReleaseStatic" links "NazaraRenderer-s" @@ -26,9 +26,9 @@ else links "NazaraCore-s" configuration "DebugDLL" - links "NazaraRendererd" - links "NazaraCored" - links "NazaraUtilityd" + links "NazaraRenderer-d" + links "NazaraCore-d" + links "NazaraUtility-d" configuration "ReleaseDLL" links "NazaraRenderer" diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua index a522b53f6..788fee7b6 100644 --- a/examples/ListSequences/build.lua +++ b/examples/ListSequences/build.lua @@ -4,28 +4,28 @@ files "main.cpp" if (_OPTIONS["one-library"]) then configuration "DebugStatic" - links "Nazarad-s" + links "Nazara-s-d" configuration "ReleaseStatic" links "Nazara-s" configuration "DebugDLL" - links "Nazarad" + links "Nazara-d" configuration "ReleaseDLL" links "Nazara" else configuration "DebugStatic" - links "NazaraCored-s" - links "NazaraUtilityd-s" + links "NazaraCore-s-d" + links "NazaraUtility-s-d" configuration "ReleaseStatic" links "NazaraCore-s" links "NazaraUtility-s" configuration "DebugDLL" - links "NazaraCored" - links "NazaraUtilityd" + links "NazaraCore-d" + links "NazaraUtility-d" configuration "ReleaseDLL" links "NazaraCore" From 71b777e732915cb596eff634694ecf5a7e95ad9a Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 18 Aug 2012 15:12:04 +0200 Subject: [PATCH 09/31] Fixed examples linking --- examples/AnimatedMesh/build.lua | 8 ++++---- examples/ListSequences/build.lua | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/AnimatedMesh/build.lua b/examples/AnimatedMesh/build.lua index 4704ecca7..7a0eae18e 100644 --- a/examples/AnimatedMesh/build.lua +++ b/examples/AnimatedMesh/build.lua @@ -4,16 +4,16 @@ files "main.cpp" if (_OPTIONS["one-library"]) then configuration "DebugStatic" - links "Nazara-s-d" + links "NazaraEngine-s-d" configuration "ReleaseStatic" - links "Nazara-s" + links "NazaraEngine-s" configuration "DebugDLL" - links "Nazara-d" + links "NazaraEngine-d" configuration "ReleaseDLL" - links "Nazara" + links "NazaraEngine" else configuration "DebugStatic" links "NazaraRenderer-s-d" diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua index 788fee7b6..9e90b1616 100644 --- a/examples/ListSequences/build.lua +++ b/examples/ListSequences/build.lua @@ -4,16 +4,16 @@ files "main.cpp" if (_OPTIONS["one-library"]) then configuration "DebugStatic" - links "Nazara-s-d" + links "NazaraEngine-s-d" configuration "ReleaseStatic" - links "Nazara-s" + links "NazaraEngine-s" configuration "DebugDLL" - links "Nazara-d" + links "NazaraEngine-d" configuration "ReleaseDLL" - links "Nazara" + links "NazaraEngine" else configuration "DebugStatic" links "NazaraCore-s-d" From 40ec2003b41eaf1351eb14ca9e8666d26bc1082e Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 21 Aug 2012 15:04:00 +0200 Subject: [PATCH 10/31] Added Audio module Fixed examples resources not being commited Temporary removed static build configurations --- .gitignore | 2 +- build/scripts/common.lua | 4 +- build/scripts/common_examples.lua | 14 +- build/scripts/module/audio.lua | 36 +++ examples/AnimatedMesh/build.lua | 2 +- examples/DopplerEffect/build.lua | 37 +++ examples/DopplerEffect/main.cpp | 68 +++++ examples/ListSequences/build.lua | 8 +- examples/bin/shaders/basic.frag | 10 + examples/bin/shaders/basic.vert | 14 + include/Nazara/Audio.hpp | 36 +++ include/Nazara/Audio/Audio.hpp | 58 ++++ include/Nazara/Audio/Config.hpp | 41 +++ include/Nazara/Audio/Debug.hpp | 11 + include/Nazara/Audio/DebugOff.hpp | 8 + include/Nazara/Audio/Enums.hpp | 32 +++ include/Nazara/Audio/Sound.hpp | 48 ++++ include/Nazara/Audio/SoundBuffer.hpp | 64 +++++ include/Nazara/Audio/SoundEmitter.hpp | 60 +++++ include/Nazara/Core/Initializer.hpp | 2 + include/Nazara/Core/Initializer.inl | 3 +- include/Nazara/Math/Basic.inl | 2 +- src/Nazara/Audio/Audio.cpp | 285 ++++++++++++++++++++ src/Nazara/Audio/Loaders/sndfile.hpp | 15 ++ src/Nazara/Audio/Loaders/sndfile/Loader.cpp | 135 ++++++++++ src/Nazara/Audio/Sound.cpp | 180 +++++++++++++ src/Nazara/Audio/SoundBuffer.cpp | 223 +++++++++++++++ src/Nazara/Audio/SoundEmitter.cpp | 156 +++++++++++ 28 files changed, 1541 insertions(+), 13 deletions(-) create mode 100644 build/scripts/module/audio.lua create mode 100644 examples/DopplerEffect/build.lua create mode 100644 examples/DopplerEffect/main.cpp create mode 100644 examples/bin/shaders/basic.frag create mode 100644 examples/bin/shaders/basic.vert create mode 100644 include/Nazara/Audio.hpp create mode 100644 include/Nazara/Audio/Audio.hpp create mode 100644 include/Nazara/Audio/Config.hpp create mode 100644 include/Nazara/Audio/Debug.hpp create mode 100644 include/Nazara/Audio/DebugOff.hpp create mode 100644 include/Nazara/Audio/Enums.hpp create mode 100644 include/Nazara/Audio/Sound.hpp create mode 100644 include/Nazara/Audio/SoundBuffer.hpp create mode 100644 include/Nazara/Audio/SoundEmitter.hpp create mode 100644 src/Nazara/Audio/Audio.cpp create mode 100644 src/Nazara/Audio/Loaders/sndfile.hpp create mode 100644 src/Nazara/Audio/Loaders/sndfile/Loader.cpp create mode 100644 src/Nazara/Audio/Sound.cpp create mode 100644 src/Nazara/Audio/SoundBuffer.cpp create mode 100644 src/Nazara/Audio/SoundEmitter.cpp diff --git a/.gitignore b/.gitignore index c8a3d8d30..05f2ebb62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Codeblocks *.cbp +*.cbTemp *.cscope_file_list *.depend *.layout @@ -126,7 +127,6 @@ publish *.Publish.xml # Others -[Bb]in [Oo]bj sql TestResults diff --git a/build/scripts/common.lua b/build/scripts/common.lua index faaa95654..f369473c4 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -1,8 +1,8 @@ -- Configuration générale configurations { - "DebugStatic", - "ReleaseStatic", +-- "DebugStatic", +-- "ReleaseStatic", "DebugDLL", "ReleaseDLL" } diff --git a/build/scripts/common_examples.lua b/build/scripts/common_examples.lua index 03b087a3d..fd00cf90c 100644 --- a/build/scripts/common_examples.lua +++ b/build/scripts/common_examples.lua @@ -1,8 +1,8 @@ -- Configuration générale configurations { - "DebugStatic", - "ReleaseStatic", +-- "DebugStatic", +-- "ReleaseStatic", "DebugDLL", "ReleaseDLL" } @@ -10,10 +10,18 @@ configurations language "C++" location("../examples/build/" .. _ACTION) +debugdir "../examples/bin" + includedirs "../include" -debugdir "../examples/bin" libdirs "../lib" + +if (_OPTIONS["x64"]) then + libdirs "../extlibs/lib/x64" +end + +libdirs "../extlibs/lib/x86" + targetdir "../examples/bin" configuration "Debug*" diff --git a/build/scripts/module/audio.lua b/build/scripts/module/audio.lua new file mode 100644 index 000000000..c46087c86 --- /dev/null +++ b/build/scripts/module/audio.lua @@ -0,0 +1,36 @@ +if (not _OPTIONS["one-library"]) then + project "NazaraAudio" +end + +files +{ + "../include/Nazara/Audio/**.hpp", + "../include/Nazara/Audio/**.inl", + "../src/Nazara/Audio/**.hpp", + "../src/Nazara/Audio/**.cpp" +} + +if (os.is("windows")) then + excludes { "../src/Nazara/Audio/Posix/*.hpp", "../src/Nazara/Audio/Posix/*.cpp" } + links "OpenAL32" + links "sndfile-1" +else + excludes { "../src/Nazara/Audio/Win32/*.hpp", "../src/Nazara/Audio/Win32/*.cpp" } + -- Link posix ? +end + +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Audio/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCore-s-d" + + configuration "ReleaseStatic" + links "NazaraCore-s" + + configuration "DebugDLL" + links "NazaraCore-d" + + configuration "ReleaseDLL" + links "NazaraCore" +end \ No newline at end of file diff --git a/examples/AnimatedMesh/build.lua b/examples/AnimatedMesh/build.lua index 7a0eae18e..a5d657395 100644 --- a/examples/AnimatedMesh/build.lua +++ b/examples/AnimatedMesh/build.lua @@ -27,8 +27,8 @@ else configuration "DebugDLL" links "NazaraRenderer-d" - links "NazaraCore-d" links "NazaraUtility-d" + links "NazaraCore-d" configuration "ReleaseDLL" links "NazaraRenderer" diff --git a/examples/DopplerEffect/build.lua b/examples/DopplerEffect/build.lua new file mode 100644 index 000000000..6e48bff00 --- /dev/null +++ b/examples/DopplerEffect/build.lua @@ -0,0 +1,37 @@ +kind "ConsoleApp" + +files "main.cpp" + +if (_OPTIONS["one-library"]) then + configuration "DebugStatic" + links "NazaraEngine-s-d" + + configuration "ReleaseStatic" + links "NazaraEngine-s" + + configuration "DebugDLL" + links "NazaraEngine-d" + + configuration "ReleaseDLL" + links "NazaraEngine" +else + configuration "DebugStatic" + links "NazaraAudio-s-d" + links "NazaraUtility-s-d" + links "NazaraCore-s-d" + + configuration "ReleaseStatic" + links "NazaraAudio-s" + links "NazaraUtility-s" + links "NazaraCore-s" + + configuration "DebugDLL" + links "NazaraAudio-d" + links "NazaraUtility-d" + links "NazaraCore-d" + + configuration "ReleaseDLL" + links "NazaraAudio" + links "NazaraUtility" + links "NazaraCore" +end diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp new file mode 100644 index 000000000..b02b416c3 --- /dev/null +++ b/examples/DopplerEffect/main.cpp @@ -0,0 +1,68 @@ +#include +#include +#include // Thread::Sleep +#include +#include + +int main() +{ + // NzKeyboard ne nécessite pas l'initialisation d'Utility + NzInitializer audio; + if (!audio) + { + std::cout << "Failed to initialize audio module" << std::endl; + std::getchar(); + return 1; + } + + NzSound sound; + if (!sound.LoadFromFile("resources/siren.wav")) + { + std::cout << "Failed to load sound" << std::endl; + std::getchar(); + return 1; + } + + std::cout << "Demonstration de l'effet doppler avec Nazara" << std::endl; + std::cout << "Appuyez sur entree pour demarrer" << std::endl; + std::cout << "Appuyez sur echap pour arreter" << std::endl; + + std::getchar(); + + // On fait en sorte de répéter le son + sound.EnableLooping(true); + + // La source du son se situe en (50, 0, 5) + sound.SetPosition(50, 0, 5); + + // Et possède une vitesse de -10 par seconde sur l'axe X + sound.SetVelocity(-10, 0, 0); + + // On joue le son + sound.Play(); + + // La boucle du programme (Pour déplacer le son) + NzClock clock; + while (sound.GetStatus() == nzSoundStatus_Playing) + { + // Comme le son se joue dans un thread séparé, on peut mettre en pause celui-ci régulièrement + int sleepTime = 1000/60 - clock.GetMilliseconds(); // 60 FPS + + if (sleepTime > 0) + NzThread::Sleep(sleepTime); + + // On bouge la source du son en fonction du au temps depuis chaque mise à jour + NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); + sound.SetPosition(pos); + + std::cout << "Sound position: " << pos << std::endl; + + // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap + if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) + sound.Stop(); // On arrête le son (Stoppant également la boucle) + + clock.Restart(); + } + + return 0; +} diff --git a/examples/ListSequences/build.lua b/examples/ListSequences/build.lua index 9e90b1616..d43cb7d64 100644 --- a/examples/ListSequences/build.lua +++ b/examples/ListSequences/build.lua @@ -16,18 +16,18 @@ if (_OPTIONS["one-library"]) then links "NazaraEngine" else configuration "DebugStatic" - links "NazaraCore-s-d" links "NazaraUtility-s-d" + links "NazaraCore-s-d" configuration "ReleaseStatic" - links "NazaraCore-s" links "NazaraUtility-s" + links "NazaraCore-s" configuration "DebugDLL" - links "NazaraCore-d" links "NazaraUtility-d" + links "NazaraCore-d" configuration "ReleaseDLL" - links "NazaraCore" links "NazaraUtility" + links "NazaraCore" end diff --git a/examples/bin/shaders/basic.frag b/examples/bin/shaders/basic.frag new file mode 100644 index 000000000..e8a5f4c69 --- /dev/null +++ b/examples/bin/shaders/basic.frag @@ -0,0 +1,10 @@ +#version 110 + +varying vec2 TexCoord; + +uniform sampler2D texture; + +void main() +{ + gl_FragColor = texture2D(texture, TexCoord); +} diff --git a/examples/bin/shaders/basic.vert b/examples/bin/shaders/basic.vert new file mode 100644 index 000000000..3f332e560 --- /dev/null +++ b/examples/bin/shaders/basic.vert @@ -0,0 +1,14 @@ +#version 110 + +attribute vec3 Position; +attribute vec2 TexCoord0; + +uniform mat4 WorldViewProjMatrix; + +varying vec2 TexCoord; + +void main() +{ + gl_Position = WorldViewProjMatrix * vec4(Position, 1.0); + TexCoord = TexCoord0; +} diff --git a/include/Nazara/Audio.hpp b/include/Nazara/Audio.hpp new file mode 100644 index 000000000..1cc185a95 --- /dev/null +++ b/include/Nazara/Audio.hpp @@ -0,0 +1,36 @@ +// This file was automatically generated by Nazara + +/* + Nazara Engine - Audio module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Audio/Audio.hpp b/include/Nazara/Audio/Audio.hpp new file mode 100644 index 000000000..adffcc110 --- /dev/null +++ b/include/Nazara/Audio/Audio.hpp @@ -0,0 +1,58 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_AUDIO_HPP +#define NAZARA_AUDIO_HPP + +#include +#include +#include +#include +#include + +class NAZARA_API NzAudio +{ + friend class NzMusic; + friend class NzSoundBuffer; + + public: + NzAudio() = delete; + ~NzAudio() = delete; + + static nzAudioFormat GetAudioFormat(unsigned int channelCount); + static float GetDopplerFactor(); + static float GetGlobalVolume(); + static NzVector3f GetListenerDirection(); + static NzVector3f GetListenerPosition(); + //static NzQuaternionf GetListenerRotation(); + static NzVector3f GetListenerVelocity(); + static float GetSpeedOfSound(); + + static bool Initialize(); + + static bool IsFormatSupported(nzAudioFormat format); + static bool IsInitialized(); + + static void SetDopplerFactor(float dopplerFactor); + static void SetGlobalVolume(float volume); + static void SetListenerDirection(const NzVector3f& direction); + static void SetListenerDirection(float dirX, float dirY, float dirZ); + static void SetListenerPosition(const NzVector3f& position); + static void SetListenerPosition(float x, float y, float z); + //static void SetListenerRotation(const NzQuaternionf& rotation); + static void SetListenerVelocity(const NzVector3f& velocity); + static void SetListenerVelocity(float velX, float velY, float velZ); + static void SetSpeedOfSound(float speed); + + static void Uninitialize(); + + private: + static unsigned int GetOpenALFormat(nzAudioFormat format); + + static unsigned int s_moduleReferenceCouter; +}; + +#endif // NAZARA_AUDIO_HPP diff --git a/include/Nazara/Audio/Config.hpp b/include/Nazara/Audio/Config.hpp new file mode 100644 index 000000000..e3b2bcd3e --- /dev/null +++ b/include/Nazara/Audio/Config.hpp @@ -0,0 +1,41 @@ +/* + Nazara Engine - Audio module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_AUDIO_HPP +#define NAZARA_CONFIG_AUDIO_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_AUDIO_MEMORYLEAKTRACKER 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_AUDIO_SAFE 1 + +// Le nombre de buffers utilisés lors du streaming d'objets audio (Au moins deux) +#define NAZARA_AUDIO_STREAMEDBUFFERCOUNT 2 + +#endif // NAZARA_CONFIG_AUDIO_HPP diff --git a/include/Nazara/Audio/Debug.hpp b/include/Nazara/Audio/Debug.hpp new file mode 100644 index 000000000..3db3dcd92 --- /dev/null +++ b/include/Nazara/Audio/Debug.hpp @@ -0,0 +1,11 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) + #include + + #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete + #define new new(__FILE__, __LINE__) +#endif diff --git a/include/Nazara/Audio/DebugOff.hpp b/include/Nazara/Audio/DebugOff.hpp new file mode 100644 index 000000000..13ff944c7 --- /dev/null +++ b/include/Nazara/Audio/DebugOff.hpp @@ -0,0 +1,8 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) + #undef delete + #undef new +#endif diff --git a/include/Nazara/Audio/Enums.hpp b/include/Nazara/Audio/Enums.hpp new file mode 100644 index 000000000..70729d19d --- /dev/null +++ b/include/Nazara/Audio/Enums.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_HPP +#define NAZARA_ENUMS_HPP + +enum nzAudioFormat +{ + nzAudioFormat_Unknown = -1, + + // La valeur entière est le nombre de canaux possédés par ce format + nzAudioFormat_Mono = 1, + nzAudioFormat_Stereo = 2, + nzAudioFormat_Quad = 4, + nzAudioFormat_5_1 = 6, + nzAudioFormat_6_1 = 7, + nzAudioFormat_7_1 = 8, + + nzAudioFormat_Max = nzAudioFormat_7_1 +}; + +enum nzSoundStatus +{ + nzSoundStatus_Playing, + nzSoundStatus_Paused, + nzSoundStatus_Stopped +}; + +#endif // NAZARA_ENUMS_HPP diff --git a/include/Nazara/Audio/Sound.hpp b/include/Nazara/Audio/Sound.hpp new file mode 100644 index 000000000..1b2ac77e6 --- /dev/null +++ b/include/Nazara/Audio/Sound.hpp @@ -0,0 +1,48 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_SOUND_HPP +#define NAZARA_SOUND_HPP + +#include +#include +#include +#include + +class NAZARA_API NzSound : public NzSoundEmitter +{ + public: + NzSound() = default; + NzSound(const NzSoundBuffer* soundBuffer); + NzSound(const NzSound& sound); + ~NzSound(); + + void EnableLooping(bool loop); + + const NzSoundBuffer* GetBuffer() const; + nzUInt32 GetDuration() const; + nzUInt32 GetPlayingOffset() const; + nzSoundStatus GetStatus() const; + + bool IsLooping() const; + + bool LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params = NzSoundBufferParams()); + bool LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params = NzSoundBufferParams()); + bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams()); + + void Pause(); + bool Play(); + + void SetBuffer(const NzSoundBuffer* buffer); + void SetPlayingOffset(nzUInt32 offset); + + void Stop(); + + private: + const NzSoundBuffer* m_buffer = nullptr; +}; + +#endif // NAZARA_SOUND_HPP diff --git a/include/Nazara/Audio/SoundBuffer.hpp b/include/Nazara/Audio/SoundBuffer.hpp new file mode 100644 index 000000000..71b69e173 --- /dev/null +++ b/include/Nazara/Audio/SoundBuffer.hpp @@ -0,0 +1,64 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_SOUNDBUFFER_HPP +#define NAZARA_SOUNDBUFFER_HPP + +#include +#include +#include +#include +#include +#include + +struct NzSoundBufferParams +{ + bool IsValid() const; +}; + +class NzSound; +class NzSoundBuffer; + +using NzSoundBufferLoader = NzResourceLoader; + +struct NzSoundBufferImpl; + +class NAZARA_API NzSoundBuffer : public NzResource, public NzNonCopyable +{ + friend NzSound; + friend NzSoundBufferLoader; + + public: + NzSoundBuffer() = default; + NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples); + ~NzSoundBuffer(); + + bool Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples); + void Destroy(); + + nzUInt32 GetDuration() const; + nzAudioFormat GetFormat() const; + const nzInt16* GetSamples() const; + unsigned int GetSampleCount() const; + unsigned int GetSampleRate() const; + + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params = NzSoundBufferParams()); + bool LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params = NzSoundBufferParams()); + bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams()); + + static bool IsFormatSupported(nzAudioFormat format); + + private: + unsigned int GetOpenALBuffer() const; + + NzSoundBufferImpl* m_impl = nullptr; + + static NzSoundBufferLoader::LoaderList s_loaders; +}; + +#endif // NAZARA_SOUNDBUFFER_HPP diff --git a/include/Nazara/Audio/SoundEmitter.hpp b/include/Nazara/Audio/SoundEmitter.hpp new file mode 100644 index 000000000..7d4d41d6a --- /dev/null +++ b/include/Nazara/Audio/SoundEmitter.hpp @@ -0,0 +1,60 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_SOUNDEMITTER_HPP +#define NAZARA_SOUNDEMITTER_HPP + +#include +#include +#include +#include +#include + +class NAZARA_API NzSoundEmitter +{ + public: + virtual ~NzSoundEmitter(); + + virtual void EnableLooping(bool loop) = 0; + void EnableSpatialization(bool spatialization); + + float GetAttenuation() const; + virtual nzUInt32 GetDuration() const = 0; + float GetMinDistance() const; + float GetPitch() const; + virtual nzUInt32 GetPlayingOffset() const = 0; + NzVector3f GetPosition() const; + NzVector3f GetVelocity() const; + virtual nzSoundStatus GetStatus() const = 0; + float GetVolume() const; + + virtual bool IsLooping() const = 0; + bool IsSpatialized() const; + + virtual void Pause() = 0; + virtual bool Play() = 0; + + void SetAttenuation(float attenuation); + void SetMinDistance(float minDistance); + void SetPitch(float pitch); + void SetPosition(const NzVector3f& position); + void SetPosition(float x, float y, float z); + void SetVelocity(const NzVector3f& velocity); + void SetVelocity(float velX, float velY, float velZ); + void SetVolume(float volume); + + virtual void Stop() = 0; + + protected: + NzSoundEmitter(); + NzSoundEmitter(const NzSoundEmitter& emitter); + + nzSoundStatus GetInternalStatus() const; + + unsigned int m_source; +}; + +#endif // NAZARA_SOUNDEMITTER_HPP diff --git a/include/Nazara/Core/Initializer.hpp b/include/Nazara/Core/Initializer.hpp index 66108a7a9..e6b04d462 100644 --- a/include/Nazara/Core/Initializer.hpp +++ b/include/Nazara/Core/Initializer.hpp @@ -7,6 +7,8 @@ #ifndef NAZARA_INITIALIZER_HPP #define NAZARA_INITIALIZER_HPP +///TODO: Utiliser les variadic template pour initialiser plusieurs modules à la fois ? + #include template diff --git a/include/Nazara/Core/Initializer.inl b/include/Nazara/Core/Initializer.inl index 2f814517d..4c031418d 100644 --- a/include/Nazara/Core/Initializer.inl +++ b/include/Nazara/Core/Initializer.inl @@ -17,7 +17,8 @@ NzInitializer::NzInitializer(Args... args) template NzInitializer::~NzInitializer() { - T::Uninitialize(); + if (T::IsInitialized()) + T::Uninitialize(); } template diff --git a/include/Nazara/Math/Basic.inl b/include/Nazara/Math/Basic.inl index 92f17ddd2..875ca00f8 100644 --- a/include/Nazara/Math/Basic.inl +++ b/include/Nazara/Math/Basic.inl @@ -193,7 +193,7 @@ T NzNormalizeAngle(T angle) template bool NzNumberEquals(T a, T b) { - return std::fabs(a-b) <= std::numeric_limits::epsilon(); + return std::fabs(a-b) < std::numeric_limits::epsilon(); } NzString NzNumberToString(long long number, nzUInt8 radix) diff --git a/src/Nazara/Audio/Audio.cpp b/src/Nazara/Audio/Audio.cpp new file mode 100644 index 000000000..eb5aaa0e6 --- /dev/null +++ b/src/Nazara/Audio/Audio.cpp @@ -0,0 +1,285 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + ALenum formats[nzAudioFormat_Max+1] = {0}; + ALCdevice* device = nullptr; + ALCcontext* context = nullptr; +} + +nzAudioFormat NzAudio::GetAudioFormat(unsigned int channelCount) +{ + switch (channelCount) + { + case 1: + case 2: + case 4: + case 6: + case 7: + case 8: + return static_cast(channelCount); + + default: + NazaraError("Invalid channel count: " + NzString::Number(channelCount)); + return nzAudioFormat_Unknown; + } +} + +float NzAudio::GetDopplerFactor() +{ + return alGetFloat(AL_DOPPLER_FACTOR); +} + +float NzAudio::GetGlobalVolume() +{ + ALfloat gain = 0.f; + alGetListenerf(AL_GAIN, &gain); + + return gain*100.f; +} + +NzVector3f NzAudio::GetListenerDirection() +{ + ALfloat orientation[6]; + alGetListenerfv(AL_ORIENTATION, orientation); + + return NzVector3f(orientation[0], orientation[1], orientation[2]); +} + +NzVector3f NzAudio::GetListenerPosition() +{ + NzVector3f position; + alGetListenerfv(AL_POSITION, position); + + return position; +} +/* +NzQuaternionf NzAudio::GetListenerRotation() +{ + // http://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-another + float orientation[6]; + alGetListenerfv(AL_ORIENTATION, orientation); + + NzVector3f forward(orientation[0], orientation[1], orientation[2]); + NzVector3f up(orientation[3], orientation[4], orientation[5]); + + NzQuaternionf rotation; + NzVector3f a = NzVector3f::CrossProduct(forward, up); + rotation.x = a.x; + rotation.y = a.y; + rotation.z = a.z; + rotation.w = std::sqrt(forward.SquaredLength() * up.SquaredLength()) + NzVector3f::DotProduct(forward, up); + + return rotation; +} +*/ +NzVector3f NzAudio::GetListenerVelocity() +{ + NzVector3f velocity; + alGetListenerfv(AL_VELOCITY, velocity); + + return velocity; +} + +float NzAudio::GetSpeedOfSound() +{ + return alGetFloat(AL_SPEED_OF_SOUND); +} + +bool NzAudio::Initialize() +{ + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation des dépendances + if (!NzCore::Initialize()) + { + NazaraError("Failed to initialize core module"); + return false; + } + + // Initialisation du module + device = alcOpenDevice(nullptr); // On choisit le device par défaut + if (!device) + { + NazaraError("Failed to open default device"); + return false; + } + + // Un seul contexte nous suffira + context = alcCreateContext(device, nullptr); + if (!context) + { + NazaraError("Failed to create context"); + + alcCloseDevice(device); + return false; + } + + if (!alcMakeContextCurrent(context)) + { + NazaraError("Failed to activate context"); + + alcDestroyContext(context); + alcCloseDevice(device); + return false; + } + + // Définition de l'orientation + /*{ + NzVector3f forward = NzVector3f::Forward(); + NzVector3f up = NzVector3f::Up(); + + ALfloat orientation[6] = + { + forward.x, forward.y, forward.z, + up.x, up.y, up.z + }; + + alListenerfv(AL_ORIENTATION, orientation); + }*/ + + formats[nzAudioFormat_Mono] = AL_FORMAT_MONO16; + formats[nzAudioFormat_Stereo] = AL_FORMAT_STEREO16; + formats[nzAudioFormat_Quad] = alGetEnumValue("AL_FORMAT_QUAD16"); + formats[nzAudioFormat_5_1] = alGetEnumValue("AL_FORMAT_51CHN16"); + formats[nzAudioFormat_6_1] = alGetEnumValue("AL_FORMAT_61CHN16"); + formats[nzAudioFormat_7_1] = alGetEnumValue("AL_FORMAT_71CHN16"); + + NzLoaders_sndfile_Register(); + + NazaraNotice("Initialized: Audio module"); + + return true; +} + +bool NzAudio::IsFormatSupported(nzAudioFormat format) +{ + if (format == nzAudioFormat_Unknown) + return false; + + return formats[format] != 0; +} + +bool NzAudio::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + +void NzAudio::SetDopplerFactor(float dopplerFactor) +{ + alDopplerFactor(dopplerFactor); +} + +void NzAudio::SetGlobalVolume(float volume) +{ + alListenerf(AL_GAIN, volume*0.01f); +} + +void NzAudio::SetListenerDirection(const NzVector3f& direction) +{ + ALfloat orientation[6] = + { + direction.x, direction.y, direction.z, + 0.f, 1.f, 0.f + }; + + alListenerfv(AL_ORIENTATION, orientation); +} + +void NzAudio::SetListenerDirection(float dirX, float dirY, float dirZ) +{ + ALfloat orientation[6] = + { + dirX, dirY, dirZ, + 0.f, 1.f, 0.f + }; + + alListenerfv(AL_ORIENTATION, orientation); +} + +void NzAudio::SetListenerPosition(const NzVector3f& position) +{ + alListenerfv(AL_POSITION, position); +} + +void NzAudio::SetListenerPosition(float x, float y, float z) +{ + alListener3f(AL_POSITION, x, y, z); +} +/* +void NzAudio::SetListenerRotation(const NzQuaternionf& rotation) +{ + NzVector3f forward = rotation * NzVector3f::Forward(); + NzVector3f up = NzVector3f::Up(); + + ALfloat orientation[6] = + { + forward.x, forward.y, forward.z, + up.x, up.y, up.z + }; + + alListenerfv(AL_ORIENTATION, orientation); +} +*/ +void NzAudio::SetListenerVelocity(const NzVector3f& velocity) +{ + alListenerfv(AL_VELOCITY, velocity); +} + +void NzAudio::SetListenerVelocity(float velX, float velY, float velZ) +{ + alListener3f(AL_VELOCITY, velX, velY, velZ); +} + +void NzAudio::SetSpeedOfSound(float speed) +{ + alSpeedOfSound(speed); +} + +void NzAudio::Uninitialize() +{ + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé + + // Libération du module + alcMakeContextCurrent(nullptr); + alcDestroyContext(context); + + if (!alcCloseDevice(device)) + // Nous n'avons pas pu fermer le device, ce qui signifie qu'il est en cours d'utilisation + NazaraWarning("Failed to close device"); + + NazaraNotice("Uninitialized: Audio module"); + + // Libération des dépendances + NzCore::Uninitialize(); +} + +unsigned int NzAudio::GetOpenALFormat(nzAudioFormat format) +{ + #ifdef NAZARA_DEBUG + if (format == nzAudioFormat_Unknown) + { + NazaraInternalError("Invalid audio format"); + return 0; + } + #endif + + return formats[format]; +} + +unsigned int NzAudio::s_moduleReferenceCouter = 0; diff --git a/src/Nazara/Audio/Loaders/sndfile.hpp b/src/Nazara/Audio/Loaders/sndfile.hpp new file mode 100644 index 000000000..73532fb87 --- /dev/null +++ b/src/Nazara/Audio/Loaders/sndfile.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_LOADERS_SNDFILE_HPP +#define NAZARA_LOADERS_SNDFILE_HPP + +#include + +void NzLoaders_sndfile_Register(); +void NzLoaders_sndfile_Unregister(); + +#endif // NAZARA_LOADERS_SNDFILE_HPP diff --git a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp new file mode 100644 index 000000000..3e0c73c51 --- /dev/null +++ b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp @@ -0,0 +1,135 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + sf_count_t GetSize(void* user_data) + { + NzInputStream* stream = reinterpret_cast(user_data); + return stream->GetSize(); + } + + sf_count_t Read(void* ptr, sf_count_t count, void* user_data) + { + NzInputStream* stream = reinterpret_cast(user_data); + return stream->Read(ptr, count); + } + + sf_count_t Seek(sf_count_t offset, int whence, void* user_data) + { + NzInputStream* stream = reinterpret_cast(user_data); + switch (whence) + { + case SEEK_CUR: + stream->Read(nullptr, offset); + break; + + case SEEK_END: + stream->SetCursorPos(stream->GetSize()+offset); + break; + + case SEEK_SET: + stream->SetCursorPos(offset); + break; + + default: + NazaraInternalError("Seek mode not handled"); + } + + return stream->GetCursorPos(); + } + + sf_count_t Tell(void* user_data) + { + NzInputStream* stream = reinterpret_cast(user_data); + return stream->GetCursorPos(); + } + + static SF_VIRTUAL_IO callbacks = {GetSize, Seek, Read, nullptr, Tell}; + + bool NzLoader_sndfile_Check(NzInputStream& stream, const NzSoundBufferParams& parameters) + { + NazaraUnused(parameters); + + SF_INFO info; + SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &info, &stream); + if (file) + { + sf_close(file); + return true; + } + else + return false; + } + + bool NzLoader_sndfile_Load(NzSoundBuffer* soundBuffer, NzInputStream& stream, const NzSoundBufferParams& parameters) + { + NazaraUnused(parameters); + + SF_INFO infos; + SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &infos, &stream); + if (!file) + { + NazaraError("Failed to load sound file: " + NzString(sf_strerror(file))); + return false; + } + + nzAudioFormat format = NzAudio::GetAudioFormat(infos.channels); + if (format == nzAudioFormat_Unknown) + { + NazaraError("Channel count not handled"); + sf_close(file); + + return false; + } + + unsigned int sampleCount = infos.frames*infos.channels; + nzInt16* samples = new nzInt16[sampleCount]; + if (sf_read_short(file, samples, sampleCount) != sampleCount) + { + NazaraError("Failed to read samples"); + delete[] samples; + sf_close(file); + + return false; + } + + if (!soundBuffer->Create(format, infos.frames*infos.channels, infos.samplerate, samples)) + { + NazaraError("Failed to create sound buffer"); + sf_close(file); + + return false; + } + + delete[] samples; + + return true; + } +} + +void NzLoaders_sndfile_Register() +{ + NzSoundBufferLoader::RegisterLoader("aiff,au,avr,caf,flac,htk,ircam,mat4,mat5,mpc2k,nist,ogg,paf,pvf,raw,rf64,sd2,sds,svx,voc,w64,wav,wve", + NzLoader_sndfile_Check, + NzLoader_sndfile_Load); +} + +void NzLoaders_sndfile_Unregister() +{ + NzSoundBufferLoader::UnregisterLoader("aiff,au,avr,caf,flac,htk,ircam,mat4,mat5,mpc2k,nist,ogg,paf,pvf,raw,rf64,sd2,sds,svx,voc,w64,wav,wve", + NzLoader_sndfile_Check, + NzLoader_sndfile_Load); +} diff --git a/src/Nazara/Audio/Sound.cpp b/src/Nazara/Audio/Sound.cpp new file mode 100644 index 000000000..9f21e3b57 --- /dev/null +++ b/src/Nazara/Audio/Sound.cpp @@ -0,0 +1,180 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +NzSound::NzSound(const NzSoundBuffer* soundBuffer) +{ + SetBuffer(soundBuffer); +} + +NzSound::NzSound(const NzSound& sound) : +NzSoundEmitter(sound) +{ + SetBuffer(sound.m_buffer); +} + +NzSound::~NzSound() +{ + Stop(); + + if (m_buffer) + m_buffer->RemoveResourceReference(); +} + +void NzSound::EnableLooping(bool loop) +{ + alSourcei(m_source, AL_LOOPING, loop); +} + +const NzSoundBuffer* NzSound::GetBuffer() const +{ + return m_buffer; +} + +nzUInt32 NzSound::GetDuration() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_buffer) + { + NazaraError("No sound buffer"); + return 0; + } + #endif + + return m_buffer->GetDuration(); +} + +nzUInt32 NzSound::GetPlayingOffset() const +{ + ALfloat seconds = -1.f; + alGetSourcef(m_source, AL_SEC_OFFSET, &seconds); + + return static_cast(seconds*1000); +} + +nzSoundStatus NzSound::GetStatus() const +{ + return GetInternalStatus(); +} + +bool NzSound::IsLooping() const +{ + ALint loop; + alGetSourcei(m_source, AL_LOOPING, &loop); + + return loop != AL_FALSE; +} + +bool NzSound::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params) +{ + NzSoundBuffer* buffer = new NzSoundBuffer; + if (!buffer->LoadFromFile(filePath, params)) + { + NazaraError("Failed to load buffer from file (" + filePath + ')'); + delete buffer; + + return false; + } + + SetBuffer(buffer); + + buffer->SetPersistent(false); + + return true; +} + +bool NzSound::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params) +{ + NzSoundBuffer* buffer = new NzSoundBuffer; + if (!buffer->LoadFromMemory(data, size, params)) + { + NazaraError("Failed to load buffer from memory (" + NzString::Pointer(data) + ')'); + delete buffer; + + return false; + } + + SetBuffer(buffer); + + buffer->SetPersistent(false); + + return true; +} + +bool NzSound::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params) +{ + NzSoundBuffer* buffer = new NzSoundBuffer; + if (!buffer->LoadFromStream(stream, params)) + { + NazaraError("Failed to load buffer from stream"); + delete buffer; + + return false; + } + + SetBuffer(buffer); + + buffer->SetPersistent(false); + + return true; +} + +void NzSound::Pause() +{ + alSourcePause(m_source); +} + +bool NzSound::Play() +{ + #if NAZARA_AUDIO_SAFE + if (!m_buffer) + { + NazaraError("No sound buffer to play"); + return false; + } + #endif + + alSourcePlay(m_source); + + return true; +} + +void NzSound::SetBuffer(const NzSoundBuffer* buffer) +{ + if (m_buffer == buffer) + return; + + Stop(); + + if (m_buffer) + m_buffer->RemoveResourceReference(); + + m_buffer = buffer; + + if (m_buffer) + { + m_buffer->AddResourceReference(); + alSourcei(m_source, AL_BUFFER, m_buffer->GetOpenALBuffer()); + } + else + alSourcei(m_source, AL_BUFFER, AL_NONE); +} + +void NzSound::SetPlayingOffset(nzUInt32 offset) +{ + alSourcef(m_source, AL_SEC_OFFSET, offset/1000.f); +} + +void NzSound::Stop() +{ + alSourceStop(m_source); +} diff --git a/src/Nazara/Audio/SoundBuffer.cpp b/src/Nazara/Audio/SoundBuffer.cpp new file mode 100644 index 000000000..6c5bdd1ac --- /dev/null +++ b/src/Nazara/Audio/SoundBuffer.cpp @@ -0,0 +1,223 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +///FIXME: Adapter la création + +bool NzSoundBufferParams::IsValid() const +{ + return true; +} + +struct NzSoundBufferImpl +{ + ALuint buffer; + nzAudioFormat format; + nzUInt32 duration; + nzInt16* samples; + unsigned int sampleCount; + unsigned int sampleRate; +}; + +NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) +{ + Create(format, sampleCount, sampleRate, samples); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create sound buffer"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzSoundBuffer::~NzSoundBuffer() +{ + Destroy(); +} + +bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) +{ + Destroy(); + + if (sampleCount == 0) + return true; + + #if NAZARA_AUDIO_SAFE + if (!IsFormatSupported(format)) + { + NazaraError("Audio format is not supported"); + return false; + } + + if (sampleRate == 0) + { + NazaraError("Sample rate must be different from zero"); + return false; + } + + if (!samples) + { + NazaraError("Invalid sample source"); + return false; + } + #endif + + // On vide le stack d'erreurs + while (alGetError() != AL_NO_ERROR); + + ALuint buffer; + alGenBuffers(1, &buffer); + + if (alGetError() != AL_NO_ERROR) + { + NazaraError("Failed to create OpenAL buffer"); + return false; + } + + alBufferData(buffer, NzAudio::GetOpenALFormat(format), samples, sampleCount*sizeof(nzInt16), sampleRate); + + if (alGetError() != AL_NO_ERROR) + { + NazaraError("Failed to set OpenAL buffer"); + alDeleteBuffers(1, &buffer); + + return false; + } + + m_impl = new NzSoundBufferImpl; + m_impl->buffer = buffer; + m_impl->duration = 1000 * (sampleCount / (format * sampleRate)); + m_impl->format = format; + m_impl->sampleCount = sampleCount; + m_impl->sampleRate = sampleRate; + m_impl->samples = new nzInt16[sampleCount]; + std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16)); + + return true; +} + +void NzSoundBuffer::Destroy() +{ + if (m_impl) + { + delete[] m_impl->samples; + delete m_impl; + m_impl = nullptr; + } +} + +nzUInt32 NzSoundBuffer::GetDuration() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->duration; +} + +nzAudioFormat NzSoundBuffer::GetFormat() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return nzAudioFormat_Unknown; + } + #endif + + return m_impl->format; +} + +const nzInt16* NzSoundBuffer::GetSamples() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return nullptr; + } + #endif + + return m_impl->samples; +} + +unsigned int NzSoundBuffer::GetSampleCount() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->sampleCount; +} + +unsigned int NzSoundBuffer::GetSampleRate() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->sampleRate; +} + +bool NzSoundBuffer::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzSoundBuffer::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromFile(this, filePath, params); +} + +bool NzSoundBuffer::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromMemory(this, data, size, params); +} + +bool NzSoundBuffer::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromStream(this, stream, params); +} + +bool NzSoundBuffer::IsFormatSupported(nzAudioFormat format) +{ + return NzAudio::IsFormatSupported(format); +} + +unsigned int NzSoundBuffer::GetOpenALBuffer() const +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Sound buffer not created"); + return AL_NONE; + } + #endif + + return m_impl->buffer; +} + +NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders; diff --git a/src/Nazara/Audio/SoundEmitter.cpp b/src/Nazara/Audio/SoundEmitter.cpp new file mode 100644 index 000000000..5ce197f47 --- /dev/null +++ b/src/Nazara/Audio/SoundEmitter.cpp @@ -0,0 +1,156 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf + +#include +#include +#include +#include + +NzSoundEmitter::NzSoundEmitter() +{ + alGenSources(1, &m_source); +} + +NzSoundEmitter::NzSoundEmitter(const NzSoundEmitter& emitter) +{ + alGenSources(1, &m_source); + + SetAttenuation(emitter.GetAttenuation()); + SetMinDistance(emitter.GetMinDistance()); + SetPitch(emitter.GetPitch()); + // Pas de copie de position ou de vitesse + SetVolume(emitter.GetVolume()); +} + +NzSoundEmitter::~NzSoundEmitter() +{ + alDeleteSources(1, &m_source); +} + +void NzSoundEmitter::EnableSpatialization(bool spatialization) +{ + alSourcei(m_source, AL_SOURCE_RELATIVE, spatialization); +} + +float NzSoundEmitter::GetAttenuation() const +{ + ALfloat attenuation; + alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &attenuation); + + return attenuation; +} + +float NzSoundEmitter::GetMinDistance() const +{ + ALfloat distance; + alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &distance); + + return distance; +} + +float NzSoundEmitter::GetPitch() const +{ + ALfloat pitch; + alGetSourcef(m_source, AL_PITCH, &pitch); + + return pitch; +} + +NzVector3f NzSoundEmitter::GetPosition() const +{ + NzVector3f position; + alGetSourcefv(m_source, AL_POSITION, position); + + return position; +} + +NzVector3f NzSoundEmitter::GetVelocity() const +{ + NzVector3f velocity; + alGetSourcefv(m_source, AL_VELOCITY, velocity); + + return velocity; +} + +float NzSoundEmitter::GetVolume() const +{ + ALfloat gain; + alGetSourcef(m_source, AL_GAIN, &gain); + + return gain * 100.f; +} + +bool NzSoundEmitter::IsSpatialized() const +{ + ALint relative; + alGetSourcei(m_source, AL_SOURCE_RELATIVE, &relative); + + return relative != AL_FALSE; +} + +void NzSoundEmitter::SetAttenuation(float attenuation) +{ + alSourcef(m_source, AL_ROLLOFF_FACTOR, attenuation); +} + +void NzSoundEmitter::SetMinDistance(float minDistance) +{ + alSourcef(m_source, AL_REFERENCE_DISTANCE, minDistance); +} + +void NzSoundEmitter::SetPitch(float pitch) +{ + alSourcef(m_source, AL_PITCH, pitch); +} + +void NzSoundEmitter::SetPosition(const NzVector3f& position) +{ + alSourcefv(m_source, AL_POSITION, position); +} + +void NzSoundEmitter::SetPosition(float x, float y, float z) +{ + alSource3f(m_source, AL_POSITION, x, y, z); +} + +void NzSoundEmitter::SetVelocity(const NzVector3f& velocity) +{ + alSourcefv(m_source, AL_VELOCITY, velocity); +} + +void NzSoundEmitter::SetVelocity(float velX, float velY, float velZ) +{ + alSource3f(m_source, AL_VELOCITY, velX, velY, velZ); +} + +void NzSoundEmitter::SetVolume(float volume) +{ + alSourcef(m_source, AL_GAIN, volume*0.01f); +} + +nzSoundStatus NzSoundEmitter::GetInternalStatus() const +{ + ALint state; + alGetSourcei(m_source, AL_SOURCE_STATE, &state); + + switch (state) + { + case AL_INITIAL: + case AL_STOPPED: + return nzSoundStatus_Stopped; + + case AL_PAUSED: + return nzSoundStatus_Paused; + + case AL_PLAYING: + return nzSoundStatus_Playing; + + default: + NazaraInternalError("Source state unrecognized"); + } + + return nzSoundStatus_Stopped; +} From a6ed70123b2ea6a1152c8d02c840ab03a1009758 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 21 Aug 2012 15:18:21 +0200 Subject: [PATCH 11/31] Added missing external libraries binaries Former-commit-id: 8c1faed067e523a94b81cbf3658df6a6096898c0 --- .gitignore | 20 +++++++------------- include/Nazara/Audio.hpp | 2 -- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 05f2ebb62..17a094d29 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,13 @@ # CodeLite *.project +# Nazara build + +examples/bin +lib/libNazara*.a +lib/Nazara*.dll +lib/Nazara*.so + # Compiled Object files *.slo *.lo @@ -20,22 +27,10 @@ # Compiled Static libraries *.lai *.la -*.a # Object files *.o -# Libraries -*.lib - -# Shared objects (inc. Windows DLLs) -*.dll -*.so - -# Executables -*.exe -*.out - # Windows image file caches Thumbs.db @@ -54,7 +49,6 @@ $RECYCLE.BIN/ *.sln.docstates # Build results - [Dd]ebug*/ [Rr]elease/ diff --git a/include/Nazara/Audio.hpp b/include/Nazara/Audio.hpp index 1cc185a95..3dbc52270 100644 --- a/include/Nazara/Audio.hpp +++ b/include/Nazara/Audio.hpp @@ -29,8 +29,6 @@ #include #include #include -#include #include #include #include -#include From cd5a1b7a5e16382f736821efed6c1c533392ab06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 20 Sep 2012 22:07:30 +0200 Subject: [PATCH 12/31] Added RenderTextures (And many others things) -Added Forward, left and up vector (Vector3) -Added Matrix4::ConcatenateAffine shortcut -Added Quaternion::GetInverse() and Quaternion::Inverse() -Added Resource listeners -Added Depth and stencil pixel formats -All enums now have an ending "max" entry -Animation/Mesh::Add[Sequence/Skin/SubMesh] now returns a boolean -Contexts are now resources -Enhanced AnimatedMesh demo -Fixed MD2 facing -Fixed Vector3::CrossProduct -Made Resource thread-safe -Made OpenGL translation table global -Many bugfixes -MLT will now write malloc failure to the log -Most of the strcpy were replaced with faster memcpy -Occlusion queries availability is now always tested -OpenGL-related includes now requires NAZARA_RENDERER_OPENGL to be defined to have any effect -Pixel formats now have a type -Renamed RenderTarget::IsValid to IsRenderable -Renamed Quaternion::GetNormalized() to GetNormal() -Renamed Texture::Bind() to Prepare() -Renamed VectorX::Make[Ceil|Floor] to Maximize/Minimize -Removed MATH_MATRIX_COLUMN_MAJOR option (all matrices are column-major) -Removed RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION option (Render windows are active upon their creation) Former-commit-id: 0d1da1e32c156a958221edf04a5315c75b354450 --- build/scripts/module/renderer.lua | 80 +- examples/AnimatedMesh/main.cpp | 1275 +- include/Nazara/Core.hpp | 123 +- include/Nazara/Core/Config.hpp | 169 +- include/Nazara/Core/Enums.hpp | 56 +- include/Nazara/Core/Resource.hpp | 102 +- include/Nazara/Core/ResourceListener.hpp | 25 + include/Nazara/Core/ResourceLoader.inl | 284 +- include/Nazara/Core/String.hpp | 642 +- include/Nazara/Math/Config.hpp | 101 +- include/Nazara/Math/Matrix4.hpp | 289 +- include/Nazara/Math/Matrix4.inl | 1940 ++-- include/Nazara/Math/Quaternion.hpp | 183 +- include/Nazara/Math/Quaternion.inl | 831 +- include/Nazara/Math/Vector2.hpp | 209 +- include/Nazara/Math/Vector2.inl | 976 +- include/Nazara/Math/Vector3.hpp | 232 +- include/Nazara/Math/Vector3.inl | 1135 +- include/Nazara/Math/Vector4.hpp | 195 +- include/Nazara/Math/Vector4.inl | 1006 +- include/Nazara/Renderer.hpp | 81 +- include/Nazara/Renderer/Config.hpp | 85 +- include/Nazara/Renderer/Context.hpp | 96 +- include/Nazara/Renderer/Enums.hpp | 315 +- include/Nazara/Renderer/OpenGL.hpp | 425 +- include/Nazara/Renderer/RenderTarget.hpp | 83 +- include/Nazara/Renderer/RenderTexture.hpp | 60 + include/Nazara/Renderer/RenderWindow.hpp | 139 +- include/Nazara/Renderer/Texture.hpp | 181 +- include/Nazara/Utility/Animation.hpp | 155 +- include/Nazara/Utility/Enums.hpp | 470 +- include/Nazara/Utility/Mesh.hpp | 191 +- include/Nazara/Utility/PixelFormat.hpp | 107 +- include/Nazara/Utility/PixelFormat.inl | 858 +- include/Nazara/Utility/StaticMesh.hpp | 100 +- include/Nazara/Utility/VertexDeclaration.hpp | 109 +- include/Nazara/Utility/Window.hpp | 223 +- src/Nazara/Audio/SoundBuffer.cpp | 452 +- src/Nazara/Core/ByteArray.cpp | 530 +- src/Nazara/Core/Debug/MemoryLeakTracker.cpp | 535 +- src/Nazara/Core/Resource.cpp | 192 +- src/Nazara/Core/ResourceListener.cpp | 26 + src/Nazara/Core/String.cpp | 10325 +++++++++-------- src/Nazara/Renderer/Context.cpp | 714 +- src/Nazara/Renderer/GLSLShader.cpp | 1290 +- src/Nazara/Renderer/GLSLShader.hpp | 154 +- src/Nazara/Renderer/HardwareBuffer.cpp | 468 +- src/Nazara/Renderer/OcclusionQuery.cpp | 200 +- src/Nazara/Renderer/OpenGL.cpp | 1717 +-- src/Nazara/Renderer/RenderTexture.cpp | 728 ++ src/Nazara/Renderer/RenderWindow.cpp | 554 +- src/Nazara/Renderer/Renderer.cpp | 1910 ++- src/Nazara/Renderer/Shader.cpp | 1251 +- src/Nazara/Renderer/Texture.cpp | 3186 +++-- src/Nazara/Renderer/Win32/ContextImpl.cpp | 465 +- src/Nazara/Utility/Animation.cpp | 659 +- src/Nazara/Utility/Buffer.cpp | 676 +- src/Nazara/Utility/Image.cpp | 2357 ++-- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 421 +- src/Nazara/Utility/Loaders/MD2/Mesh.cpp | 579 +- src/Nazara/Utility/Loaders/PCX/Loader.cpp | 698 +- src/Nazara/Utility/Mesh.cpp | 1304 ++- src/Nazara/Utility/StaticMesh.cpp | 385 +- src/Nazara/Utility/VertexDeclaration.cpp | 718 +- src/Nazara/Utility/Window.cpp | 1063 +- 65 files changed, 24385 insertions(+), 22703 deletions(-) create mode 100644 include/Nazara/Core/ResourceListener.hpp create mode 100644 include/Nazara/Renderer/RenderTexture.hpp create mode 100644 src/Nazara/Core/ResourceListener.cpp create mode 100644 src/Nazara/Renderer/RenderTexture.cpp diff --git a/build/scripts/module/renderer.lua b/build/scripts/module/renderer.lua index 391830ee2..f154cbbd7 100644 --- a/build/scripts/module/renderer.lua +++ b/build/scripts/module/renderer.lua @@ -1,40 +1,42 @@ -if (not _OPTIONS["one-library"]) then - project "NazaraRenderer" -end - -files -{ - "../include/Nazara/Renderer/**.hpp", - "../include/Nazara/Renderer/**.inl", - "../src/Nazara/Renderer/**.hpp", - "../src/Nazara/Renderer/**.cpp" -} - -if (os.is("windows")) then - excludes { "../src/Nazara/Renderer/Posix/*.hpp", "../src/Nazara/Renderer/Posix/*.cpp" } - links "gdi32" - links "opengl32" - links "winmm" -else - excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } -end - -if (_OPTIONS["one-library"]) then - excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" -else - configuration "DebugStatic" - links "NazaraCore-s-d" - links "NazaraUtility-s-d" - - configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraUtility-s" - - configuration "DebugDLL" - links "NazaraCore-d" - links "NazaraUtility-d" - - configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraUtility" +if (not _OPTIONS["one-library"]) then + project "NazaraRenderer" +end + +defines "NAZARA_RENDERER_OPENGL" + +files +{ + "../include/Nazara/Renderer/**.hpp", + "../include/Nazara/Renderer/**.inl", + "../src/Nazara/Renderer/**.hpp", + "../src/Nazara/Renderer/**.cpp" +} + +if (os.is("windows")) then + excludes { "../src/Nazara/Renderer/Posix/*.hpp", "../src/Nazara/Renderer/Posix/*.cpp" } + links "gdi32" + links "opengl32" + links "winmm" +else + excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } +end + +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCore-s-d" + links "NazaraUtility-s-d" + + configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraUtility-s" + + configuration "DebugDLL" + links "NazaraCore-d" + links "NazaraUtility-d" + + configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraUtility" end \ No newline at end of file diff --git a/examples/AnimatedMesh/main.cpp b/examples/AnimatedMesh/main.cpp index 12ba84677..fbe4af5c2 100644 --- a/examples/AnimatedMesh/main.cpp +++ b/examples/AnimatedMesh/main.cpp @@ -1,613 +1,662 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Une structure pour contenir nos informations (Cette structure est très simpliste) -struct Model -{ - NzMatrix4f matrix; // Les transformations subies par le modèle - NzMesh mesh; // Le mesh - NzTexture texture; // Sa texture -}; - -struct AnimatedModel : public Model -{ - // Quelques variables pour l'animation - const NzSequence* currentSequence = nullptr; // La séquence en cours - float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) - unsigned int currentFrame = 0; // La première frame - unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là -}; - -void AnimateModel(AnimatedModel& moedel, float elapsed); -bool CreateCheckerTexture(NzTexture* texture); -bool CreateFloorMesh(NzMesh* mesh); -void DrawModel(const Model& model); -void SetSequence(AnimatedModel& model, const NzString& name); - -int main() -{ - // Tout d'abord on affiche les instructions - std::cout << "Camera controls: ZQSD" << std::endl; - std::cout << "Dr. Freak controls: Up, down, left and right" << std::endl; - std::cout << "Escape to quit" << std::endl; - - // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) - NzContextParameters::defaultCompatibilityProfile = true; - - // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utilitaire) - // Cette étape est obligatoire pour beaucoup de fonctionnalités (Notamment le chargement de ressources et le rendu) - NzInitializer renderer; - if (!renderer) - { - // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log - std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; - std::getchar(); // On laise le temps de voir l'erreur - return EXIT_FAILURE; - } - - // 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 - // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] - // Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters - NzMeshParams parameters; - - // Le loader doit-il automatiquement charger les animations ? - // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. - // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné - // qu'elles sont fourniees avec le mesh. - // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut - // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés - parameters.loadAnimations = true; // Vaut true par défaut - - // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de - // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. - parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut - - AnimatedModel drfreak; - if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. - { - // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. - std::cout << "Failed to load mesh" << std::endl; - std::getchar(); // On laise le temps de voir l'erreur - return EXIT_FAILURE; - } - - if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? - { - // Cette démo n'a aucun intérêt sans animations - std::cout << "Mesh has no animation" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - SetSequence(drfreak, "stand"); - - // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture - if (drfreak.mesh.HasSkin()) - { - // Contrairement aux autres ressources, la texture n'est pas critique - if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin())) - drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire - else - std::cout << "Failed to load texture" << std::endl; - } - - if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée - { - std::cout << "Creating checker texture for mesh" << std::endl; - - if (!CreateCheckerTexture(&drfreak.texture)) - { - std::cout << "Failed to create mesh texture" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - } - - // Nous créons maintenant notre sol - Model floor; - if (!CreateFloorMesh(&floor.mesh)) - { - std::cout << "Failed to create floor" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - if (!CreateCheckerTexture(&floor.texture)) - { - std::cout << "Failed to create floor texture" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Le sol ne subit aucune transformation - floor.matrix.MakeIdentity(); - - // Pour effectuer un rendu, il faut que la carte graphique sache quoi faire. - // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors du pipeline. - // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! - // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. - // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL - // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. - NzShader shader; - if (!shader.Create(nzShaderLanguage_GLSL)) - { - std::cout << "Failed to load shader" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders - // Pour notre exemple nous prendrons un shader très simple - // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader - if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag")) - { - std::cout << "Failed to load fragment shader from file" << std::endl; - // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec - std::cout << "Log: " << shader.GetLog() << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Maintenant le vertex shader - if (!shader.LoadFromFile(nzShaderType_Vertex, "shaders/basic.vert")) - { - std::cout << "Failed to load vertex shader from file" << std::endl; - std::cout << "Log: " << shader.GetLog() << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Une fois le code source de nos shaders chargé, nous pouvons le compiler, afin de le rendre utilisable - if (!shader.Compile()) - { - std::cout << "Failed to compile shader" << std::endl; - std::cout << "Log: " << shader.GetLog() << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça - // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow - // Tout d'abord, sa taille, disons celle du bureau divisé par deux - NzVideoMode mode = NzVideoMode::GetDesktopMode(); - mode.width /= 2; - mode.height /= 2; - - NzString title = "Nazara Demo - AnimatedMesh"; - - NzRenderWindow window; - // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède une bordure elle sera légèrement plus grande) - // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle - // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. - // Attention que cela permet à la fenêtre d'envoyer des évènements, et de changer sa taille - // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) - if (!window.Create(mode, title, nzWindowStyle_Default)) - { - std::cout << "Failed to create window" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // On cache le curseur - window.SetCursor(nzWindowCursor_None); - - // Nous limitons les FPS à 100 - window.SetFramerateLimit(100); - - // La matrice de projection définit la transformation du vertice 3D à un point 2D - NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(window.GetWidth())/window.GetHeight(), 1.f, 1000.f)); - - // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements - NzClock secondClock, updateClock; // Des horloges pour gérer le temps - unsigned int fps = 0; // Compteur de FPS - - // Quelques variables pour notre improvisation de physique - float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Pas très exact - NzVector3f modelPos(0.f, groundPos, -50.f); - NzVector3f modelVel(0.f, 0.f, 0.f); - NzQuaternionf modelRot(NzEulerAnglesf(0.f, 0.f, 0.f)); // Les angles d'eulers sont bien plus facile à se représenter - float speed = 60.f; - - // Nous initialisons la matrice - drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); - - // Notre caméra - NzVector3f camPos(0.f, 25.f, -20.f); - NzEulerAnglesf camRot(0.f, 0.f, 0.f); - NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos); - float camSpeed = 2.f; - float sensitivity = 0.5; - - // Dernière étape, nos touches - - // Chaque touche fera bouger - struct Movement - { - NzVector3f direction; // La direction - NzQuaternionf rotation; // La rotation du modèle - }; - - std::map movements; - movements[NzKeyboard::Up] = Movement{NzVector3f(0.f, 0.f, -1.f), NzQuaternionf(NzEulerAnglesf(0.f, 180.f, 0.f))}; - movements[NzKeyboard::Down] = Movement{NzVector3f(0.f, 0.f, 1.f), NzQuaternionf(NzEulerAnglesf(0.f, 0.f, 0.f))}; - movements[NzKeyboard::Left] = Movement{NzVector3f(-1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, 90.f, 0.f))}; - movements[NzKeyboard::Right] = Movement{NzVector3f(1.f, 0.f, 0.f), NzQuaternionf(NzEulerAnglesf(0.f, -90.f, 0.f))}; - NzKeyboard::Key currentKey = NzKeyboard::Undefined; - - // Quelques booléens - bool camMode = true; - bool windowOpen = true; - - // On peut commencer la boucle du programme - while (windowOpen) - { - // Ici nous gérons les évènements - NzEvent event; - while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? - { - // Nous avons un évènement - switch (event.type) // De quel type est cet évènement ? - { - case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution - windowOpen = false; // Nous terminons alors la boucle - break; - - case nzEventType_MouseMoved: - { - // Si nous ne sommes pas en mode caméra, on ne traite pas l'évènement - if (!camMode) - break; - - // On modifie l'angle de la caméra grâce au déplacement relatif de la souris - camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity); - - // Pour éviter les loopings, on restreint les angles - camRot.pitch = NzClamp(camRot.pitch + event.mouseMove.deltaY*sensitivity, -90.f, 90.f); - - // La matrice vue représente les transformations effectuées par la caméra - // On recalcule la matrice de la caméra et on l'envoie au renderer - NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot)); - - // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre - NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window); - break; - } - - case nzEventType_MouseButtonPressed: - if (event.mouseButton.button == NzMouse::Left) - { - // L'utilisateur vient d'appuyer sur le bouton left de la souris - // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence - if (camMode) - { - camMode = false; - window.SetCursor(nzWindowCursor_Default); - } - else - { - camMode = true; - window.SetCursor(nzWindowCursor_None); - } - - } - break; - - case nzEventType_Resized: // L'utilisateur a changé notre taille, le coquin ! - NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage - - // Il nous faut aussi mettre à jour notre matrice de projection - NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(event.size.width)/event.size.height, 1.f, 1000.f)); - break; - - case nzEventType_KeyPressed: - if (!event.key.repeated) // Si la touche n'est pas répétée - { - auto it = movements.find(event.key.code); - if (it != movements.end()) - { - // Si la touche est une touche de mouvement - SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement - - modelRot = it->second.rotation; // On change la rotation du modèle - drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); // On recalcule sa matrice - modelVel = it->second.direction * speed; // On change la vitesse de déplacement - currentKey = event.key.code; - } - } - - if (event.key.code == NzKeyboard::Escape) - windowOpen = false; - - break; - - case nzEventType_KeyReleased: - if (event.key.code == currentKey) - { - SetSequence(drfreak, "stand"); - modelVel = NzVector3f(0.f); // On arrête le déplacement - break; - } - - break; - - default: // Les autres évènements, on s'en fiche - break; - } - } - - // On active le shader et paramètrons le rendu - NzRenderer::SetShader(&shader); - NzRenderer::Enable(nzRendererParameter_DepthTest, true); - - NzRenderer::SetClearColor(128, 128, 128); - NzRenderer::Clear(nzRendererClear_Color | nzRendererClear_Depth); - - if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde - { - float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour - - // Déplacement de la caméra - static const NzVector3f forward(NzVector3f::UnitZ()); - static const NzVector3f left(NzVector3f::UnitX()); - static const NzVector3f up(NzVector3f::UnitY()); - - // Notre rotation sous forme de quaternion nous permet de tourner un vecteur - NzQuaternionf quaternion(camRot); - - // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" - if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) - camPos += quaternion * forward * camSpeed; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) - camPos -= quaternion * forward * camSpeed; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) - camPos += quaternion * left * camSpeed; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) - camPos -= quaternion * left * camSpeed; - - // En revanche, ici la hauteur est toujours la même, peu importe notre orientation - if (NzKeyboard::IsKeyPressed(NzKeyboard::Space)) - camPos += up * camSpeed; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl)) - camPos -= up * camSpeed; - - // Oui le quaternion et la matrice sont calculés même si la caméra ne bouge pas - // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés - NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::Translate(camPos) * NzMatrix4f::Rotate(camRot)); - - // Animation - AnimateModel(drfreak, elapsedTime); - updateClock.Restart(); - - // "Physique" - if (modelVel != NzVector3f::Zero()) - { - modelPos += modelVel * elapsedTime; - - // Mise à jour de la matrice - drfreak.matrix = NzMatrix4f::Rotate(modelRot) * NzMatrix4f::Translate(modelPos); - } - } - - // Affichage des meshs - DrawModel(floor); - - // Notre Dr. Freak possède des normales, nous pouvons alors culler les faces qu'on ne voit pas - NzRenderer::Enable(nzRendererParameter_FaceCulling, true); - - DrawModel(drfreak); - - NzRenderer::Enable(nzRendererParameter_FaceCulling, false); - - window.Display(); // Nous mettons à jour l'écran - - fps++; - - // Toutes les secondes - if (secondClock.GetMilliseconds() >= 1000) - { - window.SetTitle(title + " (FPS: " + NzString::Number(fps) + ')'); - fps = 0; - secondClock.Restart(); - } - } - - return EXIT_SUCCESS; -} - -void AnimateModel(AnimatedModel& model, float elapsed) -{ - model.interpolation += model.currentSequence->framePerSecond * elapsed; - while (model.interpolation > 1.f) - { - model.interpolation -= 1.f; - - model.currentFrame = model.nextFrame; - if (++model.nextFrame > model.currentSequence->lastFrame) - model.nextFrame = model.currentSequence->firstFrame; - } - - model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation); -} - -bool CreateCheckerTexture(NzTexture* texture) -{ - NzImage image; - // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) - if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16)) - { - // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) - std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl; - return false; - } - - // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel - // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. - unsigned int blockCountX = image.GetWidth()/16; - unsigned int blockCountY = image.GetHeight()/16; - for (unsigned int x = 0; x < blockCountX; ++x) - { - for (unsigned int y = 0; y < blockCountY; ++y) - { - // Une belle texture de damier - NzColor color = (x%2 == y%2) ? NzColor::White : NzColor::Black; - // Fill remplit une zone de la texture avec une couleur - image.Fill(color, NzRectui(x*16, y*16, 16, 16)); - } - } - - if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image - { - // Nous n'avons vraiment pas beaucoup de chance.. - std::cout << "Failed to load image" << std::endl; - return false; - } - - texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture - texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée - - return true; -} - -bool CreateFloorMesh(NzMesh* mesh) -{ - // Cette fonction créé un mesh statique simpliste pour servir de sol - - // Nous créons un mesh statique - if (!mesh->Create(nzAnimationType_Static)) - { - // L'échec est techniquement impossible mais le moteur étant en constante évolution ... - std::cout << "Failed to create mesh" << std::endl; - return false; - } - - // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer - // Elles sont composées de VertexElement, chacun décrivant un élément du buffer - NzVertexDeclaration* declaration = new NzVertexDeclaration; - - // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) - // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) - // -Usage: Comment cette donnée doit-elle être envoyée au shader - // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) - // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) - // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. - NzVertexElement elements[2]; - elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices - elements[0].offset = 0; // Celles-ci sont placées au début - elements[0].type = nzElementType_Float3; // Sont composées de trois flottants - - elements[1].usage = nzElementUsage_TexCoord; - elements[1].offset = 3*sizeof(float); - elements[1].type = nzElementType_Float2; - - if (!declaration->Create(elements, 2)) - { - // Nos éléments sont invalides ! - std::cout << "Failed to create vertex declaration" << std::endl; - return false; - } - - // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage - // Et nous indiquons que nous n'y toucherons plus - NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static); - - // Doit respecter la declaration - float vertices[] = - { - // Vertex 1 - -1000.f, 0.f, -1000.f, // Position - 0.f, 0.f, // UV - - // Vertex 2 - -1000.f, 0.f, 1000.f, // Position - 0.f, 10.f, // UV - - // Vertex 3 - 1000.f, 0.f, -1000.f, // Position - 10.f, 0.f, // UV - - // Vertex 4 - 1000.f, 0.f, 1000.f, // Position - 10.f, 10.f // UV - }; - - // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) - if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices - { - std::cout << "Failed to fill buffer" << std::endl; - return false; - } - - NzStaticMesh* subMesh = new NzStaticMesh(mesh); - if (!subMesh->Create(declaration, buffer)) - { - std::cout << "Failed to create subMesh" << std::endl; - return false; - } - - subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip); - - // On ajoute le submesh au mesh - mesh->AddSubMesh(subMesh); - - // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. - // Les ressources seront donc automatiquement libérées lorsque plus aucune classe n'en aura besoin - buffer->SetPersistent(false); - declaration->SetPersistent(false); - subMesh->SetPersistent(false); // Pour le submesh, c'est déjà à false à la base - - return true; -} - -void DrawModel(const Model& model) -{ - // La matrice world est celle qui représente les transformations du modèle - NzRenderer::SetMatrix(nzMatrixType_World, model.matrix); - - NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu - shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture); - - // Un mesh est divisé en plusieurs submeshes - unsigned int subMeshCount = model.mesh.GetSubMeshCount(); - for (unsigned int i = 0; i < subMeshCount; ++i) - { - // On récupère le submesh - const NzSubMesh* subMesh = model.mesh.GetSubMesh(i); - - // On paramètre le Renderer avec ses données - NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer()); - NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer()); - NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration()); - - // On fait le rendu - NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount()); - } -} - -void SetSequence(AnimatedModel& model, const NzString& sequenceName) -{ - // On récupère l'animation du mesh - const NzAnimation* animation = model.mesh.GetAnimation(); - - // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) - model.currentSequence = animation->GetSequence(sequenceName); - - // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame - model.nextFrame = model.currentSequence->firstFrame; -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Une structure pour contenir nos informations (Cette structure est très simpliste) +struct Model +{ + NzMatrix4f matrix; // Les transformations subies par le modèle + NzMesh mesh; // Le mesh + NzTexture texture; // Sa texture +}; + +struct AnimatedModel : public Model +{ + // Quelques variables pour l'animation + const NzSequence* currentSequence = nullptr; // La séquence en cours + float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) + unsigned int currentFrame = 0; // La première frame + unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là +}; + +void AnimateModel(AnimatedModel& moedel, float elapsed); +bool CreateCheckerTexture(NzTexture* texture); +bool CreateFloorMesh(NzMesh* mesh); +void DrawModel(const Model& model); +void SetSequence(AnimatedModel& model, const NzString& name); + +int main() +{ + // Tout d'abord on affiche les instructions + std::cout << "Controls: ZQSD" << std::endl; + std::cout << "Escape to quit" << std::endl; + std::cout << "Left click to capture/free the mouse" << std::endl; + std::cout << "Right click to control Dr. Freak" << std::endl; + + // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) + NzContextParameters::defaultCompatibilityProfile = true; + + // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utilitaire) + // Cette étape est obligatoire pour beaucoup de fonctionnalités (Notamment le chargement de ressources et le rendu) + NzInitializer renderer; + if (!renderer) + { + // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log + std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + // 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 + // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] + // Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters + NzMeshParams parameters; + + // Le loader doit-il automatiquement charger les animations ? + // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. + // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné + // qu'elles sont fourniees avec le mesh. + // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut + // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés + parameters.loadAnimations = true; // Vaut true par défaut + + // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de + // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. + parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut + + AnimatedModel drfreak; + if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. + { + // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. + std::cout << "Failed to load mesh" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? + { + // Cette démo n'a aucun intérêt sans animations + std::cout << "Mesh has no animation" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + SetSequence(drfreak, "stand"); + + // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture + if (drfreak.mesh.HasSkin()) + { + // Contrairement aux autres ressources, la texture n'est pas critique + if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin())) + drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire + else + std::cout << "Failed to load texture" << std::endl; + } + + if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée + { + std::cout << "Creating checker texture for mesh" << std::endl; + + if (!CreateCheckerTexture(&drfreak.texture)) + { + std::cout << "Failed to create mesh texture" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + } + + // Nous créons maintenant notre sol + Model floor; + if (!CreateFloorMesh(&floor.mesh)) + { + std::cout << "Failed to create floor" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + if (!CreateCheckerTexture(&floor.texture)) + { + std::cout << "Failed to create floor texture" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Le sol ne subit aucune transformation + floor.matrix.MakeIdentity(); + + // Pour effectuer un rendu, il faut que la carte graphique sache comment le faire. + // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors de son pipeline. + // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! + // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. + // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL + // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. + NzShader shader; + if (!shader.Create(nzShaderLanguage_GLSL)) + { + std::cout << "Failed to load shader" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders + // Pour notre exemple nous prendrons un shader très simple + // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader + + // Le fragment shader traite la couleur de nos pixels + if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag")) + { + std::cout << "Failed to load fragment shader from file" << std::endl; + // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Le vertex shader (Transformation des vertices de l'espace 3D vers l'espace écran) + if (!shader.LoadFromFile(nzShaderType_Vertex, "shaders/basic.vert")) + { + std::cout << "Failed to load vertex shader from file" << std::endl; + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Une fois les codes sources de notre shader chargé, nous pouvons le compiler, afin de le rendre utilisable + if (!shader.Compile()) + { + std::cout << "Failed to compile shader" << std::endl; + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça + // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow + // Tout d'abord, sa taille, disons celle du bureau divisé par deux + + // Un VideoMode est une structure contenant une longueur (width), une largeur (height) et le nombre de bits par pixels (bitsPerPixel) + NzVideoMode mode = NzVideoMode::GetDesktopMode(); // Nous récupérons le mode actuellement utilisé par le bureau + + // Nous divisons sa longueur et sa largeur par deux + mode.width /= 2; + mode.height /= 2; + + // Maintenant le titre, rien de plus simple... + NzString windowTitle = "Nazara Demo - AnimatedMesh"; + + // Nous pouvons créer notre fenêtre ! (Via le constructeur directement ou par la méthode Create) + NzRenderWindow window; + + // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède une bordure elle sera légèrement plus grande). + // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle. + // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. + // Attention que cela permet à la fenêtre de changer sa taille et qu'il faudra donc traiter l'évènement. + // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) + if (!window.Create(mode, windowTitle, nzWindowStyle_Default)) + { + std::cout << "Failed to create window" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Notre belle fenêtre est créée, nous pouvons la configurer + + // On cache le curseur + window.SetCursor(nzWindowCursor_None); + + // Nous limitons les FPS à 100 + window.SetFramerateLimit(100); + + // La matrice de projection définit la transformation du vertice 3D à un point 2D + NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(window.GetWidth())/window.GetHeight(), 1.f, 1000.f)); + + // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements + NzClock secondClock, updateClock; // Des horloges pour gérer le temps + unsigned int fps = 0; // Compteur de FPS + + // Quelques variables pour notre improvisation de physique + float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Les coordonnées locales du "bas" du modèle + NzVector3f modelPos(0.f, -groundPos, -50.f); + NzVector3f modelVel(0.f, 0.f, 0.f); + NzQuaternionf modelOrient(NzQuaternionf::Identity()); + NzEulerAnglesf modelRot(0.f, 0.f, 0.f); + float modelSpeed = 150.f; + + // Nous initialisons la matrice + drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); + + // Notre caméra + NzVector3f camPos(0.f, 25.f, -20.f); + NzQuaternionf camOrient(NzQuaternionf::Identity()); + NzEulerAnglesf camRot(0.f, 0.f, 0.f); // Les angles d'eulers sont bien plus facile à utiliser + NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos); + float camSpeed = 100.f; + float sensitivity = 0.8f; + + // Quelques variables + bool camMode = true; + bool thirdPerson = false; + bool windowOpen = true; + + // On peut commencer la boucle du programme + while (windowOpen) + { + // Ici nous gérons les évènements + NzEvent event; + while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? + { + // Nous avons un évènement ! + + switch (event.type) // De quel type est cet évènement ? + { + case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution + windowOpen = false; // Nous terminons alors la boucle + break; + + case nzEventType_MouseMoved: // La souris a bougé + { + // Si nous ne sommes pas en mode free-fly, on ne traite pas l'évènement + if (!camMode || thirdPerson) + break; + + // On modifie l'angle de la caméra grâce au déplacement relatif de la souris + camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity); + + // Pour éviter les loopings mais surtout les problèmes de calculation de la matrice de vue, on restreint les angles + camRot.pitch = NzClamp(camRot.pitch - event.mouseMove.deltaY*sensitivity, -89.f, 89.f); + + // La matrice vue représente les transformations effectuées par la caméra + // On recalcule la matrice de la caméra et on l'envoie au renderer + camOrient = camRot; // Conversion des angles d'euler en quaternion + NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward())); + + // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre + NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window); + break; + } + + case nzEventType_MouseButtonPressed: // L'utilisateur (ou son chat) vient de cliquer sur la souris + if (event.mouseButton.button == NzMouse::Left) // Est-ce le clic gauche ? + { + // L'utilisateur vient d'appuyer sur le bouton left de la souris + // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence + if (camMode) + { + camMode = false; + window.SetCursor(nzWindowCursor_Default); + } + else + { + camMode = true; + window.SetCursor(nzWindowCursor_None); + } + } + else if (event.mouseButton.button == NzMouse::Right) // Est-ce le clic droit ? + { + if (thirdPerson) + { + // On arrête le mouvement + SetSequence(drfreak, "stand"); + + // Afin de synchroniser le quaternion avec les angles d'euler + camRot = camOrient.ToEulerAngles(); + thirdPerson = false; + } + else + thirdPerson = true; + } + break; + + case nzEventType_Resized: // L'utilisateur a changé la taille de la fenêtre, le coquin ! + NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage + + // Il nous faut aussi mettre à jour notre matrice de projection + NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(event.size.width)/event.size.height, 1.f, 1000.f)); + break; + + case nzEventType_KeyPressed: // Une touche du clavier vient d'être enfoncée + if (thirdPerson && + (event.key.code == NzKeyboard::Z || // Est-ce la touche Z ? + event.key.code == NzKeyboard::S || // Ou bien la touche S ? + event.key.code == NzKeyboard::Q || // Ou encore la touche Q ? + event.key.code == NzKeyboard::D)) // Et pourquoi pas la touche D ? + { + // Si une touche concernant le déplacement est appuyée + SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement + } + else if (event.key.code == NzKeyboard::Escape) + windowOpen = false; + + break; + + case nzEventType_KeyReleased: // Une touche du clavier vient d'être relachée + if (thirdPerson && + !NzKeyboard::IsKeyPressed(NzKeyboard::Z) && // Est-ce que la touche Z est enfoncée en ce moment ? + !NzKeyboard::IsKeyPressed(NzKeyboard::S) && // Ou bien la touche S ? + !NzKeyboard::IsKeyPressed(NzKeyboard::Q) && // Etc.. + !NzKeyboard::IsKeyPressed(NzKeyboard::D)) // Etc.. + { + // Si plus aucune touche de déplacement n'est enfoncée + SetSequence(drfreak, "stand"); + } + + break; + + default: // Les autres évènements, on s'en fiche + break; + } + } + + // Mise à jour de la partie logique + if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde + { + float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour + + // Déplacement de la caméra + static const NzVector3f forward(NzVector3f::Forward()); + static const NzVector3f left(NzVector3f::Left()); + static const NzVector3f up(NzVector3f::Up()); + + // Notre rotation sous forme de quaternion nous permet de tourner un vecteur + // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" + + if (thirdPerson) + { + // Nous déplaçons le personnage en fonction des touches pressées + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) + modelPos += modelOrient * forward * modelSpeed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) + modelPos -= modelOrient * forward * modelSpeed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) + modelRot.yaw += camSpeed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) + modelRot.yaw -= camSpeed * elapsedTime; + + modelOrient = modelRot; + } + else + { + // Sinon, c'est la caméra qui se déplace (en fonction des mêmes touches) + + // Un boost en maintenant le shift gauche + float speed = (NzKeyboard::IsKeyPressed(NzKeyboard::Key::LShift)) ? camSpeed*5 : camSpeed; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) + camPos += camOrient * forward * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) + camPos -= camOrient * forward * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) + camPos += camOrient * left * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) + camPos -= camOrient * left * speed * elapsedTime; + + // En revanche, ici la hauteur est toujours la même, peu importe notre orientation + if (NzKeyboard::IsKeyPressed(NzKeyboard::Space)) + camPos += up * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl)) + camPos -= up * speed * elapsedTime; + } + + // Oui les quaternions et les matrices sont calculés même si la caméra ne bouge pas + // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés + if (thirdPerson) + { + static NzQuaternionf rotDown(NzEulerAnglesf(-15.f, 0.f, 0.f)); // Une rotation pour regarder vers le bas + camOrient = modelOrient * rotDown; + + camPos = modelPos + camOrient * NzVector3f(0.f, 25.f, 60.f); + } + + NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward())); + + // Mise à jour de la matrice du personnage + drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); + + // Animation + AnimateModel(drfreak, elapsedTime); + updateClock.Restart(); + } + + // On active le shader et paramètrons le rendu + NzRenderer::SetShader(&shader); + + // Notre scène 3D requiert un test de profondeur + NzRenderer::Enable(nzRendererParameter_DepthTest, true); + + // Nous voulons avoir un fond bien gris + NzRenderer::SetClearColor(128, 128, 128); + + // Et nous effaçons les buffers de couleur et de profondeur + NzRenderer::Clear(nzRendererClear_Color | nzRendererClear_Depth); + + // Affichage des meshs + DrawModel(floor); + + // Notre Dr. Freak possède des normales, nous pouvons alors éliminer les faces qu'on ne voit pas + NzRenderer::Enable(nzRendererParameter_FaceCulling, true); + + DrawModel(drfreak); + + NzRenderer::Enable(nzRendererParameter_FaceCulling, false); + + // Nous mettons à jour l'écran + window.Display(); + + fps++; + + // Toutes les secondes + if (secondClock.GetMilliseconds() >= 1000) + { + window.SetTitle(windowTitle + " (FPS: " + NzString::Number(fps) + ')'); + fps = 0; + secondClock.Restart(); + } + } + + return EXIT_SUCCESS; +} + +void AnimateModel(AnimatedModel& model, float elapsed) +{ + model.interpolation += model.currentSequence->framePerSecond * elapsed; + while (model.interpolation > 1.f) + { + model.interpolation -= 1.f; + + model.currentFrame = model.nextFrame; + if (++model.nextFrame > model.currentSequence->lastFrame) + model.nextFrame = model.currentSequence->firstFrame; + } + + model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation); +} + +bool CreateCheckerTexture(NzTexture* texture) +{ + NzImage image; + // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) + if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16)) + { + // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) + std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl; + return false; + } + + // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel + // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. + unsigned int blockCountX = image.GetWidth()/16; + unsigned int blockCountY = image.GetHeight()/16; + for (unsigned int x = 0; x < blockCountX; ++x) + { + for (unsigned int y = 0; y < blockCountY; ++y) + { + // Une belle texture de damier + NzColor color = (x%2 == y%2) ? NzColor::White : NzColor::Black; + // Fill remplit une zone de la texture avec une couleur + image.Fill(color, NzRectui(x*16, y*16, 16, 16)); + } + } + + if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image + { + // Nous n'avons vraiment pas beaucoup de chance.. + std::cout << "Failed to load image" << std::endl; + return false; + } + + texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture + texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée + + return true; +} + +bool CreateFloorMesh(NzMesh* mesh) +{ + // Cette fonction créé un mesh statique simpliste pour servir de sol + + // Nous créons un mesh statique + if (!mesh->Create(nzAnimationType_Static)) + { + // L'échec est techniquement impossible mais le moteur étant en constante évolution ... + std::cout << "Failed to create mesh" << std::endl; + return false; + } + + // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer + // Elles sont composées de VertexElement, chacun décrivant un élément du buffer + NzVertexDeclaration* declaration = new NzVertexDeclaration; + + // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) + // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) + // -Usage: Comment cette donnée doit-elle être envoyée au shader + // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) + // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) + // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. + NzVertexElement elements[2]; + elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices + elements[0].offset = 0; // Celles-ci sont placées au début + elements[0].type = nzElementType_Float3; // Sont composées de trois flottants + + elements[1].usage = nzElementUsage_TexCoord; + elements[1].offset = 3*sizeof(float); + elements[1].type = nzElementType_Float2; + + if (!declaration->Create(elements, 2)) + { + // Nos éléments sont invalides ! + std::cout << "Failed to create vertex declaration" << std::endl; + return false; + } + + // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage + // Et nous indiquons que nous n'y toucherons plus + NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static); + + // Doit respecter la declaration + float vertices[] = + { + // Vertex 1 + -1000.f, 0.f, -1000.f, // Position + 0.f, 0.f, // UV + + // Vertex 2 + -1000.f, 0.f, 1000.f, // Position + 0.f, 10.f, // UV + + // Vertex 3 + 1000.f, 0.f, -1000.f, // Position + 10.f, 0.f, // UV + + // Vertex 4 + 1000.f, 0.f, 1000.f, // Position + 10.f, 10.f // UV + }; + + // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) + if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices + { + std::cout << "Failed to fill buffer" << std::endl; + return false; + } + + NzStaticMesh* subMesh = new NzStaticMesh(mesh); + if (!subMesh->Create(declaration, buffer)) + { + std::cout << "Failed to create subMesh" << std::endl; + return false; + } + + subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip); + + // On ajoute le submesh au mesh + mesh->AddSubMesh(subMesh); + + // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. + // Les ressources seront donc automatiquement libérées lorsqu'elles ne seront plus référencées par une classe + buffer->SetPersistent(false); + declaration->SetPersistent(false); + subMesh->SetPersistent(false); // Pour le submesh, c'est déjà le comportement par défaut + + return true; +} + +void DrawModel(const Model& model) +{ + // La matrice world est celle qui représente les transformations du modèle + NzRenderer::SetMatrix(nzMatrixType_World, model.matrix); + + NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu + shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture); + + // Un mesh est divisé en plusieurs submeshes + unsigned int subMeshCount = model.mesh.GetSubMeshCount(); + for (unsigned int i = 0; i < subMeshCount; ++i) + { + // On récupère le submesh + const NzSubMesh* subMesh = model.mesh.GetSubMesh(i); + + // On paramètre le Renderer avec ses données + NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer()); + NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer()); + NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration()); + + // On fait le rendu + NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount()); + } +} + +void SetSequence(AnimatedModel& model, const NzString& sequenceName) +{ + // On récupère l'animation du mesh + const NzAnimation* animation = model.mesh.GetAnimation(); + + // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) + const NzSequence* sequence = animation->GetSequence(sequenceName); + if (model.currentSequence != sequence) + { + model.currentSequence = sequence; + + // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame + model.nextFrame = model.currentSequence->firstFrame; + } +} diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index 17a1faa6b..a084f1cd2 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -1,61 +1,62 @@ -// This file was automatically generated by Nazara - -/* - Nazara Engine - Core module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// This file was automatically generated by Nazara + +/* + Nazara Engine - Core module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Core/Config.hpp b/include/Nazara/Core/Config.hpp index ddb8efb5b..021568c7f 100644 --- a/include/Nazara/Core/Config.hpp +++ b/include/Nazara/Core/Config.hpp @@ -1,84 +1,85 @@ -/* - Nazara Engine - Core module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_CORE_HPP -#define NAZARA_CONFIG_CORE_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Appelle exit dès qu'une assertion est invalide -#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1 - -// Teste les assertions -#define NAZARA_CORE_ENABLE_ASSERTS 0 - -// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash) -#define NAZARA_CORE_FILE_BUFFERSIZE 4096 - -// Le moteur doit-il incorporer les Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8) -#define NAZARA_CORE_INCLUDE_UNICODEDATA 0 - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_CORE_MEMORYLEAKTRACKER 0 - -// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution) -#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1 - -// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule) -#define NAZARA_CORE_REAL_PRECISION 6 - -// Duplique la sortie du log sur le flux de sortie standard (cout) -#define NAZARA_CORE_DUPLICATE_TO_COUT 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_CORE_SAFE 1 - -// Protège les classes des accès concurrentiels -#define NAZARA_CORE_THREADSAFE 1 - -// Les classes à protéger des accès concurrentiels -#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW) -#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock -#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory -#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib -#define NAZARA_THREADSAFETY_FILE 1 // NzFile -#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest -#define NAZARA_THREADSAFETY_LOG 1 // NzLog -#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW) -#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream - -// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver) -#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096 - -// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS) -#define NAZARA_CORE_WINDOWS_VISTA 0 - -/* -// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes) -#define NAZARA_CORE_TIMER_WAKEUPTIME 10 -*/ - -#endif // NAZARA_CONFIG_CORE_HPP +/* + Nazara Engine - Core module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_CORE_HPP +#define NAZARA_CONFIG_CORE_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Appelle exit dès qu'une assertion est invalide +#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1 + +// Teste les assertions +#define NAZARA_CORE_ENABLE_ASSERTS 0 + +// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash) +#define NAZARA_CORE_FILE_BUFFERSIZE 4096 + +// Le moteur doit-il incorporer les Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8) +#define NAZARA_CORE_INCLUDE_UNICODEDATA 0 + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_CORE_MEMORYLEAKTRACKER 0 + +// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution) +#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1 + +// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule) +#define NAZARA_CORE_REAL_PRECISION 6 + +// Duplique la sortie du log sur le flux de sortie standard (cout) +#define NAZARA_CORE_DUPLICATE_TO_COUT 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_CORE_SAFE 1 + +// Protège les classes des accès concurrentiels +#define NAZARA_CORE_THREADSAFE 1 + +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW) +#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock +#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory +#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib +#define NAZARA_THREADSAFETY_FILE 1 // NzFile +#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest +#define NAZARA_THREADSAFETY_LOG 1 // NzLog +#define NAZARA_THREADSAFETY_RESOURCE 1 // NzResource +#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW) +#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream + +// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver) +#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096 + +// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS) +#define NAZARA_CORE_WINDOWS_VISTA 0 + +/* +// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes) +#define NAZARA_CORE_TIMER_WAKEUPTIME 10 +*/ + +#endif // NAZARA_CONFIG_CORE_HPP diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 38f06d8de..21ac61c6e 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -1,26 +1,30 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_CORE_HPP -#define NAZARA_ENUMS_CORE_HPP - -enum nzEndianness -{ - nzEndianness_Unknown = -1, - - nzEndianness_BigEndian, - nzEndianness_LittleEndian -}; - -enum nzErrorType -{ - nzErrorType_AssertFailed, - nzErrorType_Internal, - nzErrorType_Normal, - nzErrorType_Warning -}; - -#endif // NAZARA_ENUMS_CORE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_CORE_HPP +#define NAZARA_ENUMS_CORE_HPP + +enum nzEndianness +{ + nzEndianness_Unknown = -1, + + nzEndianness_BigEndian, + nzEndianness_LittleEndian, + + nzEndianness_Max = nzEndianness_LittleEndian +}; + +enum nzErrorType +{ + nzErrorType_AssertFailed, + nzErrorType_Internal, + nzErrorType_Normal, + nzErrorType_Warning, + + nzErrorType_Max = nzErrorType_Warning +}; + +#endif // NAZARA_ENUMS_CORE_HPP diff --git a/include/Nazara/Core/Resource.hpp b/include/Nazara/Core/Resource.hpp index 920c4aceb..57ca3d2f5 100644 --- a/include/Nazara/Core/Resource.hpp +++ b/include/Nazara/Core/Resource.hpp @@ -1,30 +1,72 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RESOURCE_HPP -#define NAZARA_RESOURCE_HPP - -#include - -class NAZARA_API NzResource -{ - public: - NzResource(bool persistent = true); - NzResource(const NzResource& resource); - virtual ~NzResource(); - - void AddResourceReference() const; - bool IsPersistent() const; - void RemoveResourceReference() const; - void SetPersistent(bool persistent = true); - - private: - // Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms - mutable bool m_resourcePersistent; - mutable unsigned int m_resourceReferenceCount; -}; - -#endif // NAZARA_RESOURCE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RESOURCE_HPP +#define NAZARA_RESOURCE_HPP + +#include +#include + +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_RESOURCE +#include +#else +#include +#endif + +class NzResourceListener; + +struct NzResourceEntry +{ + NzResourceEntry(NzResourceListener* resourceListener, int i = 0) : + listener(resourceListener), + index(i) + { + } + + bool operator<(const NzResourceEntry& rhs) const + { + return listener < rhs.listener; + } + + NzResourceListener* listener; + int index; +}; + +class NAZARA_API NzResource +{ + public: + NzResource(bool persistent = true); + NzResource(const NzResource& resource); + virtual ~NzResource(); + + void AddResourceListener(NzResourceListener* listener, int index = 0) const; + void AddResourceReference() const; + + bool IsPersistent() const; + + void RemoveResourceListener(NzResourceListener* listener) const; + void RemoveResourceReference() const; + + void SetPersistent(bool persistent = true); + + protected: + void NotifyCreated(); + void NotifyDestroy(); + + private: + void EnsureResourceListenerUpdate() const; + + NazaraMutexAttrib(m_mutex, mutable) + + // Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms + mutable std::set m_resourceListeners; + mutable std::set m_resourceListenersCache; + mutable bool m_resourceListenerUpdated; + bool m_resourcePersistent; + mutable unsigned int m_resourceReferenceCount; +}; + +#endif // NAZARA_RESOURCE_HPP diff --git a/include/Nazara/Core/ResourceListener.hpp b/include/Nazara/Core/ResourceListener.hpp new file mode 100644 index 000000000..cff90fe58 --- /dev/null +++ b/include/Nazara/Core/ResourceListener.hpp @@ -0,0 +1,25 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RESOURCELISTENER_HPP +#define NAZARA_RESOURCELISTENER_HPP + +#include + +class NzResource; + +class NAZARA_API NzResourceListener +{ + public: + NzResourceListener() = default; + virtual ~NzResourceListener(); + + virtual void OnResourceCreated(const NzResource* resource, int index); + virtual void OnResourceDestroy(const NzResource* resource, int index); + virtual void OnResourceReleased(const NzResource* resource, int index); +}; + +#endif // NAZARA_RESOURCELISTENER_HPP diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl index 321279ed6..392c04c0e 100644 --- a/include/Nazara/Core/ResourceLoader.inl +++ b/include/Nazara/Core/ResourceLoader.inl @@ -1,142 +1,142 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -template -bool NzResourceLoader::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters) -{ - #if NAZARA_CORE_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid Parameters"); - return false; - } - #endif - - NzString path = NzFile::NormalizePath(filePath); - NzString ext = path.SubstrFrom('.', -1, true); - if (ext.IsEmpty()) - { - NazaraError("Failed to get file extension"); - return false; - } - - NzFile file(path, NzFile::ReadOnly); - if (!file.IsOpen()) - { - NazaraError("Failed to open file"); - return false; - } - - for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) - { - for (const NzString& loaderExt : std::get<0>(*loader)) - { - int cmp = NzString::Compare(loaderExt, ext); - if (cmp == 0) - { - if (!std::get<1>(*loader)(file, parameters)) - continue; - - file.SetCursorPos(0); - - // Chargement de la ressource - if (std::get<2>(*loader)(resource, file, parameters)) - return true; - - NazaraWarning("Loader failed"); - - file.SetCursorPos(0); - } - else if (cmp < 0) // S'il est encore possible que l'extension se situe après - continue; - - break; - } - } - - NazaraError("Failed to load file: no loader"); - - return false; -} - -template -bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) -{ - NzMemoryStream stream(data, size); - - return LoadFromStream(resource, stream, parameters); -} - -template -bool NzResourceLoader::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters) -{ - #if NAZARA_CORE_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid Parameters"); - return false; - } - - if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize()) - { - NazaraError("No data to load"); - return false; - } - #endif - - nzUInt64 streamPos = stream.GetCursorPos(); - for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) - { - // Le loader supporte-t-il les données ? - if (!std::get<1>(*loader)(stream, parameters)) - continue; - - // On repositionne le stream au début - stream.SetCursorPos(streamPos); - - // Chargement de la ressource - if (std::get<2>(*loader)(resource, stream, parameters)) - return true; - - NazaraWarning("Loader failed"); - stream.SetCursorPos(streamPos); // On repositionne au début - } - - NazaraError("Failed to load file: no loader"); - return false; -} - -template -void NzResourceLoader::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) -{ - /// Trouver une alternative à ce code monstrueux - std::vector exts; - fileExtensions.SplitAny(exts, " /\\.,;|-_"); - - std::set extensions; - std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); - - Type::s_loaders.insert(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); -} - -template -void NzResourceLoader::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) -{ - std::vector exts; - fileExtensions.SplitAny(exts, " /\\.,;|-_"); - - std::set extensions; - std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); - - Type::s_loaders.erase(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); -} - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +template +bool NzResourceLoader::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters) +{ + #if NAZARA_CORE_SAFE + if (!parameters.IsValid()) + { + NazaraError("Invalid parameters"); + return false; + } + #endif + + NzString path = NzFile::NormalizePath(filePath); + NzString ext = path.SubstrFrom('.', -1, true); + if (ext.IsEmpty()) + { + NazaraError("Failed to get file extension"); + return false; + } + + NzFile file(path, NzFile::ReadOnly); + if (!file.IsOpen()) + { + NazaraError("Failed to open file"); + return false; + } + + for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) + { + for (const NzString& loaderExt : std::get<0>(*loader)) + { + int cmp = NzString::Compare(loaderExt, ext); + if (cmp == 0) + { + if (!std::get<1>(*loader)(file, parameters)) + continue; + + file.SetCursorPos(0); + + // Chargement de la ressource + if (std::get<2>(*loader)(resource, file, parameters)) + return true; + + NazaraWarning("Loader failed"); + + file.SetCursorPos(0); + } + else if (cmp < 0) // S'il est encore possible que l'extension se situe après + continue; + + break; + } + } + + NazaraError("Failed to load file: no loader"); + + return false; +} + +template +bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) +{ + NzMemoryStream stream(data, size); + + return LoadFromStream(resource, stream, parameters); +} + +template +bool NzResourceLoader::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters) +{ + #if NAZARA_CORE_SAFE + if (!parameters.IsValid()) + { + NazaraError("Invalid parameters"); + return false; + } + + if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize()) + { + NazaraError("No data to load"); + return false; + } + #endif + + nzUInt64 streamPos = stream.GetCursorPos(); + for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) + { + // Le loader supporte-t-il les données ? + if (!std::get<1>(*loader)(stream, parameters)) + continue; + + // On repositionne le stream au début + stream.SetCursorPos(streamPos); + + // Chargement de la ressource + if (std::get<2>(*loader)(resource, stream, parameters)) + return true; + + NazaraWarning("Loader failed"); + stream.SetCursorPos(streamPos); // On repositionne au début + } + + NazaraError("Failed to load file: no loader"); + return false; +} + +template +void NzResourceLoader::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + ///FIXME: Trouver une alternative à ce code monstrueux + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set extensions; + std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); + + Type::s_loaders.insert(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); +} + +template +void NzResourceLoader::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set extensions; + std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); + + Type::s_loaders.erase(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); +} + +#include diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp index 33b323d01..52f715e9f 100644 --- a/include/Nazara/Core/String.hpp +++ b/include/Nazara/Core/String.hpp @@ -1,321 +1,321 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_STRING_HPP -#define NAZARA_STRING_HPP - -#include -#include -#include -#include -#include - -#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING -#include -#else -#include -#endif - -class NzAbstractHash; -class NzHashDigest; - -class NAZARA_API NzString : public NzHashable -{ - public: - enum Flags - { - None = 0x00, // Mode par défaut - CaseInsensitive = 0x01, // Insensible à la casse - HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 - TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne - TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne - }; - - struct SharedString; - - NzString(); - NzString(char character); - NzString(const char* string); - NzString(const std::string& string); - NzString(const NzString& string); - NzString(NzString&& string) noexcept; - NzString(SharedString* sharedString); - ~NzString(); - - NzString& Append(char character); - NzString& Append(const char* string); - NzString& Append(const NzString& string); - - void Clear(bool keepBuffer = false); - - bool Contains(char character, int start = 0, nzUInt32 flags = None) const; - bool Contains(const char* string, int start = 0, nzUInt32 flags = None) const; - bool Contains(const NzString& string, int start = 0, nzUInt32 flags = None) const; - - unsigned int Count(char character, int start = 0, nzUInt32 flags = None) const; - unsigned int Count(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int Count(const NzString& string, int start = 0, nzUInt32 flags = None) const; - unsigned int CountAny(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int CountAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; - - bool EndsWith(char character, nzUInt32 flags = None) const; - bool EndsWith(const char* string, nzUInt32 flags = None) const; - bool EndsWith(const NzString& string, nzUInt32 flags = None) const; - - unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const; - unsigned int Find(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int Find(const NzString& string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindAny(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindLast(char character, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLast(const char *string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLast(const NzString& string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastAny(const char* string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastAny(const NzString& string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastWord(const char* string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastWord(const NzString& string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindWord(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindWord(const NzString& string, int start = 0, nzUInt32 flags = None) const; - - char* GetBuffer(); - unsigned int GetCapacity() const; - const char* GetConstBuffer() const; - unsigned int GetLength() const; - unsigned int GetSize() const; - char* GetUtf8Buffer(unsigned int* size = nullptr) const; - char16_t* GetUtf16Buffer(unsigned int* size = nullptr) const; - char32_t* GetUtf32Buffer(unsigned int* size = nullptr) const; - wchar_t* GetWideBuffer(unsigned int* size = nullptr) const; - - NzString GetWord(unsigned int index, nzUInt32 flags = None) const; - unsigned int GetWordPosition(unsigned int index, nzUInt32 flags = None) const; - - NzString& Insert(int pos, char character); - NzString& Insert(int pos, const char* string); - NzString& Insert(int pos, const NzString& string); - - bool IsEmpty() const; - bool IsNull() const; - bool IsNumber(nzUInt8 radix = 10, nzUInt32 flags = CaseInsensitive) const; - - bool Match(const char* pattern) const; - bool Match(const NzString& pattern) const; - - NzString& Prepend(char character); - NzString& Prepend(const char* string); - NzString& Prepend(const NzString& string); - - unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None); - unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None); - unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None); - unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None); - //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); - //unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None); - - void Reserve(unsigned int bufferSize); - - NzString& Resize(int size, char character = ' '); - NzString Resized(int size, char character = ' ') const; - - NzString& Reverse(); - NzString Reversed() const; - - NzString Simplified(nzUInt32 flags = None) const; - NzString& Simplify(nzUInt32 flags = None); - - unsigned int Split(std::vector& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const; - unsigned int Split(std::vector& result, const char* separation, int start = 0, nzUInt32 flags = None) const; - unsigned int Split(std::vector& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const; - unsigned int SplitAny(std::vector& result, const char* separations, int start = 0, nzUInt32 flags = None) const; - unsigned int SplitAny(std::vector& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const; - - bool StartsWith(char character, nzUInt32 flags = None) const; - bool StartsWith(const char* string, nzUInt32 flags = None) const; - bool StartsWith(const NzString& string, nzUInt32 flags = None) const; - - NzString Substr(int startPos, int endPos = -1) const; - NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; - - void Swap(NzString& str); - - bool ToBool(bool* value, nzUInt32 flags = None) const; - bool ToDouble(double* value) const; - bool ToInteger(long long* value, nzUInt8 radix = 10) const; - NzString ToLower(nzUInt32 flags = None) const; - NzString ToUpper(nzUInt32 flags = None) const; - - NzString& Trim(nzUInt32 flags = None); - NzString& Trim(char character, nzUInt32 flags = None); - NzString Trimmed(nzUInt32 flags = None) const; - NzString Trimmed(char character, nzUInt32 flags = None) const; - - // Méthodes STD - char* begin(); - const char* begin() const; - char* end(); - const char* end() const; - void push_front(char c); - void push_back(char c); - /*char* rbegin(); - const char* rbegin() const; - char* rend(); - const char* rend() const;*/ - - typedef const char& const_reference; - typedef char* iterator; - //typedef char* reverse_iterator; - typedef char value_type; - // Méthodes STD - - operator std::string() const; - - char& operator[](unsigned int pos); - char operator[](unsigned int pos) const; - - NzString& operator=(char character); - NzString& operator=(const char* string); - NzString& operator=(const std::string& string); - NzString& operator=(const NzString& string); - NzString& operator=(NzString&& string) noexcept; - - NzString operator+(char character) const; - NzString operator+(const char* string) const; - NzString operator+(const std::string& string) const; - NzString operator+(const NzString& string) const; - - NzString& operator+=(char character); - NzString& operator+=(const char* string); - NzString& operator+=(const std::string& string); - NzString& operator+=(const NzString& string); - - bool operator==(char character) const; - bool operator==(const char* string) const; - bool operator==(const std::string& string) const; - - bool operator!=(char character) const; - bool operator!=(const char* string) const; - bool operator!=(const std::string& string) const; - - bool operator<(char character) const; - bool operator<(const char* string) const; - bool operator<(const std::string& string) const; - - bool operator<=(char character) const; - bool operator<=(const char* string) const; - bool operator<=(const std::string& string) const; - - bool operator>(char character) const; - bool operator>(const char* string) const; - bool operator>(const std::string& string) const; - - bool operator>=(char character) const; - bool operator>=(const char* string) const; - bool operator>=(const std::string& string) const; - - static NzString Boolean(bool boolean); - static int Compare(const NzString& first, const NzString& second); - static NzString Number(float number); - static NzString Number(double number); - static NzString Number(long double number); - static NzString Number(signed char number, nzUInt8 radix = 10); - static NzString Number(unsigned char number, nzUInt8 radix = 10); - static NzString Number(short number, nzUInt8 radix = 10); - static NzString Number(unsigned short number, nzUInt8 radix = 10); - static NzString Number(int number, nzUInt8 radix = 10); - static NzString Number(unsigned int number, nzUInt8 radix = 10); - static NzString Number(long number, nzUInt8 radix = 10); - static NzString Number(unsigned long number, nzUInt8 radix = 10); - static NzString Number(long long number, nzUInt8 radix = 10); - static NzString Number(unsigned long long number, nzUInt8 radix = 10); - static NzString Pointer(const void* ptr); - static NzString Unicode(char32_t character); - static NzString Unicode(const char* u8String); - static NzString Unicode(const char16_t* u16String); - static NzString Unicode(const char32_t* u32String); - static NzString Unicode(const wchar_t* wString); - - NAZARA_API friend std::istream& operator>>(std::istream& in, NzString& string); - NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzString& string); - - NAZARA_API friend NzString operator+(char character, const NzString& string); - NAZARA_API friend NzString operator+(const char* string, const NzString& nstring); - NAZARA_API friend NzString operator+(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator==(const NzString& first, const NzString& second); - NAZARA_API friend bool operator!=(const NzString& first, const NzString& second); - NAZARA_API friend bool operator<(const NzString& first, const NzString& second); - NAZARA_API friend bool operator<=(const NzString& first, const NzString& second); - NAZARA_API friend bool operator>(const NzString& first, const NzString& second); - NAZARA_API friend bool operator>=(const NzString& first, const NzString& second); - - NAZARA_API friend bool operator==(char character, const NzString& nstring); - NAZARA_API friend bool operator==(const char* string, const NzString& nstring); - NAZARA_API friend bool operator==(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator!=(char character, const NzString& nstring); - NAZARA_API friend bool operator!=(const char* string, const NzString& nstring); - NAZARA_API friend bool operator!=(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator<(char character, const NzString& nstring); - NAZARA_API friend bool operator<(const char* string, const NzString& nstring); - NAZARA_API friend bool operator<(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator<=(char character, const NzString& nstring); - NAZARA_API friend bool operator<=(const char* string, const NzString& nstring); - NAZARA_API friend bool operator<=(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator>(char character, const NzString& nstring); - NAZARA_API friend bool operator>(const char* string, const NzString& nstring); - NAZARA_API friend bool operator>(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator>=(char character, const NzString& nstring); - NAZARA_API friend bool operator>=(const char* string, const NzString& nstring); - NAZARA_API friend bool operator>=(const std::string& string, const NzString& nstring); - - struct NAZARA_API SharedString - { - SharedString() = default; - - SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) : - capacity(bufferSize), - size(stringSize), - string(str), - refCount(referenceCount) - { - } - - unsigned int capacity; - unsigned int size; - char* string; - - unsigned short refCount = 1; - NazaraMutex(mutex) - }; - - static SharedString emptyString; - static unsigned int npos; - - private: - void EnsureOwnership(); - bool FillHash(NzHashImpl* hash) const; - void ReleaseString(); - - SharedString* m_sharedString; -}; - -namespace std -{ - NAZARA_API istream& getline(istream& is, NzString& str); - NAZARA_API istream& getline(istream& is, NzString& str, char delim); - NAZARA_API void swap(NzString& lhs, NzString& rhs); -} - -#endif // NAZARA_STRING_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_STRING_HPP +#define NAZARA_STRING_HPP + +#include +#include +#include +#include +#include + +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING +#include +#else +#include +#endif + +class NzAbstractHash; +class NzHashDigest; + +class NAZARA_API NzString : public NzHashable +{ + public: + enum Flags + { + None = 0x00, // Mode par défaut + CaseInsensitive = 0x01, // Insensible à la casse + HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 + TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne + TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne + }; + + struct SharedString; + + NzString(); + NzString(char character); + NzString(const char* string); + NzString(const std::string& string); + NzString(const NzString& string); + NzString(NzString&& string) noexcept; + NzString(SharedString* sharedString); + ~NzString(); + + NzString& Append(char character); + NzString& Append(const char* string); + NzString& Append(const NzString& string); + + void Clear(bool keepBuffer = false); + + bool Contains(char character, int start = 0, nzUInt32 flags = None) const; + bool Contains(const char* string, int start = 0, nzUInt32 flags = None) const; + bool Contains(const NzString& string, int start = 0, nzUInt32 flags = None) const; + + unsigned int Count(char character, int start = 0, nzUInt32 flags = None) const; + unsigned int Count(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int Count(const NzString& string, int start = 0, nzUInt32 flags = None) const; + unsigned int CountAny(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int CountAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; + + bool EndsWith(char character, nzUInt32 flags = None) const; + bool EndsWith(const char* string, nzUInt32 flags = None) const; + bool EndsWith(const NzString& string, nzUInt32 flags = None) const; + + unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const; + unsigned int Find(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int Find(const NzString& string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindAny(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindLast(char character, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLast(const char *string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLast(const NzString& string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastAny(const char* string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastAny(const NzString& string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastWord(const char* string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastWord(const NzString& string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindWord(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindWord(const NzString& string, int start = 0, nzUInt32 flags = None) const; + + char* GetBuffer(); + unsigned int GetCapacity() const; + const char* GetConstBuffer() const; + unsigned int GetLength() const; + unsigned int GetSize() const; + char* GetUtf8Buffer(unsigned int* size = nullptr) const; + char16_t* GetUtf16Buffer(unsigned int* size = nullptr) const; + char32_t* GetUtf32Buffer(unsigned int* size = nullptr) const; + wchar_t* GetWideBuffer(unsigned int* size = nullptr) const; + + NzString GetWord(unsigned int index, nzUInt32 flags = None) const; + unsigned int GetWordPosition(unsigned int index, nzUInt32 flags = None) const; + + NzString& Insert(int pos, char character); + NzString& Insert(int pos, const char* string); + NzString& Insert(int pos, const NzString& string); + + bool IsEmpty() const; + bool IsNull() const; + bool IsNumber(nzUInt8 radix = 10, nzUInt32 flags = CaseInsensitive) const; + + bool Match(const char* pattern) const; + bool Match(const NzString& pattern) const; + + NzString& Prepend(char character); + NzString& Prepend(const char* string); + NzString& Prepend(const NzString& string); + + unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None); + unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None); + unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None); + unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None); + //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); + //unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None); + + void Reserve(unsigned int bufferSize); + + NzString& Resize(int size, char character = ' '); + NzString Resized(int size, char character = ' ') const; + + NzString& Reverse(); + NzString Reversed() const; + + NzString Simplified(nzUInt32 flags = None) const; + NzString& Simplify(nzUInt32 flags = None); + + unsigned int Split(std::vector& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const; + unsigned int Split(std::vector& result, const char* separation, int start = 0, nzUInt32 flags = None) const; + unsigned int Split(std::vector& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const; + unsigned int SplitAny(std::vector& result, const char* separations, int start = 0, nzUInt32 flags = None) const; + unsigned int SplitAny(std::vector& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const; + + bool StartsWith(char character, nzUInt32 flags = None) const; + bool StartsWith(const char* string, nzUInt32 flags = None) const; + bool StartsWith(const NzString& string, nzUInt32 flags = None) const; + + NzString Substr(int startPos, int endPos = -1) const; + NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; + + void Swap(NzString& str); + + bool ToBool(bool* value, nzUInt32 flags = None) const; + bool ToDouble(double* value) const; + bool ToInteger(long long* value, nzUInt8 radix = 10) const; + NzString ToLower(nzUInt32 flags = None) const; + NzString ToUpper(nzUInt32 flags = None) const; + + NzString& Trim(nzUInt32 flags = None); + NzString& Trim(char character, nzUInt32 flags = None); + NzString Trimmed(nzUInt32 flags = None) const; + NzString Trimmed(char character, nzUInt32 flags = None) const; + + // Méthodes STD + char* begin(); + const char* begin() const; + char* end(); + const char* end() const; + void push_front(char c); + void push_back(char c); + /*char* rbegin(); + const char* rbegin() const; + char* rend(); + const char* rend() const;*/ + + typedef const char& const_reference; + typedef char* iterator; + //typedef char* reverse_iterator; + typedef char value_type; + // Méthodes STD + + operator std::string() const; + + char& operator[](unsigned int pos); + char operator[](unsigned int pos) const; + + NzString& operator=(char character); + NzString& operator=(const char* string); + NzString& operator=(const std::string& string); + NzString& operator=(const NzString& string); + NzString& operator=(NzString&& string) noexcept; + + NzString operator+(char character) const; + NzString operator+(const char* string) const; + NzString operator+(const std::string& string) const; + NzString operator+(const NzString& string) const; + + NzString& operator+=(char character); + NzString& operator+=(const char* string); + NzString& operator+=(const std::string& string); + NzString& operator+=(const NzString& string); + + bool operator==(char character) const; + bool operator==(const char* string) const; + bool operator==(const std::string& string) const; + + bool operator!=(char character) const; + bool operator!=(const char* string) const; + bool operator!=(const std::string& string) const; + + bool operator<(char character) const; + bool operator<(const char* string) const; + bool operator<(const std::string& string) const; + + bool operator<=(char character) const; + bool operator<=(const char* string) const; + bool operator<=(const std::string& string) const; + + bool operator>(char character) const; + bool operator>(const char* string) const; + bool operator>(const std::string& string) const; + + bool operator>=(char character) const; + bool operator>=(const char* string) const; + bool operator>=(const std::string& string) const; + + static NzString Boolean(bool boolean); + static int Compare(const NzString& first, const NzString& second); + static NzString Number(float number); + static NzString Number(double number); + static NzString Number(long double number); + static NzString Number(signed char number, nzUInt8 radix = 10); + static NzString Number(unsigned char number, nzUInt8 radix = 10); + static NzString Number(short number, nzUInt8 radix = 10); + static NzString Number(unsigned short number, nzUInt8 radix = 10); + static NzString Number(int number, nzUInt8 radix = 10); + static NzString Number(unsigned int number, nzUInt8 radix = 10); + static NzString Number(long number, nzUInt8 radix = 10); + static NzString Number(unsigned long number, nzUInt8 radix = 10); + static NzString Number(long long number, nzUInt8 radix = 10); + static NzString Number(unsigned long long number, nzUInt8 radix = 10); + static NzString Pointer(const void* ptr); + static NzString Unicode(char32_t character); + static NzString Unicode(const char* u8String); + static NzString Unicode(const char16_t* u16String); + static NzString Unicode(const char32_t* u32String); + static NzString Unicode(const wchar_t* wString); + + NAZARA_API friend std::istream& operator>>(std::istream& in, NzString& string); + NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzString& string); + + NAZARA_API friend NzString operator+(char character, const NzString& string); + NAZARA_API friend NzString operator+(const char* string, const NzString& nstring); + NAZARA_API friend NzString operator+(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator==(const NzString& first, const NzString& second); + NAZARA_API friend bool operator!=(const NzString& first, const NzString& second); + NAZARA_API friend bool operator<(const NzString& first, const NzString& second); + NAZARA_API friend bool operator<=(const NzString& first, const NzString& second); + NAZARA_API friend bool operator>(const NzString& first, const NzString& second); + NAZARA_API friend bool operator>=(const NzString& first, const NzString& second); + + NAZARA_API friend bool operator==(char character, const NzString& nstring); + NAZARA_API friend bool operator==(const char* string, const NzString& nstring); + NAZARA_API friend bool operator==(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator!=(char character, const NzString& nstring); + NAZARA_API friend bool operator!=(const char* string, const NzString& nstring); + NAZARA_API friend bool operator!=(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator<(char character, const NzString& nstring); + NAZARA_API friend bool operator<(const char* string, const NzString& nstring); + NAZARA_API friend bool operator<(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator<=(char character, const NzString& nstring); + NAZARA_API friend bool operator<=(const char* string, const NzString& nstring); + NAZARA_API friend bool operator<=(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator>(char character, const NzString& nstring); + NAZARA_API friend bool operator>(const char* string, const NzString& nstring); + NAZARA_API friend bool operator>(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator>=(char character, const NzString& nstring); + NAZARA_API friend bool operator>=(const char* string, const NzString& nstring); + NAZARA_API friend bool operator>=(const std::string& string, const NzString& nstring); + + struct NAZARA_API SharedString + { + SharedString() = default; + + SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) : + capacity(bufferSize), + size(stringSize), + string(str), + refCount(referenceCount) + { + } + + unsigned int capacity; + unsigned int size; + char* string; + + unsigned short refCount = 1; + NazaraMutex(mutex) + }; + + static SharedString emptyString; + static const unsigned int npos; + + private: + void EnsureOwnership(); + bool FillHash(NzHashImpl* hash) const; + void ReleaseString(); + + SharedString* m_sharedString; +}; + +namespace std +{ + NAZARA_API istream& getline(istream& is, NzString& str); + NAZARA_API istream& getline(istream& is, NzString& str, char delim); + NAZARA_API void swap(NzString& lhs, NzString& rhs); +} + +#endif // NAZARA_STRING_HPP diff --git a/include/Nazara/Math/Config.hpp b/include/Nazara/Math/Config.hpp index 6adf384cf..71ee93ee4 100644 --- a/include/Nazara/Math/Config.hpp +++ b/include/Nazara/Math/Config.hpp @@ -1,52 +1,49 @@ -/* - Nazara Engine - Mathematics module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - Rémi "overdrivr" Bèges (remi.beges@laposte.net) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_MATH_HPP -#define NAZARA_CONFIG_MATH_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Définit le radian comme l'unité utilisée pour les angles -#define NAZARA_MATH_ANGLE_RADIAN 0 - -// Définit la disposition des matrices en colonnes (Façon OpenGL) -#define NAZARA_MATH_MATRIX_COLUMN_MAJOR 1 - -// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) -#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_MATH_SAFE 1 - -// Protège les classes des accès concurrentiels -#define NAZARA_MATH_THREADSAFE 1 - -// Les classes à protéger des accès concurrentiels -#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) -#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) - -#endif // NAZARA_CONFIG_MATH_HPP +/* + Nazara Engine - Mathematics module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Rémi "overdrivr" Bèges (remi.beges@laposte.net) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_MATH_HPP +#define NAZARA_CONFIG_MATH_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Définit le radian comme l'unité utilisée pour les angles +#define NAZARA_MATH_ANGLE_RADIAN 0 + +// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) +#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_MATH_SAFE 1 + +// Protège les classes des accès concurrentiels +#define NAZARA_MATH_THREADSAFE 1 + +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) +#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) + +#endif // NAZARA_CONFIG_MATH_HPP diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 076d1b373..82919f28a 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -1,144 +1,145 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MATRIX4_HPP -#define NAZARA_MATRIX4_HPP - -#include -#include - -#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4 -#include -#else -#include -#endif - -template class NzEulerAngles; -template class NzQuaternion; -template class NzVector2; -template class NzVector3; -template class NzVector4; - -template class NzMatrix4 -{ - public: - NzMatrix4(); - NzMatrix4(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44); - NzMatrix4(const T matrix[16]); - //NzMatrix4(const NzMatrix3& matrix); - template explicit NzMatrix4(const NzMatrix4& matrix); - NzMatrix4(const NzMatrix4& matrix); - NzMatrix4(NzMatrix4&& matrix) noexcept; - ~NzMatrix4(); - - NzMatrix4 Concatenate(const NzMatrix4& matrix) const; - - T GetDeterminant() const; - NzMatrix4 GetInverse() const; - NzQuaternion GetRotation() const; - //NzMatrix3 GetRotationMatrix() const; - NzVector3 GetScale() const; - NzVector3 GetTranslation() const; - NzMatrix4 GetTransposed() const; - - bool HasNegativeScale() const; - bool HasScale() const; - - bool IsAffine() const; - bool IsDefined() const; - - void MakeIdentity(); - void MakeLookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up); - void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); - void MakePerspective(T angle, T ratio, T zNear, T zFar); - void MakeRotation(const NzQuaternion& rotation); - void MakeScale(const NzVector3& scale); - void MakeTranslation(const NzVector3& translation); - void MakeZero(); - - void Set(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44); - void Set(const T matrix[16]); - //NzMatrix4(const NzMatrix3& matrix); - void Set(const NzMatrix4& matrix); - void Set(NzMatrix4&& matrix); - template void Set(const NzMatrix4& matrix); - void SetRotation(const NzQuaternion& rotation); - void SetScale(const NzVector3& scale); - void SetTranslation(const NzVector3& translation); - - NzString ToString() const; - - NzVector2 Transform(const NzVector2& vector, T z = 0.0, T w = 1.0) const; - NzVector3 Transform(const NzVector3& vector, T w = 1.0) const; - NzVector4 Transform(const NzVector4& vector) const; - - NzMatrix4& Transpose(); - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator()(unsigned int x, unsigned int y); - const T& operator()(unsigned int x, unsigned int y) const; - - NzMatrix4& operator=(const NzMatrix4& matrix); - NzMatrix4& operator=(NzMatrix4&& matrix) noexcept; - - NzMatrix4 operator*(const NzMatrix4& matrix) const; - NzVector2 operator*(const NzVector2& vector) const; - NzVector3 operator*(const NzVector3& vector) const; - NzVector4 operator*(const NzVector4& vector) const; - NzMatrix4 operator*(T scalar) const; - - NzMatrix4& operator*=(const NzMatrix4& matrix); - NzMatrix4& operator*=(T scalar); - - static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); - static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); - static NzMatrix4 Identity(); - static NzMatrix4 LookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up); - static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); - static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar); - static NzMatrix4 Rotate(const NzQuaternion& rotation); - static NzMatrix4 Scale(const NzVector3& scale); - static NzMatrix4 Translate(const NzVector3& translation); - static NzMatrix4 Zero(); - - struct SharedMatrix - { - T m11, m12, m13, m14, - m21, m22, m23, m24, - m31, m32, m33, m34, - m41, m42, m43, m44; - - unsigned short refCount = 1; - NazaraMutex(mutex) - }; - - private: - void EnsureOwnership(); - void ReleaseMatrix(); - - SharedMatrix* m_sharedMatrix = nullptr; -}; - -template std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix); - -template NzMatrix4 operator*(T scale, const NzMatrix4& matrix); - -typedef NzMatrix4 NzMatrix4d; -typedef NzMatrix4 NzMatrix4f; - -#include - -#endif // NAZARA_MATRIX4_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_MATRIX4_HPP +#define NAZARA_MATRIX4_HPP + +#include +#include + +#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4 +#include +#else +#include +#endif + +template class NzEulerAngles; +template class NzQuaternion; +template class NzVector2; +template class NzVector3; +template class NzVector4; + +template class NzMatrix4 +{ + public: + NzMatrix4(); + NzMatrix4(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44); + NzMatrix4(const T matrix[16]); + //NzMatrix4(const NzMatrix3& matrix); + template explicit NzMatrix4(const NzMatrix4& matrix); + NzMatrix4(const NzMatrix4& matrix); + NzMatrix4(NzMatrix4&& matrix) noexcept; + ~NzMatrix4(); + + NzMatrix4 Concatenate(const NzMatrix4& matrix) const; + NzMatrix4 ConcatenateAffine(const NzMatrix4& matrix) const; + + T GetDeterminant() const; + NzMatrix4 GetInverse() const; + NzQuaternion GetRotation() const; + //NzMatrix3 GetRotationMatrix() const; + NzVector3 GetScale() const; + NzVector3 GetTranslation() const; + NzMatrix4 GetTransposed() const; + + bool HasNegativeScale() const; + bool HasScale() const; + + bool IsAffine() const; + bool IsDefined() const; + + void MakeIdentity(); + void MakeLookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); + void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); + void MakePerspective(T angle, T ratio, T zNear, T zFar); + void MakeRotation(const NzQuaternion& rotation); + void MakeScale(const NzVector3& scale); + void MakeTranslation(const NzVector3& translation); + void MakeZero(); + + void Set(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44); + void Set(const T matrix[16]); + //NzMatrix4(const NzMatrix3& matrix); + void Set(const NzMatrix4& matrix); + void Set(NzMatrix4&& matrix); + template void Set(const NzMatrix4& matrix); + void SetRotation(const NzQuaternion& rotation); + void SetScale(const NzVector3& scale); + void SetTranslation(const NzVector3& translation); + + NzString ToString() const; + + NzVector2 Transform(const NzVector2& vector, T z = 0.0, T w = 1.0) const; + NzVector3 Transform(const NzVector3& vector, T w = 1.0) const; + NzVector4 Transform(const NzVector4& vector) const; + + NzMatrix4& Transpose(); + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator()(unsigned int x, unsigned int y); + const T& operator()(unsigned int x, unsigned int y) const; + + NzMatrix4& operator=(const NzMatrix4& matrix); + NzMatrix4& operator=(NzMatrix4&& matrix) noexcept; + + NzMatrix4 operator*(const NzMatrix4& matrix) const; + NzVector2 operator*(const NzVector2& vector) const; + NzVector3 operator*(const NzVector3& vector) const; + NzVector4 operator*(const NzVector4& vector) const; + NzMatrix4 operator*(T scalar) const; + + NzMatrix4& operator*=(const NzMatrix4& matrix); + NzMatrix4& operator*=(T scalar); + + static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); + static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); + static NzMatrix4 Identity(); + static NzMatrix4 LookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); + static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); + static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar); + static NzMatrix4 Rotate(const NzQuaternion& rotation); + static NzMatrix4 Scale(const NzVector3& scale); + static NzMatrix4 Translate(const NzVector3& translation); + static NzMatrix4 Zero(); + + struct SharedMatrix + { + T m11, m12, m13, m14, + m21, m22, m23, m24, + m31, m32, m33, m34, + m41, m42, m43, m44; + + unsigned short refCount = 1; + NazaraMutex(mutex) + }; + + private: + void EnsureOwnership(); + void ReleaseMatrix(); + + SharedMatrix* m_sharedMatrix = nullptr; +}; + +template std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix); + +template NzMatrix4 operator*(T scale, const NzMatrix4& matrix); + +typedef NzMatrix4 NzMatrix4d; +typedef NzMatrix4 NzMatrix4f; + +#include + +#endif // NAZARA_MATRIX4_HPP diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 2f11f83dd..0e4d6b230 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -1,998 +1,942 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) - -#define F(a) static_cast(a) - -template -NzMatrix4::NzMatrix4() -{ -} - -template -NzMatrix4::NzMatrix4(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44) -{ - Set(r11, r12, r13, r14, - r21, r22, r23, r24, - r31, r32, r33, r34, - r41, r42, r43, r44); -} - -template -NzMatrix4::NzMatrix4(const T matrix[16]) -{ - Set(matrix); -} - -template -template -NzMatrix4::NzMatrix4(const NzMatrix4& matrix) -{ - Set(matrix); -} - -template -NzMatrix4::NzMatrix4(const NzMatrix4& matrix) -{ - Set(matrix); -} - -template -NzMatrix4::NzMatrix4(NzMatrix4&& matrix) noexcept -{ - Set(matrix); -} - -template -NzMatrix4::~NzMatrix4() -{ - ReleaseMatrix(); -} - -template -NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& matrix) const -{ - return Concatenate(*this, matrix); -} - -template -T NzMatrix4::GetDeterminant() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return F(0.0); - } - #endif - - T A = m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24); - T B = m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14); - T C = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); - T D = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); - - return m_sharedMatrix->m11*A - m_sharedMatrix->m21*B + m_sharedMatrix->m31*C - m_sharedMatrix->m41*D; -} - -template -NzMatrix4 NzMatrix4::GetInverse() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzMatrix4(); - } - #endif - - T det = GetDeterminant(); - if (!NzNumberEquals(det, F(0.0))) - { - return NzMatrix4((m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24)) / det, - -(m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14)) / det, - (m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, - -(m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, - - -(m_sharedMatrix->m21*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m33) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31)) / det, - - (m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det, - - -(m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det); - } - else - { - NazaraError("Matrix has no inverse"); - - return Identity(); - } -} - -template -NzVector3 NzMatrix4::GetScale() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzVector3(); - } - #endif - - return NzVector3(std::sqrt(m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31), - std::sqrt(m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32), - std::sqrt(m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33)); -} - -template -NzVector3 NzMatrix4::GetTranslation() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzVector3(); - } - #endif - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - return NzVector3(m_sharedMatrix->m41, m_sharedMatrix->m42, m_sharedMatrix->m43); - #else - return NzVector3(m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34); - #endif -} - -template -NzMatrix4 NzMatrix4::GetTransposed() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzMatrix4(); - } - #endif - - return NzMatrix4(m_sharedMatrix->m11, m_sharedMatrix->m21, m_sharedMatrix->m31, m_sharedMatrix->m41, - m_sharedMatrix->m12, m_sharedMatrix->m22, m_sharedMatrix->m32, m_sharedMatrix->m42, - m_sharedMatrix->m13, m_sharedMatrix->m23, m_sharedMatrix->m33, m_sharedMatrix->m43, - m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34, m_sharedMatrix->m44); -} - -template -bool NzMatrix4::HasNegativeScale() const -{ - return GetDeterminant() < F(0.0); -} - -template -bool NzMatrix4::HasScale() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return false; - } - #endif - - T t = m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31; - if (!NzNumberEquals(t, F(1.0))) - return true; - - t = m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32; - if (!NzNumberEquals(t, F(1.0))) - return true; - - t = m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33; - if (!NzNumberEquals(t, F(1.0))) - return true; - - return false; -} - -template -bool NzMatrix4::IsAffine() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return false; - } - #endif - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - return NzNumberEquals(m_sharedMatrix->m14, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m24, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m34, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m44, F(1.0)); - #else - return NzNumberEquals(m_sharedMatrix->m41, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m42, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m43, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m44, F(1.0)); - #endif -} - -template -bool NzMatrix4::IsDefined() const -{ - return m_sharedMatrix != nullptr; -} - -template -void NzMatrix4::MakeIdentity() -{ - Set(F(1.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(1.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzMatrix4::MakeOrtho(T left, T top, T width, T height, T zNear, T zFar) -{ - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(F(2.0)/(width-left), F(0.0), F(0.0), -(width+left)/(width-left), - F(0.0), F(2.0)/(top-height), F(0.0), -(top+height)/(top-height), - F(0.0), F(0.0), F(-2.0)/(zFar-zNear), -(zFar+zNear)/(zFar-zNear), - F(0.0), F(0.0), F(0.0), F(1.0)); - #else - Set(F(2.0)/(width-left), F(0.0), F(0.0), F(0.0), - F(0.0), F(2.0)/(top-height), F(0.0), F(0.0), - F(0.0), F(0.0), F(-2.0)/(zFar-zNear), F(0.0), - -(width+left)/(width-left), -(top+height)/(top-height), -(zFar+zNear)/(zFar-zNear), F(1.0)); - #endif -} - -template -void NzMatrix4::MakeLookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up) -{ - // http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml - NzVector3 f = center - eye; - f.Normalize(); - - NzVector3 u = up; - u.Normalize(); - - NzVector3 s = f.CrossProduct(u); - u = s.CrossProduct(f); - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(s.x, s.y, s.z, F(0.0), - u.x, u.y, u.z, F(0.0), - -f.x, -f.y, -f.z, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); - #else - Set(s.x, u.x, -f.x, F(0.0), - s.y, u.y, -f.y, F(0.0), - s.z, u.z, -f.z, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); - #endif - - Concatenate(Translate(-eye)); -} - -template -void NzMatrix4::MakePerspective(T angle, T ratio, T zNear, T zFar) -{ - #if NAZARA_MATH_ANGLE_RADIAN - angle /= F(2.0); - #else - angle = NzDegreeToRadian(angle/2); - #endif - - T f = F(1.0) / std::tan(angle); - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(f / ratio, F(0.0), F(0.0), F(0.0), - F(0.0), f, F(0.0), F(0.0), - F(0.0), F(0.0), (zNear+zFar) / (zNear-zFar), F(-1.0), - F(0.0), F(0.0), (F(2.0)*zNear*zFar) / (zNear-zFar), F(1.0)); - #else - Set(f / ratio, F(0.0), F(0.0), F(0.0), - F(0.0), f, F(0.0), F(0.0), - F(0.0), F(0.0), (zNear+zFar) / (zNear-zFar), (F(2.0)*zNear*zFar) / (zNear-zFar), - F(0.0), F(0.0), F(-1.0), F(1.0)); - #endif -} - -template -void NzMatrix4::MakeRotation(const NzQuaternion& rotation) -{ - // http://stackoverflow.com/questions/1556260/convert-quaternion-rotation-to-rotation-matrix - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, F(0.0), - F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, F(0.0), - F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); - #else - Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, F(0.0), - F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, F(0.0), - F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); - #endif -} - -template -void NzMatrix4::MakeScale(const NzVector3& scale) -{ - Set(scale.x, F(0.0), F(0.0), F(0.0), - F(0.0), scale.y, F(0.0), F(0.0), - F(0.0), F(0.0), scale.z, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzMatrix4::MakeTranslation(const NzVector3& translation) -{ - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - Set(F(1.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(1.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0), F(0.0), - translation.x, translation.y, translation.z, F(1.0)); - #else - Set(F(1.0), F(0.0), F(0.0), translation.x, - F(0.0), F(1.0), F(0.0), translation.y, - F(0.0), F(0.0), F(1.0), translation.z, - F(0.0), F(0.0), F(0.0), F(1.0)); - #endif -} - -template -void NzMatrix4::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0)); -} - -template -void NzMatrix4::Set(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44) -{ - EnsureOwnership(); - - m_sharedMatrix->m11 = r11; - m_sharedMatrix->m12 = r12; - m_sharedMatrix->m13 = r13; - m_sharedMatrix->m14 = r14; - m_sharedMatrix->m21 = r21; - m_sharedMatrix->m22 = r22; - m_sharedMatrix->m23 = r23; - m_sharedMatrix->m24 = r24; - m_sharedMatrix->m31 = r31; - m_sharedMatrix->m32 = r32; - m_sharedMatrix->m33 = r33; - m_sharedMatrix->m34 = r34; - m_sharedMatrix->m41 = r41; - m_sharedMatrix->m42 = r42; - m_sharedMatrix->m43 = r43; - m_sharedMatrix->m44 = r44; -} - -template -void NzMatrix4::Set(const T matrix[16]) -{ - EnsureOwnership(); - - // Ici nous sommes certains de la continuité des éléments en mémoire - std::memcpy(&m_sharedMatrix->m11, matrix, 16*sizeof(T)); -} - -template -void NzMatrix4::Set(const NzMatrix4& matrix) -{ - ReleaseMatrix(); - - m_sharedMatrix = matrix.m_sharedMatrix; - if (m_sharedMatrix) - { - NazaraMutexLock(m_sharedMatrix->mutex); - m_sharedMatrix->refCount++; - NazaraMutexUnlock(m_sharedMatrix->mutex); - } -} - -template -void NzMatrix4::Set(NzMatrix4&& matrix) -{ - std::swap(m_sharedMatrix, matrix.m_sharedMatrix); -} - -template -template -void NzMatrix4::Set(const NzMatrix4& matrix) -{ - Set(F(matrix.m_sharedMatrix->m11), F(matrix.m_sharedMatrix->m12), F(matrix.m_sharedMatrix->m13), F(matrix.m_sharedMatrix->m14), - F(matrix.m_sharedMatrix->m21), F(matrix.m_sharedMatrix->m22), F(matrix.m_sharedMatrix->m23), F(matrix.m_sharedMatrix->m24), - F(matrix.m_sharedMatrix->m31), F(matrix.m_sharedMatrix->m32), F(matrix.m_sharedMatrix->m33), F(matrix.m_sharedMatrix->m34), - F(matrix.m_sharedMatrix->m41), F(matrix.m_sharedMatrix->m42), F(matrix.m_sharedMatrix->m43), F(matrix.m_sharedMatrix->m44)); -} - -template -void NzMatrix4::SetRotation(const NzQuaternion& rotation) -{ - // http://www.flipcode.com/documents/matrfaq.html#Q54 - EnsureOwnership(); - - m_sharedMatrix->m11 = F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z; - m_sharedMatrix->m22 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z; - m_sharedMatrix->m33 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y; - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; - m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; - m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; - m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; - m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; - m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; - #else - m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; - m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; - m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; - m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; - m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; - m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; - #endif -} - -template -void NzMatrix4::SetScale(const NzVector3& scale) -{ - EnsureOwnership(); - - m_sharedMatrix->m11 = scale.x; - m_sharedMatrix->m22 = scale.y; - m_sharedMatrix->m33 = scale.z; -} - -template -void NzMatrix4::SetTranslation(const NzVector3& translation) -{ - EnsureOwnership(); - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - m_sharedMatrix->m41 = translation.x; - m_sharedMatrix->m42 = translation.y; - m_sharedMatrix->m43 = translation.z; - m_sharedMatrix->m44 = F(1.0); - #else - m_sharedMatrix->m14 = translation.x; - m_sharedMatrix->m24 = translation.y; - m_sharedMatrix->m34 = translation.z; - m_sharedMatrix->m44 = F(1.0); - #endif -} - -template -NzString NzMatrix4::ToString() const -{ - if (!m_sharedMatrix) - return "Matrix4(undefined)"; - - NzStringStream ss; - return ss << "Matrix4(" << m_sharedMatrix->m11 << ", " << m_sharedMatrix->m12 << ", " << m_sharedMatrix->m13 << ", " << m_sharedMatrix->m14 << ",\n" - << " " << m_sharedMatrix->m21 << ", " << m_sharedMatrix->m22 << ", " << m_sharedMatrix->m23 << ", " << m_sharedMatrix->m24 << ",\n" - << " " << m_sharedMatrix->m31 << ", " << m_sharedMatrix->m32 << ", " << m_sharedMatrix->m33 << ", " << m_sharedMatrix->m34 << ",\n" - << " " << m_sharedMatrix->m41 << ", " << m_sharedMatrix->m42 << ", " << m_sharedMatrix->m43 << ", " << m_sharedMatrix->m44 << ')'; -} - -template -NzVector2 NzMatrix4::Transform(const NzVector2& vector, T z, T w) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return vector; - } - #endif - - return NzVector2(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*z + m_sharedMatrix->m14*w, - m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*z + m_sharedMatrix->m24*w); -} - -template -NzVector3 NzMatrix4::Transform(const NzVector3& vector, T w) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return vector; - } - #endif - - return NzVector3(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*w, - m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*w, - m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*w); -} - -template -NzVector4 NzMatrix4::Transform(const NzVector4& vector) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return vector; - } - #endif - - return NzVector4(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*vector.w, - m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*vector.w, - m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*vector.w, - m_sharedMatrix->m41*vector.x + m_sharedMatrix->m42*vector.y + m_sharedMatrix->m43*vector.z + m_sharedMatrix->m44*vector.w); -} - -template -NzMatrix4& NzMatrix4::Transpose() -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - std::swap(m_sharedMatrix->m12, m_sharedMatrix->m21); - std::swap(m_sharedMatrix->m13, m_sharedMatrix->m31); - std::swap(m_sharedMatrix->m14, m_sharedMatrix->m41); - std::swap(m_sharedMatrix->m23, m_sharedMatrix->m32); - std::swap(m_sharedMatrix->m24, m_sharedMatrix->m42); - std::swap(m_sharedMatrix->m34, m_sharedMatrix->m43); - - return *this; -} - -template -NzMatrix4::operator NzString() const -{ - return ToString(); -} - -template -NzMatrix4::operator T*() -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return nullptr; - } - #endif - - EnsureOwnership(); - - return &m_sharedMatrix->m11; -} - -template -NzMatrix4::operator const T*() const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return nullptr; - } - #endif - - return &m_sharedMatrix->m11; -} - -template -T& NzMatrix4::operator()(unsigned int x, unsigned int y) -{ - #if NAZARA_MATH_SAFE - if (x > 3 || y > 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - EnsureOwnership(); - - return (&m_sharedMatrix->m11)[y*4+x]; -} - -template -const T& NzMatrix4::operator()(unsigned int x, unsigned int y) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - throw std::runtime_error("Tried to access element of Matrix not defined"); - } - - if (x > 3 || y > 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - return (&m_sharedMatrix->m11)[y*4+x]; -} - -template -NzMatrix4& NzMatrix4::operator=(const NzMatrix4& matrix) -{ - Set(matrix); - - return *this; -} - -template -NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) noexcept -{ - Set(matrix); - - return *this; -} - -template -NzMatrix4 NzMatrix4::operator*(const NzMatrix4& matrix) const -{ - return Concatenate(matrix); -} - -template -NzVector2 NzMatrix4::operator*(const NzVector2& vector) const -{ - return Transform(vector); -} - -template -NzVector3 NzMatrix4::operator*(const NzVector3& vector) const -{ - return Transform(vector); -} - -template -NzVector4 NzMatrix4::operator*(const NzVector4& vector) const -{ - return Transform(vector); -} - -template -NzMatrix4 NzMatrix4::operator*(T scalar) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - return NzMatrix4(m_sharedMatrix->m11 * scalar, m_sharedMatrix->m12 * scalar, m_sharedMatrix->m13 * scalar, m_sharedMatrix->m14 * scalar, - m_sharedMatrix->m21 * scalar, m_sharedMatrix->m22 * scalar, m_sharedMatrix->m23 * scalar, m_sharedMatrix->m24 * scalar, - m_sharedMatrix->m31 * scalar, m_sharedMatrix->m32 * scalar, m_sharedMatrix->m33 * scalar, m_sharedMatrix->m34 * scalar, - m_sharedMatrix->m41 * scalar, m_sharedMatrix->m42 * scalar, m_sharedMatrix->m43 * scalar, m_sharedMatrix->m44 * scalar); -} - -template -NzMatrix4& NzMatrix4::operator*=(const NzMatrix4& matrix) -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - Set(Concatenate(*this, matrix)); - - return *this; -} - -template -NzMatrix4& NzMatrix4::operator*=(T scalar) -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - m_sharedMatrix->m11 *= scalar; - m_sharedMatrix->m12 *= scalar; - m_sharedMatrix->m13 *= scalar; - m_sharedMatrix->m14 *= scalar; - m_sharedMatrix->m21 *= scalar; - m_sharedMatrix->m22 *= scalar; - m_sharedMatrix->m23 *= scalar; - m_sharedMatrix->m24 *= scalar; - m_sharedMatrix->m31 *= scalar; - m_sharedMatrix->m32 *= scalar; - m_sharedMatrix->m33 *= scalar; - m_sharedMatrix->m34 *= scalar; - m_sharedMatrix->m41 *= scalar; - m_sharedMatrix->m42 *= scalar; - m_sharedMatrix->m43 *= scalar; - m_sharedMatrix->m44 *= scalar; - - return *this; -} - -template -NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) -{ - #if NAZARA_MATH_SAFE - if (!m1.IsDefined()) - { - NazaraError("First matrix not defined"); - return NzMatrix4(); - } - - if (!m2.IsDefined()) - { - NazaraError("Second matrix not defined"); - return NzMatrix4(); - } - #endif - - #if NAZARA_MATH_MATRIX4_CHECK_AFFINE - if (m1.IsAffine() && m2.IsAffine()) - return ConcatenateAffine(m1, m2); - #endif - - return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m44, - - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m44, - - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m44, - - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m44); -} - -template -NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2) -{ - #if NAZARA_MATH_SAFE - if (!m1.IsDefined()) - { - NazaraError("First matrix not defined"); - return NzMatrix4(); - } - - if (!m2.IsDefined()) - { - NazaraError("Second matrix not defined"); - return NzMatrix4(); - } - #endif - - #ifdef NAZARA_DEBUG - if (!m1.IsAffine()) - { - NazaraError("First matrix not affine"); - return NzMatrix4(); - } - - if (!m2.IsAffine()) - { - NazaraError("Second matrix not affine"); - return NzMatrix4(); - } - #endif - - #if NAZARA_MATH_MATRIX_COLUMN_MAJOR - return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, - F(0.0), - - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, - F(0.0), - - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, - F(0.0), - - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m2.m_sharedMatrix->m43, - F(1.0)); - #else - return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14, - - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24, - - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34, - - F(0.0), - F(0.0), - F(0.0), - F(1.0)); - #endif -} - -template -NzMatrix4 NzMatrix4::Identity() -{ - NzMatrix4 matrix; - matrix.MakeIdentity(); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::LookAt(const NzVector3& eye, const NzVector3& center, const NzVector3& up) -{ - NzMatrix4 matrix; - matrix.MakeLookAt(eye, center, up); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Ortho(T left, T top, T width, T height, T zNear, T zFar) -{ - NzMatrix4 matrix; - matrix.MakeOrtho(left, top, width, height, zNear, zFar); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Perspective(T angle, T ratio, T zNear, T zFar) -{ - NzMatrix4 matrix; - matrix.MakePerspective(angle, ratio, zNear, zFar); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Rotate(const NzQuaternion& rotation) -{ - NzMatrix4 matrix; - matrix.MakeRotation(rotation); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Scale(const NzVector3& scale) -{ - NzMatrix4 matrix; - matrix.MakeScale(scale); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Translate(const NzVector3& translation) -{ - NzMatrix4 mat; - mat.MakeTranslation(translation); - - return mat; -} - -template -NzMatrix4 NzMatrix4::Zero() -{ - NzMatrix4 matrix; - matrix.MakeZero(); - - return matrix; -} - -template -std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix) -{ - return out << matrix.ToString(); -} - -template -NzMatrix4 operator*(T scale, const NzMatrix4& matrix) -{ - return matrix * scale; -} - -template -void NzMatrix4::EnsureOwnership() -{ - if (m_sharedMatrix) - { - NazaraLock(m_sharedMatrix->mutex); - if (m_sharedMatrix->refCount > 1) - { - m_sharedMatrix->refCount--; - - SharedMatrix* sharedMatrix = new SharedMatrix; - std::memcpy(&sharedMatrix->m11, &m_sharedMatrix->m11, 16*sizeof(T)); - } - } - else - m_sharedMatrix = new SharedMatrix; -} - -template -void NzMatrix4::ReleaseMatrix() -{ - if (!m_sharedMatrix) - return; - - NazaraMutexLock(m_sharedMatrix->mutex); - bool freeSharedMatrix = (--m_sharedMatrix->refCount == 0); - NazaraMutexUnlock(m_sharedMatrix->mutex); - - if (freeSharedMatrix) - delete m_sharedMatrix; - - m_sharedMatrix = nullptr; -} - -#undef F - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) + +#define F(a) static_cast(a) + +template +NzMatrix4::NzMatrix4() +{ +} + +template +NzMatrix4::NzMatrix4(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44) +{ + Set(r11, r12, r13, r14, + r21, r22, r23, r24, + r31, r32, r33, r34, + r41, r42, r43, r44); +} + +template +NzMatrix4::NzMatrix4(const T matrix[16]) +{ + Set(matrix); +} + +template +template +NzMatrix4::NzMatrix4(const NzMatrix4& matrix) +{ + Set(matrix); +} + +template +NzMatrix4::NzMatrix4(const NzMatrix4& matrix) +{ + Set(matrix); +} + +template +NzMatrix4::NzMatrix4(NzMatrix4&& matrix) noexcept +{ + Set(matrix); +} + +template +NzMatrix4::~NzMatrix4() +{ + ReleaseMatrix(); +} + +template +NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& matrix) const +{ + return Concatenate(*this, matrix); +} + +template +NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& matrix) const +{ + return ConcatenateAffine(*this, matrix); +} + +template +T NzMatrix4::GetDeterminant() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return F(0.0); + } + #endif + + T A = m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24); + T B = m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14); + T C = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); + T D = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); + + return m_sharedMatrix->m11*A - m_sharedMatrix->m21*B + m_sharedMatrix->m31*C - m_sharedMatrix->m41*D; +} + +template +NzMatrix4 NzMatrix4::GetInverse() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzMatrix4(); + } + #endif + + T det = GetDeterminant(); + if (!NzNumberEquals(det, F(0.0))) + { + return NzMatrix4((m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24)) / det, + -(m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14)) / det, + (m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, + -(m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, + + -(m_sharedMatrix->m21*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m33) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31)) / det, + + (m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det, + + -(m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det); + } + else + { + NazaraError("Matrix has no inverse"); + + return Identity(); + } +} + +template +NzVector3 NzMatrix4::GetScale() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzVector3(); + } + #endif + + return NzVector3(std::sqrt(m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31), + std::sqrt(m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32), + std::sqrt(m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33)); +} + +template +NzVector3 NzMatrix4::GetTranslation() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzVector3(); + } + #endif + + return NzVector3(m_sharedMatrix->m41, m_sharedMatrix->m42, m_sharedMatrix->m43); +} + +template +NzMatrix4 NzMatrix4::GetTransposed() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzMatrix4(); + } + #endif + + return NzMatrix4(m_sharedMatrix->m11, m_sharedMatrix->m21, m_sharedMatrix->m31, m_sharedMatrix->m41, + m_sharedMatrix->m12, m_sharedMatrix->m22, m_sharedMatrix->m32, m_sharedMatrix->m42, + m_sharedMatrix->m13, m_sharedMatrix->m23, m_sharedMatrix->m33, m_sharedMatrix->m43, + m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34, m_sharedMatrix->m44); +} + +template +bool NzMatrix4::HasNegativeScale() const +{ + return GetDeterminant() < F(0.0); +} + +template +bool NzMatrix4::HasScale() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return false; + } + #endif + + T t = m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31; + if (!NzNumberEquals(t, F(1.0))) + return true; + + t = m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32; + if (!NzNumberEquals(t, F(1.0))) + return true; + + t = m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33; + if (!NzNumberEquals(t, F(1.0))) + return true; + + return false; +} + +template +bool NzMatrix4::IsAffine() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return false; + } + #endif + + return NzNumberEquals(m_sharedMatrix->m14, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m24, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m34, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m44, F(1.0)); +} + +template +bool NzMatrix4::IsDefined() const +{ + return m_sharedMatrix != nullptr; +} + +template +void NzMatrix4::MakeIdentity() +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(1.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(1.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeOrtho(T left, T top, T width, T height, T zNear, T zFar) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204941(v=vs.85).aspx + Set(F(2.0)/(width-left), F(0.0), F(0.0), -(width+left)/(width-left), + F(0.0), F(2.0)/(top-height), F(0.0), -(top+height)/(top-height), + F(0.0), F(0.0), F(-2.0)/(zFar-zNear), -(zFar+zNear)/(zFar-zNear), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeLookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up) +{ + NzVector3 f = NzVector3::Normalize(target - eye); + NzVector3 u(up.GetNormal()); + NzVector3 s = NzVector3::Normalize(f.CrossProduct(u)); + u = s.CrossProduct(f); + + Set(s.x, u.x, -f.x, T(0.0), + s.y, u.y, -f.y, T(0.0), + s.z, u.z, -f.z, T(0.0), + -s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0)); +} + +template +void NzMatrix4::MakePerspective(T angle, T ratio, T zNear, T zFar) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204944(v=vs.85).aspx + #if NAZARA_MATH_ANGLE_RADIAN + angle /= F(2.0); + #else + angle = NzDegreeToRadian(angle/F(2.0)); + #endif + + T yScale = F(1.0) / std::tan(angle); + + Set(yScale / ratio, F(0.0), F(0.0), F(0.0), + F(0.0), yScale, F(0.0), F(0.0), + F(0.0), F(0.0), zFar / (zNear-zFar), F(-1.0), + F(0.0), F(0.0), (zNear*zFar) / (zNear-zFar), F(0.0)); +} + +template +void NzMatrix4::MakeRotation(const NzQuaternion& rotation) +{ + // http://www.flipcode.com/documents/matrfaq.html#Q54 +/* + | 2 2 | + | 1 - 2Y - 2Z 2XY + 2ZW 2XZ - 2YW | + | | + | 2 2 | + M = | 2XY - 2ZW 1 - 2X - 2Z 2YZ + 2XW | + | | + | 2 2 | + | 2XZ + 2YW 2YZ - 2XW 1 - 2X - 2Y | + | | +*/ + ///FIXME: À corriger (Rotation quaternino != rotation matricielle) + Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, + F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, + F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, + F(0.0), + + F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, + F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, + F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, + F(0.0), + + F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, + F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, + F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, + F(0.0), + + F(0.0), + F(0.0), + F(0.0), + F(1.0)); +} + +template +void NzMatrix4::MakeScale(const NzVector3& scale) +{ + Set(scale.x, F(0.0), F(0.0), F(0.0), + F(0.0), scale.y, F(0.0), F(0.0), + F(0.0), F(0.0), scale.z, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeTranslation(const NzVector3& translation) +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(1.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(1.0), F(0.0), + translation.x, translation.y, translation.z, F(1.0)); +} + +template +void NzMatrix4::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0)); +} + +template +void NzMatrix4::Set(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44) +{ + EnsureOwnership(); + + m_sharedMatrix->m11 = r11; + m_sharedMatrix->m12 = r12; + m_sharedMatrix->m13 = r13; + m_sharedMatrix->m14 = r14; + m_sharedMatrix->m21 = r21; + m_sharedMatrix->m22 = r22; + m_sharedMatrix->m23 = r23; + m_sharedMatrix->m24 = r24; + m_sharedMatrix->m31 = r31; + m_sharedMatrix->m32 = r32; + m_sharedMatrix->m33 = r33; + m_sharedMatrix->m34 = r34; + m_sharedMatrix->m41 = r41; + m_sharedMatrix->m42 = r42; + m_sharedMatrix->m43 = r43; + m_sharedMatrix->m44 = r44; +} + +template +void NzMatrix4::Set(const T matrix[16]) +{ + EnsureOwnership(); + + // Ici nous sommes certains de la continuité des éléments en mémoire + std::memcpy(&m_sharedMatrix->m11, matrix, 16*sizeof(T)); +} + +template +void NzMatrix4::Set(const NzMatrix4& matrix) +{ + ReleaseMatrix(); + + m_sharedMatrix = matrix.m_sharedMatrix; + if (m_sharedMatrix) + { + NazaraMutexLock(m_sharedMatrix->mutex); + m_sharedMatrix->refCount++; + NazaraMutexUnlock(m_sharedMatrix->mutex); + } +} + +template +void NzMatrix4::Set(NzMatrix4&& matrix) +{ + std::swap(m_sharedMatrix, matrix.m_sharedMatrix); +} + +template +template +void NzMatrix4::Set(const NzMatrix4& matrix) +{ + Set(F(matrix.m_sharedMatrix->m11), F(matrix.m_sharedMatrix->m12), F(matrix.m_sharedMatrix->m13), F(matrix.m_sharedMatrix->m14), + F(matrix.m_sharedMatrix->m21), F(matrix.m_sharedMatrix->m22), F(matrix.m_sharedMatrix->m23), F(matrix.m_sharedMatrix->m24), + F(matrix.m_sharedMatrix->m31), F(matrix.m_sharedMatrix->m32), F(matrix.m_sharedMatrix->m33), F(matrix.m_sharedMatrix->m34), + F(matrix.m_sharedMatrix->m41), F(matrix.m_sharedMatrix->m42), F(matrix.m_sharedMatrix->m43), F(matrix.m_sharedMatrix->m44)); +} + +template +void NzMatrix4::SetRotation(const NzQuaternion& rotation) +{ + // http://www.flipcode.com/documents/matrfaq.html#Q54 + EnsureOwnership(); + + m_sharedMatrix->m11 = F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z; + m_sharedMatrix->m22 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z; + m_sharedMatrix->m33 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y; + + m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; + m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; +} + +template +void NzMatrix4::SetScale(const NzVector3& scale) +{ + EnsureOwnership(); + + m_sharedMatrix->m11 = scale.x; + m_sharedMatrix->m22 = scale.y; + m_sharedMatrix->m33 = scale.z; +} + +template +void NzMatrix4::SetTranslation(const NzVector3& translation) +{ + EnsureOwnership(); + + m_sharedMatrix->m41 = translation.x; + m_sharedMatrix->m42 = translation.y; + m_sharedMatrix->m43 = translation.z; + m_sharedMatrix->m44 = F(1.0); +} + +template +NzString NzMatrix4::ToString() const +{ + if (!m_sharedMatrix) + return "Matrix4(undefined)"; + + NzStringStream ss; + return ss << "Matrix4(" << m_sharedMatrix->m11 << ", " << m_sharedMatrix->m12 << ", " << m_sharedMatrix->m13 << ", " << m_sharedMatrix->m14 << ",\n" + << " " << m_sharedMatrix->m21 << ", " << m_sharedMatrix->m22 << ", " << m_sharedMatrix->m23 << ", " << m_sharedMatrix->m24 << ",\n" + << " " << m_sharedMatrix->m31 << ", " << m_sharedMatrix->m32 << ", " << m_sharedMatrix->m33 << ", " << m_sharedMatrix->m34 << ",\n" + << " " << m_sharedMatrix->m41 << ", " << m_sharedMatrix->m42 << ", " << m_sharedMatrix->m43 << ", " << m_sharedMatrix->m44 << ')'; +} + +template +NzVector2 NzMatrix4::Transform(const NzVector2& vector, T z, T w) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return vector; + } + #endif + + return NzVector2(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*z + m_sharedMatrix->m14*w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*z + m_sharedMatrix->m24*w); +} + +template +NzVector3 NzMatrix4::Transform(const NzVector3& vector, T w) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return vector; + } + #endif + + return NzVector3(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*w, + m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*w); +} + +template +NzVector4 NzMatrix4::Transform(const NzVector4& vector) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return vector; + } + #endif + + return NzVector4(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*vector.w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*vector.w, + m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*vector.w, + m_sharedMatrix->m41*vector.x + m_sharedMatrix->m42*vector.y + m_sharedMatrix->m43*vector.z + m_sharedMatrix->m44*vector.w); +} + +template +NzMatrix4& NzMatrix4::Transpose() +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + std::swap(m_sharedMatrix->m12, m_sharedMatrix->m21); + std::swap(m_sharedMatrix->m13, m_sharedMatrix->m31); + std::swap(m_sharedMatrix->m14, m_sharedMatrix->m41); + std::swap(m_sharedMatrix->m23, m_sharedMatrix->m32); + std::swap(m_sharedMatrix->m24, m_sharedMatrix->m42); + std::swap(m_sharedMatrix->m34, m_sharedMatrix->m43); + + return *this; +} + +template +NzMatrix4::operator NzString() const +{ + return ToString(); +} + +template +NzMatrix4::operator T*() +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return nullptr; + } + #endif + + EnsureOwnership(); + + return &m_sharedMatrix->m11; +} + +template +NzMatrix4::operator const T*() const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return nullptr; + } + #endif + + return &m_sharedMatrix->m11; +} + +template +T& NzMatrix4::operator()(unsigned int x, unsigned int y) +{ + #if NAZARA_MATH_SAFE + if (x > 3 || y > 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + EnsureOwnership(); + + return (&m_sharedMatrix->m11)[y*4+x]; +} + +template +const T& NzMatrix4::operator()(unsigned int x, unsigned int y) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + throw std::runtime_error("Tried to access element of Matrix not defined"); + } + + if (x > 3 || y > 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + return (&m_sharedMatrix->m11)[y*4+x]; +} + +template +NzMatrix4& NzMatrix4::operator=(const NzMatrix4& matrix) +{ + Set(matrix); + + return *this; +} + +template +NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) noexcept +{ + Set(matrix); + + return *this; +} + +template +NzMatrix4 NzMatrix4::operator*(const NzMatrix4& matrix) const +{ + return Concatenate(matrix); +} + +template +NzVector2 NzMatrix4::operator*(const NzVector2& vector) const +{ + return Transform(vector); +} + +template +NzVector3 NzMatrix4::operator*(const NzVector3& vector) const +{ + return Transform(vector); +} + +template +NzVector4 NzMatrix4::operator*(const NzVector4& vector) const +{ + return Transform(vector); +} + +template +NzMatrix4 NzMatrix4::operator*(T scalar) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + return NzMatrix4(m_sharedMatrix->m11 * scalar, m_sharedMatrix->m12 * scalar, m_sharedMatrix->m13 * scalar, m_sharedMatrix->m14 * scalar, + m_sharedMatrix->m21 * scalar, m_sharedMatrix->m22 * scalar, m_sharedMatrix->m23 * scalar, m_sharedMatrix->m24 * scalar, + m_sharedMatrix->m31 * scalar, m_sharedMatrix->m32 * scalar, m_sharedMatrix->m33 * scalar, m_sharedMatrix->m34 * scalar, + m_sharedMatrix->m41 * scalar, m_sharedMatrix->m42 * scalar, m_sharedMatrix->m43 * scalar, m_sharedMatrix->m44 * scalar); +} + +template +NzMatrix4& NzMatrix4::operator*=(const NzMatrix4& matrix) +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + Set(Concatenate(*this, matrix)); + + return *this; +} + +template +NzMatrix4& NzMatrix4::operator*=(T scalar) +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + m_sharedMatrix->m11 *= scalar; + m_sharedMatrix->m12 *= scalar; + m_sharedMatrix->m13 *= scalar; + m_sharedMatrix->m14 *= scalar; + m_sharedMatrix->m21 *= scalar; + m_sharedMatrix->m22 *= scalar; + m_sharedMatrix->m23 *= scalar; + m_sharedMatrix->m24 *= scalar; + m_sharedMatrix->m31 *= scalar; + m_sharedMatrix->m32 *= scalar; + m_sharedMatrix->m33 *= scalar; + m_sharedMatrix->m34 *= scalar; + m_sharedMatrix->m41 *= scalar; + m_sharedMatrix->m42 *= scalar; + m_sharedMatrix->m43 *= scalar; + m_sharedMatrix->m44 *= scalar; + + return *this; +} + +template +NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) +{ + #if NAZARA_MATH_SAFE + if (!m1.IsDefined()) + { + NazaraError("First matrix not defined"); + return NzMatrix4(); + } + + if (!m2.IsDefined()) + { + NazaraError("Second matrix not defined"); + return NzMatrix4(); + } + #endif + + #if NAZARA_MATH_MATRIX4_CHECK_AFFINE + if (m1.IsAffine() && m2.IsAffine()) + return ConcatenateAffine(m1, m2); + #endif + + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m44); +} + +template +NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2) +{ + #if NAZARA_MATH_SAFE + if (!m1.IsDefined()) + { + NazaraError("First matrix not defined"); + return NzMatrix4(); + } + + if (!m2.IsDefined()) + { + NazaraError("Second matrix not defined"); + return NzMatrix4(); + } + #endif + + #ifdef NAZARA_DEBUG + if (!m1.IsAffine()) + { + NazaraError("First matrix not affine"); + return NzMatrix4(); + } + + if (!m2.IsAffine()) + { + NazaraError("Second matrix not affine"); + return NzMatrix4(); + } + #endif + + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m2.m_sharedMatrix->m43, + F(1.0)); +} + +template +NzMatrix4 NzMatrix4::Identity() +{ + NzMatrix4 matrix; + matrix.MakeIdentity(); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::LookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up) +{ + NzMatrix4 matrix; + matrix.MakeLookAt(eye, target, up); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Ortho(T left, T top, T width, T height, T zNear, T zFar) +{ + NzMatrix4 matrix; + matrix.MakeOrtho(left, top, width, height, zNear, zFar); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Perspective(T angle, T ratio, T zNear, T zFar) +{ + NzMatrix4 matrix; + matrix.MakePerspective(angle, ratio, zNear, zFar); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Rotate(const NzQuaternion& rotation) +{ + NzMatrix4 matrix; + matrix.MakeRotation(rotation); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Scale(const NzVector3& scale) +{ + NzMatrix4 matrix; + matrix.MakeScale(scale); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Translate(const NzVector3& translation) +{ + NzMatrix4 mat; + mat.MakeTranslation(translation); + + return mat; +} + +template +NzMatrix4 NzMatrix4::Zero() +{ + NzMatrix4 matrix; + matrix.MakeZero(); + + return matrix; +} + +template +std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix) +{ + return out << matrix.ToString(); +} + +template +NzMatrix4 operator*(T scale, const NzMatrix4& matrix) +{ + return matrix * scale; +} + +template +void NzMatrix4::EnsureOwnership() +{ + if (m_sharedMatrix) + { + NazaraLock(m_sharedMatrix->mutex); + if (m_sharedMatrix->refCount > 1) + { + m_sharedMatrix->refCount--; + + SharedMatrix* sharedMatrix = new SharedMatrix; + std::memcpy(&sharedMatrix->m11, &m_sharedMatrix->m11, 16*sizeof(T)); + } + } + else + m_sharedMatrix = new SharedMatrix; +} + +template +void NzMatrix4::ReleaseMatrix() +{ + if (!m_sharedMatrix) + return; + + NazaraMutexLock(m_sharedMatrix->mutex); + bool freeSharedMatrix = (--m_sharedMatrix->refCount == 0); + NazaraMutexUnlock(m_sharedMatrix->mutex); + + if (freeSharedMatrix) + delete m_sharedMatrix; + + m_sharedMatrix = nullptr; +} + +#undef F + +#include diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index 6b3c0e7b7..f4b2ab97a 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -1,90 +1,93 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_QUATERNION_HPP -#define NAZARA_QUATERNION_HPP - -#include - -template class NzEulerAngles; -template class NzVector3; - -template class NzQuaternion -{ - public: - NzQuaternion(); - NzQuaternion(T W, T X, T Y, T Z); - NzQuaternion(T quat[4]); - NzQuaternion(T angle, const NzVector3& axis); - NzQuaternion(const NzEulerAngles& angles); - //NzQuaternion(const NzMatrix3& mat); - template explicit NzQuaternion(const NzQuaternion& quat); - NzQuaternion(const NzQuaternion& quat) = default; - ~NzQuaternion() = default; - - T DotProduct(const NzQuaternion& vec) const; - - NzQuaternion GetConjugate() const; - NzQuaternion GetNormalized() const; - - void MakeIdentity(); - void MakeZero(); - - T Magnitude() const; - - T Normalize(); - - void Set(T W, T X, T Y, T Z); - void Set(T quat[4]); - void Set(T angle, const NzVector3& normalizedAxis); - void Set(const NzEulerAngles& angles); - //void Set(const NzMatrix3& mat); - void Set(const NzQuaternion& quat); - template void Set(const NzQuaternion& quat); - - T SquaredMagnitude() const; - - NzEulerAngles ToEulerAngles() const; - //NzMatrix3 ToRotationMatrix() const; - NzString ToString() const; - - operator NzString() const; - - NzQuaternion& operator=(const NzQuaternion& quat); - - NzQuaternion operator+(const NzQuaternion& quat) const; - NzQuaternion operator*(const NzQuaternion& quat) const; - NzVector3 operator*(const NzVector3& vec) const; - NzQuaternion operator*(T scale) const; - NzQuaternion operator/(const NzQuaternion& quat) const; - - NzQuaternion& operator+=(const NzQuaternion& quat); - NzQuaternion& operator*=(const NzQuaternion& quat); - NzQuaternion& operator*=(T scale); - NzQuaternion& operator/=(const NzQuaternion& quat); - - bool operator==(const NzQuaternion& quat) const; - bool operator!=(const NzQuaternion& quat) const; - bool operator<(const NzQuaternion& quat) const; - bool operator<=(const NzQuaternion& quat) const; - bool operator>(const NzQuaternion& quat) const; - bool operator>=(const NzQuaternion& quat) const; - - static NzQuaternion Identity(); - static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp); - static NzQuaternion Zero(); - - T w, x, y, z; -}; - -template std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat); - -typedef NzQuaternion NzQuaterniond; -typedef NzQuaternion NzQuaternionf; - -#include - -#endif // NAZARA_QUATERNION_HPP +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_QUATERNION_HPP +#define NAZARA_QUATERNION_HPP + +#include + +template class NzEulerAngles; +template class NzVector3; + +template class NzQuaternion +{ + public: + NzQuaternion(); + NzQuaternion(T W, T X, T Y, T Z); + NzQuaternion(T quat[4]); + NzQuaternion(T angle, const NzVector3& axis); + NzQuaternion(const NzEulerAngles& angles); + //NzQuaternion(const NzMatrix3& mat); + template explicit NzQuaternion(const NzQuaternion& quat); + NzQuaternion(const NzQuaternion& quat) = default; + ~NzQuaternion() = default; + + T DotProduct(const NzQuaternion& vec) const; + + NzQuaternion GetConjugate() const; + NzQuaternion GetInverse() const; + NzQuaternion GetNormal() const; + + void Inverse(); + + void MakeIdentity(); + void MakeZero(); + + T Magnitude() const; + + T Normalize(); + + void Set(T W, T X, T Y, T Z); + void Set(T quat[4]); + void Set(T angle, const NzVector3& normalizedAxis); + void Set(const NzEulerAngles& angles); + //void Set(const NzMatrix3& mat); + void Set(const NzQuaternion& quat); + template void Set(const NzQuaternion& quat); + + T SquaredMagnitude() const; + + NzEulerAngles ToEulerAngles() const; + //NzMatrix3 ToRotationMatrix() const; + NzString ToString() const; + + operator NzString() const; + + NzQuaternion& operator=(const NzQuaternion& quat); + + NzQuaternion operator+(const NzQuaternion& quat) const; + NzQuaternion operator*(const NzQuaternion& quat) const; + NzVector3 operator*(const NzVector3& vec) const; + NzQuaternion operator*(T scale) const; + NzQuaternion operator/(const NzQuaternion& quat) const; + + NzQuaternion& operator+=(const NzQuaternion& quat); + NzQuaternion& operator*=(const NzQuaternion& quat); + NzQuaternion& operator*=(T scale); + NzQuaternion& operator/=(const NzQuaternion& quat); + + bool operator==(const NzQuaternion& quat) const; + bool operator!=(const NzQuaternion& quat) const; + bool operator<(const NzQuaternion& quat) const; + bool operator<=(const NzQuaternion& quat) const; + bool operator>(const NzQuaternion& quat) const; + bool operator>=(const NzQuaternion& quat) const; + + static NzQuaternion Identity(); + static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp); + static NzQuaternion Zero(); + + T w, x, y, z; +}; + +template std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat); + +typedef NzQuaternion NzQuaterniond; +typedef NzQuaternion NzQuaternionf; + +#include + +#endif // NAZARA_QUATERNION_HPP diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index c17e5b026..92bf1329d 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -1,403 +1,428 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzQuaternion::NzQuaternion() -{ -} - -template -NzQuaternion::NzQuaternion(T W, T X, T Y, T Z) -{ - Set(W, X, Y, Z); -} - -template -NzQuaternion::NzQuaternion(T quat[4]) -{ - Set(quat); -} - -template -NzQuaternion::NzQuaternion(T angle, const NzVector3& axis) -{ - Set(angle, axis); -} - -template -NzQuaternion::NzQuaternion(const NzEulerAngles& angles) -{ - Set(angles); -} -/* -template -NzQuaternion::NzQuaternion(const NzMatrix3& mat) -{ - Set(mat); -} -*/ -template -template -NzQuaternion::NzQuaternion(const NzQuaternion& quat) -{ - Set(quat); -} - -template -T NzQuaternion::DotProduct(const NzQuaternion& quat) const -{ - return w*quat.w + x*quat.x + y*quat.y + z*quat.z; -} - -template -NzQuaternion NzQuaternion::GetConjugate() const -{ - return NzQuaternion(w, -x, -y, -z); -} - -template -NzQuaternion NzQuaternion::GetNormalized() const -{ - NzQuaternion quat(*this); - quat.Normalize(); - - return quat; -} - -template -void NzQuaternion::MakeIdentity() -{ - Set(1.0, 0.0, 0.0, 0.0); -} - -template -void NzQuaternion::MakeZero() -{ - Set(0.0, 0.0, 0.0, 0.0); -} - -template -T NzQuaternion::Magnitude() const -{ - return std::sqrt(SquaredMagnitude()); -} - -template -T NzQuaternion::Normalize() -{ - T squaredMagnitude = SquaredMagnitude(); - - if (squaredMagnitude-F(1.0) > std::numeric_limits::epsilon()) - { - T magnitude = std::sqrt(squaredMagnitude); - - w /= magnitude; - x /= magnitude; - y /= magnitude; - z /= magnitude; - - return magnitude; - } - else - return F(1.0); // Le quaternion est déjà normalisé -} - -template -void NzQuaternion::Set(T W, T X, T Y, T Z) -{ - w = W; - x = X; - y = Y; - z = Z; -} - -template -void NzQuaternion::Set(T quat[4]) -{ - w = quat[0]; - x = quat[1]; - y = quat[2]; - z = quat[3]; -} - -template -void NzQuaternion::Set(T angle, const NzVector3& normalizedAxis) -{ - #if !NAZARA_MATH_ANGLE_RADIAN - angle = NzDegreeToRadian(angle); - #endif - - angle /= 2; - - auto sinAngle = std::sin(angle); - - w = std::cos(angle); - x = normalizedAxis.x * sinAngle; - y = normalizedAxis.y * sinAngle; - z = normalizedAxis.z * sinAngle; -} - -template -void NzQuaternion::Set(const NzEulerAngles& angles) -{ - Set(angles.ToQuaternion()); -} - -template -template -void NzQuaternion::Set(const NzQuaternion& quat) -{ - w = static_cast(quat.w); - x = static_cast(quat.x); - y = static_cast(quat.y); - z = static_cast(quat.z); -} - -template -void NzQuaternion::Set(const NzQuaternion& quat) -{ - w = quat.w; - x = quat.x; - y = quat.y; - z = quat.z; -} - -template -T NzQuaternion::SquaredMagnitude() const -{ - return w*w + x*x + y*y + z*z; -} - -template -NzEulerAngles NzQuaternion::ToEulerAngles() const -{ - T test = x*y + z*w; - if (test > F(0.499)) - // singularity at north pole - return NzEulerAngles(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0)); - - if (test < F(-0.499)) - return NzEulerAngles(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0)); - - T xx = x*x; - T yy = y*y; - T zz = z*z; - - return NzEulerAngles(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*xx - F(2.0)*zz)), - NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*yy - F(2.0)*zz)), - NzRadians(std::asin(F(2.0)*test))); -} - -template -NzString NzQuaternion::ToString() const -{ - NzStringStream ss; - - return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')'; -} - -template -NzQuaternion::operator NzString() const -{ - return ToString(); -} - -template -NzQuaternion& NzQuaternion::operator=(const NzQuaternion& quat) -{ - Set(quat); - - return *this; -} - -template -NzQuaternion NzQuaternion::operator+(const NzQuaternion& quat) const -{ - return NzQuaternion(w + quat.w, - x + quat.x, - y + quat.y, - z + quat.z); -} - -template -NzQuaternion NzQuaternion::operator*(const NzQuaternion& quat) const -{ - return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z, - w*quat.x + x*quat.w + y*quat.z - z*quat.y, - w*quat.y + y*quat.w + z*quat.x - x*quat.z, - w*quat.z + z*quat.w + x*quat.y - y*quat.x); -} - -template -NzVector3 NzQuaternion::operator*(const NzVector3& vec) const -{ - NzVector3 normal(vec); - normal.Normalize(); - - NzQuaternion qvec(0.0, normal.x, normal.y, normal.z); - NzQuaternion result(operator*(qvec * GetConjugate())); - - return NzVector3(result.x, result.y, result.z); - -} - -template -NzQuaternion NzQuaternion::operator*(T scale) const -{ - return NzQuaternion(w * scale, - x * scale, - y * scale, - z * scale); -} - -template -NzQuaternion NzQuaternion::operator/(const NzQuaternion& quat) const -{ - return GetConjugate(quat) * (*this); -} - -template -NzQuaternion& NzQuaternion::operator+=(const NzQuaternion& quat) -{ - return operator=(operator+(quat)); -} - -template -NzQuaternion& NzQuaternion::operator*=(const NzQuaternion& quat) -{ - return operator=(operator*(quat)); -} - -template -NzQuaternion& NzQuaternion::operator*=(T scale) -{ - return operator=(operator*(scale)); -} - -template -NzQuaternion& NzQuaternion::operator/=(const NzQuaternion& quat) -{ - return operator=(operator/(quat)); -} - -template -bool NzQuaternion::operator==(const NzQuaternion& quat) const -{ - return NzNumberEquals(w, quat.w) && - NzNumberEquals(x, quat.x) && - NzNumberEquals(y, quat.y) && - NzNumberEquals(z, quat.z); -} - -template -bool NzQuaternion::operator!=(const NzQuaternion& quat) const -{ - return !operator==(quat); -} - -template -bool NzQuaternion::operator<(const NzQuaternion& quat) const -{ - return w < quat.w && x < quat.x && y < quat.y && z < quat.z; -} - -template -bool NzQuaternion::operator<=(const NzQuaternion& quat) const -{ - return operator<(quat) || operator==(quat); -} - -template -bool NzQuaternion::operator>(const NzQuaternion& quat) const -{ - return !operator<=(quat); -} - -template -bool NzQuaternion::operator>=(const NzQuaternion& quat) const -{ - return !operator<(quat); -} - -template -NzQuaternion NzQuaternion::Identity() -{ - NzQuaternion quaternion; - quaternion.MakeIdentity(); - - return quaternion; -} - -template -NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp) -{ - if (interp <= F(0.0)) - return quatA; - - if (interp >= F(1.0)) - return quatB; - - NzQuaternion q; - - T cosOmega = quatA.DotProduct(quatB); - if (cosOmega < F(0.0)) - { - // On inverse tout - q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z); - cosOmega = -cosOmega; - } - else - q.Set(quatB); - - T k0, k1; - if (cosOmega > F(0.9999)) - { - // Interpolation linéaire pour éviter une division par zéro - k0 = F(1.0) - interp; - k1 = interp; - } - else - { - T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); - T omega = std::atan2(sinOmega, cosOmega); - - // Pour éviter deux divisions - sinOmega = F(1.0)/sinOmega; - - k0 = std::sin((F(1.0) - interp) * omega) * sinOmega; - k1 = std::sin(interp*omega) * sinOmega; - } - - NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z); - return result += q*k1; -} - -template -NzQuaternion NzQuaternion::Zero() -{ - NzQuaternion quaternion; - quaternion.MakeZero(); - - return quaternion; -} - -template -std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat) -{ - return out << quat.ToString(); -} - -#undef F - -#include +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzQuaternion::NzQuaternion() +{ +} + +template +NzQuaternion::NzQuaternion(T W, T X, T Y, T Z) +{ + Set(W, X, Y, Z); +} + +template +NzQuaternion::NzQuaternion(T quat[4]) +{ + Set(quat); +} + +template +NzQuaternion::NzQuaternion(T angle, const NzVector3& axis) +{ + Set(angle, axis); +} + +template +NzQuaternion::NzQuaternion(const NzEulerAngles& angles) +{ + Set(angles); +} +/* +template +NzQuaternion::NzQuaternion(const NzMatrix3& mat) +{ + Set(mat); +} +*/ +template +template +NzQuaternion::NzQuaternion(const NzQuaternion& quat) +{ + Set(quat); +} + +template +T NzQuaternion::DotProduct(const NzQuaternion& quat) const +{ + return w*quat.w + x*quat.x + y*quat.y + z*quat.z; +} + +template +NzQuaternion NzQuaternion::GetConjugate() const +{ + return NzQuaternion(w, -x, -y, -z); +} + +template +NzQuaternion NzQuaternion::GetInverse() const +{ + NzQuaternion quat(*this); + quat.Inverse(); + + return quat; +} + +template +NzQuaternion NzQuaternion::GetNormal() const +{ + NzQuaternion quat(*this); + quat.Normalize(); + + return quat; +} + +template +void NzQuaternion::Inverse() +{ + T norm = SquaredMagnitude(); + if (norm > F(0.0)) + { + T invNorm = F(1.0) / norm; + + w *= invNorm; + x *= -invNorm; + y *= -invNorm; + z *= -invNorm; + } +} + +template +void NzQuaternion::MakeIdentity() +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0)); +} + +template +void NzQuaternion::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0)); +} + +template +T NzQuaternion::Magnitude() const +{ + return std::sqrt(SquaredMagnitude()); +} + +template +T NzQuaternion::Normalize() +{ + T squaredMagnitude = SquaredMagnitude(); + + // Inutile de vérifier si la magnitude au carrée est négative (Elle ne peut pas l'être) + if (!NzNumberEquals(squaredMagnitude, F(1.0))) + { + T norm = std::sqrt(squaredMagnitude); + T invNorm = F(1.0) / norm; + + w *= invNorm; + x *= invNorm; + y *= invNorm; + z *= invNorm; + + return norm; + } + else + return F(1.0); // Le quaternion est déjà normalisé +} + +template +void NzQuaternion::Set(T W, T X, T Y, T Z) +{ + w = W; + x = X; + y = Y; + z = Z; +} + +template +void NzQuaternion::Set(T quat[4]) +{ + w = quat[0]; + x = quat[1]; + y = quat[2]; + z = quat[3]; +} + +template +void NzQuaternion::Set(T angle, const NzVector3& axis) +{ + angle /= F(2.0); + + #if !NAZARA_MATH_ANGLE_RADIAN + angle = NzDegreeToRadian(angle); + #endif + + NzVector3 normalizedAxis = axis.GetNormal(); + + T sinAngle = std::sin(angle); + + w = std::cos(angle); + x = normalizedAxis.x * sinAngle; + y = normalizedAxis.y * sinAngle; + z = normalizedAxis.z * sinAngle; + + Normalize(); +} + +template +void NzQuaternion::Set(const NzEulerAngles& angles) +{ + Set(angles.ToQuaternion()); +} + +template +template +void NzQuaternion::Set(const NzQuaternion& quat) +{ + w = static_cast(quat.w); + x = static_cast(quat.x); + y = static_cast(quat.y); + z = static_cast(quat.z); +} + +template +void NzQuaternion::Set(const NzQuaternion& quat) +{ + w = quat.w; + x = quat.x; + y = quat.y; + z = quat.z; +} + +template +T NzQuaternion::SquaredMagnitude() const +{ + return w*w + x*x + y*y + z*z; +} + +template +NzEulerAngles NzQuaternion::ToEulerAngles() const +{ + T test = x*y + z*w; + if (test > F(0.499)) + // singularity at north pole + return NzEulerAngles(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0)); + + if (test < F(-0.499)) + return NzEulerAngles(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0)); + + return NzEulerAngles(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*x* - F(2.0)*z*z)), + NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*y*y - F(2.0)*z*z)), + NzRadians(std::asin(F(2.0)*test))); +} + +template +NzString NzQuaternion::ToString() const +{ + NzStringStream ss; + + return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')'; +} + +template +NzQuaternion::operator NzString() const +{ + return ToString(); +} + +template +NzQuaternion& NzQuaternion::operator=(const NzQuaternion& quat) +{ + Set(quat); + + return *this; +} + +template +NzQuaternion NzQuaternion::operator+(const NzQuaternion& quat) const +{ + return NzQuaternion(w + quat.w, + x + quat.x, + y + quat.y, + z + quat.z); +} + +template +NzQuaternion NzQuaternion::operator*(const NzQuaternion& quat) const +{ + return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z, + w*quat.x + x*quat.w + y*quat.z - z*quat.y, + w*quat.y + y*quat.w + z*quat.x - x*quat.z, + w*quat.z + z*quat.w + x*quat.y - y*quat.x); +} + +template +NzVector3 NzQuaternion::operator*(const NzVector3& vec) const +{ + NzVector3f quatVec(x, y, z); + NzVector3f uv = quatVec.CrossProduct(vec); + NzVector3f uuv = quatVec.CrossProduct(uv); + uv *= F(2.0) * w; + uuv *= F(2.0); + + return vec + uv + uuv; +} + +template +NzQuaternion NzQuaternion::operator*(T scale) const +{ + return NzQuaternion(w * scale, + x * scale, + y * scale, + z * scale); +} + +template +NzQuaternion NzQuaternion::operator/(const NzQuaternion& quat) const +{ + return GetConjugate(quat) * (*this); +} + +template +NzQuaternion& NzQuaternion::operator+=(const NzQuaternion& quat) +{ + return operator=(operator+(quat)); +} + +template +NzQuaternion& NzQuaternion::operator*=(const NzQuaternion& quat) +{ + return operator=(operator*(quat)); +} + +template +NzQuaternion& NzQuaternion::operator*=(T scale) +{ + return operator=(operator*(scale)); +} + +template +NzQuaternion& NzQuaternion::operator/=(const NzQuaternion& quat) +{ + return operator=(operator/(quat)); +} + +template +bool NzQuaternion::operator==(const NzQuaternion& quat) const +{ + return NzNumberEquals(w, quat.w) && + NzNumberEquals(x, quat.x) && + NzNumberEquals(y, quat.y) && + NzNumberEquals(z, quat.z); +} + +template +bool NzQuaternion::operator!=(const NzQuaternion& quat) const +{ + return !operator==(quat); +} + +template +bool NzQuaternion::operator<(const NzQuaternion& quat) const +{ + return w < quat.w && x < quat.x && y < quat.y && z < quat.z; +} + +template +bool NzQuaternion::operator<=(const NzQuaternion& quat) const +{ + return operator<(quat) || operator==(quat); +} + +template +bool NzQuaternion::operator>(const NzQuaternion& quat) const +{ + return !operator<=(quat); +} + +template +bool NzQuaternion::operator>=(const NzQuaternion& quat) const +{ + return !operator<(quat); +} + +template +NzQuaternion NzQuaternion::Identity() +{ + NzQuaternion quaternion; + quaternion.MakeIdentity(); + + return quaternion; +} + +template +NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp) +{ + if (interp <= F(0.0)) + return quatA; + + if (interp >= F(1.0)) + return quatB; + + NzQuaternion q; + + T cosOmega = quatA.DotProduct(quatB); + if (cosOmega < F(0.0)) + { + // On inverse tout + q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z); + cosOmega = -cosOmega; + } + else + q.Set(quatB); + + T k0, k1; + if (cosOmega > F(0.9999)) + { + // Interpolation linéaire pour éviter une division par zéro + k0 = F(1.0) - interp; + k1 = interp; + } + else + { + T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); + T omega = std::atan2(sinOmega, cosOmega); + + // Pour éviter deux divisions + sinOmega = F(1.0)/sinOmega; + + k0 = std::sin((F(1.0) - interp) * omega) * sinOmega; + k1 = std::sin(interp*omega) * sinOmega; + } + + NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z); + return result += q*k1; +} + +template +NzQuaternion NzQuaternion::Zero() +{ + NzQuaternion quaternion; + quaternion.MakeZero(); + + return quaternion; +} + +template +std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat) +{ + return out << quat.ToString(); +} + +#undef F + +#include diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 4f02ae77e..9d24dbc69 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -1,104 +1,105 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_VECTOR2_HPP -#define NAZARA_VECTOR2_HPP - -#include - -template class NzVector2 -{ - public: - NzVector2(); - NzVector2(T X, T Y); - explicit NzVector2(T scale); - NzVector2(T vec[2]); - template explicit NzVector2(const NzVector2& vec); - NzVector2(const NzVector2& vec) = default; - ~NzVector2() = default; - - T AbsDotProduct(const NzVector2& vec) const; - - T Distance(const NzVector2& vec) const; - float Distancef(const NzVector2& vec) const; - - T DotProduct(const NzVector2& vec) const; - - NzVector2 GetNormal() const; - - void MakeCeil(const NzVector2& vec); - void MakeFloor(const NzVector2& vec); - void MakeUnitX(); - void MakeUnitY(); - void MakeZero(); - - T Length() const; - float Lengthf() const; - - void Normalize(); - - void Set(T X, T Y); - void Set(T scale); - void Set(T vec[2]); - template void Set(const NzVector2& vec); - - T SquaredDistance(const NzVector2& vec) const; - T SquaredLength() const; - - NzString ToString() const; - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - const NzVector2& operator+() const; - NzVector2 operator-() const; - - NzVector2 operator+(const NzVector2& vec) const; - NzVector2 operator-(const NzVector2& vec) const; - NzVector2 operator*(const NzVector2& vec) const; - NzVector2 operator*(T scale) const; - NzVector2 operator/(const NzVector2& vec) const; - NzVector2 operator/(T scale) const; - - NzVector2& operator+=(const NzVector2& vec); - NzVector2& operator-=(const NzVector2& vec); - NzVector2& operator*=(const NzVector2& vec); - NzVector2& operator*=(T scale); - NzVector2& operator/=(const NzVector2& vec); - NzVector2& operator/=(T scale); - - bool operator==(const NzVector2& vec) const; - bool operator!=(const NzVector2& vec) const; - bool operator<(const NzVector2& vec) const; - bool operator<=(const NzVector2& vec) const; - bool operator>(const NzVector2& vec) const; - bool operator>=(const NzVector2& vec) const; - - static NzVector2 UnitX(); - static NzVector2 UnitY(); - static NzVector2 Zero(); - - T x, y; -}; - -template std::ostream& operator<<(std::ostream& out, const NzVector2& vec); - -template NzVector2 operator*(T scale, const NzVector2& vec); -template NzVector2 operator/(T scale, const NzVector2& vec); - -typedef NzVector2 NzVector2d; -typedef NzVector2 NzVector2f; -typedef NzVector2 NzVector2i; -typedef NzVector2 NzVector2ui; - -#include - -#endif // NAZARA_VECTOR2_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VECTOR2_HPP +#define NAZARA_VECTOR2_HPP + +#include + +template class NzVector2 +{ + public: + NzVector2(); + NzVector2(T X, T Y); + explicit NzVector2(T scale); + NzVector2(T vec[2]); + template explicit NzVector2(const NzVector2& vec); + NzVector2(const NzVector2& vec) = default; + ~NzVector2() = default; + + T AbsDotProduct(const NzVector2& vec) const; + + T Distance(const NzVector2& vec) const; + float Distancef(const NzVector2& vec) const; + + T DotProduct(const NzVector2& vec) const; + + NzVector2 GetNormal() const; + + T Length() const; + float Lengthf() const; + + void MakeUnitX(); + void MakeUnitY(); + void MakeZero(); + + void Maximize(const NzVector2& vec); + void Minimize(const NzVector2& vec); + + void Normalize(); + + void Set(T X, T Y); + void Set(T scale); + void Set(T vec[2]); + template void Set(const NzVector2& vec); + + T SquaredDistance(const NzVector2& vec) const; + T SquaredLength() const; + + NzString ToString() const; + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + const NzVector2& operator+() const; + NzVector2 operator-() const; + + NzVector2 operator+(const NzVector2& vec) const; + NzVector2 operator-(const NzVector2& vec) const; + NzVector2 operator*(const NzVector2& vec) const; + NzVector2 operator*(T scale) const; + NzVector2 operator/(const NzVector2& vec) const; + NzVector2 operator/(T scale) const; + + NzVector2& operator+=(const NzVector2& vec); + NzVector2& operator-=(const NzVector2& vec); + NzVector2& operator*=(const NzVector2& vec); + NzVector2& operator*=(T scale); + NzVector2& operator/=(const NzVector2& vec); + NzVector2& operator/=(T scale); + + bool operator==(const NzVector2& vec) const; + bool operator!=(const NzVector2& vec) const; + bool operator<(const NzVector2& vec) const; + bool operator<=(const NzVector2& vec) const; + bool operator>(const NzVector2& vec) const; + bool operator>=(const NzVector2& vec) const; + + static NzVector2 UnitX(); + static NzVector2 UnitY(); + static NzVector2 Zero(); + + T x, y; +}; + +template std::ostream& operator<<(std::ostream& out, const NzVector2& vec); + +template NzVector2 operator*(T scale, const NzVector2& vec); +template NzVector2 operator/(T scale, const NzVector2& vec); + +typedef NzVector2 NzVector2d; +typedef NzVector2 NzVector2f; +typedef NzVector2 NzVector2i; +typedef NzVector2 NzVector2ui; + +#include + +#endif // NAZARA_VECTOR2_HPP diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index f1a716f7b..1c4639a52 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -1,488 +1,488 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzVector2::NzVector2() -{ -} - -template -NzVector2::NzVector2(T X, T Y) -{ - Set(X, Y); -} - -template -NzVector2::NzVector2(T scale) -{ - Set(scale); -} - -template -NzVector2::NzVector2(T vec[2]) -{ - Set(vec); -} - -template -template -NzVector2::NzVector2(const NzVector2& vec) -{ - Set(vec); -} - -template -T NzVector2::AbsDotProduct(const NzVector2& vec) const -{ - return std::fabs(x * vec.x) + std::fabs(y * vec.y); -} - -template<> -inline int NzVector2::AbsDotProduct(const NzVector2& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y); -} - -template<> -inline unsigned int NzVector2::AbsDotProduct(const NzVector2& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y); -} - -template -T NzVector2::Distance(const NzVector2& vec) const -{ - return std::sqrt(SquaredDistance(vec)); -} - -template -float NzVector2::Distancef(const NzVector2& vec) const -{ - return std::sqrt(static_cast(SquaredDistance(vec))); -} - -template -T NzVector2::DotProduct(const NzVector2& vec) const -{ - return x*vec.x + y*vec.y; -} - -template -NzVector2 NzVector2::GetNormal() const -{ - NzVector2 vec(*this); - vec.Normalize(); - - return vec; -} - -template -T NzVector2::Length() const -{ - return std::sqrt(SquaredLength()); -} - -template -float NzVector2::Lengthf() const -{ - return std::sqrt(static_cast(SquaredLength())); -} - -template -void NzVector2::MakeCeil(const NzVector2& vec) -{ - if (vec.x > x) - x = vec.x; - - if (vec.y > y) - y = vec.y; -} - -template -void NzVector2::MakeFloor(const NzVector2& vec) -{ - if (vec.x < x) - x = vec.x; - - if (vec.y < y) - y = vec.y; -} - -template -void NzVector2::MakeUnitX() -{ - Set(F(1.0), F(0.0)); -} - -template -void NzVector2::MakeUnitY() -{ - Set(F(0.0), F(1.0)); -} - -template -void NzVector2::MakeZero() -{ - Set(F(0.0), F(0.0)); -} - -template -void NzVector2::Normalize() -{ - T squaredLength = SquaredLength(); - - if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) - { - T length = std::sqrt(squaredLength); - - x /= length; - y /= length; - } -} - -template -void NzVector2::Set(T X, T Y) -{ - x = X; - y = Y; -} - -template -void NzVector2::Set(T scale) -{ - x = scale; - y = scale; -} - -template -void NzVector2::Set(T vec[2]) -{ - std::memcpy(&x, vec, 2*sizeof(T)); -} - -template -template -void NzVector2::Set(const NzVector2& vec) -{ - x = F(vec.x); - y = F(vec.y); -} - -template -T NzVector2::SquaredDistance(const NzVector2& vec) const -{ - return operator-(vec).SquaredLength(); -} - -template -T NzVector2::SquaredLength() const -{ - return x*x + y*y; -} - -template -NzString NzVector2::ToString() const -{ - NzStringStream ss; - - return ss << "Vector2(" << x << ", " << y << ')'; -} - -template -NzVector2::operator NzString() const -{ - return ToString(); -} - -template -NzVector2::operator T*() -{ - return &x; -} - -template -NzVector2::operator const T*() const -{ - return &x; -} - -template -T& NzVector2::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 2) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector2::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 2) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -const NzVector2& NzVector2::operator+() const -{ - return *this; -} - -template -NzVector2 NzVector2::operator-() const -{ - return NzVector2(-x, -y); -} - -template -NzVector2 NzVector2::operator+(const NzVector2& vec) const -{ - return NzVector2(x + vec.x, y + vec.y); -} - -template -NzVector2 NzVector2::operator-(const NzVector2& vec) const -{ - return NzVector2(x - vec.x, y - vec.y); -} - -template -NzVector2 NzVector2::operator*(const NzVector2& vec) const -{ - return NzVector2(x * vec.x, y * vec.y); -} - -template -NzVector2 NzVector2::operator*(T scale) const -{ - return NzVector2(x * scale, y * scale); -} - -template -NzVector2 NzVector2::operator/(const NzVector2& vec) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector2(x / vec.x, y / vec.y); -} - -template -NzVector2 NzVector2::operator/(T scale) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector2(x / scale, y / scale); -} - -template -NzVector2& NzVector2::operator+=(const NzVector2& vec) -{ - x += vec.x; - y += vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator-=(const NzVector2& vec) -{ - x -= vec.x; - y -= vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator*=(const NzVector2& vec) -{ - x *= vec.x; - y *= vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator*=(T scale) -{ - x *= scale; - y *= scale; - - return *this; -} - -template -NzVector2& NzVector2::operator/=(const NzVector2& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= vec.x; - y /= vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator/=(T scale) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= scale; - y /= scale; - - return *this; -} - -template -bool NzVector2::operator==(const NzVector2& vec) const -{ - return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y); -} - -template -bool NzVector2::operator!=(const NzVector2& vec) const -{ - return !operator==(vec); -} - -template -bool NzVector2::operator<(const NzVector2& vec) const -{ - return x < vec.x && y < vec.y; -} - -template -bool NzVector2::operator<=(const NzVector2& vec) const -{ - return operator<(vec) || operator==(vec); -} - -template -bool NzVector2::operator>(const NzVector2& vec) const -{ - return !operator<=(vec); -} - -template -bool NzVector2::operator>=(const NzVector2& vec) const -{ - return !operator<(vec); -} - -template -NzVector2 NzVector2::UnitX() -{ - NzVector2 vector; - vector.MakeUnitX(); - - return vector; -} - -template -NzVector2 NzVector2::UnitY() -{ - NzVector2 vector; - vector.MakeUnitY(); - - return vector; -} - -template -NzVector2 NzVector2::Zero() -{ - NzVector2 vector; - vector.MakeZero(); - - return vector; -} - -template -std::ostream& operator<<(std::ostream& out, const NzVector2& vec) -{ - return out << vec.ToString(); -} - -template -NzVector2 operator*(T scale, const NzVector2& vec) -{ - return NzVector2(scale * vec.x, scale * vec.y); -} - -template -NzVector2 operator/(T scale, const NzVector2& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector2(scale/vec.x, scale/vec.y); -} - -#undef F - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzVector2::NzVector2() +{ +} + +template +NzVector2::NzVector2(T X, T Y) +{ + Set(X, Y); +} + +template +NzVector2::NzVector2(T scale) +{ + Set(scale); +} + +template +NzVector2::NzVector2(T vec[2]) +{ + Set(vec); +} + +template +template +NzVector2::NzVector2(const NzVector2& vec) +{ + Set(vec); +} + +template +T NzVector2::AbsDotProduct(const NzVector2& vec) const +{ + return std::fabs(x * vec.x) + std::fabs(y * vec.y); +} + +template<> +inline int NzVector2::AbsDotProduct(const NzVector2& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y); +} + +template<> +inline unsigned int NzVector2::AbsDotProduct(const NzVector2& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y); +} + +template +T NzVector2::Distance(const NzVector2& vec) const +{ + return std::sqrt(SquaredDistance(vec)); +} + +template +float NzVector2::Distancef(const NzVector2& vec) const +{ + return std::sqrt(static_cast(SquaredDistance(vec))); +} + +template +T NzVector2::DotProduct(const NzVector2& vec) const +{ + return x*vec.x + y*vec.y; +} + +template +NzVector2 NzVector2::GetNormal() const +{ + NzVector2 vec(*this); + vec.Normalize(); + + return vec; +} + +template +T NzVector2::Length() const +{ + return std::sqrt(SquaredLength()); +} + +template +float NzVector2::Lengthf() const +{ + return std::sqrt(static_cast(SquaredLength())); +} + +template +void NzVector2::MakeUnitX() +{ + Set(F(1.0), F(0.0)); +} + +template +void NzVector2::MakeUnitY() +{ + Set(F(0.0), F(1.0)); +} + +template +void NzVector2::MakeZero() +{ + Set(F(0.0), F(0.0)); +} + +template +void NzVector2::Maximize(const NzVector2& vec) +{ + if (vec.x > x) + x = vec.x; + + if (vec.y > y) + y = vec.y; +} + +template +void NzVector2::Minimize(const NzVector2& vec) +{ + if (vec.x < x) + x = vec.x; + + if (vec.y < y) + y = vec.y; +} + +template +void NzVector2::Normalize() +{ + T squaredLength = SquaredLength(); + + if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) + { + T length = std::sqrt(squaredLength); + + x /= length; + y /= length; + } +} + +template +void NzVector2::Set(T X, T Y) +{ + x = X; + y = Y; +} + +template +void NzVector2::Set(T scale) +{ + x = scale; + y = scale; +} + +template +void NzVector2::Set(T vec[2]) +{ + std::memcpy(&x, vec, 2*sizeof(T)); +} + +template +template +void NzVector2::Set(const NzVector2& vec) +{ + x = F(vec.x); + y = F(vec.y); +} + +template +T NzVector2::SquaredDistance(const NzVector2& vec) const +{ + return operator-(vec).SquaredLength(); +} + +template +T NzVector2::SquaredLength() const +{ + return x*x + y*y; +} + +template +NzString NzVector2::ToString() const +{ + NzStringStream ss; + + return ss << "Vector2(" << x << ", " << y << ')'; +} + +template +NzVector2::operator NzString() const +{ + return ToString(); +} + +template +NzVector2::operator T*() +{ + return &x; +} + +template +NzVector2::operator const T*() const +{ + return &x; +} + +template +T& NzVector2::operator[](unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i >= 2) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +T NzVector2::operator[](unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i >= 2) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +const NzVector2& NzVector2::operator+() const +{ + return *this; +} + +template +NzVector2 NzVector2::operator-() const +{ + return NzVector2(-x, -y); +} + +template +NzVector2 NzVector2::operator+(const NzVector2& vec) const +{ + return NzVector2(x + vec.x, y + vec.y); +} + +template +NzVector2 NzVector2::operator-(const NzVector2& vec) const +{ + return NzVector2(x - vec.x, y - vec.y); +} + +template +NzVector2 NzVector2::operator*(const NzVector2& vec) const +{ + return NzVector2(x * vec.x, y * vec.y); +} + +template +NzVector2 NzVector2::operator*(T scale) const +{ + return NzVector2(x * scale, y * scale); +} + +template +NzVector2 NzVector2::operator/(const NzVector2& vec) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector2(x / vec.x, y / vec.y); +} + +template +NzVector2 NzVector2::operator/(T scale) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector2(x / scale, y / scale); +} + +template +NzVector2& NzVector2::operator+=(const NzVector2& vec) +{ + x += vec.x; + y += vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator-=(const NzVector2& vec) +{ + x -= vec.x; + y -= vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator*=(const NzVector2& vec) +{ + x *= vec.x; + y *= vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator*=(T scale) +{ + x *= scale; + y *= scale; + + return *this; +} + +template +NzVector2& NzVector2::operator/=(const NzVector2& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= vec.x; + y /= vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator/=(T scale) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= scale; + y /= scale; + + return *this; +} + +template +bool NzVector2::operator==(const NzVector2& vec) const +{ + return NzNumberEquals(x, vec.x) && + NzNumberEquals(y, vec.y); +} + +template +bool NzVector2::operator!=(const NzVector2& vec) const +{ + return !operator==(vec); +} + +template +bool NzVector2::operator<(const NzVector2& vec) const +{ + return x < vec.x && y < vec.y; +} + +template +bool NzVector2::operator<=(const NzVector2& vec) const +{ + return operator<(vec) || operator==(vec); +} + +template +bool NzVector2::operator>(const NzVector2& vec) const +{ + return !operator<=(vec); +} + +template +bool NzVector2::operator>=(const NzVector2& vec) const +{ + return !operator<(vec); +} + +template +NzVector2 NzVector2::UnitX() +{ + NzVector2 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector2 NzVector2::UnitY() +{ + NzVector2 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector2 NzVector2::Zero() +{ + NzVector2 vector; + vector.MakeZero(); + + return vector; +} + +template +std::ostream& operator<<(std::ostream& out, const NzVector2& vec) +{ + return out << vec.ToString(); +} + +template +NzVector2 operator*(T scale, const NzVector2& vec) +{ + return NzVector2(scale * vec.x, scale * vec.y); +} + +template +NzVector2 operator/(T scale, const NzVector2& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector2(scale/vec.x, scale/vec.y); +} + +#undef F + +#include diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index b501fee58..8734bed41 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -1,111 +1,121 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_VECTOR3_HPP -#define NAZARA_VECTOR3_HPP - -#include -#include - -template class NzVector3 -{ - public: - NzVector3(); - NzVector3(T X, T Y, T Z); - explicit NzVector3(T scale); - NzVector3(T vec[3]); - NzVector3(const NzVector2& vec, T Z = 0.0); - template explicit NzVector3(const NzVector3& vec); - NzVector3(const NzVector3& vec) = default; - ~NzVector3() = default; - - T AbsDotProduct(const NzVector3& vec) const; - - NzVector3 CrossProduct(const NzVector3& vec) const; - - T Distance(const NzVector3& vec) const; - float Distancef(const NzVector3& vec) const; - - T DotProduct(const NzVector3& vec) const; - - NzVector3 GetNormal() const; - - T Length() const; - float Lengthf() const; - - void MakeCeil(const NzVector3& vec); - void MakeFloor(const NzVector3& vec); - void MakeUnitX(); - void MakeUnitY(); - void MakeUnitZ(); - void MakeZero(); - - void Normalize(); - - void Set(T X, T Y, T Z); - void Set(T scale); - void Set(T vec[3]); - void Set(const NzVector2& vec, T Z = 0.0); - template void Set(const NzVector3& vec); - - T SquaredDistance(const NzVector3& vec) const; - T SquaredLength() const; - - NzString ToString() const; - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - const NzVector3& operator+() const; - NzVector3 operator-() const; - - NzVector3 operator+(const NzVector3& vec) const; - NzVector3 operator-(const NzVector3& vec) const; - NzVector3 operator*(const NzVector3& vec) const; - NzVector3 operator*(T scale) const; - NzVector3 operator/(const NzVector3& vec) const; - NzVector3 operator/(T scale) const; - - NzVector3& operator+=(const NzVector3& vec); - NzVector3& operator-=(const NzVector3& vec); - NzVector3& operator*=(const NzVector3& vec); - NzVector3& operator*=(T scale); - NzVector3& operator/=(const NzVector3& vec); - NzVector3& operator/=(T scale); - - bool operator==(const NzVector3& vec) const; - bool operator!=(const NzVector3& vec) const; - bool operator<(const NzVector3& vec) const; - bool operator<=(const NzVector3& vec) const; - bool operator>(const NzVector3& vec) const; - bool operator>=(const NzVector3& vec) const; - - static NzVector3 UnitX(); - static NzVector3 UnitY(); - static NzVector3 UnitZ(); - static NzVector3 Zero(); - - T x, y, z; -}; - -template std::ostream& operator<<(std::ostream& out, const NzVector3& vec); - -template NzVector3 operator*(T scale, const NzVector3& vec); -template NzVector3 operator/(T scale, const NzVector3& vec); - -typedef NzVector3 NzVector3d; -typedef NzVector3 NzVector3f; -typedef NzVector3 NzVector3i; -typedef NzVector3 NzVector3ui; - -#include - -#endif // NAZARA_VECTOR3_HPP +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VECTOR3_HPP +#define NAZARA_VECTOR3_HPP + +#include +#include + +template class NzVector3 +{ + public: + NzVector3(); + NzVector3(T X, T Y, T Z); + explicit NzVector3(T scale); + NzVector3(T vec[3]); + NzVector3(const NzVector2& vec, T Z = 0.0); + template explicit NzVector3(const NzVector3& vec); + NzVector3(const NzVector3& vec) = default; + ~NzVector3() = default; + + T AbsDotProduct(const NzVector3& vec) const; + + NzVector3 CrossProduct(const NzVector3& vec) const; + + T Distance(const NzVector3& vec) const; + float Distancef(const NzVector3& vec) const; + + T DotProduct(const NzVector3& vec) const; + + NzVector3 GetNormal() const; + + T Length() const; + float Lengthf() const; + + void MakeForward(); + void MakeLeft(); + void MakeUnitX(); + void MakeUnitY(); + void MakeUnitZ(); + void MakeUp(); + void MakeZero(); + + void Maximize(const NzVector3& vec); + void Minimize(const NzVector3& vec); + + void Normalize(); + + void Set(T X, T Y, T Z); + void Set(T scale); + void Set(T vec[3]); + void Set(const NzVector2& vec, T Z = 0.0); + template void Set(const NzVector3& vec); + + T SquaredDistance(const NzVector3& vec) const; + T SquaredLength() const; + + NzString ToString() const; + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + const NzVector3& operator+() const; + NzVector3 operator-() const; + + NzVector3 operator+(const NzVector3& vec) const; + NzVector3 operator-(const NzVector3& vec) const; + NzVector3 operator*(const NzVector3& vec) const; + NzVector3 operator*(T scale) const; + NzVector3 operator/(const NzVector3& vec) const; + NzVector3 operator/(T scale) const; + + NzVector3& operator+=(const NzVector3& vec); + NzVector3& operator-=(const NzVector3& vec); + NzVector3& operator*=(const NzVector3& vec); + NzVector3& operator*=(T scale); + NzVector3& operator/=(const NzVector3& vec); + NzVector3& operator/=(T scale); + + bool operator==(const NzVector3& vec) const; + bool operator!=(const NzVector3& vec) const; + bool operator<(const NzVector3& vec) const; + bool operator<=(const NzVector3& vec) const; + bool operator>(const NzVector3& vec) const; + bool operator>=(const NzVector3& vec) const; + + static NzVector3 CrossProduct(const NzVector3& vec1, const NzVector3& vec2); + static T DotProduct(const NzVector3& vec1, const NzVector3& vec2); + static NzVector3 Forward(); + static NzVector3 Left(); + static NzVector3 Normalize(const NzVector3& vec); + static NzVector3 UnitX(); + static NzVector3 UnitY(); + static NzVector3 UnitZ(); + static NzVector3 Up(); + static NzVector3 Zero(); + + T x, y, z; +}; + +template std::ostream& operator<<(std::ostream& out, const NzVector3& vec); + +template NzVector3 operator*(T scale, const NzVector3& vec); +template NzVector3 operator/(T scale, const NzVector3& vec); + +typedef NzVector3 NzVector3d; +typedef NzVector3 NzVector3f; +typedef NzVector3 NzVector3i; +typedef NzVector3 NzVector3ui; + +#include + +#endif // NAZARA_VECTOR3_HPP diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 671b3898e..294aceaac 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -1,536 +1,599 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzVector3::NzVector3() -{ -} - -template -NzVector3::NzVector3(T X, T Y, T Z) -{ - Set(X, Y, Z); -} - -template -NzVector3::NzVector3(T scale) -{ - Set(scale); -} - -template -NzVector3::NzVector3(T vec[3]) -{ - Set(vec); -} - -template -NzVector3::NzVector3(const NzVector2& vec, T Z) -{ - Set(vec, Z); -} - -template -template -NzVector3::NzVector3(const NzVector3& vec) -{ - Set(vec); -} - -template -T NzVector3::AbsDotProduct(const NzVector3& vec) const -{ - return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z); -} - -template<> -inline int NzVector3::AbsDotProduct(const NzVector3& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); -} - -template<> -inline unsigned int NzVector3::AbsDotProduct(const NzVector3& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); -} - -template -NzVector3 NzVector3::CrossProduct(const NzVector3& vec) const -{ - return NzVector3(y * vec.z - z * vec.y, z * vec.x - x * vec.y, x * vec.y - y * vec.x); -} - -template -T NzVector3::Distance(const NzVector3& vec) const -{ - return std::sqrt(SquaredDistance(vec)); -} - -template -float NzVector3::Distancef(const NzVector3& vec) const -{ - return std::sqrt(static_cast(SquaredDistance())); -} - -template -T NzVector3::DotProduct(const NzVector3& vec) const -{ - return x*vec.x + y*vec.y + z*vec.z; -} - -template -NzVector3 NzVector3::GetNormal() const -{ - NzVector3 vec(*this); - vec.Normalize(); - - return vec; -} - -template -void NzVector3::MakeCeil(const NzVector3& vec) -{ - if (vec.x > x) - x = vec.x; - - if (vec.y > y) - y = vec.y; - - if (vec.z > z) - z = vec.z; -} - -template -void NzVector3::MakeFloor(const NzVector3& vec) -{ - if (vec.x < x) - x = vec.x; - - if (vec.y < y) - y = vec.y; - - if (vec.z < z) - z = vec.z; -} - -template -void NzVector3::MakeUnitX() -{ - Set(F(1.0), F(0.0), F(0.0)); -} - -template -void NzVector3::MakeUnitY() -{ - Set(F(0.0), F(1.0), F(0.0)); -} - -template -void NzVector3::MakeUnitZ() -{ - Set(F(0.0), F(0.0), F(1.0)); -} - -template -void NzVector3::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0)); -} - -template -T NzVector3::Length() const -{ - return std::sqrt(SquaredLength()); -} - -template -float NzVector3::Lengthf() const -{ - return std::sqrt(static_cast(SquaredLength())); -} - -template -void NzVector3::Normalize() -{ - T squaredLength = SquaredLength(); - - if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) - { - T length = std::sqrt(squaredLength); - - x /= length; - y /= length; - z /= length; - } -} - -template -void NzVector3::Set(T X, T Y, T Z) -{ - x = X; - y = Y; - z = Z; -} - -template -void NzVector3::Set(T scale) -{ - x = scale; - y = scale; - z = scale; -} - -template -void NzVector3::Set(T vec[3]) -{ - std::memcpy(&x, vec, 3*sizeof(T)); -} - -template -void NzVector3::Set(const NzVector2& vec, T Z) -{ - x = vec.x; - y = vec.y; - z = Z; -} - -template -template -void NzVector3::Set(const NzVector3& vec) -{ - x = F(vec.x); - y = F(vec.y); - z = F(vec.z); -} - -template -T NzVector3::SquaredDistance(const NzVector3& vec) const -{ - return operator-(vec).SquaredLength(); -} - -template -T NzVector3::SquaredLength() const -{ - return x*x + y*y + z*z; -} - -template -NzString NzVector3::ToString() const -{ - NzStringStream ss; - - return ss << "Vector3(" << x << ", " << y << ", " << z <<')'; -} - -template -NzVector3::operator NzString() const -{ - return ToString(); -} - -template -NzVector3::operator T*() -{ - return &x; -} - -template -NzVector3::operator const T*() const -{ - return &x; -} - -template -T& NzVector3::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector3::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -const NzVector3& NzVector3::operator+() const -{ - return *this; -} - -template -NzVector3 NzVector3::operator-() const -{ - return NzVector3(-x, -y, -z); -} - -template -NzVector3 NzVector3::operator+(const NzVector3& vec) const -{ - return NzVector3(x + vec.x, y + vec.y, z + vec.z); -} - -template -NzVector3 NzVector3::operator-(const NzVector3& vec) const -{ - return NzVector3(x - vec.x, y - vec.y, z - vec.z); -} - -template -NzVector3 NzVector3::operator*(const NzVector3& vec) const -{ - return NzVector3(x * vec.x, y * vec.y, z * vec.z); -} - -template -NzVector3 NzVector3::operator*(T scale) const -{ - return NzVector3(x * scale, y * scale, z * scale); -} - -template -NzVector3 NzVector3::operator/(const NzVector3& vec) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector3(x / vec.x, y / vec.y, z / vec.z); -} - -template -NzVector3 NzVector3::operator/(T scale) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector3(x / scale, y / scale, z / scale); -} - -template -NzVector3& NzVector3::operator+=(const NzVector3& vec) -{ - x += vec.x; - y += vec.y; - z += vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator-=(const NzVector3& vec) -{ - x -= vec.x; - y -= vec.y; - z -= vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator*=(const NzVector3& vec) -{ - x *= vec.x; - y *= vec.y; - z *= vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator*=(T scale) -{ - x *= scale; - y *= scale; - z *= scale; - - return *this; -} - -template -NzVector3& NzVector3::operator/=(const NzVector3& vec) -{ - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - - x /= vec.x; - y /= vec.y; - z /= vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator/=(T scale) -{ - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - - x /= scale; - y /= scale; - z /= scale; - - return *this; -} - -template -bool NzVector3::operator==(const NzVector3& vec) const -{ - return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y) && - NzNumberEquals(z, vec.z); -} - -template -bool NzVector3::operator!=(const NzVector3& vec) const -{ - return !operator==(vec); -} - -template -bool NzVector3::operator<(const NzVector3& vec) const -{ - return x < vec.x && y < vec.y && z < vec.z; -} - -template -bool NzVector3::operator<=(const NzVector3& vec) const -{ - return operator<(vec) || operator==(vec); -} - -template -bool NzVector3::operator>(const NzVector3& vec) const -{ - return !operator<=(vec); -} - -template -bool NzVector3::operator>=(const NzVector3& vec) const -{ - return !operator<(vec); -} - -template -NzVector3 NzVector3::UnitX() -{ - NzVector3 vector; - vector.MakeUnitX(); - - return vector; -} - -template -NzVector3 NzVector3::UnitY() -{ - NzVector3 vector; - vector.MakeUnitY(); - - return vector; -} - -template -NzVector3 NzVector3::UnitZ() -{ - NzVector3 vector; - vector.MakeUnitZ(); - - return vector; -} - -template -NzVector3 NzVector3::Zero() -{ - NzVector3 vector; - vector.MakeZero(); - - return vector; -} - -template -std::ostream& operator<<(std::ostream& out, const NzVector3& vec) -{ - return out << vec.ToString(); -} - -template -NzVector3 operator*(T scale, const NzVector3& vec) -{ - return NzVector3(scale * vec.x, scale * vec.y, scale * vec.z); -} - -template -NzVector3 operator/(T scale, const NzVector3& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector3(scale / vec.x, scale / vec.y, scale / vec.z); -} - -#undef F - -#include +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzVector3::NzVector3() +{ +} + +template +NzVector3::NzVector3(T X, T Y, T Z) +{ + Set(X, Y, Z); +} + +template +NzVector3::NzVector3(T scale) +{ + Set(scale); +} + +template +NzVector3::NzVector3(T vec[3]) +{ + Set(vec); +} + +template +NzVector3::NzVector3(const NzVector2& vec, T Z) +{ + Set(vec, Z); +} + +template +template +NzVector3::NzVector3(const NzVector3& vec) +{ + Set(vec); +} + +template +T NzVector3::AbsDotProduct(const NzVector3& vec) const +{ + return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z); +} + +template<> +inline int NzVector3::AbsDotProduct(const NzVector3& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); +} + +template<> +inline unsigned int NzVector3::AbsDotProduct(const NzVector3& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); +} + +template +NzVector3 NzVector3::CrossProduct(const NzVector3& vec) const +{ + return NzVector3(y * vec.z - z * vec.y, z * vec.x - x * vec.z, x * vec.y - y * vec.x); +} + +template +T NzVector3::Distance(const NzVector3& vec) const +{ + return std::sqrt(SquaredDistance(vec)); +} + +template +float NzVector3::Distancef(const NzVector3& vec) const +{ + return std::sqrt(static_cast(SquaredDistance())); +} + +template +T NzVector3::DotProduct(const NzVector3& vec) const +{ + return x*vec.x + y*vec.y + z*vec.z; +} + +template +NzVector3 NzVector3::GetNormal() const +{ + NzVector3 vec(*this); + vec.Normalize(); + + return vec; +} + +template +T NzVector3::Length() const +{ + return std::sqrt(SquaredLength()); +} + +template +float NzVector3::Lengthf() const +{ + return std::sqrt(static_cast(SquaredLength())); +} + +template +void NzVector3::MakeForward() +{ + Set(F(0.0), F(0.0), F(-1.0)); +} + +template +void NzVector3::MakeLeft() +{ + Set(F(-1.0), F(0.0), F(0.0)); +} + +template +void NzVector3::MakeUnitX() +{ + Set(F(1.0), F(0.0), F(0.0)); +} + +template +void NzVector3::MakeUnitY() +{ + Set(F(0.0), F(1.0), F(0.0)); +} + +template +void NzVector3::MakeUnitZ() +{ + Set(F(0.0), F(0.0), F(1.0)); +} + +template +void NzVector3::MakeUp() +{ + Set(F(0.0), F(1.0), F(0.0)); +} + +template +void NzVector3::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0)); +} + +template +void NzVector3::Maximize(const NzVector3& vec) +{ + if (vec.x > x) + x = vec.x; + + if (vec.y > y) + y = vec.y; + + if (vec.z > z) + z = vec.z; +} + +template +void NzVector3::Minimize(const NzVector3& vec) +{ + if (vec.x < x) + x = vec.x; + + if (vec.y < y) + y = vec.y; + + if (vec.z < z) + z = vec.z; +} + +template +void NzVector3::Normalize() +{ + T squaredLength = SquaredLength(); + + if (!NzNumberEquals(squaredLength, F(1.0))) + { + T invLength = F(1.0) / std::sqrt(squaredLength); + + x *= invLength; + y *= invLength; + z *= invLength; + } +} + +template +void NzVector3::Set(T X, T Y, T Z) +{ + x = X; + y = Y; + z = Z; +} + +template +void NzVector3::Set(T scale) +{ + x = scale; + y = scale; + z = scale; +} + +template +void NzVector3::Set(T vec[3]) +{ + std::memcpy(&x, vec, 3*sizeof(T)); +} + +template +void NzVector3::Set(const NzVector2& vec, T Z) +{ + x = vec.x; + y = vec.y; + z = Z; +} + +template +template +void NzVector3::Set(const NzVector3& vec) +{ + x = F(vec.x); + y = F(vec.y); + z = F(vec.z); +} + +template +T NzVector3::SquaredDistance(const NzVector3& vec) const +{ + return operator-(vec).SquaredLength(); +} + +template +T NzVector3::SquaredLength() const +{ + return x*x + y*y + z*z; +} + +template +NzString NzVector3::ToString() const +{ + NzStringStream ss; + + return ss << "Vector3(" << x << ", " << y << ", " << z <<')'; +} + +template +NzVector3::operator NzString() const +{ + return ToString(); +} + +template +NzVector3::operator T*() +{ + return &x; +} + +template +NzVector3::operator const T*() const +{ + return &x; +} + +template +T& NzVector3::operator[](unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i >= 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +T NzVector3::operator[](unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i >= 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +const NzVector3& NzVector3::operator+() const +{ + return *this; +} + +template +NzVector3 NzVector3::operator-() const +{ + return NzVector3(-x, -y, -z); +} + +template +NzVector3 NzVector3::operator+(const NzVector3& vec) const +{ + return NzVector3(x + vec.x, y + vec.y, z + vec.z); +} + +template +NzVector3 NzVector3::operator-(const NzVector3& vec) const +{ + return NzVector3(x - vec.x, y - vec.y, z - vec.z); +} + +template +NzVector3 NzVector3::operator*(const NzVector3& vec) const +{ + return NzVector3(x * vec.x, y * vec.y, z * vec.z); +} + +template +NzVector3 NzVector3::operator*(T scale) const +{ + return NzVector3(x * scale, y * scale, z * scale); +} + +template +NzVector3 NzVector3::operator/(const NzVector3& vec) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector3(x / vec.x, y / vec.y, z / vec.z); +} + +template +NzVector3 NzVector3::operator/(T scale) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector3(x / scale, y / scale, z / scale); +} + +template +NzVector3& NzVector3::operator+=(const NzVector3& vec) +{ + x += vec.x; + y += vec.y; + z += vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator-=(const NzVector3& vec) +{ + x -= vec.x; + y -= vec.y; + z -= vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator*=(const NzVector3& vec) +{ + x *= vec.x; + y *= vec.y; + z *= vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator*=(T scale) +{ + x *= scale; + y *= scale; + z *= scale; + + return *this; +} + +template +NzVector3& NzVector3::operator/=(const NzVector3& vec) +{ + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + + x /= vec.x; + y /= vec.y; + z /= vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator/=(T scale) +{ + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + + x /= scale; + y /= scale; + z /= scale; + + return *this; +} + +template +bool NzVector3::operator==(const NzVector3& vec) const +{ + return NzNumberEquals(x, vec.x) && + NzNumberEquals(y, vec.y) && + NzNumberEquals(z, vec.z); +} + +template +bool NzVector3::operator!=(const NzVector3& vec) const +{ + return !operator==(vec); +} + +template +bool NzVector3::operator<(const NzVector3& vec) const +{ + return x < vec.x && y < vec.y && z < vec.z; +} + +template +bool NzVector3::operator<=(const NzVector3& vec) const +{ + return operator<(vec) || operator==(vec); +} + +template +bool NzVector3::operator>(const NzVector3& vec) const +{ + return !operator<=(vec); +} + +template +bool NzVector3::operator>=(const NzVector3& vec) const +{ + return !operator<(vec); +} + +template +NzVector3 NzVector3::CrossProduct(const NzVector3& vec1, const NzVector3& vec2) +{ + return vec1.CrossProduct(vec2); +} + +template +T NzVector3::DotProduct(const NzVector3& vec1, const NzVector3& vec2) +{ + return vec1.DotProduct(vec2); +} + +template +NzVector3 NzVector3::Forward() +{ + NzVector3 vector; + vector.MakeForward(); + + return vector; +} + +template +NzVector3 NzVector3::Left() +{ + NzVector3 vector; + vector.MakeLeft(); + + return vector; +} + +template +NzVector3 NzVector3::Normalize(const NzVector3& vec) +{ + return vec.GetNormal(); +} + +template +NzVector3 NzVector3::UnitX() +{ + NzVector3 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector3 NzVector3::UnitY() +{ + NzVector3 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector3 NzVector3::UnitZ() +{ + NzVector3 vector; + vector.MakeUnitZ(); + + return vector; +} + +template +NzVector3 NzVector3::Up() +{ + NzVector3 vector; + vector.MakeUp(); + + return vector; +} + +template +NzVector3 NzVector3::Zero() +{ + NzVector3 vector; + vector.MakeZero(); + + return vector; +} + +template +std::ostream& operator<<(std::ostream& out, const NzVector3& vec) +{ + return out << vec.ToString(); +} + +template +NzVector3 operator*(T scale, const NzVector3& vec) +{ + return NzVector3(scale * vec.x, scale * vec.y, scale * vec.z); +} + +template +NzVector3 operator/(T scale, const NzVector3& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector3(scale / vec.x, scale / vec.y, scale / vec.z); +} + +#undef F + +#include diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 3987a6b76..b48502127 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -1,97 +1,98 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_VECTOR4_HPP -#define NAZARA_VECTOR4_HPP - -#include -#include - -template class NzVector4 -{ - public: - NzVector4(); - NzVector4(T X, T Y, T Z, T W = 1.0); - explicit NzVector4(T scale); - NzVector4(T vec[4]); - NzVector4(const NzVector3& vec, T W = 1.0); - template explicit NzVector4(const NzVector4& vec); - NzVector4(const NzVector4& vec) = default; - ~NzVector4() = default; - - T AbsDotProduct(const NzVector4& vec) const; - - T DotProduct(const NzVector4& vec) const; - - void MakeCeil(const NzVector4& vec); - void MakeFloor(const NzVector4& vec); - void MakeUnitX(); - void MakeUnitY(); - void MakeUnitZ(); - void MakeZero(); - - void Normalize(); - - void Set(T X, T Y, T Z, T W = 1.0); - void Set(T scale); - void Set(T vec[4]); - void Set(const NzVector3& vec, T W = 1.0); - template void Set(const NzVector4& vec); - - NzString ToString() const; - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - const NzVector4& operator+() const; - NzVector4 operator-() const; - - NzVector4 operator+(const NzVector4& vec) const; - NzVector4 operator-(const NzVector4& vec) const; - NzVector4 operator*(const NzVector4& vec) const; - NzVector4 operator*(T scale) const; - NzVector4 operator/(const NzVector4& vec) const; - NzVector4 operator/(T scale) const; - - NzVector4& operator+=(const NzVector4& vec); - NzVector4& operator-=(const NzVector4& vec); - NzVector4& operator*=(const NzVector4& vec); - NzVector4& operator*=(T scale); - NzVector4& operator/=(const NzVector4& vec); - NzVector4& operator/=(T scale); - - bool operator==(const NzVector4& vec) const; - bool operator!=(const NzVector4& vec) const; - bool operator<(const NzVector4& vec) const; - bool operator<=(const NzVector4& vec) const; - bool operator>(const NzVector4& vec) const; - bool operator>=(const NzVector4& vec) const; - - static NzVector4 UnitX(); - static NzVector4 UnitY(); - static NzVector4 UnitZ(); - static NzVector4 Zero(); - - T x, y, z, w; -}; - -template std::ostream& operator<<(std::ostream& out, const NzVector4& vec); - -template NzVector4 operator*(T scale, const NzVector4& vec); -template NzVector4 operator/(T scale, const NzVector4& vec); - -typedef NzVector4 NzVector4d; -typedef NzVector4 NzVector4f; -typedef NzVector4 NzVector4i; - -#include - -#endif // NAZARA_VECTOR4_HPP +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VECTOR4_HPP +#define NAZARA_VECTOR4_HPP + +#include +#include + +template class NzVector4 +{ + public: + NzVector4(); + NzVector4(T X, T Y, T Z, T W = 1.0); + explicit NzVector4(T scale); + NzVector4(T vec[4]); + NzVector4(const NzVector3& vec, T W = 1.0); + template explicit NzVector4(const NzVector4& vec); + NzVector4(const NzVector4& vec) = default; + ~NzVector4() = default; + + T AbsDotProduct(const NzVector4& vec) const; + + T DotProduct(const NzVector4& vec) const; + + void MakeUnitX(); + void MakeUnitY(); + void MakeUnitZ(); + void MakeZero(); + + void Maximize(const NzVector4& vec); + void Minimize(const NzVector4& vec); + + void Normalize(); + + void Set(T X, T Y, T Z, T W = 1.0); + void Set(T scale); + void Set(T vec[4]); + void Set(const NzVector3& vec, T W = 1.0); + template void Set(const NzVector4& vec); + + NzString ToString() const; + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + const NzVector4& operator+() const; + NzVector4 operator-() const; + + NzVector4 operator+(const NzVector4& vec) const; + NzVector4 operator-(const NzVector4& vec) const; + NzVector4 operator*(const NzVector4& vec) const; + NzVector4 operator*(T scale) const; + NzVector4 operator/(const NzVector4& vec) const; + NzVector4 operator/(T scale) const; + + NzVector4& operator+=(const NzVector4& vec); + NzVector4& operator-=(const NzVector4& vec); + NzVector4& operator*=(const NzVector4& vec); + NzVector4& operator*=(T scale); + NzVector4& operator/=(const NzVector4& vec); + NzVector4& operator/=(T scale); + + bool operator==(const NzVector4& vec) const; + bool operator!=(const NzVector4& vec) const; + bool operator<(const NzVector4& vec) const; + bool operator<=(const NzVector4& vec) const; + bool operator>(const NzVector4& vec) const; + bool operator>=(const NzVector4& vec) const; + + static NzVector4 UnitX(); + static NzVector4 UnitY(); + static NzVector4 UnitZ(); + static NzVector4 Zero(); + + T x, y, z, w; +}; + +template std::ostream& operator<<(std::ostream& out, const NzVector4& vec); + +template NzVector4 operator*(T scale, const NzVector4& vec); +template NzVector4 operator/(T scale, const NzVector4& vec); + +typedef NzVector4 NzVector4d; +typedef NzVector4 NzVector4f; +typedef NzVector4 NzVector4i; + +#include + +#endif // NAZARA_VECTOR4_HPP diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 18e915e96..e3245c0ac 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -1,503 +1,503 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D - -#define F(a) static_cast(a) - -template -NzVector4::NzVector4() -{ -} - -template -NzVector4::NzVector4(T X, T Y, T Z, T W) -{ - Set(X, Y, Z, W); -} - -template -NzVector4::NzVector4(T scale) -{ - Set(scale); -} - -template -NzVector4::NzVector4(T vec[4]) -{ - Set(vec); -} - -template -NzVector4::NzVector4(const NzVector3& vec, T W) -{ - Set(vec, W); -} - -template -template -NzVector4::NzVector4(const NzVector4& vec) -{ - Set(vec); -} - -template -T NzVector4::AbsDotProduct(const NzVector4& vec) const -{ - return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z) + std::fabs(w * vec.w); -} - -template<> -inline int NzVector4::AbsDotProduct(const NzVector4& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); -} - -template<> -inline unsigned int NzVector4::AbsDotProduct(const NzVector4& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); -} - -template -T NzVector4::DotProduct(const NzVector4& vec) const -{ - return x*vec.x + y*vec.y + z*vec.z + w*vec.w; -} - -template -void NzVector4::MakeCeil(const NzVector4& vec) -{ - if (vec.x > x) - x = vec.x; - - if (vec.y > y) - y = vec.y; - - if (vec.z > z) - z = vec.z; - - if (vec.w > w) - w = vec.w; -} - -template -void NzVector4::MakeFloor(const NzVector4& vec) -{ - if (vec.x < x) - x = vec.x; - - if (vec.y < y) - y = vec.y; - - if (vec.z < z) - z = vec.z; - - if (vec.w < w) - w = vec.w; -} - -template -void NzVector4::MakeUnitX() -{ - Set(F(1.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzVector4::MakeUnitY() -{ - Set(F(0.0), F(1.0), F(0.0), F(1.0)); -} - -template -void NzVector4::MakeUnitZ() -{ - Set(F(0.0), F(0.0), F(1.0), F(1.0)); -} - -template -void NzVector4::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0), F(0.0)); -} - -template -void NzVector4::Normalize() -{ - if (!NzNumberEquals(w, F(0.0))) - { - x /= w; - y /= w; - z /= w; - } -} - -template -void NzVector4::Set(T X, T Y, T Z, T W) -{ - w = W; - x = X; - y = Y; - z = Z; -} - -template -void NzVector4::Set(T scale) -{ - w = scale; - x = scale; - y = scale; - z = scale; -} - -template -void NzVector4::Set(T vec[4]) -{ - std::memcpy(&x, vec, 4*sizeof(T)); -} - -template -void NzVector4::Set(const NzVector3& vec, T W) -{ - w = W; - x = vec.x; - y = vec.y; - z = vec.z; -} - -template -template -void NzVector4::Set(const NzVector4& vec) -{ - w = F(vec.w); - x = F(vec.x); - y = F(vec.y); - z = F(vec.z); -} - -template -NzString NzVector4::ToString() const -{ - NzStringStream ss; - - return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')'; -} - -template -NzVector4::operator NzString() const -{ - return ToString(); -} - -template -NzVector4::operator T*() -{ - return &x; -} - -template -NzVector4::operator const T*() const -{ - return &x; -} - -template -T& NzVector4::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 4) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector4::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 4) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -const NzVector4& NzVector4::operator+() const -{ - return *this; -} - -template -NzVector4 NzVector4::operator-() const -{ - return NzVector4(-x, -y, -z, -w); -} - -template -NzVector4 NzVector4::operator+(const NzVector4& vec) const -{ - return NzVector4(x + vec.x, y + vec.y, z + vec.z, w + vec.w); -} - -template -NzVector4 NzVector4::operator-(const NzVector4& vec) const -{ - return NzVector4(x - vec.x, y - vec.y, z - vec.z, w - vec.w); -} - -template -NzVector4 NzVector4::operator*(const NzVector4& vec) const -{ - return NzVector4(x * vec.x, y * vec.y, z * vec.z, w * vec.w); -} - -template -NzVector4 NzVector4::operator*(T scale) const -{ - return NzVector4(x * scale, y * scale, z * scale, w * scale); -} - -template -NzVector4 NzVector4::operator/(const NzVector4& vec) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w); -} - -template -NzVector4 NzVector4::operator/(T scale) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector4(x / scale, y / scale, z / scale, w / scale); -} - -template -NzVector4& NzVector4::operator+=(const NzVector4& vec) -{ - x += vec.x; - y += vec.y; - z += vec.z; - w += vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator-=(const NzVector4& vec) -{ - x -= vec.x; - y -= vec.y; - z -= vec.z; - w -= vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator*=(const NzVector4& vec) -{ - x *= vec.x; - y *= vec.y; - z *= vec.z; - w *= vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator*=(T scale) -{ - x *= scale; - y *= scale; - z *= scale; - w *= scale; - - return *this; -} - -template -NzVector4& NzVector4::operator/=(const NzVector4& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= vec.x; - y /= vec.y; - z /= vec.z; - w /= vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator/=(T scale) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= scale; - y /= scale; - z /= scale; - w /= scale; - - return *this; -} - -template -bool NzVector4::operator==(const NzVector4& vec) const -{ - return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y) && - NzNumberEquals(z, vec.z) && - NzNumberEquals(w, vec.w); -} - -template -bool NzVector4::operator!=(const NzVector4& vec) const -{ - return !operator==(vec); -} - -template -bool NzVector4::operator<(const NzVector4& vec) const -{ - return x < vec.x && y < vec.y && z < vec.z && w < vec.w; -} - -template -bool NzVector4::operator<=(const NzVector4& vec) const -{ - return operator<(vec) || operator==(vec); -} - -template -bool NzVector4::operator>(const NzVector4& vec) const -{ - return !operator<=(vec); -} - -template -bool NzVector4::operator>=(const NzVector4& vec) const -{ - return !operator<(vec); -} - -template -NzVector4 NzVector4::UnitX() -{ - NzVector4 vector; - vector.MakeUnitX(); - - return vector; -} - -template -NzVector4 NzVector4::UnitY() -{ - NzVector4 vector; - vector.MakeUnitY(); - - return vector; -} - -template -NzVector4 NzVector4::UnitZ() -{ - NzVector4 vector; - vector.MakeUnitZ(); - - return vector; -} - -template -NzVector4 NzVector4::Zero() -{ - NzVector4 vector; - vector.MakeZero(); - - return vector; -} - -template -std::ostream& operator<<(std::ostream& out, const NzVector4& vec) -{ - return out << vec.ToString(); -} - -template -NzVector4 operator*(T scale, const NzVector4& vec) -{ - return NzVector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); -} - -template -NzVector4 operator/(T scale, const NzVector4& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); -} - -#undef F - -#include +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D + +#define F(a) static_cast(a) + +template +NzVector4::NzVector4() +{ +} + +template +NzVector4::NzVector4(T X, T Y, T Z, T W) +{ + Set(X, Y, Z, W); +} + +template +NzVector4::NzVector4(T scale) +{ + Set(scale); +} + +template +NzVector4::NzVector4(T vec[4]) +{ + Set(vec); +} + +template +NzVector4::NzVector4(const NzVector3& vec, T W) +{ + Set(vec, W); +} + +template +template +NzVector4::NzVector4(const NzVector4& vec) +{ + Set(vec); +} + +template +T NzVector4::AbsDotProduct(const NzVector4& vec) const +{ + return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z) + std::fabs(w * vec.w); +} + +template<> +inline int NzVector4::AbsDotProduct(const NzVector4& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); +} + +template<> +inline unsigned int NzVector4::AbsDotProduct(const NzVector4& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); +} + +template +T NzVector4::DotProduct(const NzVector4& vec) const +{ + return x*vec.x + y*vec.y + z*vec.z + w*vec.w; +} + +template +void NzVector4::MakeUnitX() +{ + Set(F(1.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzVector4::MakeUnitY() +{ + Set(F(0.0), F(1.0), F(0.0), F(1.0)); +} + +template +void NzVector4::MakeUnitZ() +{ + Set(F(0.0), F(0.0), F(1.0), F(1.0)); +} + +template +void NzVector4::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0)); +} + +template +void NzVector4::Maximize(const NzVector4& vec) +{ + if (vec.x > x) + x = vec.x; + + if (vec.y > y) + y = vec.y; + + if (vec.z > z) + z = vec.z; + + if (vec.w > w) + w = vec.w; +} + +template +void NzVector4::Minimize(const NzVector4& vec) +{ + if (vec.x < x) + x = vec.x; + + if (vec.y < y) + y = vec.y; + + if (vec.z < z) + z = vec.z; + + if (vec.w < w) + w = vec.w; +} + +template +void NzVector4::Normalize() +{ + if (!NzNumberEquals(w, F(0.0))) + { + x /= w; + y /= w; + z /= w; + } +} + +template +void NzVector4::Set(T X, T Y, T Z, T W) +{ + w = W; + x = X; + y = Y; + z = Z; +} + +template +void NzVector4::Set(T scale) +{ + w = scale; + x = scale; + y = scale; + z = scale; +} + +template +void NzVector4::Set(T vec[4]) +{ + std::memcpy(&x, vec, 4*sizeof(T)); +} + +template +void NzVector4::Set(const NzVector3& vec, T W) +{ + w = W; + x = vec.x; + y = vec.y; + z = vec.z; +} + +template +template +void NzVector4::Set(const NzVector4& vec) +{ + w = F(vec.w); + x = F(vec.x); + y = F(vec.y); + z = F(vec.z); +} + +template +NzString NzVector4::ToString() const +{ + NzStringStream ss; + + return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')'; +} + +template +NzVector4::operator NzString() const +{ + return ToString(); +} + +template +NzVector4::operator T*() +{ + return &x; +} + +template +NzVector4::operator const T*() const +{ + return &x; +} + +template +T& NzVector4::operator[](unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i >= 4) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +T NzVector4::operator[](unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i >= 4) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +const NzVector4& NzVector4::operator+() const +{ + return *this; +} + +template +NzVector4 NzVector4::operator-() const +{ + return NzVector4(-x, -y, -z, -w); +} + +template +NzVector4 NzVector4::operator+(const NzVector4& vec) const +{ + return NzVector4(x + vec.x, y + vec.y, z + vec.z, w + vec.w); +} + +template +NzVector4 NzVector4::operator-(const NzVector4& vec) const +{ + return NzVector4(x - vec.x, y - vec.y, z - vec.z, w - vec.w); +} + +template +NzVector4 NzVector4::operator*(const NzVector4& vec) const +{ + return NzVector4(x * vec.x, y * vec.y, z * vec.z, w * vec.w); +} + +template +NzVector4 NzVector4::operator*(T scale) const +{ + return NzVector4(x * scale, y * scale, z * scale, w * scale); +} + +template +NzVector4 NzVector4::operator/(const NzVector4& vec) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w); +} + +template +NzVector4 NzVector4::operator/(T scale) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector4(x / scale, y / scale, z / scale, w / scale); +} + +template +NzVector4& NzVector4::operator+=(const NzVector4& vec) +{ + x += vec.x; + y += vec.y; + z += vec.z; + w += vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator-=(const NzVector4& vec) +{ + x -= vec.x; + y -= vec.y; + z -= vec.z; + w -= vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator*=(const NzVector4& vec) +{ + x *= vec.x; + y *= vec.y; + z *= vec.z; + w *= vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator*=(T scale) +{ + x *= scale; + y *= scale; + z *= scale; + w *= scale; + + return *this; +} + +template +NzVector4& NzVector4::operator/=(const NzVector4& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= vec.x; + y /= vec.y; + z /= vec.z; + w /= vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator/=(T scale) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= scale; + y /= scale; + z /= scale; + w /= scale; + + return *this; +} + +template +bool NzVector4::operator==(const NzVector4& vec) const +{ + return NzNumberEquals(x, vec.x) && + NzNumberEquals(y, vec.y) && + NzNumberEquals(z, vec.z) && + NzNumberEquals(w, vec.w); +} + +template +bool NzVector4::operator!=(const NzVector4& vec) const +{ + return !operator==(vec); +} + +template +bool NzVector4::operator<(const NzVector4& vec) const +{ + return x < vec.x && y < vec.y && z < vec.z && w < vec.w; +} + +template +bool NzVector4::operator<=(const NzVector4& vec) const +{ + return operator<(vec) || operator==(vec); +} + +template +bool NzVector4::operator>(const NzVector4& vec) const +{ + return !operator<=(vec); +} + +template +bool NzVector4::operator>=(const NzVector4& vec) const +{ + return !operator<(vec); +} + +template +NzVector4 NzVector4::UnitX() +{ + NzVector4 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector4 NzVector4::UnitY() +{ + NzVector4 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector4 NzVector4::UnitZ() +{ + NzVector4 vector; + vector.MakeUnitZ(); + + return vector; +} + +template +NzVector4 NzVector4::Zero() +{ + NzVector4 vector; + vector.MakeZero(); + + return vector; +} + +template +std::ostream& operator<<(std::ostream& out, const NzVector4& vec) +{ + return out << vec.ToString(); +} + +template +NzVector4 operator*(T scale, const NzVector4& vec) +{ + return NzVector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); +} + +template +NzVector4 operator/(T scale, const NzVector4& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); +} + +#undef F + +#include diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index f4c24dbfb..1b9a4dd0b 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -1,40 +1,41 @@ -// This file was automatically generated by Nazara - -/* - Nazara Engine - Renderer module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// This file was automatically generated by Nazara + +/* + Nazara Engine - Renderer module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Renderer/Config.hpp b/include/Nazara/Renderer/Config.hpp index 5fa27a4f0..1fafa11e6 100644 --- a/include/Nazara/Renderer/Config.hpp +++ b/include/Nazara/Renderer/Config.hpp @@ -1,44 +1,41 @@ -/* - Nazara Engine - Renderer module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_RENDERER_HPP -#define NAZARA_CONFIG_RENDERER_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Active une fenêtre de rendu (NzRenderWindow) lors de sa création -#define NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION 1 - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 - -// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL) -#define NAZARA_RENDERER_OPENGL_DEBUG 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_RENDERER_SAFE 1 - -#endif // NAZARA_CONFIG_MODULENAME_HPP +/* + Nazara Engine - Renderer module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_RENDERER_HPP +#define NAZARA_CONFIG_RENDERER_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 + +// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL) +#define NAZARA_RENDERER_OPENGL_DEBUG 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_RENDERER_SAFE 1 + +#endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/Renderer/Context.hpp b/include/Nazara/Renderer/Context.hpp index b24f1e106..f4bb5be7c 100644 --- a/include/Nazara/Renderer/Context.hpp +++ b/include/Nazara/Renderer/Context.hpp @@ -1,47 +1,49 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifdef NAZARA_RENDERER_COMMON -#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it -#endif - -#pragma once - -#ifndef NAZARA_CONTEXT_HPP -#define NAZARA_CONTEXT_HPP - -#include - -class NzContextImpl; - -class NAZARA_API NzContext -{ - friend NzContextImpl; - - public: - NzContext(); - ~NzContext(); - - bool Create(const NzContextParameters& parameters = NzContextParameters()); - void Destroy(); - const NzContextParameters& GetParameters() const; - bool IsActive() const; - bool SetActive(bool active); - void SwapBuffers(); - - static bool EnsureContext(); - static NzContext* GetCurrent(); - static const NzContext* GetReference(); - static NzContext* GetThreadContext(); - static bool Initialize(); - static void Uninitialize(); - - private: - NzContextParameters m_parameters; - NzContextImpl* m_impl; - - static NzContext* s_reference; -}; - -#endif // NAZARA_CONTEXT_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CONTEXT_HPP +#define NAZARA_CONTEXT_HPP + +#ifdef NAZARA_RENDERER_OPENGL + +#include +#include + +class NzContextImpl; + +class NAZARA_API NzContext : public NzResource +{ + friend NzContextImpl; + + public: + NzContext(); + ~NzContext(); + + bool Create(const NzContextParameters& parameters = NzContextParameters()); + void Destroy(); + + const NzContextParameters& GetParameters() const; + bool IsActive() const; + bool SetActive(bool active); + void SwapBuffers(); + + static bool EnsureContext(); + static NzContext* GetCurrent(); + static const NzContext* GetReference(); + static NzContext* GetThreadContext(); + static bool Initialize(); + static void Uninitialize(); + + private: + NzContextParameters m_parameters; + NzContextImpl* m_impl; + + static NzContext* s_reference; +}; + +#endif // NAZARA_RENDERER_OPENGL + +#endif // NAZARA_CONTEXT_HPP diff --git a/include/Nazara/Renderer/Enums.hpp b/include/Nazara/Renderer/Enums.hpp index 459ea4d4a..7abeca5ec 100644 --- a/include/Nazara/Renderer/Enums.hpp +++ b/include/Nazara/Renderer/Enums.hpp @@ -1,141 +1,174 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_RENDERER_HPP -#define NAZARA_ENUMS_RENDERER_HPP - -enum nzBlendFunc -{ - nzBlendFunc_DestAlpha, - nzBlendFunc_DestColor, - nzBlendFunc_SrcAlpha, - nzBlendFunc_SrcColor, - nzBlendFunc_InvDestAlpha, - nzBlendFunc_InvDestColor, - nzBlendFunc_InvSrcAlpha, - nzBlendFunc_InvSrcColor, - nzBlendFunc_One, - nzBlendFunc_Zero -}; - -enum nzFaceCulling -{ - nzFaceCulling_Back, - nzFaceCulling_Front, - nzFaceCulling_FrontAndBack -}; - -enum nzFaceFilling -{ - nzFaceFilling_Point, - nzFaceFilling_Line, - nzFaceFilling_Fill -}; - -enum nzMatrixType -{ - nzMatrixType_Projection, - nzMatrixType_View, - nzMatrixType_World, - - nzMatrixType_Max = nzMatrixType_World -}; - -enum nzPixelBufferType -{ - nzPixelBufferType_Pack, - nzPixelBufferType_Unpack -}; - -enum nzRendererCap -{ - nzRendererCap_AnisotropicFilter, - nzRendererCap_FP64, - nzRendererCap_HardwareBuffer, - nzRendererCap_MultipleRenderTargets, - nzRendererCap_OcclusionQuery, - nzRendererCap_PixelBufferObject, - nzRendererCap_Texture3D, - nzRendererCap_TextureCubemap, - nzRendererCap_TextureMulti, - nzRendererCap_TextureNPOT, - - nzRendererCap_Max = nzRendererCap_TextureNPOT -}; - -enum nzRendererClear -{ - nzRendererClear_Color = 0x01, - nzRendererClear_Depth = 0x02, - nzRendererClear_Stencil = 0x04 -}; - -enum nzRendererComparison -{ - nzRendererComparison_Always, - nzRendererComparison_Equal, - nzRendererComparison_Greater, - nzRendererComparison_GreaterOrEqual, - nzRendererComparison_Less, - nzRendererComparison_LessOrEqual, - nzRendererComparison_Never -}; - -enum nzRendererParameter -{ - nzRendererParameter_Blend, - nzRendererParameter_ColorWrite, - nzRendererParameter_DepthTest, - nzRendererParameter_DepthWrite, - nzRendererParameter_FaceCulling, - nzRendererParameter_Stencil -}; - -enum nzShaderLanguage -{ - nzShaderLanguage_Unknown, - - nzShaderLanguage_Cg, - nzShaderLanguage_GLSL -}; - -enum nzShaderType -{ - nzShaderType_Fragment, - nzShaderType_Geometry, - nzShaderType_Vertex, - - nzShaderType_Max = nzShaderType_Vertex -}; - -enum nzStencilOperation -{ - nzStencilOperation_Decrement, - nzStencilOperation_DecrementToSaturation, - nzStencilOperation_Increment, - nzStencilOperation_IncrementToSaturation, - nzStencilOperation_Invert, - nzStencilOperation_Keep, - nzStencilOperation_Replace, - nzStencilOperation_Zero -}; - -enum nzTextureFilter -{ - nzTextureFilter_Bilinear, - nzTextureFilter_Nearest, - nzTextureFilter_Trilinear, - nzTextureFilter_Unknown -}; - -enum nzTextureWrap -{ - nzTextureWrap_Clamp, - nzTextureWrap_Repeat, - nzTextureWrap_Unknown -}; - -#endif // NAZARA_ENUMS_RENDERER_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_RENDERER_HPP +#define NAZARA_ENUMS_RENDERER_HPP + +enum nzAttachmentPoint +{ + nzAttachmentPoint_Color, + nzAttachmentPoint_Depth, + nzAttachmentPoint_DepthStencil, + nzAttachmentPoint_Stencil, + + nzAttachmentPoint_Max = nzAttachmentPoint_Stencil +}; + +enum nzBlendFunc +{ + nzBlendFunc_DestAlpha, + nzBlendFunc_DestColor, + nzBlendFunc_SrcAlpha, + nzBlendFunc_SrcColor, + nzBlendFunc_InvDestAlpha, + nzBlendFunc_InvDestColor, + nzBlendFunc_InvSrcAlpha, + nzBlendFunc_InvSrcColor, + nzBlendFunc_One, + nzBlendFunc_Zero, + + nzBlendFunc_Max = nzBlendFunc_Zero +}; + +enum nzFaceCulling +{ + nzFaceCulling_Back, + nzFaceCulling_Front, + nzFaceCulling_FrontAndBack, + + nzFaceCulling_Max = nzFaceCulling_FrontAndBack +}; + +enum nzFaceFilling +{ + nzFaceFilling_Point, + nzFaceFilling_Line, + nzFaceFilling_Fill, + + nzFaceFilling_Max = nzFaceFilling_Fill +}; + +enum nzMatrixType +{ + nzMatrixType_Projection, + nzMatrixType_View, + nzMatrixType_World, + + nzMatrixType_Max = nzMatrixType_World +}; + +enum nzPixelBufferType +{ + nzPixelBufferType_Pack, + nzPixelBufferType_Unpack, + + nzPixelBufferType_Max = nzPixelBufferType_Unpack +}; + +enum nzRendererCap +{ + nzRendererCap_AnisotropicFilter, + nzRendererCap_FP64, + nzRendererCap_HardwareBuffer, + nzRendererCap_MultipleRenderTargets, + nzRendererCap_OcclusionQuery, + nzRendererCap_PixelBufferObject, + nzRendererCap_RenderTexture, + nzRendererCap_Texture3D, + nzRendererCap_TextureCubemap, + nzRendererCap_TextureMulti, + nzRendererCap_TextureNPOT, + + nzRendererCap_Max = nzRendererCap_TextureNPOT +}; + +enum nzRendererClearFlags +{ + nzRendererClear_Color = 0x01, + nzRendererClear_Depth = 0x02, + nzRendererClear_Stencil = 0x04 +}; + +enum nzRendererComparison +{ + nzRendererComparison_Always, + nzRendererComparison_Equal, + nzRendererComparison_Greater, + nzRendererComparison_GreaterOrEqual, + nzRendererComparison_Less, + nzRendererComparison_LessOrEqual, + nzRendererComparison_Never, + + nzRendererComparison_Max = nzRendererComparison_Never +}; + +enum nzRendererParameter +{ + nzRendererParameter_Blend, + nzRendererParameter_ColorWrite, + nzRendererParameter_DepthTest, + nzRendererParameter_DepthWrite, + nzRendererParameter_FaceCulling, + nzRendererParameter_Stencil, + + nzRendererParameter_Max = nzRendererParameter_Stencil +}; + +enum nzShaderLanguage +{ + nzShaderLanguage_Unknown = -1, + + nzShaderLanguage_Cg, + nzShaderLanguage_GLSL, + + nzShaderLanguage_Max = nzShaderLanguage_GLSL +}; + +enum nzShaderType +{ + nzShaderType_Fragment, + nzShaderType_Geometry, + nzShaderType_Vertex, + + nzShaderType_Max = nzShaderType_Vertex +}; + +enum nzStencilOperation +{ + nzStencilOperation_Decrement, + nzStencilOperation_DecrementToSaturation, + nzStencilOperation_Increment, + nzStencilOperation_IncrementToSaturation, + nzStencilOperation_Invert, + nzStencilOperation_Keep, + nzStencilOperation_Replace, + nzStencilOperation_Zero, + + nzStencilOperation_Max = nzStencilOperation_Zero +}; + +enum nzTextureFilter +{ + nzTextureFilter_Unknown = -1, + + nzTextureFilter_Bilinear, + nzTextureFilter_Nearest, + nzTextureFilter_Trilinear, + + nzTextureFilter_Max = nzTextureFilter_Trilinear +}; + +enum nzTextureWrap +{ + nzTextureWrap_Unknown = -1, + + nzTextureWrap_Clamp, + nzTextureWrap_Repeat, + + nzTextureWrap_Max = nzTextureWrap_Repeat +}; + +#endif // NAZARA_ENUMS_RENDERER_HPP diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 1944054e6..ce4468096 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -1,192 +1,233 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifdef NAZARA_RENDERER_COMMON - #error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it -#endif - -#pragma once - -#ifndef NAZARA_OPENGL_HPP -#define NAZARA_OPENGL_HPP - -// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier -#include -#include -#include - -// Inclusion des extensions -#include -#if defined(NAZARA_PLATFORM_WINDOWS) - #include -#elif defined(NAZARA_PLATFORM_LINUX) - #include -#endif - -using NzOpenGLFunc = void (*)(); - -class NAZARA_API NzOpenGL -{ - public: - enum Extension - { - AnisotropicFilter, - DebugOutput, - FP64, - FrameBufferObject, - PixelBufferObject, - SeparateShaderObjects, - Texture3D, - TextureArray, - TextureCompression_s3tc, - TextureStorage, - VertexArrayObject, - - Max = VertexArrayObject - }; - - static NzOpenGLFunc GetEntry(const NzString& entryPoint); - static unsigned int GetVersion(); - static bool Initialize(); - static bool IsSupported(Extension extension); - static bool IsSupported(const NzString& string); - static void Uninitialize(); -}; - -NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; -NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader; -NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery; -NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; -NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer; -NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; -NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture; -NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; -NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc; -NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData; -NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; -NAZARA_API extern PFNGLCLEARPROC glClear; -NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor; -NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth; -NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil; -NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; -NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader; -NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; -NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; -NAZARA_API extern PFNGLCULLFACEPROC glCullFace; -NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; -NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; -NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; -NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; -NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; -NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; -NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; -NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; -NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; -NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; -NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader; -NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; -NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; -NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc; -NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask; -NAZARA_API extern PFNGLDISABLEPROC glDisable; -NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; -NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays; -NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; -NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; -NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements; -NAZARA_API extern PFNGLENDQUERYPROC glEndQuery; -NAZARA_API extern PFNGLFLUSHPROC glFlush; -NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; -NAZARA_API extern PFNGLENABLEPROC glEnable; -NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; -NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; -NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers; -NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; -NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries; -NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; -NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures; -NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; -NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; -NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; -NAZARA_API extern PFNGLGETERRORPROC glGetError; -NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv; -NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; -NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; -NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv; -NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; -NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; -NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; -NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv; -NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; -NAZARA_API extern PFNGLGETSTRINGPROC glGetString; -NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi; -NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; -NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; -NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; -NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; -NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; -NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; -NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram; -NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer; -NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; -NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei; -NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode; -NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; -NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; -NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; -NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; -NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; -NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; -NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; -NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; -NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels; -NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; -NAZARA_API extern PFNGLSCISSORPROC glScissor; -NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource; -NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc; -NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp; -NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; -NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; -NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; -NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; -NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; -NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; -NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; -NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; -NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; -NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; -NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; -NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d; -NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f; -NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i; -NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv; -NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv; -NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv; -NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv; -NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv; -NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv; -NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; -NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; -NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; -NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram; -NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; -NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; -NAZARA_API extern PFNGLVIEWPORTPROC glViewport; -#if defined(NAZARA_PLATFORM_WINDOWS) -NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; -NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; -NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; -NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; -NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; -#elif defined(NAZARA_PLATFORM_LINUX) -NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; -NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval; -#endif - -#endif // NAZARA_OPENGL_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_OPENGL_HPP +#define NAZARA_OPENGL_HPP + +#ifdef NAZARA_RENDERER_OPENGL + +// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier +#include +#include +#include +#include +#include + +// Inclusion des extensions +#include +#if defined(NAZARA_PLATFORM_WINDOWS) + #include +#elif defined(NAZARA_PLATFORM_LINUX) + #include +#endif + +enum nzOpenGLExtension +{ + nzOpenGLExtension_AnisotropicFilter, + nzOpenGLExtension_DebugOutput, + nzOpenGLExtension_FP64, + nzOpenGLExtension_FrameBufferObject, + nzOpenGLExtension_PixelBufferObject, + nzOpenGLExtension_SeparateShaderObjects, + nzOpenGLExtension_TextureArray, + nzOpenGLExtension_TextureCompression_s3tc, + nzOpenGLExtension_TextureStorage, + nzOpenGLExtension_VertexArrayObject, + + nzOpenGLExtension_Max = nzOpenGLExtension_VertexArrayObject +}; + +using NzOpenGLFunc = void (*)(); + +namespace NzOpenGL +{ + enum FormatType + { + FormatType_RenderBuffer, +// FormatType_MultisampleTexture, + FormatType_Texture + }; + + struct Format + { + GLenum dataFormat; + GLenum dataType; + GLint internalFormat; + }; + + NzOpenGLFunc GetEntry(const NzString& entryPoint); + unsigned int GetVersion(); + bool Initialize(); + bool IsSupported(nzOpenGLExtension extension); + bool IsSupported(const NzString& string); + bool TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType target); + void Uninitialize(); + + extern GLenum Attachment[nzAttachmentPoint_Max+1]; + extern nzUInt8 AttributeIndex[nzElementUsage_Max+1]; + extern GLenum BlendFunc[nzBlendFunc_Max+1]; + extern GLenum BufferLock[nzBufferAccess_Max+1]; + extern GLenum BufferLockRange[nzBufferAccess_Max+1]; + extern GLenum BufferTarget[nzBufferType_Max+1]; + extern GLenum BufferTargetBinding[nzBufferType_Max+1]; + extern GLenum BufferUsage[nzBufferUsage_Max+1]; + extern GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas prêt de changer + extern GLenum ElementType[nzElementType_Max+1]; + extern GLenum FaceCulling[nzFaceCulling_Max+1]; + extern GLenum FaceFilling[nzFaceFilling_Max+1]; + extern GLenum PrimitiveType[nzPrimitiveType_Max+1]; + extern GLenum RendererComparison[nzRendererComparison_Max+1]; + extern GLenum RendererParameter[nzRendererParameter_Max+1]; + extern GLenum ShaderType[nzShaderType_Max+1]; + extern GLenum StencilOperation[nzStencilOperation_Max+1]; + extern GLenum TextureTarget[nzImageType_Max+1]; + extern GLenum TextureTargetBinding[nzImageType_Max+1]; + extern GLenum TextureTargetProxy[nzImageType_Max+1]; +} + +NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; +NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader; +NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery; +NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; +NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer; +NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +NAZARA_API extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; +NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; +NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture; +NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; +NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc; +NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData; +NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; +NAZARA_API extern PFNGLCLEARPROC glClear; +NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor; +NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth; +NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil; +NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; +NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader; +NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; +NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; +NAZARA_API extern PFNGLCULLFACEPROC glCullFace; +NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; +NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; +NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; +NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; +NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; +NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; +NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; +NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; +NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; +NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; +NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader; +NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; +NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; +NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc; +NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask; +NAZARA_API extern PFNGLDISABLEPROC glDisable; +NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; +NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays; +NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; +NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; +NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements; +NAZARA_API extern PFNGLENDQUERYPROC glEndQuery; +NAZARA_API extern PFNGLFLUSHPROC glFlush; +NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; +NAZARA_API extern PFNGLENABLEPROC glEnable; +NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; +NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; +NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers; +NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries; +NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; +NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures; +NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; +NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; +NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; +NAZARA_API extern PFNGLGETERRORPROC glGetError; +NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv; +NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; +NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; +NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv; +NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; +NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; +NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; +NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv; +NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; +NAZARA_API extern PFNGLGETSTRINGPROC glGetString; +NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi; +NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; +NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; +NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; +NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; +NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; +NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; +NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram; +NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer; +NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei; +NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode; +NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; +NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; +NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; +NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; +NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; +NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; +NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; +NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; +NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels; +NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; +NAZARA_API extern PFNGLSCISSORPROC glScissor; +NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource; +NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc; +NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp; +NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; +NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; +NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; +NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; +NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; +NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; +NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; +NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; +NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; +NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; +NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; +NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d; +NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f; +NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i; +NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv; +NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv; +NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv; +NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv; +NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv; +NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv; +NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; +NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; +NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; +NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram; +NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; +NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; +NAZARA_API extern PFNGLVIEWPORTPROC glViewport; +#if defined(NAZARA_PLATFORM_WINDOWS) +NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; +NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; +NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; +NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; +NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; +#elif defined(NAZARA_PLATFORM_LINUX) +NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; +NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval; +#endif + +#endif // NAZARA_RENDERER_OPENGL + +#endif // NAZARA_OPENGL_HPP diff --git a/include/Nazara/Renderer/RenderTarget.hpp b/include/Nazara/Renderer/RenderTarget.hpp index 347bf90fb..1c7ddaab9 100644 --- a/include/Nazara/Renderer/RenderTarget.hpp +++ b/include/Nazara/Renderer/RenderTarget.hpp @@ -1,42 +1,41 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RENDERTARGET_HPP -#define NAZARA_RENDERTARGET_HPP - -#include -#include -#include - -class NzRenderer; - -class NAZARA_API NzRenderTarget -{ - friend class NzRenderer; - - public: - NzRenderTarget() = default; - virtual ~NzRenderTarget(); - - #ifndef NAZARA_RENDERER_COMMON - virtual bool HasContext() const = 0; - #endif - - virtual unsigned int GetHeight() const = 0; - virtual NzRenderTargetParameters GetParameters() const = 0; - virtual unsigned int GetWidth() const = 0; - - bool IsActive() const; - virtual bool IsValid() const = 0; - - bool SetActive(bool active); - - protected: - virtual bool Activate() = 0; - virtual void Desactivate(); -}; - -#endif // NAZARA_RENDERTARGET_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RENDERTARGET_HPP +#define NAZARA_RENDERTARGET_HPP + +#include +#include +#include + +class NzRenderer; + +class NAZARA_API NzRenderTarget +{ + friend class NzRenderer; + + public: + NzRenderTarget() = default; + virtual ~NzRenderTarget(); + + virtual unsigned int GetHeight() const = 0; + virtual NzRenderTargetParameters GetParameters() const = 0; + virtual unsigned int GetWidth() const = 0; + + bool IsActive() const; + virtual bool IsRenderable() const = 0; + + bool SetActive(bool active); + + // Fonctions OpenGL + virtual bool HasContext() const = 0; + + protected: + virtual bool Activate() = 0; + virtual void Desactivate(); +}; + +#endif // NAZARA_RENDERTARGET_HPP diff --git a/include/Nazara/Renderer/RenderTexture.hpp b/include/Nazara/Renderer/RenderTexture.hpp new file mode 100644 index 000000000..e7be88f88 --- /dev/null +++ b/include/Nazara/Renderer/RenderTexture.hpp @@ -0,0 +1,60 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RENDERTEXTURE_HPP +#define NAZARA_RENDERTEXTURE_HPP + +#include +#include +#include +#include +#include +#include + +struct NzRenderTextureImpl; + +class NAZARA_API NzRenderTexture : public NzRenderTarget, NzResourceListener, NzNonCopyable +{ + public: + NzRenderTexture() = default; + ~NzRenderTexture(); + + bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format); + bool AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture); + bool AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z); + + bool Create(unsigned int width, unsigned int height, bool lock = false); + void Destroy(); + + void Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index); + + unsigned int GetHeight() const; + NzRenderTargetParameters GetParameters() const; + unsigned int GetWidth() const; + + bool IsComplete() const; + bool IsRenderable() const; + bool IsValid() const; + + bool Lock() const; + void Unlock() const; + + // Fonctions OpenGL + bool HasContext() const; + + static bool IsSupported(); + + protected: + bool Activate() override; + void Desactivate() override; + + private: + void OnResourceDestroy(const NzResource* resource, int index) override; + + NzRenderTextureImpl* m_impl = nullptr; +}; + +#endif // NAZARA_RENDERTEXTURE_HPP diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index d9b932d09..fdef4b2c0 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -1,71 +1,68 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// Interface inspirée de la SFML par Laurent Gomila - -#pragma once - -#ifndef NAZARA_RENDERWINDOW_HPP -#define NAZARA_RENDERWINDOW_HPP - -#include -#include -#include -#include -#include -#include - -class NzContext; -class NzImage; -class NzTexture; -struct NzContextParameters; - -class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow -{ - public: - NzRenderWindow() = default; - NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); - NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); - virtual ~NzRenderWindow(); - - bool CopyToImage(NzImage* image); ///TODO: Const - bool CopyToTexture(NzTexture* texture); ///TODO: Const - - bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); - bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); - - void Display(); - - void EnableVerticalSync(bool enabled); - - #ifndef NAZARA_RENDERER_COMMON - NzContextParameters GetContextParameters() const; - #endif - - unsigned int GetHeight() const; - NzRenderTargetParameters GetParameters() const; - unsigned int GetWidth() const; - - #ifndef NAZARA_RENDERER_COMMON - bool HasContext() const; - #endif - - bool IsValid() const; - - void SetFramerateLimit(unsigned int limit); - - protected: - virtual bool Activate() override; - - private: - virtual void OnWindowDestroying() override; - virtual bool OnWindowCreated() override; - - NzClock m_clock; - NzContextParameters m_parameters; - NzContext* m_context = nullptr; - unsigned int m_framerateLimit = 0; -}; - -#endif // NAZARA_RENDERWINDOW_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Interface inspirée de la SFML par Laurent Gomila + +#pragma once + +#ifndef NAZARA_RENDERWINDOW_HPP +#define NAZARA_RENDERWINDOW_HPP + +#include +#include +#include +#include +#include +#include + +class NzContext; +class NzImage; +class NzTexture; +struct NzContextParameters; + +class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow +{ + public: + NzRenderWindow() = default; + NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); + NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); + virtual ~NzRenderWindow(); + + bool CopyToImage(NzImage* image); ///TODO: Const + bool CopyToTexture(NzTexture* texture); ///TODO: Const + + bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); + bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); + + void Display(); + + void EnableVerticalSync(bool enabled); + + unsigned int GetHeight() const; + NzRenderTargetParameters GetParameters() const; + unsigned int GetWidth() const; + + bool IsRenderable() const; + bool IsValid() const; + + void SetFramerateLimit(unsigned int limit); + + // Fonctions OpenGL + NzContextParameters GetContextParameters() const; + bool HasContext() const; + + protected: + bool Activate() override; + + private: + bool OnWindowCreated() override; + void OnWindowDestroy() override; + + NzClock m_clock; + NzContextParameters m_parameters; + NzContext* m_context = nullptr; + unsigned int m_framerateLimit = 0; +}; + +#endif // NAZARA_RENDERWINDOW_HPP diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index 0d9611865..9dc2e6222 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -1,89 +1,92 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_TEXTURE_HPP -#define NAZARA_TEXTURE_HPP - -#include -#include -#include -#include -#include - -struct NzTextureImpl; - -class NAZARA_API NzTexture : public NzResource, NzNonCopyable -{ - friend class NzShader; - - public: - NzTexture(); - explicit NzTexture(const NzImage& image); - ~NzTexture(); - - #ifndef NAZARA_RENDERER_COMMON - bool Bind() const; - #endif - - bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false); - void Destroy(); - - bool Download(NzImage* image) const; - - bool EnableMipmapping(bool enable); - - unsigned int GetAnisotropyLevel() const; - nzUInt8 GetBPP() const; - unsigned int GetDepth() const; - nzTextureFilter GetFilterMode() const; - nzPixelFormat GetFormat() const; - unsigned int GetHeight() const; - nzImageType GetType() const; - unsigned int GetWidth() const; - nzTextureWrap GetWrapMode() const; - - bool IsCompressed() const; - bool IsCubemap() const; - bool IsTarget() const; - bool IsValid() const; - - bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams()); - bool LoadFromImage(const NzImage& image); - bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams()); - bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams()); - - bool Lock(); - - bool SetAnisotropyLevel(unsigned int anistropyLevel); - bool SetFilterMode(nzTextureFilter filter); - bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel); - bool SetWrapMode(nzTextureWrap wrap); - - bool Update(const NzImage& image, nzUInt8 level = 0); - bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); - bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0); - - void Unlock(); - - static unsigned int GetValidSize(unsigned int size); - static bool IsFormatSupported(nzPixelFormat format); - static bool IsMipmappingSupported(); - static bool IsTypeSupported(nzImageType type); - - private: - void SetTarget(bool isTarget); - - NzTextureImpl* m_impl; -}; - -#endif // NAZARA_TEXTURE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_TEXTURE_HPP +#define NAZARA_TEXTURE_HPP + +#include +#include +#include +#include +#include + +class NzRenderTexture; +struct NzTextureImpl; + +class NAZARA_API NzTexture : public NzResource, NzNonCopyable +{ + friend NzRenderTexture; + friend class NzShader; + + public: + NzTexture(); + explicit NzTexture(const NzImage& image); + ~NzTexture(); + + bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false); + void Destroy(); + + bool Download(NzImage* image) const; + + bool EnableMipmapping(bool enable); + + unsigned int GetAnisotropyLevel() const; + nzUInt8 GetBPP() const; + unsigned int GetDepth() const; + nzTextureFilter GetFilterMode() const; + nzPixelFormat GetFormat() const; + unsigned int GetHeight() const; + nzImageType GetType() const; + unsigned int GetWidth() const; + nzTextureWrap GetWrapMode() const; + + bool IsCompressed() const; + bool IsCubemap() const; + bool IsTarget() const; + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams()); + bool LoadFromImage(const NzImage& image); + bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams()); + bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams()); + + bool Lock(); + + bool SetAnisotropyLevel(unsigned int anistropyLevel); + bool SetFilterMode(nzTextureFilter filter); + bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel); + bool SetWrapMode(nzTextureWrap wrap); + + bool Update(const NzImage& image, nzUInt8 level = 0); + bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); + bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0); + + void Unlock(); + + // Fonctions OpenGL + unsigned int GetOpenGLID() const; + bool Prepare() const; + + static unsigned int GetValidSize(unsigned int size); + static bool IsFormatSupported(nzPixelFormat format); + static bool IsMipmappingSupported(); + static bool IsTypeSupported(nzImageType type); + + private: + NzRenderTexture* GetRenderTexture() const; + void SetRenderTexture(NzRenderTexture* renderTexture); + + NzTextureImpl* m_impl; +}; + +#endif // NAZARA_TEXTURE_HPP diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index cc13bc7b2..c5403b9f3 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -1,77 +1,78 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ANIMATION_HPP -#define NAZARA_ANIMATION_HPP - -#include -#include -#include -#include -#include - -struct NzAnimationParams -{ - unsigned int endFrame = static_cast(-1); - unsigned int startFrame = 0; - - bool IsValid() const; -}; - -struct NzSequence -{ - NzString name; - unsigned int firstFrame; - unsigned int lastFrame; - unsigned int framePerSecond; -}; - -class NzAnimation; - -using NzAnimationLoader = NzResourceLoader; - -struct NzAnimationImpl; - -class NAZARA_API NzAnimation : public NzResource -{ - friend NzAnimationLoader; - - public: - NzAnimation() = default; - ~NzAnimation(); - - unsigned int AddSequence(const NzSequence& sequence); - - bool Create(nzAnimationType type, unsigned int frameCount); - void Destroy(); - - unsigned int GetFrameCount() const; - NzSequence* GetSequence(const NzString& sequenceName); - NzSequence* GetSequence(unsigned int index); - const NzSequence* GetSequence(const NzString& sequenceName) const; - const NzSequence* GetSequence(unsigned int index) const; - unsigned int GetSequenceCount() const; - nzAnimationType GetType() const; - - bool HasSequence(const NzString& sequenceName) const; - bool HasSequence(unsigned int index = 0) const; - - bool IsValid() const; - - bool LoadFromFile(const NzString& filePath, const NzAnimationParams& params = NzAnimationParams()); - bool LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params = NzAnimationParams()); - bool LoadFromStream(NzInputStream& stream, const NzAnimationParams& params = NzAnimationParams()); - - void RemoveSequence(const NzString& sequenceName); - void RemoveSequence(unsigned int index); - - private: - NzAnimationImpl* m_impl = nullptr; - - static NzAnimationLoader::LoaderList s_loaders; -}; - -#endif // NAZARA_ANIMATION_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ANIMATION_HPP +#define NAZARA_ANIMATION_HPP + +#include +#include +#include +#include +#include + +struct NzAnimationParams +{ + unsigned int endFrame = static_cast(-1); + unsigned int startFrame = 0; + + bool IsValid() const; +}; + +struct NzSequence +{ + NzString name; + unsigned int firstFrame; + unsigned int lastFrame; + unsigned int framePerSecond; +}; + +class NzAnimation; + +using NzAnimationLoader = NzResourceLoader; + +struct NzAnimationImpl; + +class NAZARA_API NzAnimation : public NzResource +{ + friend NzAnimationLoader; + + public: + NzAnimation() = default; + ~NzAnimation(); + + bool AddSequence(const NzSequence& sequence); + + bool Create(nzAnimationType type, unsigned int frameCount); + void Destroy(); + + unsigned int GetFrameCount() const; + NzSequence* GetSequence(const NzString& sequenceName); + NzSequence* GetSequence(unsigned int index); + const NzSequence* GetSequence(const NzString& sequenceName) const; + const NzSequence* GetSequence(unsigned int index) const; + unsigned int GetSequenceCount() const; + int GetSequenceIndex(const NzString& sequenceName) const; + nzAnimationType GetType() const; + + bool HasSequence(const NzString& sequenceName) const; + bool HasSequence(unsigned int index = 0) const; + + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzAnimationParams& params = NzAnimationParams()); + bool LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params = NzAnimationParams()); + bool LoadFromStream(NzInputStream& stream, const NzAnimationParams& params = NzAnimationParams()); + + void RemoveSequence(const NzString& sequenceName); + void RemoveSequence(unsigned int index); + + private: + NzAnimationImpl* m_impl = nullptr; + + static NzAnimationLoader::LoaderList s_loaders; +}; + +#endif // NAZARA_ANIMATION_HPP diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 9d044c7c1..8cf5bd786 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -1,220 +1,250 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_UTILITY_HPP -#define NAZARA_ENUMS_UTILITY_HPP - -enum nzAnimationType -{ - nzAnimationType_Keyframe, - nzAnimationType_Skeletal, - nzAnimationType_Static -}; - -enum nzBufferAccess -{ - nzBufferAccess_DiscardAndWrite, - nzBufferAccess_ReadOnly, - nzBufferAccess_ReadWrite, - nzBufferAccess_WriteOnly -}; - -enum nzBufferStorage -{ - //nzBufferStorage_Both, - nzBufferStorage_Hardware, - nzBufferStorage_Software, - - nzBufferStorage_Max = nzBufferStorage_Software -}; - -enum nzBufferType -{ - nzBufferType_Index, - nzBufferType_Vertex -}; - -enum nzBufferUsage -{ - nzBufferUsage_Dynamic, - nzBufferUsage_Static -}; - -enum nzCubemapFace -{ - // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap - // L'ordre est X, -X, Y, -Y, Z, -Z - nzCubemapFace_PositiveX = 0, - nzCubemapFace_PositiveY = 2, - nzCubemapFace_PositiveZ = 4, - nzCubemapFace_NegativeX = 1, - nzCubemapFace_NegativeY = 3, - nzCubemapFace_NegativeZ = 5 -}; - -enum nzElementStream -{ - nzElementStream_VertexData, - nzElementStream_InstancedData, - - nzElementStream_Max = nzElementStream_InstancedData -}; - -enum nzElementType -{ - nzElementType_Color, - nzElementType_Double1, - nzElementType_Double2, - nzElementType_Double3, - nzElementType_Double4, - nzElementType_Float1, - nzElementType_Float2, - nzElementType_Float3, - nzElementType_Float4 -}; - -enum nzElementUsage -{ - nzElementUsage_Diffuse, - nzElementUsage_Normal, - nzElementUsage_Position, - nzElementUsage_Tangent, - nzElementUsage_TexCoord, - - nzElementUsage_Max = nzElementUsage_TexCoord -}; - -enum nzEventType -{ - nzEventType_GainedFocus, - nzEventType_LostFocus, - nzEventType_KeyPressed, - nzEventType_KeyReleased, - nzEventType_MouseButtonDoubleClicked, - nzEventType_MouseButtonPressed, - nzEventType_MouseButtonReleased, - nzEventType_MouseEntered, - nzEventType_MouseLeft, - nzEventType_MouseMoved, - nzEventType_MouseWheelMoved, - nzEventType_Moved, - nzEventType_Quit, - nzEventType_Resized, - nzEventType_TextEntered -}; - -enum nzExtend -{ - nzExtend_Finite, - nzExtend_Infinite, - nzExtend_Null -}; - -enum nzImageType -{ - nzImageType_1D, - nzImageType_1D_Array, - nzImageType_2D, - nzImageType_2D_Array, - nzImageType_3D, - nzImageType_Cubemap, - - nzImageType_Max = nzImageType_Cubemap -}; - -enum nzPixelFormat -{ - nzPixelFormat_Undefined = -1, - - nzPixelFormat_BGR8, // 3*nzUInt8 - nzPixelFormat_BGRA8, // 4*nzUInt8 - nzPixelFormat_DXT1, - nzPixelFormat_DXT3, - nzPixelFormat_DXT5, - nzPixelFormat_L8, // 1*nzUInt8 - nzPixelFormat_LA8, // 2*nzUInt8 - /* - nzPixelFormat_RGB16F, - nzPixelFormat_RGB16I, // 4*nzUInt16 - nzPixelFormat_RGB32F, - nzPixelFormat_RGB32I, // 4*nzUInt32 - nzPixelFormat_RGBA16F, - nzPixelFormat_RGBA16I, // 4*nzUInt16 - nzPixelFormat_RGBA32F, - nzPixelFormat_RGBA32I, // 4*nzUInt32 - */ - nzPixelFormat_RGBA4, // 1*nzUInt16 - nzPixelFormat_RGB5A1, // 1*nzUInt16 - nzPixelFormat_RGB8, // 3*nzUInt8 - nzPixelFormat_RGBA8, // 4*nzUInt8 - /* - nzPixelFormat_Depth16, - nzPixelFormat_Depth24, - nzPixelFormat_Depth24Stencil8, - nzPixelFormat_Depth32, - nzPixelFormat_Stencil1, - nzPixelFormat_Stencil4, - nzPixelFormat_Stencil8, - nzPixelFormat_Stencil16, - */ - - nzPixelFormat_Max = nzPixelFormat_RGBA8 -}; - -enum nzPixelFlipping -{ - nzPixelFlipping_Horizontally, - nzPixelFlipping_Vertically, - - nzPixelFlipping_Max = nzPixelFlipping_Vertically -}; - -enum nzPrimitiveType -{ - nzPrimitiveType_LineList, - nzPrimitiveType_LineStrip, - nzPrimitiveType_PointList, - nzPrimitiveType_TriangleList, - nzPrimitiveType_TriangleStrip, - nzPrimitiveType_TriangleFan -}; - -enum nzWindowCursor -{ - nzWindowCursor_None, - nzWindowCursor_Default, - - nzWindowCursor_Crosshair, - nzWindowCursor_Hand, - nzWindowCursor_Help, - nzWindowCursor_Move, - nzWindowCursor_Pointer, - nzWindowCursor_Progress, - nzWindowCursor_ResizeE, - nzWindowCursor_ResizeN, - nzWindowCursor_ResizeNE, - nzWindowCursor_ResizeNW, - nzWindowCursor_ResizeS, - nzWindowCursor_ResizeSE, - nzWindowCursor_ResizeSW, - nzWindowCursor_ResizeW, - nzWindowCursor_Text, - nzWindowCursor_Wait -}; - -enum nzWindowStyle -{ - nzWindowStyle_None = 0x0, - nzWindowStyle_Fullscreen = 0x1, - - nzWindowStyle_Closable = 0x2, - nzWindowStyle_Resizable = 0x4, - nzWindowStyle_Titlebar = 0x4, - - nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar -}; - -#endif // NAZARA_ENUMS_UTILITY_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_UTILITY_HPP +#define NAZARA_ENUMS_UTILITY_HPP + +enum nzAnimationType +{ + nzAnimationType_Keyframe, + nzAnimationType_Skeletal, + nzAnimationType_Static, + + nzAnimationType_Max = nzAnimationType_Static +}; + +enum nzBufferAccess +{ + nzBufferAccess_DiscardAndWrite, + nzBufferAccess_ReadOnly, + nzBufferAccess_ReadWrite, + nzBufferAccess_WriteOnly, + + nzBufferAccess_Max = nzBufferAccess_WriteOnly +}; + +enum nzBufferStorage +{ + //nzBufferStorage_Both, + nzBufferStorage_Hardware, + nzBufferStorage_Software, + + nzBufferStorage_Max = nzBufferStorage_Software +}; + +enum nzBufferType +{ + nzBufferType_Index, + nzBufferType_Vertex, + + nzBufferType_Max = nzBufferType_Vertex +}; + +enum nzBufferUsage +{ + nzBufferUsage_Dynamic, + nzBufferUsage_Static, + + nzBufferUsage_Max = nzBufferUsage_Static +}; + +enum nzCubemapFace +{ + // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap + // L'ordre est X, -X, Y, -Y, Z, -Z + nzCubemapFace_PositiveX = 0, + nzCubemapFace_PositiveY = 2, + nzCubemapFace_PositiveZ = 4, + nzCubemapFace_NegativeX = 1, + nzCubemapFace_NegativeY = 3, + nzCubemapFace_NegativeZ = 5, + + nzCubemapFace_Max = nzCubemapFace_NegativeZ +}; + +enum nzElementStream +{ + nzElementStream_VertexData, + nzElementStream_InstancedData, + + nzElementStream_Max = nzElementStream_InstancedData +}; + +enum nzElementType +{ + nzElementType_Color, + nzElementType_Double1, + nzElementType_Double2, + nzElementType_Double3, + nzElementType_Double4, + nzElementType_Float1, + nzElementType_Float2, + nzElementType_Float3, + nzElementType_Float4, + + nzElementType_Max = nzElementType_Float4 +}; + +enum nzElementUsage +{ + nzElementUsage_Diffuse, + nzElementUsage_Normal, + nzElementUsage_Position, + nzElementUsage_Tangent, + nzElementUsage_TexCoord, + + nzElementUsage_Max = nzElementUsage_TexCoord +}; + +enum nzEventType +{ + nzEventType_GainedFocus, + nzEventType_LostFocus, + nzEventType_KeyPressed, + nzEventType_KeyReleased, + nzEventType_MouseButtonDoubleClicked, + nzEventType_MouseButtonPressed, + nzEventType_MouseButtonReleased, + nzEventType_MouseEntered, + nzEventType_MouseLeft, + nzEventType_MouseMoved, + nzEventType_MouseWheelMoved, + nzEventType_Moved, + nzEventType_Quit, + nzEventType_Resized, + nzEventType_TextEntered, + + nzEventType_Max = nzEventType_TextEntered +}; + +enum nzExtend +{ + nzExtend_Finite, + nzExtend_Infinite, + nzExtend_Null, + + nzExtend_Max = nzExtend_Null +}; + +enum nzImageType +{ + nzImageType_1D, + nzImageType_1D_Array, + nzImageType_2D, + nzImageType_2D_Array, + nzImageType_3D, + nzImageType_Cubemap, + + nzImageType_Max = nzImageType_Cubemap +}; + +enum nzPixelFormat +{ + nzPixelFormat_Undefined = -1, + + nzPixelFormat_BGR8, // 3*nzUInt8 + nzPixelFormat_BGRA8, // 4*nzUInt8 + nzPixelFormat_DXT1, + nzPixelFormat_DXT3, + nzPixelFormat_DXT5, + nzPixelFormat_L8, // 1*nzUInt8 + nzPixelFormat_LA8, // 2*nzUInt8 + /* + nzPixelFormat_RGB16F, + nzPixelFormat_RGB16I, // 4*nzUInt16 + nzPixelFormat_RGB32F, + nzPixelFormat_RGB32I, // 4*nzUInt32 + nzPixelFormat_RGBA16F, + nzPixelFormat_RGBA16I, // 4*nzUInt16 + nzPixelFormat_RGBA32F, + nzPixelFormat_RGBA32I, // 4*nzUInt32 + */ + nzPixelFormat_RGBA4, // 1*nzUInt16 + nzPixelFormat_RGB5A1, // 1*nzUInt16 + nzPixelFormat_RGB8, // 3*nzUInt8 + nzPixelFormat_RGBA8, // 4*nzUInt8 + nzPixelFormat_Depth16, + nzPixelFormat_Depth24, + nzPixelFormat_Depth24Stencil8, + nzPixelFormat_Depth32, + nzPixelFormat_Stencil1, + nzPixelFormat_Stencil4, + nzPixelFormat_Stencil8, + nzPixelFormat_Stencil16, + + nzPixelFormat_Max = nzPixelFormat_Stencil16 +}; + +enum nzPixelFormatType +{ + nzPixelFormatType_Undefined = -1, + + nzPixelFormatType_Color, + nzPixelFormatType_Depth, + nzPixelFormatType_DepthStencil, + nzPixelFormatType_Stencil, + + nzPixelFormatType_Max = nzPixelFormatType_Stencil +}; + +enum nzPixelFlipping +{ + nzPixelFlipping_Horizontally, + nzPixelFlipping_Vertically, + + nzPixelFlipping_Max = nzPixelFlipping_Vertically +}; + +enum nzPrimitiveType +{ + nzPrimitiveType_LineList, + nzPrimitiveType_LineStrip, + nzPrimitiveType_PointList, + nzPrimitiveType_TriangleList, + nzPrimitiveType_TriangleStrip, + nzPrimitiveType_TriangleFan, + + nzPrimitiveType_Max = nzPrimitiveType_TriangleFan +}; + +enum nzWindowCursor +{ + nzWindowCursor_None, + nzWindowCursor_Default, + + nzWindowCursor_Crosshair, + nzWindowCursor_Hand, + nzWindowCursor_Help, + nzWindowCursor_Move, + nzWindowCursor_Pointer, + nzWindowCursor_Progress, + nzWindowCursor_ResizeE, + nzWindowCursor_ResizeN, + nzWindowCursor_ResizeNE, + nzWindowCursor_ResizeNW, + nzWindowCursor_ResizeS, + nzWindowCursor_ResizeSE, + nzWindowCursor_ResizeSW, + nzWindowCursor_ResizeW, + nzWindowCursor_Text, + nzWindowCursor_Wait, + + nzWindowCursor_Max = nzWindowCursor_Wait +}; + +enum nzWindowStyleFlags +{ + nzWindowStyle_None = 0x0, + nzWindowStyle_Fullscreen = 0x1, + + nzWindowStyle_Closable = 0x2, + nzWindowStyle_Resizable = 0x4, + nzWindowStyle_Titlebar = 0x4, + + nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar +}; + +#endif // NAZARA_ENUMS_UTILITY_HPP diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index c8ca8b814..de8f071f7 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -1,93 +1,98 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MESH_HPP -#define NAZARA_MESH_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -class NzVertexDeclaration; - -struct NzMeshParams -{ - NzAnimationParams animation; - //const NzVertexDeclaration* declaration = nullptr; - nzBufferStorage storage = nzBufferStorage_Hardware; - bool loadAnimations = true; - - bool IsValid() const; -}; - -class NzMesh; - -using NzMeshLoader = NzResourceLoader; - -struct NzMeshImpl; - -class NAZARA_API NzMesh : public NzResource -{ - friend NzMeshLoader; - - public: - NzMesh() = default; - ~NzMesh(); - - unsigned int AddSkin(const NzString& skin, bool setDefault = false); - nzUInt8 AddSubMesh(NzSubMesh* subMesh); - nzUInt8 AddSubMesh(const NzString& identifier, NzSubMesh* subMesh); - - void Animate(unsigned int frameA, unsigned int frameB, float interpolation); - - bool Create(nzAnimationType type); - void Destroy(); - - const NzAxisAlignedBox& GetAABB() const; - const NzAnimation* GetAnimation() const; - nzAnimationType GetAnimationType() const; - unsigned int GetFrameCount() const; - NzString GetSkin(unsigned int index = 0) const; - unsigned int GetSkinCount() const; - NzSubMesh* GetSubMesh(const NzString& identifier); - NzSubMesh* GetSubMesh(nzUInt8 index); - const NzSubMesh* GetSubMesh(const NzString& identifier) const; - const NzSubMesh* GetSubMesh(nzUInt8 index) const; - nzUInt8 GetSubMeshCount() const; - unsigned int GetVertexCount() const; - - bool HasAnimation() const; - bool HasSkin(unsigned int index = 0) const; - bool HasSubMesh(const NzString& identifier) const; - bool HasSubMesh(nzUInt8 index = 0) const; - - void InvalidateAABB() const; - - bool IsAnimable() const; - bool IsValid() const; - - bool LoadFromFile(const NzString& filePath, const NzMeshParams& params = NzMeshParams()); - bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams()); - bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams()); - - void RemoveSkin(unsigned int index = 0); - void RemoveSubMesh(const NzString& identifier); - void RemoveSubMesh(nzUInt8 index = 0); - - bool SetAnimation(const NzAnimation* animation); - - private: - NzMeshImpl* m_impl = nullptr; - - static NzMeshLoader::LoaderList s_loaders; -}; - -#endif // NAZARA_MESH_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_MESH_HPP +#define NAZARA_MESH_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class NzVertexDeclaration; + +struct NzMeshParams +{ + NzAnimationParams animation; + //const NzVertexDeclaration* declaration = nullptr; + nzBufferStorage storage = nzBufferStorage_Hardware; + bool loadAnimations = true; + + bool IsValid() const; +}; + +class NzMesh; + +using NzMeshLoader = NzResourceLoader; + +struct NzMeshImpl; + +class NAZARA_API NzMesh : public NzResource, NzResourceListener +{ + friend NzMeshLoader; + + public: + NzMesh() = default; + ~NzMesh(); + + bool AddSkin(const NzString& skin, bool setDefault = false); + bool AddSubMesh(NzSubMesh* subMesh); + bool AddSubMesh(const NzString& identifier, NzSubMesh* subMesh); + + void Animate(unsigned int frameA, unsigned int frameB, float interpolation); + + bool Create(nzAnimationType type); + void Destroy(); + + const NzAxisAlignedBox& GetAABB() const; + const NzAnimation* GetAnimation() const; + nzAnimationType GetAnimationType() const; + unsigned int GetFrameCount() const; + NzString GetSkin(unsigned int index = 0) const; + unsigned int GetSkinCount() const; + NzSubMesh* GetSubMesh(const NzString& identifier); + NzSubMesh* GetSubMesh(unsigned int index); + const NzSubMesh* GetSubMesh(const NzString& identifier) const; + const NzSubMesh* GetSubMesh(unsigned int index) const; + unsigned int GetSubMeshCount() const; + int GetSubMeshIndex(const NzString& identifier) const; + unsigned int GetVertexCount() const; + + bool HasAnimation() const; + bool HasSkin(unsigned int index = 0) const; + bool HasSubMesh(const NzString& identifier) const; + bool HasSubMesh(unsigned int index = 0) const; + + void InvalidateAABB() const; + + bool IsAnimable() const; + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzMeshParams& params = NzMeshParams()); + bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams()); + bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams()); + + void RemoveSkin(unsigned int index = 0); + void RemoveSubMesh(const NzString& identifier); + void RemoveSubMesh(unsigned int index = 0); + + bool SetAnimation(const NzAnimation* animation); + + private: + void OnResourceCreated(const NzResource* resource, int index) override; + void OnResourceReleased(const NzResource* resource, int index) override; + + NzMeshImpl* m_impl = nullptr; + + static NzMeshLoader::LoaderList s_loaders; +}; + +#endif // NAZARA_MESH_HPP diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 396fa8056..646f91e55 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -1,53 +1,54 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PIXELFORMAT_HPP -#define NAZARA_PIXELFORMAT_HPP - -#include -#include -#include -#include - -class NzUtility; - -class NzPixelFormat -{ - friend class NzUtility; - - public: - using ConvertFunction = nzUInt8* (*)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst); - using FlipFunction = void (*)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst); - - static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst); - static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst); - - static bool Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); - - static nzUInt8 GetBPP(nzPixelFormat format); - - static bool HasAlpha(nzPixelFormat format); - - static bool IsCompressed(nzPixelFormat format); - static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat); - static bool IsValid(nzPixelFormat format); - - static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func); - static void SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func); - - static NzString ToString(nzPixelFormat format); - - private: - static bool Initialize(); - static void Uninitialize(); - - static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1]; - static NAZARA_API std::map s_flipFunctions[nzPixelFlipping_Max+1]; -}; - -#include - -#endif // NAZARA_PIXELFORMAT_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_PIXELFORMAT_HPP +#define NAZARA_PIXELFORMAT_HPP + +#include +#include +#include +#include + +class NzUtility; + +class NzPixelFormat +{ + friend class NzUtility; + + public: + using ConvertFunction = nzUInt8* (*)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst); + using FlipFunction = void (*)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst); + + static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst); + static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst); + + static bool Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); + + static nzUInt8 GetBPP(nzPixelFormat format); + static nzPixelFormatType GetType(nzPixelFormat format); + + static bool HasAlpha(nzPixelFormat format); + + static bool IsCompressed(nzPixelFormat format); + static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat); + static bool IsValid(nzPixelFormat format); + + static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func); + static void SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func); + + static NzString ToString(nzPixelFormat format); + + private: + static bool Initialize(); + static void Uninitialize(); + + static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1]; + static NAZARA_API std::map s_flipFunctions[nzPixelFlipping_Max+1]; +}; + +#include + +#endif // NAZARA_PIXELFORMAT_HPP diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index 9660a3d63..8f3335af0 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -1,371 +1,487 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst) -{ - if (srcFormat == dstFormat) - { - std::memcpy(dst, src, GetBPP(srcFormat)); - return true; - } - - #if NAZARA_UTILITY_SAFE - if (IsCompressed(srcFormat)) - { - NazaraError("Cannot convert single pixel from compressed format"); - return false; - } - - if (IsCompressed(dstFormat)) - { - NazaraError("Cannot convert single pixel to compressed format"); - return false; - } - #endif - - ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; - if (!func) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); - return false; - } - - if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBPP(srcFormat), reinterpret_cast(dst))) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); - return false; - } - - return true; -} - -inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst) -{ - if (srcFormat == dstFormat) - { - std::memcpy(dst, start, reinterpret_cast(end)-reinterpret_cast(start)); - return true; - } - - ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; - if (!func) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); - return false; - } - - if (!func(reinterpret_cast(start), reinterpret_cast(end), reinterpret_cast(dst))) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); - return false; - } - - return true; -} - -inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst) -{ - #if NAZARA_UTILITY_SAFE - if (!IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - #endif - - auto it = s_flipFunctions[flipping].find(format); - if (it != s_flipFunctions[flipping].end()) - it->second(width, height, depth, reinterpret_cast(src), reinterpret_cast(dst)); - else - { - // Flipping générique - - #if NAZARA_UTILITY_SAFE - if (IsCompressed(format)) - { - NazaraError("No function to flip compressed format"); - return false; - } - #endif - - nzUInt8 bpp = GetBPP(format); - unsigned int lineStride = width*bpp; - switch (flipping) - { - case nzPixelFlipping_Horizontally: - { - if (src == dst) - { - for (unsigned int z = 0; z < depth; ++z) - { - nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; - for (unsigned int y = 0; y < height; ++y) - { - for (unsigned int x = 0; x < width/2; ++x) - std::swap_ranges(&ptr[x*bpp], &ptr[(x+1)*bpp], &ptr[(width-x)*bpp]); - - ptr += lineStride; - } - } - } - else - { - for (unsigned int z = 0; z < depth; ++z) - { - nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; - for (unsigned int y = 0; y < height; ++y) - { - for (unsigned int x = 0; x < width; ++x) - std::memcpy(&ptr[x*bpp], &ptr[(width-x)*bpp], bpp); - - ptr += lineStride; - } - } - } - break; - } - - case nzPixelFlipping_Vertically: - { - if (src == dst) - { - for (unsigned int z = 0; z < depth; ++z) - { - nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; - for (unsigned int y = 0; y < height/2; ++y) - std::swap_ranges(&ptr[y*lineStride], &ptr[(y+1)*lineStride-1], &ptr[(height-y-1)*lineStride]); - } - } - else - { - for (unsigned int z = 0; z < depth; ++z) - { - const nzUInt8* srcPtr = reinterpret_cast(src); - nzUInt8* dstPtr = reinterpret_cast(dst) + (width-1)*height*depth*bpp; - for (unsigned int y = 0; y < height; ++y) - { - std::memcpy(dstPtr, srcPtr, lineStride); - - srcPtr += lineStride; - dstPtr -= lineStride; - } - } - } - break; - } - } - } - - return true; -} - -inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGR8: - return 3; - - case nzPixelFormat_BGRA8: - return 4; - - case nzPixelFormat_DXT1: - return 1; - - case nzPixelFormat_DXT3: - return 2; - - case nzPixelFormat_DXT5: - return 2; - - case nzPixelFormat_L8: - return 1; - - case nzPixelFormat_LA8: - return 2; -/* - case nzPixelFormat_RGB16F: - return 6; - - case nzPixelFormat_RGB16I: - return 6; - - case nzPixelFormat_RGB32F: - return 12; - - case nzPixelFormat_RGB32I: - return 12; - - case nzPixelFormat_RGBA16F: - return 8; - - case nzPixelFormat_RGBA16I: - return 8; - - case nzPixelFormat_RGBA32F: - return 16; - - case nzPixelFormat_RGBA32I: - return 16; -*/ - case nzPixelFormat_RGBA4: - return 2; - - case nzPixelFormat_RGB5A1: - return 2; - - case nzPixelFormat_RGB8: - return 3; - - case nzPixelFormat_RGBA8: - return 4; - - case nzPixelFormat_Undefined: - NazaraError("Invalid pixel format"); - return 0; - } - - NazaraInternalError("Invalid pixel format"); - - return 0; -} - -inline bool NzPixelFormat::HasAlpha(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGRA8: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - case nzPixelFormat_LA8: - case nzPixelFormat_RGB5A1: - case nzPixelFormat_RGBA4: - case nzPixelFormat_RGBA8: - return true; - - case nzPixelFormat_BGR8: - case nzPixelFormat_DXT1: - case nzPixelFormat_L8: - case nzPixelFormat_RGB8: - return false; - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return false; -} - -inline bool NzPixelFormat::IsCompressed(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_DXT1: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - return true; - - default: - return false; - } -} - -inline bool NzPixelFormat::IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat) -{ - if (srcFormat == dstFormat) - return true; - - return s_convertFunctions[srcFormat][dstFormat] != nullptr; -} - -inline bool NzPixelFormat::IsValid(nzPixelFormat format) -{ - return format != nzPixelFormat_Undefined; -} - -inline void NzPixelFormat::SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func) -{ - s_convertFunctions[srcFormat][dstFormat] = func; -} - -inline void NzPixelFormat::SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func) -{ - s_flipFunctions[flipping][format] = func; -} - -inline NzString NzPixelFormat::ToString(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGR8: - return "BGR8"; - - case nzPixelFormat_BGRA8: - return "BGRA8"; - - case nzPixelFormat_DXT1: - return "DXT1"; - - case nzPixelFormat_DXT3: - return "DXT3"; - - case nzPixelFormat_DXT5: - return "DXT5"; - - case nzPixelFormat_L8: - return "L8"; - - case nzPixelFormat_LA8: - return "LA8"; -/* - case nzPixelFormat_RGB16F: - return "RGB16F"; - - case nzPixelFormat_RGB16I: - return "RGB16I"; - - case nzPixelFormat_RGB32F: - return "RGB32F"; - - case nzPixelFormat_RGB32I: - return "RGB32I"; - - case nzPixelFormat_RGBA16F: - return "RGBA16F"; - - case nzPixelFormat_RGBA16I: - return "RGBA16I"; - - case nzPixelFormat_RGBA32F: - return "RGBA32F"; - - case nzPixelFormat_RGBA32I: - return "RGBA32I"; -*/ - case nzPixelFormat_RGBA4: - return "RGBA4"; - - case nzPixelFormat_RGB5A1: - return "RGB5A1"; - - case nzPixelFormat_RGB8: - return "RGB8"; - - case nzPixelFormat_RGBA8: - return "RGBA8"; - - case nzPixelFormat_Undefined: - return "Undefined"; - } - - NazaraError("Invalid pixel format"); - return "Invalid format"; -} - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst) +{ + if (srcFormat == dstFormat) + { + std::memcpy(dst, src, GetBPP(srcFormat)); + return true; + } + + #if NAZARA_UTILITY_SAFE + if (IsCompressed(srcFormat)) + { + NazaraError("Cannot convert single pixel from compressed format"); + return false; + } + + if (IsCompressed(dstFormat)) + { + NazaraError("Cannot convert single pixel to compressed format"); + return false; + } + #endif + + ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; + if (!func) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); + return false; + } + + if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBPP(srcFormat), reinterpret_cast(dst))) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); + return false; + } + + return true; +} + +inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst) +{ + if (srcFormat == dstFormat) + { + std::memcpy(dst, start, reinterpret_cast(end)-reinterpret_cast(start)); + return true; + } + + ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; + if (!func) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); + return false; + } + + if (!func(reinterpret_cast(start), reinterpret_cast(end), reinterpret_cast(dst))) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); + return false; + } + + return true; +} + +inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst) +{ + #if NAZARA_UTILITY_SAFE + if (!IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + #endif + + auto it = s_flipFunctions[flipping].find(format); + if (it != s_flipFunctions[flipping].end()) + it->second(width, height, depth, reinterpret_cast(src), reinterpret_cast(dst)); + else + { + // Flipping générique + + #if NAZARA_UTILITY_SAFE + if (IsCompressed(format)) + { + NazaraError("No function to flip compressed format"); + return false; + } + #endif + + nzUInt8 bpp = GetBPP(format); + unsigned int lineStride = width*bpp; + switch (flipping) + { + case nzPixelFlipping_Horizontally: + { + if (src == dst) + { + for (unsigned int z = 0; z < depth; ++z) + { + nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; + for (unsigned int y = 0; y < height; ++y) + { + for (unsigned int x = 0; x < width/2; ++x) + std::swap_ranges(&ptr[x*bpp], &ptr[(x+1)*bpp], &ptr[(width-x)*bpp]); + + ptr += lineStride; + } + } + } + else + { + for (unsigned int z = 0; z < depth; ++z) + { + nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; + for (unsigned int y = 0; y < height; ++y) + { + for (unsigned int x = 0; x < width; ++x) + std::memcpy(&ptr[x*bpp], &ptr[(width-x)*bpp], bpp); + + ptr += lineStride; + } + } + } + break; + } + + case nzPixelFlipping_Vertically: + { + if (src == dst) + { + for (unsigned int z = 0; z < depth; ++z) + { + nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; + for (unsigned int y = 0; y < height/2; ++y) + std::swap_ranges(&ptr[y*lineStride], &ptr[(y+1)*lineStride-1], &ptr[(height-y-1)*lineStride]); + } + } + else + { + for (unsigned int z = 0; z < depth; ++z) + { + const nzUInt8* srcPtr = reinterpret_cast(src); + nzUInt8* dstPtr = reinterpret_cast(dst) + (width-1)*height*depth*bpp; + for (unsigned int y = 0; y < height; ++y) + { + std::memcpy(dstPtr, srcPtr, lineStride); + + srcPtr += lineStride; + dstPtr -= lineStride; + } + } + } + break; + } + } + } + + return true; +} + +inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGR8: + return 3; + + case nzPixelFormat_BGRA8: + return 4; + + case nzPixelFormat_DXT1: + return 1; + + case nzPixelFormat_DXT3: + return 2; + + case nzPixelFormat_DXT5: + return 2; + + case nzPixelFormat_L8: + return 1; + + case nzPixelFormat_LA8: + return 2; +/* + case nzPixelFormat_RGB16F: + return 6; + + case nzPixelFormat_RGB16I: + return 6; + + case nzPixelFormat_RGB32F: + return 12; + + case nzPixelFormat_RGB32I: + return 12; + + case nzPixelFormat_RGBA16F: + return 8; + + case nzPixelFormat_RGBA16I: + return 8; + + case nzPixelFormat_RGBA32F: + return 16; + + case nzPixelFormat_RGBA32I: + return 16; +*/ + case nzPixelFormat_RGBA4: + return 2; + + case nzPixelFormat_RGB5A1: + return 2; + + case nzPixelFormat_RGB8: + return 3; + + case nzPixelFormat_RGBA8: + return 4; + + case nzPixelFormat_Depth16: + return 2; + + case nzPixelFormat_Depth24: + return 3; + + case nzPixelFormat_Depth24Stencil8: + return 4; + + case nzPixelFormat_Depth32: + return 4; + + case nzPixelFormat_Stencil1: + NazaraWarning("This format uses less than one byte per pixel"); + return 0; + + case nzPixelFormat_Stencil4: + NazaraWarning("This format uses less than one byte per pixel"); + return 0; + + case nzPixelFormat_Stencil8: + return 1; + + case nzPixelFormat_Stencil16: + return 2; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return 0; +} + +inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGR8: + case nzPixelFormat_BGRA8: + case nzPixelFormat_DXT1: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGB8: + case nzPixelFormat_RGBA4: + case nzPixelFormat_RGBA8: + return nzPixelFormatType_Color; + + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth32: + return nzPixelFormatType_Depth; + + case nzPixelFormat_Depth24Stencil8: + return nzPixelFormatType_DepthStencil; + + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return nzPixelFormatType_Stencil; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return nzPixelFormatType_Undefined; +} + +inline bool NzPixelFormat::HasAlpha(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGRA8: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + case nzPixelFormat_LA8: + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGBA4: + case nzPixelFormat_RGBA8: + return true; + + case nzPixelFormat_BGR8: + case nzPixelFormat_DXT1: + case nzPixelFormat_L8: + case nzPixelFormat_RGB8: + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth24Stencil8: + case nzPixelFormat_Depth32: + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return false; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return false; +} + +inline bool NzPixelFormat::IsCompressed(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_DXT1: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + return true; + + case nzPixelFormat_BGRA8: + case nzPixelFormat_LA8: + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGBA4: + case nzPixelFormat_RGBA8: + case nzPixelFormat_BGR8: + case nzPixelFormat_L8: + case nzPixelFormat_RGB8: + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth24Stencil8: + case nzPixelFormat_Depth32: + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return false; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return false; +} + +inline bool NzPixelFormat::IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat) +{ + if (srcFormat == dstFormat) + return true; + + return s_convertFunctions[srcFormat][dstFormat] != nullptr; +} + +inline bool NzPixelFormat::IsValid(nzPixelFormat format) +{ + return format != nzPixelFormat_Undefined; +} + +inline void NzPixelFormat::SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func) +{ + s_convertFunctions[srcFormat][dstFormat] = func; +} + +inline void NzPixelFormat::SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func) +{ + s_flipFunctions[flipping][format] = func; +} + +inline NzString NzPixelFormat::ToString(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGR8: + return "BGR8"; + + case nzPixelFormat_BGRA8: + return "BGRA8"; + + case nzPixelFormat_DXT1: + return "DXT1"; + + case nzPixelFormat_DXT3: + return "DXT3"; + + case nzPixelFormat_DXT5: + return "DXT5"; + + case nzPixelFormat_L8: + return "L8"; + + case nzPixelFormat_LA8: + return "LA8"; +/* + case nzPixelFormat_RGB16F: + return "RGB16F"; + + case nzPixelFormat_RGB16I: + return "RGB16I"; + + case nzPixelFormat_RGB32F: + return "RGB32F"; + + case nzPixelFormat_RGB32I: + return "RGB32I"; + + case nzPixelFormat_RGBA16F: + return "RGBA16F"; + + case nzPixelFormat_RGBA16I: + return "RGBA16I"; + + case nzPixelFormat_RGBA32F: + return "RGBA32F"; + + case nzPixelFormat_RGBA32I: + return "RGBA32I"; +*/ + case nzPixelFormat_RGBA4: + return "RGBA4"; + + case nzPixelFormat_RGB5A1: + return "RGB5A1"; + + case nzPixelFormat_RGB8: + return "RGB8"; + + case nzPixelFormat_RGBA8: + return "RGBA8"; + + case nzPixelFormat_Depth16: + return "Depth16"; + + case nzPixelFormat_Depth24: + return "Depth24"; + + case nzPixelFormat_Depth24Stencil8: + return "Depth24Stencil8"; + + case nzPixelFormat_Depth32: + return "Depth32"; + + case nzPixelFormat_Stencil1: + return "Stencil1"; + + case nzPixelFormat_Stencil4: + return "Stencil4"; + + case nzPixelFormat_Stencil8: + return "Stencil8"; + + case nzPixelFormat_Stencil16: + return "Stencil16"; + + case nzPixelFormat_Undefined: + return "Undefined"; + } + + NazaraError("Invalid pixel format"); + return "Invalid format"; +} + +#include diff --git a/include/Nazara/Utility/StaticMesh.hpp b/include/Nazara/Utility/StaticMesh.hpp index 2d8ae3ec1..745ec1471 100644 --- a/include/Nazara/Utility/StaticMesh.hpp +++ b/include/Nazara/Utility/StaticMesh.hpp @@ -1,49 +1,51 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_STATICMESH_HPP -#define NAZARA_STATICMESH_HPP - -#include -#include - -class NAZARA_API NzStaticMesh final : public NzSubMesh -{ - public: - NzStaticMesh(const NzMesh* parent); - NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); - virtual ~NzStaticMesh(); - - bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); - void Destroy(); - - bool GenerateAABB(); - - const NzAxisAlignedBox& GetAABB() const; - nzAnimationType GetAnimationType() const; - unsigned int GetFrameCount() const; - const NzIndexBuffer* GetIndexBuffer() const; - nzPrimitiveType GetPrimitiveType() const; - const NzVertexBuffer* GetVertexBuffer() const; - const NzVertexDeclaration* GetVertexDeclaration() const; - - bool IsAnimated() const; - bool IsValid() const; - - void SetAABB(const NzAxisAlignedBox& aabb); - void SetPrimitiveType(nzPrimitiveType primitiveType); - - private: - void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation); - - nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList; - NzAxisAlignedBox m_aabb; - NzIndexBuffer* m_indexBuffer = nullptr; - NzVertexBuffer* m_vertexBuffer = nullptr; - const NzVertexDeclaration* m_vertexDeclaration = nullptr; -}; - -#endif // NAZARA_STATICMESH_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_STATICMESH_HPP +#define NAZARA_STATICMESH_HPP + +#include +#include +#include + +class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener +{ + public: + NzStaticMesh(const NzMesh* parent); + NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); + virtual ~NzStaticMesh(); + + bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); + void Destroy(); + + bool GenerateAABB(); + + const NzAxisAlignedBox& GetAABB() const; + nzAnimationType GetAnimationType() const; + unsigned int GetFrameCount() const; + const NzIndexBuffer* GetIndexBuffer() const; + nzPrimitiveType GetPrimitiveType() const; + const NzVertexBuffer* GetVertexBuffer() const; + const NzVertexDeclaration* GetVertexDeclaration() const; + + bool IsAnimated() const; + bool IsValid() const; + + void SetAABB(const NzAxisAlignedBox& aabb); + void SetPrimitiveType(nzPrimitiveType primitiveType); + + private: + void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation); + void OnResourceReleased(const NzResource* resource, int index) override; + + nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList; + NzAxisAlignedBox m_aabb; + NzIndexBuffer* m_indexBuffer = nullptr; + NzVertexBuffer* m_vertexBuffer = nullptr; + const NzVertexDeclaration* m_vertexDeclaration = nullptr; +}; + +#endif // NAZARA_STATICMESH_HPP diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 09977ebe9..a13e40e00 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -1,53 +1,56 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_VERTEXDECLARATION_HPP -#define NAZARA_VERTEXDECLARATION_HPP - -#include -#include -#include - -struct NzVertexElement -{ - unsigned int offset; - unsigned int usageIndex = 0; - nzElementStream stream = nzElementStream_VertexData; - nzElementType type; - nzElementUsage usage; -}; - -struct NzVertexDeclarationImpl; - -class NAZARA_API NzVertexDeclaration : public NzResource -{ - public: - NzVertexDeclaration() = default; - NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount); - NzVertexDeclaration(const NzVertexDeclaration& declaration); - NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept; - ~NzVertexDeclaration(); - - bool Create(const NzVertexElement* elements, unsigned int elementCount); - void Destroy(); - - const NzVertexElement* GetElement(unsigned int i) const; - const NzVertexElement* GetElement(nzElementStream stream, unsigned int i) const; - const NzVertexElement* GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const; - unsigned int GetElementCount() const; - unsigned int GetElementCount(nzElementStream stream) const; - unsigned int GetStride(nzElementStream stream) const; - - bool HasStream(nzElementStream stream) const; - - bool IsValid() const; - - NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); - NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept; - - private: - NzVertexDeclarationImpl* m_sharedImpl = nullptr; -}; - -#endif // NAZARA_VERTEXDECLARATION_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#ifndef NAZARA_VERTEXDECLARATION_HPP +#define NAZARA_VERTEXDECLARATION_HPP + +#include +#include +#include + +struct NzVertexElement +{ + unsigned int offset; + unsigned int usageIndex = 0; + nzElementStream stream = nzElementStream_VertexData; + nzElementType type; + nzElementUsage usage; +}; + +struct NzVertexDeclarationImpl; + +class NAZARA_API NzVertexDeclaration : public NzResource +{ + public: + NzVertexDeclaration() = default; + NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount); + NzVertexDeclaration(const NzVertexDeclaration& declaration); + NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept; + ~NzVertexDeclaration(); + + bool Create(const NzVertexElement* elements, unsigned int elementCount); + void Destroy(); + + const NzVertexElement* GetElement(unsigned int i) const; + const NzVertexElement* GetElement(nzElementStream stream, unsigned int i) const; + const NzVertexElement* GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const; + unsigned int GetElementCount() const; + unsigned int GetElementCount(nzElementStream stream) const; + unsigned int GetStride(nzElementStream stream) const; + + bool HasStream(nzElementStream stream) const; + + bool IsValid() const; + + NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); + NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept; + + static unsigned int GetElementCount(nzElementType type); + static unsigned int GetElementSize(nzElementType type); + + private: + NzVertexDeclarationImpl* m_sharedImpl = nullptr; +}; + +#endif // NAZARA_VERTEXDECLARATION_HPP diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index 2e14e3913..7864d64a1 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -1,111 +1,112 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// Interface inspirée de la SFML par Laurent Gomila - -#pragma once - -#ifndef NAZARA_WINDOW_HPP -#define NAZARA_WINDOW_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if NAZARA_UTILITY_THREADED_WINDOW -#include -#include -#endif - -class NzCursor; -class NzImage; -class NzIcon; -class NzWindowImpl; - -class NAZARA_API NzWindow : NzNonCopyable -{ - friend NzWindowImpl; - friend class NzMouse; - friend class NzUtility; - - public: - NzWindow(); - NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); - NzWindow(NzWindowHandle handle); - virtual ~NzWindow(); - - bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); - bool Create(NzWindowHandle handle); - - void Destroy(); - - void EnableKeyRepeat(bool enable); - void EnableSmoothScrolling(bool enable); - - NzWindowHandle GetHandle() const; - unsigned int GetHeight() const; - NzVector2i GetPosition() const; - NzVector2ui GetSize() const; - NzString GetTitle() const; - unsigned int GetWidth() const; - - bool HasFocus() const; - - bool IsMinimized() const; - bool IsOpen() const; - bool IsVisible() const; - - bool PollEvent(NzEvent* event); - - void SetCursor(nzWindowCursor cursor); - void SetCursor(const NzCursor& cursor); - void SetEventListener(bool listener); - void SetFocus(); - void SetIcon(const NzIcon& icon); - void SetMaximumSize(const NzVector2i& maxSize); - void SetMaximumSize(int width, int height); - void SetMinimumSize(const NzVector2i& minSize); - void SetMinimumSize(int width, int height); - void SetPosition(const NzVector2i& position); - void SetPosition(int x, int y); - void SetSize(const NzVector2i& size); - void SetSize(unsigned int width, unsigned int height); - void SetStayOnTop(bool stayOnTop); - void SetTitle(const NzString& title); - void SetVisible(bool visible); - - bool WaitEvent(NzEvent* event); - - protected: - virtual void OnWindowDestroying(); - virtual bool OnWindowCreated(); - - NzWindowImpl* m_impl; - - private: - void IgnoreNextMouseEvent(int mouseX, int mouseY) const; - void PushEvent(const NzEvent& event); - - static bool Initialize(); - static void Uninitialize(); - - std::queue m_events; - #if NAZARA_UTILITY_THREADED_WINDOW - NzConditionVariable m_eventCondition; - NzMutex m_eventMutex; - NzMutex m_eventConditionMutex; - bool m_eventListener; - bool m_waitForEvent; - #endif - bool m_ownsWindow; -}; - -#endif // NAZARA_WINDOW_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Interface inspirée de la SFML par Laurent Gomila + +#pragma once + +#ifndef NAZARA_WINDOW_HPP +#define NAZARA_WINDOW_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if NAZARA_UTILITY_THREADED_WINDOW +#include +#include +#endif + +class NzCursor; +class NzImage; +class NzIcon; +class NzWindowImpl; + +class NAZARA_API NzWindow : NzNonCopyable +{ + friend NzWindowImpl; + friend class NzMouse; + friend class NzUtility; + + public: + NzWindow(); + NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); + NzWindow(NzWindowHandle handle); + virtual ~NzWindow(); + + bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); + bool Create(NzWindowHandle handle); + + void Destroy(); + + void EnableKeyRepeat(bool enable); + void EnableSmoothScrolling(bool enable); + + NzWindowHandle GetHandle() const; + unsigned int GetHeight() const; + NzVector2i GetPosition() const; + NzVector2ui GetSize() const; + NzString GetTitle() const; + unsigned int GetWidth() const; + + bool HasFocus() const; + + bool IsMinimized() const; + bool IsOpen() const; + bool IsValid() const; + bool IsVisible() const; + + bool PollEvent(NzEvent* event); + + void SetCursor(nzWindowCursor cursor); + void SetCursor(const NzCursor& cursor); + void SetEventListener(bool listener); + void SetFocus(); + void SetIcon(const NzIcon& icon); + void SetMaximumSize(const NzVector2i& maxSize); + void SetMaximumSize(int width, int height); + void SetMinimumSize(const NzVector2i& minSize); + void SetMinimumSize(int width, int height); + void SetPosition(const NzVector2i& position); + void SetPosition(int x, int y); + void SetSize(const NzVector2i& size); + void SetSize(unsigned int width, unsigned int height); + void SetStayOnTop(bool stayOnTop); + void SetTitle(const NzString& title); + void SetVisible(bool visible); + + bool WaitEvent(NzEvent* event); + + protected: + virtual bool OnWindowCreated(); + virtual void OnWindowDestroy(); + + NzWindowImpl* m_impl; + + private: + void IgnoreNextMouseEvent(int mouseX, int mouseY) const; + void PushEvent(const NzEvent& event); + + static bool Initialize(); + static void Uninitialize(); + + std::queue m_events; + #if NAZARA_UTILITY_THREADED_WINDOW + NzConditionVariable m_eventCondition; + NzMutex m_eventMutex; + NzMutex m_eventConditionMutex; + bool m_eventListener; + bool m_waitForEvent; + #endif + bool m_ownsWindow; +}; + +#endif // NAZARA_WINDOW_HPP diff --git a/src/Nazara/Audio/SoundBuffer.cpp b/src/Nazara/Audio/SoundBuffer.cpp index 6c5bdd1ac..950c57da1 100644 --- a/src/Nazara/Audio/SoundBuffer.cpp +++ b/src/Nazara/Audio/SoundBuffer.cpp @@ -1,223 +1,229 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Audio module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -///FIXME: Adapter la création - -bool NzSoundBufferParams::IsValid() const -{ - return true; -} - -struct NzSoundBufferImpl -{ - ALuint buffer; - nzAudioFormat format; - nzUInt32 duration; - nzInt16* samples; - unsigned int sampleCount; - unsigned int sampleRate; -}; - -NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) -{ - Create(format, sampleCount, sampleRate, samples); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create sound buffer"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzSoundBuffer::~NzSoundBuffer() -{ - Destroy(); -} - -bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) -{ - Destroy(); - - if (sampleCount == 0) - return true; - - #if NAZARA_AUDIO_SAFE - if (!IsFormatSupported(format)) - { - NazaraError("Audio format is not supported"); - return false; - } - - if (sampleRate == 0) - { - NazaraError("Sample rate must be different from zero"); - return false; - } - - if (!samples) - { - NazaraError("Invalid sample source"); - return false; - } - #endif - - // On vide le stack d'erreurs - while (alGetError() != AL_NO_ERROR); - - ALuint buffer; - alGenBuffers(1, &buffer); - - if (alGetError() != AL_NO_ERROR) - { - NazaraError("Failed to create OpenAL buffer"); - return false; - } - - alBufferData(buffer, NzAudio::GetOpenALFormat(format), samples, sampleCount*sizeof(nzInt16), sampleRate); - - if (alGetError() != AL_NO_ERROR) - { - NazaraError("Failed to set OpenAL buffer"); - alDeleteBuffers(1, &buffer); - - return false; - } - - m_impl = new NzSoundBufferImpl; - m_impl->buffer = buffer; - m_impl->duration = 1000 * (sampleCount / (format * sampleRate)); - m_impl->format = format; - m_impl->sampleCount = sampleCount; - m_impl->sampleRate = sampleRate; - m_impl->samples = new nzInt16[sampleCount]; - std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16)); - - return true; -} - -void NzSoundBuffer::Destroy() -{ - if (m_impl) - { - delete[] m_impl->samples; - delete m_impl; - m_impl = nullptr; - } -} - -nzUInt32 NzSoundBuffer::GetDuration() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return 0; - } - #endif - - return m_impl->duration; -} - -nzAudioFormat NzSoundBuffer::GetFormat() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return nzAudioFormat_Unknown; - } - #endif - - return m_impl->format; -} - -const nzInt16* NzSoundBuffer::GetSamples() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return nullptr; - } - #endif - - return m_impl->samples; -} - -unsigned int NzSoundBuffer::GetSampleCount() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return 0; - } - #endif - - return m_impl->sampleCount; -} - -unsigned int NzSoundBuffer::GetSampleRate() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return 0; - } - #endif - - return m_impl->sampleRate; -} - -bool NzSoundBuffer::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzSoundBuffer::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params) -{ - return NzSoundBufferLoader::LoadFromFile(this, filePath, params); -} - -bool NzSoundBuffer::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params) -{ - return NzSoundBufferLoader::LoadFromMemory(this, data, size, params); -} - -bool NzSoundBuffer::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params) -{ - return NzSoundBufferLoader::LoadFromStream(this, stream, params); -} - -bool NzSoundBuffer::IsFormatSupported(nzAudioFormat format) -{ - return NzAudio::IsFormatSupported(format); -} - -unsigned int NzSoundBuffer::GetOpenALBuffer() const -{ - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraInternalError("Sound buffer not created"); - return AL_NONE; - } - #endif - - return m_impl->buffer; -} - -NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +///FIXME: Adapter la création + +bool NzSoundBufferParams::IsValid() const +{ + return true; +} + +struct NzSoundBufferImpl +{ + ALuint buffer; + nzAudioFormat format; + nzUInt32 duration; + nzInt16* samples; + unsigned int sampleCount; + unsigned int sampleRate; +}; + +NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) +{ + Create(format, sampleCount, sampleRate, samples); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create sound buffer"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzSoundBuffer::~NzSoundBuffer() +{ + Destroy(); +} + +bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) +{ + Destroy(); + + #if NAZARA_AUDIO_SAFE + if (!IsFormatSupported(format)) + { + NazaraError("Audio format is not supported"); + return false; + } + + if (sampleCount == 0) + { + NazaraError("Sample rate must be different from zero"); + return false; + } + + if (sampleRate == 0) + { + NazaraError("Sample rate must be different from zero"); + return false; + } + + if (!samples) + { + NazaraError("Invalid sample source"); + return false; + } + #endif + + // On vide le stack d'erreurs + while (alGetError() != AL_NO_ERROR); + + ALuint buffer; + alGenBuffers(1, &buffer); + + if (alGetError() != AL_NO_ERROR) + { + NazaraError("Failed to create OpenAL buffer"); + return false; + } + + alBufferData(buffer, NzAudio::GetOpenALFormat(format), samples, sampleCount*sizeof(nzInt16), sampleRate); + + if (alGetError() != AL_NO_ERROR) + { + NazaraError("Failed to set OpenAL buffer"); + alDeleteBuffers(1, &buffer); + + return false; + } + + m_impl = new NzSoundBufferImpl; + m_impl->buffer = buffer; + m_impl->duration = 1000 * (sampleCount / (format * sampleRate)); + m_impl->format = format; + m_impl->sampleCount = sampleCount; + m_impl->sampleRate = sampleRate; + m_impl->samples = new nzInt16[sampleCount]; + std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16)); + + NotifyCreated(); + return true; +} + +void NzSoundBuffer::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + delete[] m_impl->samples; + delete m_impl; + m_impl = nullptr; + } +} + +nzUInt32 NzSoundBuffer::GetDuration() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->duration; +} + +nzAudioFormat NzSoundBuffer::GetFormat() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return nzAudioFormat_Unknown; + } + #endif + + return m_impl->format; +} + +const nzInt16* NzSoundBuffer::GetSamples() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return nullptr; + } + #endif + + return m_impl->samples; +} + +unsigned int NzSoundBuffer::GetSampleCount() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->sampleCount; +} + +unsigned int NzSoundBuffer::GetSampleRate() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->sampleRate; +} + +bool NzSoundBuffer::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzSoundBuffer::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromFile(this, filePath, params); +} + +bool NzSoundBuffer::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromMemory(this, data, size, params); +} + +bool NzSoundBuffer::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromStream(this, stream, params); +} + +bool NzSoundBuffer::IsFormatSupported(nzAudioFormat format) +{ + return NzAudio::IsFormatSupported(format); +} + +unsigned int NzSoundBuffer::GetOpenALBuffer() const +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Sound buffer not created"); + return AL_NONE; + } + #endif + + return m_impl->buffer; +} + +NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders; diff --git a/src/Nazara/Core/ByteArray.cpp b/src/Nazara/Core/ByteArray.cpp index d390d6611..f5508af3e 100644 --- a/src/Nazara/Core/ByteArray.cpp +++ b/src/Nazara/Core/ByteArray.cpp @@ -1,265 +1,265 @@ -/* -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -inline unsigned int nzPow2(unsigned int n) -{ - unsigned int x = 1; - - while(x <= n) - x <<= 1; - - return x; -} -// Cet algorithme est inspiré de la documentation de Qt -inline unsigned int nzGetNewSize(unsigned int newSize) -{ - if (newSize < 20) - return newSize+4; - else - { - if (newSize < (1 << 12)-12) - return nzPow2(newSize << 1)-12; - else - return newSize + (1 << 11); - } -} - -NzByteArray::NzByteArray() : -m_sharedArray(&emptyArray) -{ -} - -NzByteArray::NzByteArray(const nzUInt8* buffer, unsigned int bufferLength) -{ - if (bufferLength > 0) - { - m_sharedArray = new SharedArray; - m_sharedArray->buffer = new nzUInt8[bufferLength]; - m_sharedArray->capacity = bufferLength; - m_sharedArray->size = bufferLength; - std::memcpy(m_sharedArray->buffer, buffer, bufferLength); - } - else - m_sharedArray = &emptyArray; -} - -NzByteArray::NzByteArray(const NzByteArray& buffer) : -m_sharedArray(buffer.m_sharedArray) -{ - if (m_sharedArray != &emptyArray) - { - NazaraMutexLock(m_sharedArray->mutex); - m_sharedArray->refCount++; - NazaraMutexUnlock(m_sharedArray->mutex); - } -} - -NzByteArray::NzByteArray(NzByteArray&& buffer) : -m_sharedArray(buffer.m_sharedArray) -{ - buffer.m_sharedArray = &emptyArray; -} - -NzByteArray::NzByteArray(SharedArray* sharedArray) : -m_sharedArray(sharedArray) -{ -} - -NzByteArray::~NzByteArray() -{ - ReleaseArray(); -} - -NzByteArray& NzByteArray::Append(const NzByteArray& byteArray) -{ - if (byteArray.m_sharedArray->size == 0) - return *this; - - if (m_sharedArray->size == 0 && m_sharedArray->capacity < byteArray.m_sharedArray->size) - return operator=(byteArray); - - if (m_sharedArray->capacity >= m_sharedArray->size + byteArray.m_sharedArray->size) - { - EnsureOwnership(); - - std::memcpy(&m_sharedArray->buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); - m_sharedArray->size += byteArray.m_sharedArray->size; - } - else - { - unsigned int newSize = m_sharedArray->size + byteArray.m_sharedArray->size; - unsigned int bufferSize = nzGetNewSize(newSize); - - nzUInt8* buffer = new nzUInt8[bufferSize+1]; - std::memcpy(buffer, m_sharedArray->buffer, m_sharedArray->size); - std::memcpy(&buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); - - ReleaseArray(); - m_sharedArray = new SharedArray; - m_sharedArray->buffer = buffer; - m_sharedArray->capacity = bufferSize; - m_sharedArray->size = newSize; - } - - return *this; -} - -void NzByteArray::Clear() -{ - ReleaseArray(); -} - -nzUInt8* NzByteArray::GetBuffer() -{ - EnsureOwnership(); - - return m_sharedArray->buffer; -} - -unsigned int NzByteArray::GetCapacity() const -{ - return m_sharedArray->capacity; -} - -const nzUInt8* NzByteArray::GetConstBuffer() const -{ - return m_sharedArray->buffer; -} - -unsigned int NzByteArray::GetSize() const -{ - return m_sharedArray->size; -} - -NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength) -{ - if (bufferLength == 0) - return *this; - - if (m_sharedArray->size == 0) - return operator=(string); - - if (pos < 0) - pos = std::max(static_cast(m_sharedArray->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedArray->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength) - { - EnsureOwnership(); - - std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size); - std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength); - - m_sharedArray->size += bufferLength; - } - else - { - unsigned int newSize = m_sharedArray->size+bufferLength; - nzUInt8* newBuffer = new nzUInt8[newSize+1]; - - nzUInt8* ptr = newBuffer; - const nzUInt8* s = m_sharedArray->buffer; - - while (ptr != &newBuffer[start]) - *ptr++ = *s++; - - while (ptr != &newBuffer[start+bufferLength]) - *ptr++ = *buffer++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedArray = new SharedString; - m_sharedArray->allocatedSize = newSize; - m_sharedArray->buffer = newBuffer; - m_sharedArray->size = newSize; - } - - return *this; -} - -NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray) -{ - if (string.m_sharedArray->size == 0) - return *this; - - if (m_sharedArray->size == 0 && m_sharedArray->capacity < string.m_sharedArray->size) - return operator=(string); - - if (pos < 0) - pos = std::max(static_cast(m_sharedArray->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedArray->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size) - { - EnsureOwnership(); - - std::memmove(&m_sharedArray->string[start+string.m_sharedArray->size], &m_sharedArray->string[start], m_sharedArray->size*sizeof(char)); - std::memcpy(&m_sharedArray->string[start], string.m_sharedArray->string, string.m_sharedArray->size*sizeof(char)); - - m_sharedArray->size += string.m_sharedArray->size; - } - else - { - unsigned int newSize = m_sharedArray->size+string.m_sharedArray->size; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedArray->string; - - while (ptr != &newString[start]) - *ptr++ = *s++; - - const char* p = string.m_sharedArray->string; - while (ptr != &newString[start+string.m_sharedArray->size]) - *ptr++ = *p++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedArray = new SharedString; - m_sharedArray->capacity = newSize; - m_sharedArray->size = newSize; - m_sharedArray->string = newString; - } - - return *this; -} - -bool NzByteArray::IsEmpty() const -{ - return m_sharedArray->size == 0; -} - -void NzByteArray::Reserve(unsigned int bufferSize) -{ - if (m_sharedArray->allocatedSize >= bufferSize) - return; - - nzUInt8* ptr = new nzUInt8[bufferSize+1]; - if (m_sharedArray->size > 0) - std::memcpy(ptr, m_sharedArray->buffer, m_sharedArray->size); - - unsigned int size = m_sharedArray->size; - - ReleaseArray(); - m_sharedArray = new SharedString; - m_sharedArray->allocatedSize = bufferSize; - m_sharedArray->buffer = ptr; - m_sharedArray->size = size; -} - -NzByteArray::SharedString NzByteArray::emptyArray(0, 0, 0, nullptr); -unsigned int NzByteArray::npos(static_cast(-1)); -*/ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +/* +#include +#include +#include +#include + +inline unsigned int nzPow2(unsigned int n) +{ + unsigned int x = 1; + + while(x <= n) + x <<= 1; + + return x; +} +// Cet algorithme est inspiré de la documentation de Qt +inline unsigned int nzGetNewSize(unsigned int newSize) +{ + if (newSize < 20) + return newSize+4; + else + { + if (newSize < (1 << 12)-12) + return nzPow2(newSize << 1)-12; + else + return newSize + (1 << 11); + } +} + +NzByteArray::NzByteArray() : +m_sharedArray(&emptyArray) +{ +} + +NzByteArray::NzByteArray(const nzUInt8* buffer, unsigned int bufferLength) +{ + if (bufferLength > 0) + { + m_sharedArray = new SharedArray; + m_sharedArray->buffer = new nzUInt8[bufferLength]; + m_sharedArray->capacity = bufferLength; + m_sharedArray->size = bufferLength; + std::memcpy(m_sharedArray->buffer, buffer, bufferLength); + } + else + m_sharedArray = &emptyArray; +} + +NzByteArray::NzByteArray(const NzByteArray& buffer) : +m_sharedArray(buffer.m_sharedArray) +{ + if (m_sharedArray != &emptyArray) + { + NazaraMutexLock(m_sharedArray->mutex); + m_sharedArray->refCount++; + NazaraMutexUnlock(m_sharedArray->mutex); + } +} + +NzByteArray::NzByteArray(NzByteArray&& buffer) noexcept : +m_sharedArray(buffer.m_sharedArray) +{ + buffer.m_sharedArray = &emptyArray; +} + +NzByteArray::NzByteArray(SharedArray* sharedArray) : +m_sharedArray(sharedArray) +{ +} + +NzByteArray::~NzByteArray() +{ + ReleaseArray(); +} + +NzByteArray& NzByteArray::Append(const NzByteArray& byteArray) +{ + if (byteArray.m_sharedArray->size == 0) + return *this; + + if (m_sharedArray->size == 0 && m_sharedArray->capacity < byteArray.m_sharedArray->size) + return operator=(byteArray); + + if (m_sharedArray->capacity >= m_sharedArray->size + byteArray.m_sharedArray->size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedArray->buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); + m_sharedArray->size += byteArray.m_sharedArray->size; + } + else + { + unsigned int newSize = m_sharedArray->size + byteArray.m_sharedArray->size; + unsigned int bufferSize = nzGetNewSize(newSize); + + nzUInt8* buffer = new nzUInt8[bufferSize+1]; + std::memcpy(buffer, m_sharedArray->buffer, m_sharedArray->size); + std::memcpy(&buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); + + ReleaseArray(); + m_sharedArray = new SharedArray; + m_sharedArray->buffer = buffer; + m_sharedArray->capacity = bufferSize; + m_sharedArray->size = newSize; + } + + return *this; +} + +void NzByteArray::Clear() +{ + ReleaseArray(); +} + +nzUInt8* NzByteArray::GetBuffer() +{ + EnsureOwnership(); + + return m_sharedArray->buffer; +} + +unsigned int NzByteArray::GetCapacity() const +{ + return m_sharedArray->capacity; +} + +const nzUInt8* NzByteArray::GetConstBuffer() const +{ + return m_sharedArray->buffer; +} + +unsigned int NzByteArray::GetSize() const +{ + return m_sharedArray->size; +} + +NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength) +{ + if (bufferLength == 0) + return *this; + + if (m_sharedArray->size == 0) + return operator=(string); + + if (pos < 0) + pos = std::max(static_cast(m_sharedArray->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedArray->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength) + { + EnsureOwnership(); + + std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size); + std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength); + + m_sharedArray->size += bufferLength; + } + else + { + unsigned int newSize = m_sharedArray->size+bufferLength; + nzUInt8* newBuffer = new nzUInt8[newSize+1]; + + nzUInt8* ptr = newBuffer; + const nzUInt8* s = m_sharedArray->buffer; + + while (ptr != &newBuffer[start]) + *ptr++ = *s++; + + while (ptr != &newBuffer[start+bufferLength]) + *ptr++ = *buffer++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedArray = new SharedString; + m_sharedArray->allocatedSize = newSize; + m_sharedArray->buffer = newBuffer; + m_sharedArray->size = newSize; + } + + return *this; +} + +NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray) +{ + if (string.m_sharedArray->size == 0) + return *this; + + if (m_sharedArray->size == 0 && m_sharedArray->capacity < string.m_sharedArray->size) + return operator=(string); + + if (pos < 0) + pos = std::max(static_cast(m_sharedArray->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedArray->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size) + { + EnsureOwnership(); + + std::memmove(&m_sharedArray->string[start+string.m_sharedArray->size], &m_sharedArray->string[start], m_sharedArray->size*sizeof(char)); + std::memcpy(&m_sharedArray->string[start], string.m_sharedArray->string, string.m_sharedArray->size*sizeof(char)); + + m_sharedArray->size += string.m_sharedArray->size; + } + else + { + unsigned int newSize = m_sharedArray->size+string.m_sharedArray->size; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedArray->string; + + while (ptr != &newString[start]) + *ptr++ = *s++; + + const char* p = string.m_sharedArray->string; + while (ptr != &newString[start+string.m_sharedArray->size]) + *ptr++ = *p++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedArray = new SharedString; + m_sharedArray->capacity = newSize; + m_sharedArray->size = newSize; + m_sharedArray->string = newString; + } + + return *this; +} + +bool NzByteArray::IsEmpty() const +{ + return m_sharedArray->size == 0; +} + +void NzByteArray::Reserve(unsigned int bufferSize) +{ + if (m_sharedArray->allocatedSize >= bufferSize) + return; + + nzUInt8* ptr = new nzUInt8[bufferSize+1]; + if (m_sharedArray->size > 0) + std::memcpy(ptr, m_sharedArray->buffer, m_sharedArray->size); + + unsigned int size = m_sharedArray->size; + + ReleaseArray(); + m_sharedArray = new SharedString; + m_sharedArray->allocatedSize = bufferSize; + m_sharedArray->buffer = ptr; + m_sharedArray->size = size; +} + +NzByteArray::SharedString NzByteArray::emptyArray(0, 0, 0, nullptr); +unsigned int NzByteArray::npos(static_cast(-1)); +*/ diff --git a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp index b88073725..c507ba42c 100644 --- a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp +++ b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp @@ -1,264 +1,271 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#elif defined(NAZARA_PLATFORM_POSIX) -#include -#endif - -namespace -{ - struct Block - { - std::size_t size; - const char* file; - Block* prev; - Block* next; - bool array; - unsigned int line; - unsigned int magic; - }; - - bool initialized = false; - const unsigned int magic = 0x51429EE; - const char* MLTFileName = "NazaraLeaks.log"; - const char* nextFreeFile = "Internal error"; - unsigned int nextFreeLine = 0; - - Block ptrList = - { - 0, - nullptr, - &ptrList, - &ptrList, - false, - 0, - magic - }; - - #if defined(NAZARA_PLATFORM_WINDOWS) - CRITICAL_SECTION mutex; - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - #endif -} - -NzMemoryManager::NzMemoryManager() -{ -} - -NzMemoryManager::~NzMemoryManager() -{ - Uninitialize(); -} - -void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file, unsigned int line) -{ - if (!initialized) - Initialize(); - - #if defined(NAZARA_PLATFORM_WINDOWS) - EnterCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_lock(&mutex); - #endif - - Block* ptr = reinterpret_cast(std::malloc(size+sizeof(Block))); - if (!ptr) - return nullptr; // Impossible d'envoyer une exception car cela allouerait de la mémoire avec new (boucle infinie) - - ptr->array = multi; - ptr->file = file; - ptr->line = line; - ptr->size = size; - ptr->magic = magic; - - ptr->prev = ptrList.prev; - ptr->next = &ptrList; - ptrList.prev->next = ptr; - ptrList.prev = ptr; - - #if defined(NAZARA_PLATFORM_WINDOWS) - LeaveCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_unlock(&mutex); - #endif - - return reinterpret_cast(ptr)+sizeof(Block); -} - -void NzMemoryManager::Free(void* pointer, bool multi) -{ - if (!pointer) - return; - - Block* ptr = reinterpret_cast(reinterpret_cast(pointer)-sizeof(Block)); - if (ptr->magic != magic) - return; - - #if defined(NAZARA_PLATFORM_WINDOWS) - EnterCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_lock(&mutex); - #endif - - if (ptr->array != multi) - { - char* time = TimeInfo(); - - FILE* log = std::fopen(MLTFileName, "a"); - - if (nextFreeFile) - { - if (multi) - std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine); - else - std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine); - } - else - { - if (multi) - std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time); - else - std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time); - } - - std::fclose(log); - - std::free(time); - } - - ptr->magic = 0; - ptr->prev->next = ptr->next; - ptr->next->prev = ptr->prev; - - std::free(ptr); - - nextFreeFile = nullptr; - nextFreeLine = 0; - - #if defined(NAZARA_PLATFORM_WINDOWS) - LeaveCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_unlock(&mutex); - #endif -} - -void NzMemoryManager::NextFree(const char* file, unsigned int line) -{ - nextFreeFile = file; - nextFreeLine = line; -} - -void NzMemoryManager::Initialize() -{ - char* time = TimeInfo(); - - FILE* file = std::fopen(MLTFileName, "w"); - std::fprintf(file, "%s ==============================\n", time); - std::fprintf(file, "%s Nazara Memory Leak Tracker \n", time); - std::fprintf(file, "%s ==============================\n", time); - std::fclose(file); - - std::free(time); - - if (std::atexit(Uninitialize) != 0) - { - static NzMemoryManager manager; - } - - #ifdef NAZARA_PLATFORM_WINDOWS - InitializeCriticalSection(&mutex); - #endif - - initialized = true; -} - -char* NzMemoryManager::TimeInfo() -{ - char* buffer = reinterpret_cast(std::malloc(23*sizeof(char))); - - time_t currentTime = std::time(nullptr); - std::strftime(buffer, 23, "%d/%m/%Y - %H:%M:%S:", std::localtime(¤tTime)); - - return buffer; -} - -void NzMemoryManager::Uninitialize() -{ - #ifdef NAZARA_PLATFORM_WINDOWS - DeleteCriticalSection(&mutex); - #endif - - FILE* log = std::fopen(MLTFileName, "a"); - - char* time = TimeInfo(); - - std::fprintf(log, "%s Application finished, checking leaks...\n", time); - - if (ptrList.next == &ptrList) - { - std::fprintf(log, "%s ==============================\n", time); - std::fprintf(log, "%s No leak detected \n", time); - std::fprintf(log, "%s ==============================", time); - } - else - { - std::fprintf(log, "%s ==============================\n", time); - std::fprintf(log, "%s Leaks have been detected \n", time); - std::fprintf(log, "%s ==============================\n\n", time); - std::fputs("Leak list:\n", log); - - Block* ptr = ptrList.next; - unsigned int count = 0; - unsigned int totalSize = 0; - while (ptr != &ptrList) - { - count++; - totalSize += ptr->size; - if (ptr->file) - std::fprintf(log, "-0x%p -> %d bytes allocated at %s:%d\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size, ptr->file, ptr->line); - else - std::fprintf(log, "-0x%p -> %d bytes allocated at unknown position\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size); - - void* pointer = ptr; - ptr = ptr->next; - std::free(pointer); - } - - std::fprintf(log, "\n%d blocks leaked (%d bytes)", count, totalSize); - } - - std::free(time); - std::fclose(log); -} - -void* operator new(std::size_t size, const char* file, unsigned int line) -{ - return NzMemoryManager::Allocate(size, false, file, line); -} - -void* operator new[](std::size_t size, const char* file, unsigned int line) -{ - return NzMemoryManager::Allocate(size, true, file, line); -} - -void operator delete(void* ptr, const char* file, unsigned int line) throw() -{ - NzMemoryManager::NextFree(file, line); - NzMemoryManager::Free(ptr, false); -} - -void operator delete[](void* ptr, const char* file, unsigned int line) throw() -{ - NzMemoryManager::NextFree(file, line); - NzMemoryManager::Free(ptr, true); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) +#include +#elif defined(NAZARA_PLATFORM_POSIX) +#include +#endif + +namespace +{ + struct Block + { + std::size_t size; + const char* file; + Block* prev; + Block* next; + bool array; + unsigned int line; + unsigned int magic; + }; + + bool initialized = false; + const unsigned int magic = 0x51429EE; + const char* MLTFileName = "NazaraLeaks.log"; + const char* nextFreeFile = "Internal error"; + unsigned int nextFreeLine = 0; + + Block ptrList = + { + 0, + nullptr, + &ptrList, + &ptrList, + false, + 0, + magic + }; + + #if defined(NAZARA_PLATFORM_WINDOWS) + CRITICAL_SECTION mutex; + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + #endif +} + +NzMemoryManager::NzMemoryManager() +{ +} + +NzMemoryManager::~NzMemoryManager() +{ + Uninitialize(); +} + +void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file, unsigned int line) +{ + if (!initialized) + Initialize(); + + #if defined(NAZARA_PLATFORM_WINDOWS) + EnterCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_lock(&mutex); + #endif + + Block* ptr = reinterpret_cast(std::malloc(size+sizeof(Block))); + if (!ptr) + { + // Pas d'information de temps (Car nécessitant une allocation) + FILE* log = std::fopen(MLTFileName, "a"); + std::fprintf(log, "Failed to allocate memory (%d bytes)\n", size); + std::fclose(log); + + return nullptr; // Impossible d'envoyer une exception car cela allouerait de la mémoire avec new (boucle infinie) + } + + ptr->array = multi; + ptr->file = file; + ptr->line = line; + ptr->size = size; + ptr->magic = magic; + + ptr->prev = ptrList.prev; + ptr->next = &ptrList; + ptrList.prev->next = ptr; + ptrList.prev = ptr; + + #if defined(NAZARA_PLATFORM_WINDOWS) + LeaveCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_unlock(&mutex); + #endif + + return reinterpret_cast(ptr)+sizeof(Block); +} + +void NzMemoryManager::Free(void* pointer, bool multi) +{ + if (!pointer) + return; + + Block* ptr = reinterpret_cast(reinterpret_cast(pointer)-sizeof(Block)); + if (ptr->magic != magic) + return; + + #if defined(NAZARA_PLATFORM_WINDOWS) + EnterCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_lock(&mutex); + #endif + + if (ptr->array != multi) + { + char* time = TimeInfo(); + + FILE* log = std::fopen(MLTFileName, "a"); + + if (nextFreeFile) + { + if (multi) + std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine); + else + std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine); + } + else + { + if (multi) + std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time); + else + std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time); + } + + std::fclose(log); + + std::free(time); + } + + ptr->magic = 0; + ptr->prev->next = ptr->next; + ptr->next->prev = ptr->prev; + + std::free(ptr); + + nextFreeFile = nullptr; + nextFreeLine = 0; + + #if defined(NAZARA_PLATFORM_WINDOWS) + LeaveCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_unlock(&mutex); + #endif +} + +void NzMemoryManager::NextFree(const char* file, unsigned int line) +{ + nextFreeFile = file; + nextFreeLine = line; +} + +void NzMemoryManager::Initialize() +{ + char* time = TimeInfo(); + + FILE* file = std::fopen(MLTFileName, "w"); + std::fprintf(file, "%s ==============================\n", time); + std::fprintf(file, "%s Nazara Memory Leak Tracker \n", time); + std::fprintf(file, "%s ==============================\n", time); + std::fclose(file); + + std::free(time); + + if (std::atexit(Uninitialize) != 0) + { + static NzMemoryManager manager; + } + + #ifdef NAZARA_PLATFORM_WINDOWS + InitializeCriticalSection(&mutex); + #endif + + initialized = true; +} + +char* NzMemoryManager::TimeInfo() +{ + char* buffer = reinterpret_cast(std::malloc(23*sizeof(char))); + + time_t currentTime = std::time(nullptr); + std::strftime(buffer, 23, "%d/%m/%Y - %H:%M:%S:", std::localtime(¤tTime)); + + return buffer; +} + +void NzMemoryManager::Uninitialize() +{ + #ifdef NAZARA_PLATFORM_WINDOWS + DeleteCriticalSection(&mutex); + #endif + + FILE* log = std::fopen(MLTFileName, "a"); + + char* time = TimeInfo(); + + std::fprintf(log, "%s Application finished, checking leaks...\n", time); + + if (ptrList.next == &ptrList) + { + std::fprintf(log, "%s ==============================\n", time); + std::fprintf(log, "%s No leak detected \n", time); + std::fprintf(log, "%s ==============================", time); + } + else + { + std::fprintf(log, "%s ==============================\n", time); + std::fprintf(log, "%s Leaks have been detected \n", time); + std::fprintf(log, "%s ==============================\n\n", time); + std::fputs("Leak list:\n", log); + + Block* ptr = ptrList.next; + unsigned int count = 0; + unsigned int totalSize = 0; + while (ptr != &ptrList) + { + count++; + totalSize += ptr->size; + if (ptr->file) + std::fprintf(log, "-0x%p -> %d bytes allocated at %s:%d\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size, ptr->file, ptr->line); + else + std::fprintf(log, "-0x%p -> %d bytes allocated at unknown position\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size); + + void* pointer = ptr; + ptr = ptr->next; + std::free(pointer); + } + + std::fprintf(log, "\n%d blocks leaked (%d bytes)", count, totalSize); + } + + std::free(time); + std::fclose(log); +} + +void* operator new(std::size_t size, const char* file, unsigned int line) +{ + return NzMemoryManager::Allocate(size, false, file, line); +} + +void* operator new[](std::size_t size, const char* file, unsigned int line) +{ + return NzMemoryManager::Allocate(size, true, file, line); +} + +void operator delete(void* ptr, const char* file, unsigned int line) throw() +{ + NzMemoryManager::NextFree(file, line); + NzMemoryManager::Free(ptr, false); +} + +void operator delete[](void* ptr, const char* file, unsigned int line) throw() +{ + NzMemoryManager::NextFree(file, line); + NzMemoryManager::Free(ptr, true); +} diff --git a/src/Nazara/Core/Resource.cpp b/src/Nazara/Core/Resource.cpp index c83346d78..8014220e1 100644 --- a/src/Nazara/Core/Resource.cpp +++ b/src/Nazara/Core/Resource.cpp @@ -1,54 +1,138 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -NzResource::NzResource(bool persistent) : -m_resourcePersistent(persistent), -m_resourceReferenceCount(0) -{ -} - -NzResource::NzResource(const NzResource& resource) : -m_resourcePersistent(resource.m_resourcePersistent), -m_resourceReferenceCount(0) -{ -} - -NzResource::~NzResource() = default; - -void NzResource::AddResourceReference() const -{ - m_resourceReferenceCount++; -} - -bool NzResource::IsPersistent() const -{ - return m_resourcePersistent; -} - -void NzResource::RemoveResourceReference() const -{ - #if NAZARA_CORE_SAFE - if (m_resourceReferenceCount == 0) - { - NazaraError("Impossible to remove reference (Ref. counter is already 0)"); - return; - } - #endif - - if (--m_resourceReferenceCount == 0 && !m_resourcePersistent) - delete this; -} - -void NzResource::SetPersistent(bool persistent) -{ - m_resourcePersistent = persistent; - - if (!persistent && m_resourceReferenceCount == 0) - delete this; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include + +NzResource::NzResource(bool persistent) : +m_resourcePersistent(persistent), +m_resourceReferenceCount(0) +{ +} + +NzResource::NzResource(const NzResource& resource) : +m_resourcePersistent(resource.m_resourcePersistent), +m_resourceReferenceCount(0) +{ +} + +NzResource::~NzResource() +{ + EnsureResourceListenerUpdate(); + + for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) + (*it).listener->OnResourceReleased(this, (*it).index); +} + +void NzResource::AddResourceListener(NzResourceListener* listener, int index) const +{ + NazaraLock(m_mutex) + + if (m_resourceListeners.insert(NzResourceEntry(listener, index)).second) + { + m_resourceListenerUpdated = false; + + // AddResourceReference() + m_resourceReferenceCount++; + } +} + +void NzResource::AddResourceReference() const +{ + NazaraLock(m_mutex) + + m_resourceReferenceCount++; +} + +bool NzResource::IsPersistent() const +{ + NazaraLock(m_mutex) + + return m_resourcePersistent; +} + +void NzResource::RemoveResourceListener(NzResourceListener* listener) const +{ + NazaraLock(m_mutex) + + if (m_resourceListeners.erase(listener) != 0) + m_resourceListenerUpdated = false; + else + NazaraError(NzString::Pointer(listener) + " is not listening to " + NzString::Pointer(this)); + + RemoveResourceReference(); +} + +void NzResource::RemoveResourceReference() const +{ + NazaraMutexLock(m_mutex); + + #if NAZARA_CORE_SAFE + if (m_resourceReferenceCount == 0) + { + NazaraError("Impossible to remove reference (Ref. counter is already 0)"); + return; + } + #endif + + if (--m_resourceReferenceCount == 0 && !m_resourcePersistent) + { + NazaraMutexUnlock(m_mutex); + delete this; + } + else + { + NazaraMutexUnlock(m_mutex); + } +} + +void NzResource::SetPersistent(bool persistent) +{ + NazaraMutexLock(m_mutex); + + m_resourcePersistent = persistent; + + if (!persistent && m_resourceReferenceCount == 0) + { + NazaraMutexUnlock(m_mutex); + delete this; + } + else + { + NazaraMutexUnlock(m_mutex); + } +} + +void NzResource::NotifyCreated() +{ + NazaraLock(m_mutex) + + EnsureResourceListenerUpdate(); + + for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) + (*it).listener->OnResourceCreated(this, (*it).index); +} + +void NzResource::NotifyDestroy() +{ + NazaraLock(m_mutex) + + EnsureResourceListenerUpdate(); + + for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) + (*it).listener->OnResourceDestroy(this, (*it).index); +} + +void NzResource::EnsureResourceListenerUpdate() const +{ + // Déjà bloqué par une mutex + if (!m_resourceListenerUpdated) + { + m_resourceListenersCache = m_resourceListeners; + m_resourceListenerUpdated = true; + } +} diff --git a/src/Nazara/Core/ResourceListener.cpp b/src/Nazara/Core/ResourceListener.cpp new file mode 100644 index 000000000..981872bb6 --- /dev/null +++ b/src/Nazara/Core/ResourceListener.cpp @@ -0,0 +1,26 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +NzResourceListener::~NzResourceListener() = default; + +void NzResourceListener::OnResourceCreated(const NzResource* resource, int index) +{ + NazaraUnused(resource); + NazaraUnused(index); +} + +void NzResourceListener::OnResourceDestroy(const NzResource* resource, int index) +{ + NazaraUnused(resource); + NazaraUnused(index); +} + +void NzResourceListener::OnResourceReleased(const NzResource* resource, int index) +{ + NazaraUnused(resource); + NazaraUnused(index); +} diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index 419e748de..e9c5b6e83 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -1,5162 +1,5163 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -inline unsigned int nzPow2(unsigned int n) -{ - unsigned int x = 1; - - // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux - while(x <= n) - x <<= 1; - - return x; -} -// Cet algorithme est inspiré de la documentation de Qt -inline unsigned int nzGetNewSize(unsigned int newSize) -{ - if (newSize < 20) - return newSize+4; - else - { - if (newSize < (1 << 12)-12) - return nzPow2(newSize << 1)-12; - else - return newSize + (1 << 11); - } -} - -inline char nzToLower(char character) -{ - if (character >= 'A' && character <= 'Z') - return character + ('a' - 'A'); - else - return character; -} - -inline char nzToUpper(char character) -{ - if (character >= 'a' && character <= 'z') - return character + ('A' - 'a'); - else - return character; -} - -inline int nzStrcasecmp(const char* s1, const char* s2) -{ - int ret = 0; - - while (!(ret = static_cast(nzToLower(*s1)) - static_cast(nzToLower(*s2))) && *s2) - ++s1, ++s2; - - return ret != 0 ? (ret > 0 ? 1 : -1) : 0; -} - -inline int nzUnicodecasecmp(const char* s1, const char* s2) -{ - int ret = 0; - utf8::unchecked::iterator it1(s1); - utf8::unchecked::iterator it2(s2); - - while (!(ret = NzUnicode::GetLowercase(*it1) - NzUnicode::GetLowercase(*it2)) && *it2) - ++it1, ++it2; - - return ret != 0 ? (ret > 0 ? 1 : -1) : 0; -} - -NzString::NzString() : -m_sharedString(&emptyString) -{ -} - -NzString::NzString(char character) -{ - if (character == '\0') - m_sharedString = &emptyString; - else - { - m_sharedString = new SharedString; - m_sharedString->capacity = 1; - m_sharedString->size = 1; - m_sharedString->string = new char[2]; - m_sharedString->string[0] = character; - m_sharedString->string[1] = '\0'; - } -} - -NzString::NzString(const char* string) -{ - if (string) - { - unsigned int size = std::strlen(string); - if (size > 0) - { - m_sharedString = new SharedString; - m_sharedString->capacity = size; - m_sharedString->size = size; - m_sharedString->string = new char[size+1]; - std::strcpy(m_sharedString->string, string); - } - else - m_sharedString = &emptyString; - } - else - m_sharedString = &emptyString; -} - -NzString::NzString(const std::string& string) -{ - if (string.size() > 0) - { - m_sharedString = new SharedString; - m_sharedString->capacity = string.capacity(); - m_sharedString->size = string.size(); - m_sharedString->string = new char[string.capacity()+1]; - std::strcpy(m_sharedString->string, string.c_str()); - } - else - m_sharedString = &emptyString; -} - -NzString::NzString(const NzString& string) : -m_sharedString(string.m_sharedString) -{ - if (m_sharedString != &emptyString) - { - NazaraMutexLock(m_sharedString->mutex); - m_sharedString->refCount++; - NazaraMutexUnlock(m_sharedString->mutex); - } -} - -NzString::NzString(NzString&& string) noexcept : -m_sharedString(string.m_sharedString) -{ - string.m_sharedString = &emptyString; -} - -NzString::NzString(SharedString* sharedString) : -m_sharedString(sharedString) -{ -} - -NzString::~NzString() -{ - ReleaseString(); -} - -NzString& NzString::Append(char character) -{ - if (character == '\0') - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity == 0) - return operator=(character); - - if (m_sharedString->capacity > m_sharedString->size) - { - EnsureOwnership(); - - m_sharedString->string[m_sharedString->size] = character; - m_sharedString->string[m_sharedString->size+1] = '\0'; - m_sharedString->size++; - } - else - { - unsigned int newSize = m_sharedString->size+1; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - str[m_sharedString->size] = character; - str[newSize] = '\0'; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::Append(const char* string) -{ - if (!string || !string[0]) - return *this; - - unsigned int length = std::strlen(string); - if (length == 0) - return *this; - - if (m_sharedString->capacity >= m_sharedString->size + length) - { - EnsureOwnership(); - - std::strcpy(&m_sharedString->string[m_sharedString->size], string); - m_sharedString->size += length; - } - else - { - unsigned int newSize = m_sharedString->size + length; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::Append(const NzString& string) -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) - return operator=(string); - - if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) - { - EnsureOwnership(); - - std::strcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string); - m_sharedString->size += string.m_sharedString->size; - } - else - { - unsigned int newSize = m_sharedString->size + string.m_sharedString->size; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string.m_sharedString->string); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -void NzString::Clear(bool keepBuffer) -{ - if (keepBuffer) - { - EnsureOwnership(); - m_sharedString->size = 0; - } - else - ReleaseString(); -} - -bool NzString::Contains(char character, int start, nzUInt32 flags) const -{ - return Find(character, start, flags) != npos; -} - -bool NzString::Contains(const char* string, int start, nzUInt32 flags) const -{ - return Find(string, start, flags) != npos; -} - -bool NzString::Contains(const NzString& string, int start, nzUInt32 flags) const -{ - return Find(string, start, flags) != npos; -} - -unsigned int NzString::Count(char character, int start, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - char character_lower = nzToLower(character); - char character_upper = nzToUpper(character); - do - { - if (*str == character_lower || *str == character_upper) - count++; - } - while (*++str); - } - else - { - while ((str = std::strchr(str, character))) - { - count++; - str++; - } - } - - return count; -} - -unsigned int NzString::Count(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - { - count++; - break; - } - - if (*it == '\0') - return count; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*str) == c) - { - str++; - - const char* ptr = &string[1]; - while (true) - { - if (*ptr == '\0') - { - count++; - break; - } - - if (*str == '\0') - return count; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - while ((str = std::strstr(str, string))) - { - count++; - str++; - } - } - - return count; -} - -unsigned int NzString::Count(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string.m_sharedString->string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - { - count++; - break; - } - - if (*it == '\0') - return count; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string.m_sharedString->string[0]); - do - { - if (nzToLower(*str) == c) - { - str++; - - const char* ptr = &string.m_sharedString->string[1]; - while (true) - { - if (*ptr == '\0') - { - count++; - break; - } - - if (*str == '\0') - return count; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - while ((str = std::strstr(str, string.m_sharedString->string))) - { - count++; - str++; - } - } - - return count; -} - -unsigned int NzString::CountAny(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - do - { - if (nzToLower(*str) == nzToLower(*c)) - { - count++; - break; - } - } - while (*++c); - } - while (*++str); - } - else - { - while ((str = std::strpbrk(str, string))) - { - count++; - str++; - } - } - } - - return count; -} - -unsigned int NzString::CountAny(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - else - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it == *it2) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string.m_sharedString->string; - do - { - if (nzToLower(*str) == nzToLower(*c)) - { - count++; - break; - } - } - while (*++c); - } - while (*++str); - } - else - { - while ((str = std::strpbrk(str, string.m_sharedString->string))) - { - count++; - str++; - } - } - } - - return count; -} - -bool NzString::EndsWith(char character, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - - if (flags & CaseInsensitive) - return nzToLower(m_sharedString->string[m_sharedString->size-1]) == nzToLower(character); - else - return m_sharedString->string[m_sharedString->size-1] == character; // character == '\0' sera toujours faux -} - -bool NzString::EndsWith(const char* string, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return false; - - unsigned int len = std::strlen(string); - if (len > m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; - else - return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; - } - else - return std::strcmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; -} - -bool NzString::EndsWith(const NzString& string, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; - else - return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; - } - else - return std::strcmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; -} - -unsigned int NzString::Find(char character, int start, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - if (flags & CaseInsensitive) - { - char ch = nzToLower(character); - const char* str = m_sharedString->string; - do - { - if (nzToLower(*str) == ch) - return static_cast(str - m_sharedString->string); - } - while (*++str); - - return npos; - } - else - { - char* ch = std::strchr(&m_sharedString->string[pos], character); - if (ch) - return static_cast(ch - m_sharedString->string); - else - return npos; - } -} - -unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - const char* ptrPos = it.base(); - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*it == '\0') - return npos; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*str) == c) - { - char* ptrPos = str; - str++; - - const char* ptr = &string[1]; - while (true) - { - if (*ptr == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*str == '\0') - return npos; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - char* ch = std::strstr(&m_sharedString->string[pos], string); - if (ch) - return static_cast(ch - m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string.m_sharedString->string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - const char* ptrPos = it.base(); - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*it == '\0') - return npos; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string.m_sharedString->string[0]); - do - { - if (nzToLower(*str) == c) - { - char* ptrPos = str; - str++; - - const char* ptr = &string.m_sharedString->string[1]; - while (true) - { - if (*ptr == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*str == '\0') - return npos; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - char* ch = std::strstr(&m_sharedString->string[pos], string.m_sharedString->string); - if (ch) - return static_cast(ch - m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::FindAny(const char* string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || !string || !string[0]) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (*++str); - } - else - { - str = std::strpbrk(str, string); - if (str) - return str - m_sharedString->string; - } - } - - return npos; -} - -unsigned int NzString::FindAny(const NzString& string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || string.m_sharedString->size == 0) - return npos; - - if (string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - else - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string.m_sharedString->string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (*++str); - } - else - { - str = std::strpbrk(str, string.m_sharedString->string); - if (str) - return str - m_sharedString->string; - } - } - - return npos; -} - -unsigned int NzString::FindLast(char character, int start, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* ptr = &m_sharedString->string[m_sharedString->size-1]; - - if (flags & CaseInsensitive) - { - character = nzToLower(character); - do - { - if (nzToLower(*ptr) == character) - return static_cast(ptr - m_sharedString->string); - } - while (ptr-- != m_sharedString->string); - } - else - { - // strrchr ? - do - { - if (*ptr == character) - return static_cast(ptr - m_sharedString->string); - } - while (ptr-- != m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::FindLast(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] ||m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 1.FindLast#3 (Taille du pattern inconnue) - const char* ptr = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - const char* t = string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - utf8::unchecked::iterator it2(t); - utf8::unchecked::iterator tIt(it); - ++tIt; - - while (true) - { - if (*it2 == '\0') - return it.base() - m_sharedString->string; - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) - break; - - ++it2; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - else - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*ptr) == c) - { - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - return ptr - m_sharedString->string; - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - } - else - { - do - { - if (*ptr == string[0]) - { - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - return ptr - m_sharedString->string; - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::FindLast(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size || string.m_sharedString->size > m_sharedString->size) - return npos; - - const char* ptr = &m_sharedString->string[pos]; - const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - ///Algo 1.FindLast#3 (Itérateur non-adapté) - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - const char* t = string.m_sharedString->string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - utf8::unchecked::iterator it2(t); - utf8::unchecked::iterator tIt(it); - ++tIt; - - while (true) - { - if (*it2 == '\0') - return it.base() - m_sharedString->string; - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) - break; - - ++it2; - ++tIt; - } - } - } - while (it--.base() != limit); - } - else - { - ///Algo 1.FindLast#4 (Taille du pattern connue) - char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); - while (true) - { - if (nzToLower(*ptr) == c) - { - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (nzToLower(*ptr) != nzToLower(*p)) - break; - - if (p == &string.m_sharedString->string[0]) - return ptr-m_sharedString->string; - - if (ptr == m_sharedString->string) - return npos; - } - } - else if (ptr-- <= limit) - break; - } - } - } - else - { - ///Algo 1.FindLast#4 (Taille du pattern connue) - while (true) - { - if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) - { - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (*ptr != *p) - break; - - if (p == &string.m_sharedString->string[0]) - return ptr-m_sharedString->string; - - if (ptr == m_sharedString->string) - return npos; - } - } - else if (ptr-- <= limit) - break; - } - } - - return npos; -} - -unsigned int NzString::FindLastAny(const char* string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || !string || !string[0]) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - else - { - do - { - const char* c = string; - do - { - if (*str == *c) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - } - - return npos; -} - -unsigned int NzString::FindLastAny(const NzString& string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || string.m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - else - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string.m_sharedString->string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - else - { - do - { - const char* c = string.m_sharedString->string; - do - { - if (*str == *c) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - } - - return npos; -} - -unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 2.FindLastWord#1 (Taille du pattern inconnue) - const char* ptr = &m_sharedString->string[pos]; - - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - else - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = utf8::unchecked::next(t); - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - } - else - { - if (flags & CaseInsensitive) - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*ptr) == c) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr-m_sharedString->string; - else - break; - } - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - else - { - do - { - if (*ptr == string[0]) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr-m_sharedString->string; - else - break; - } - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - } - - return npos; -} - -unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - const char* ptr = &m_sharedString->string[pos]; - const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; - - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - else - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = utf8::unchecked::next(t); - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - } - else - { - ///Algo 2.FindLastWord#2 (Taille du pattern connue) - if (flags & CaseInsensitive) - { - char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); - do - { - if (nzToLower(*ptr) == c) - { - if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) - continue; - - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (nzToLower(*ptr) != nzToLower(*p)) - break; - - if (p == &string.m_sharedString->string[0]) - { - if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) - return ptr-m_sharedString->string; - else - break; - } - - if (ptr == m_sharedString->string) - return npos; - } - } - } - while (ptr-- > limit); - } - else - { - do - { - if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) - { - if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) - continue; - - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (*ptr != *p) - break; - - if (p == &string.m_sharedString->string[0]) - { - if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) - return ptr-m_sharedString->string; - else - break; - } - - if (ptr == m_sharedString->string) - return npos; - } - } - } - while (ptr-- > limit); - } - } - - return npos; -} - -unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 3.FindWord#3 (Taille du pattern inconnue) - const char* ptr = m_sharedString->string; - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - else - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (*tIt != *p) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - } - else - { - if (flags & CaseInsensitive) - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*ptr) == c) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr - m_sharedString->string; - else - break; - } - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - else - { - do - { - if (*ptr == string[0]) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr - m_sharedString->string; - else - break; - } - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - } - - return npos; -} - -unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* ptr = m_sharedString->string; - if (flags & HandleUtf8) - { - ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - else - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (*tIt != *p) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - } - else - { - ///Algo 3.FindWord#2 (Taille du pattern connue) - if (flags & CaseInsensitive) - { - char c = nzToLower(string.m_sharedString->string[0]); - do - { - if (nzToLower(*ptr) == c) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string.m_sharedString->string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr - m_sharedString->string; - else - break; - } - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - else - { - while ((ptr = std::strstr(ptr, string.m_sharedString->string))) - { - // Si le mot est bien isolé - if ((ptr == m_sharedString->string || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) - return ptr - m_sharedString->string; - - ptr++; - } - } - } - - return npos; -} - -char* NzString::GetBuffer() -{ - EnsureOwnership(); - - return m_sharedString->string; -} - -unsigned int NzString::GetCapacity() const -{ - return m_sharedString->capacity; -} - -const char* NzString::GetConstBuffer() const -{ - return m_sharedString->string; -} - -unsigned int NzString::GetLength() const -{ - #if NAZARA_CORE_SAFE - try - { - #endif - return utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return 0; - } - #endif -} - -unsigned int NzString::GetSize() const -{ - return m_sharedString->size; -} - -char* NzString::GetUtf8Buffer(unsigned int* size) const -{ - if (m_sharedString->size == 0) - return nullptr; - - char* buffer = new char[m_sharedString->size+1]; - std::strcpy(buffer, m_sharedString->string); - - if (size) - *size = m_sharedString->size; - - return buffer; -} - -char16_t* NzString::GetUtf16Buffer(unsigned int* size) const -{ - if (m_sharedString->size == 0) - return nullptr; - - std::vector utf16; - utf16.reserve(m_sharedString->size); - #if NAZARA_CORE_SAFE - try - { - #endif - utf8::utf8to16(m_sharedString->string, &m_sharedString->string[m_sharedString->size], std::back_inserter(utf16)); - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return nullptr; - } - #endif - - unsigned int bufferSize = utf16.size(); - if (bufferSize == 0) - return nullptr; - - char16_t* buffer = new char16_t[bufferSize+1]; - std::memcpy(buffer, &utf16[0], bufferSize*sizeof(char16_t)); - buffer[bufferSize] ='\0'; - - if (size) - *size = bufferSize; - - return buffer; -} - -char32_t* NzString::GetUtf32Buffer(unsigned int* size) const -{ - if (m_sharedString->size == 0) - return nullptr; - - #if NAZARA_CORE_SAFE - try - { - #endif - unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); - if (bufferSize == 0) - return nullptr; - - char32_t* buffer = new char32_t[bufferSize+1]; - utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); - buffer[bufferSize] ='\0'; - - if (size) - *size = bufferSize; - - return buffer; - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return nullptr; - } - #endif -} - -wchar_t* NzString::GetWideBuffer(unsigned int* size) const -{ - static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t size is not supported"); - if (m_sharedString->size == 0) - return nullptr; - - #if NAZARA_CORE_SAFE - try - { - #endif - unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); - if (bufferSize == 0) - return nullptr; - - wchar_t* buffer = new wchar_t[bufferSize+1]; - if (sizeof(wchar_t) == 4) - utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); - else - { - wchar_t* ptr = buffer; - - utf8::unchecked::iterator it(m_sharedString->string); - do - { - char32_t cp = *it; - if (cp <= 0xFFFF && (cp < 0xD800 || cp > 0xDFFF)) // @Laurent Gomila - *ptr++ = static_cast(cp); - else - *ptr++ = static_cast('?'); - } - while (*it++); - } - - if (size) - *size = bufferSize; - - return buffer; - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return nullptr; - } - #endif -} - -NzString NzString::GetWord(unsigned int index, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return NzString(); - - NzString temp = Simplified(flags); // Évitons les mauvaises surprises - if (temp.IsEmpty()) - return NzString(); - - unsigned int foundPos = temp.Find(' '); // Simplified nous assure que nous n'avons plus que des espaces comme séparation - unsigned int lastPos = 0; - for (; index > 0; --index) - { - if (foundPos == npos) - return NzString(); - - lastPos = foundPos; - foundPos = temp.Find(' ', foundPos+1); - } - return temp.Substr((lastPos == 0) ? 0 : lastPos+1, (foundPos == npos) ? -1 : static_cast(foundPos-1)); -} - -unsigned int NzString::GetWordPosition(unsigned int index, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return npos; - - unsigned int currentWord = 0; - bool inWord = false; - - const char* ptr = m_sharedString->string; - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - inWord = false; - else - { - if (!inWord) - { - inWord = true; - if (++currentWord > index) - return static_cast(it.base() - m_sharedString->string); - } - } - } - while (*++it); - } - else - { - while (ptr != &m_sharedString->string[m_sharedString->size]) - { - if (!std::isspace(*ptr++)) - { - if (!inWord) - { - inWord = true; - if (++currentWord > index) - return ptr-m_sharedString->string; - } - } - else - inWord = false; - } - } - - return npos; -} - -NzString& NzString::Insert(int pos, char character) -{ - if (character == '\0') - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity == 0) - return operator=(character); - - if (pos < 0) - pos = std::max(static_cast(m_sharedString->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedString->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedString->capacity >= m_sharedString->size+1) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+1], &m_sharedString->string[start], m_sharedString->size*sizeof(char)); - m_sharedString->string[start] = character; - - m_sharedString->size += 1; - } - else - { - unsigned int newSize = m_sharedString->size+1; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedString->string; - while (ptr != &newString[start]) - *ptr++ = *s++; - - *ptr++ = character; - - std::strcpy(ptr, s); - - ReleaseString(); - - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -NzString& NzString::Insert(int pos, const char* string) -{ - if (!string || !string[0]) - return *this; - - if (pos < 0) - pos = std::max(static_cast(m_sharedString->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedString->size); - - // Si le buffer est déjà suffisamment grand - unsigned int len = std::strlen(string); - if (m_sharedString->capacity >= m_sharedString->size+len) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+len], &m_sharedString->string[start], m_sharedString->size*sizeof(char)); - std::memcpy(&m_sharedString->string[start], string, len*sizeof(char)); - - m_sharedString->size += len; - } - else - { - unsigned int newSize = m_sharedString->size+len; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedString->string; - - while (ptr != &newString[start]) - *ptr++ = *s++; - - const char* p = string; - while (ptr != &newString[start+len]) - *ptr++ = *p++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -NzString& NzString::Insert(int pos, const NzString& string) -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) - return operator=(string); - - if (pos < 0) - pos = std::max(static_cast(m_sharedString->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedString->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+string.m_sharedString->size], &m_sharedString->string[start], m_sharedString->size*sizeof(char)); - std::memcpy(&m_sharedString->string[start], string.m_sharedString->string, string.m_sharedString->size*sizeof(char)); - - m_sharedString->size += string.m_sharedString->size; - } - else - { - unsigned int newSize = m_sharedString->size+string.m_sharedString->size; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedString->string; - - while (ptr != &newString[start]) - *ptr++ = *s++; - - const char* p = string.m_sharedString->string; - while (ptr != &newString[start+string.m_sharedString->size]) - *ptr++ = *p++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -bool NzString::IsEmpty() const -{ - return m_sharedString->size == 0; -} - -bool NzString::IsNull() const -{ - return m_sharedString == &emptyString; -} - -bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const -{ - #if NAZARA_CORE_SAFE - if (base < 2 || base > 36) - { - NazaraError("Base must be between 2 and 36"); - return false; - } - #endif - - if (m_sharedString->size == 0) - return false; - - NzString check = Simplified(); - if (check.m_sharedString->size) - return false; - - char* ptr = (check.m_sharedString->string[0] == '-') ? &check.m_sharedString->string[1] : check.m_sharedString->string; - - if (base > 10) - { - if (flags & CaseInsensitive) - { - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || (c > '9' && c < 'A') || (c > 'A'+base-1 && c < 'a') || c > 'a'+base-1)) - return false; - } - while (*++ptr); - } - else - { - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || (c > '9' && c < 'a') || c > 'a'+base-1)) - return false; - } - while (*++ptr); - } - } - else - { - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || c > '0'+base-1)) - return false; - } - while (*++ptr); - } - - return true; -} - -bool NzString::Match(const char* pattern) const -{ - if (m_sharedString->size == 0 || !pattern) - return false; - - // Par Jack Handy - akkhandy@hotmail.com - // From : http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing - const char* str = m_sharedString->string; - while (*str && *pattern != '*') - { - if (*pattern != *str && *pattern != '?') - return false; - - pattern++; - str++; - } - - const char* cp = nullptr; - const char* mp = nullptr; - while (*str) - { - if (*pattern == '*') - { - if (!*++pattern) - return true; - - mp = pattern; - cp = str+1; - } - else if (*pattern == *str || *pattern == '?') - { - pattern++; - str++; - } - else - { - pattern = mp; - str = cp++; - } - } - - while (*pattern == '*') - pattern++; - - return !*pattern; -} - -bool NzString::Match(const NzString& pattern) const -{ - return Match(pattern.m_sharedString->string); -} - -NzString& NzString::Prepend(char character) -{ - return Insert(0, character); -} - -NzString& NzString::Prepend(const char* string) -{ - return Insert(0, string); -} - -NzString& NzString::Prepend(const NzString& string) -{ - return Insert(0, string); -} - -unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start, nzUInt32 flags) -{ - if (oldCharacter == '\0' || oldCharacter == newCharacter) - return 0; - - if (newCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe - return Replace(NzString(oldCharacter), NzString(), start); - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - unsigned int count = 0; - char* ptr = &m_sharedString->string[pos]; - bool found = false; - if (flags & CaseInsensitive) - { - char character_lower = nzToLower(oldCharacter); - char character_upper = nzToUpper(oldCharacter); - do - { - if (*ptr == character_lower || *ptr == character_upper) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = newCharacter; - ++count; - } - } - while (*++ptr); - } - else - { - while ((ptr = std::strchr(ptr, oldCharacter))) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = newCharacter; - ++count; - } - } - - return count; -} - -unsigned int NzString::Replace(const char* oldString, const char* replaceString, int start, nzUInt32 flags) -{ - if (!oldString || !oldString[0]) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - unsigned int oSize = std::strlen(oldString); - if (oSize == 0) - return 0; - - unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; - - unsigned int count = 0; - if (oSize == rSize) - { - bool found = false; - - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide - while ((pos = Find(oldString, pos, flags)) != npos) - { - if (!found) - { - EnsureOwnership(); - found = true; - } - - std::memcpy(&m_sharedString->string[pos], replaceString, oSize*sizeof(char)); - pos += oSize; - - ++count; - } - } - else ///TODO: Algorithme de remplacement sans changement de buffer (si rSize < oSize) - { - unsigned int newSize = m_sharedString->size + Count(oldString)*(rSize - oSize); - if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 - return 0; - - char* newString = new char[newSize+1]; - - ///Algo 4.Replace#2 - char* ptr = newString; - const char* p = m_sharedString->string; - - while ((pos = Find(oldString, pos, flags)) != npos) - { - const char* r = &m_sharedString->string[pos]; - - std::memcpy(ptr, p, (r-p)*sizeof(char)); - ptr += r-p; - std::memcpy(ptr, replaceString, rSize*sizeof(char)); - ptr += rSize; - p = r+oSize; - pos += oSize; - - count++; - } - - std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; -} - -unsigned int NzString::Replace(const NzString& oldString, const NzString& replaceString, int start, nzUInt32 flags) -{ - if (oldString.m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size || oldString.m_sharedString->size == 0) - return 0; - - unsigned int count = 0; - if (oldString.m_sharedString->size == replaceString.m_sharedString->size) - { - bool found = false; - - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide - while ((pos = Find(oldString, pos, flags)) != npos) - { - if (!found) - { - EnsureOwnership(); - found = true; - } - - std::memcpy(&m_sharedString->string[pos], replaceString.m_sharedString->string, oldString.m_sharedString->size*sizeof(char)); - pos += oldString.m_sharedString->size; - - ++count; - } - } - else - { - unsigned int newSize = m_sharedString->size + Count(oldString)*(replaceString.m_sharedString->size - oldString.m_sharedString->size); - if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 - return 0; - - char* newString = new char[newSize+1]; - - ///Algo 4.Replace#2 - char* ptr = newString; - const char* p = m_sharedString->string; - - while ((pos = Find(oldString, pos, flags)) != npos) - { - const char* r = &m_sharedString->string[pos]; - - std::memcpy(ptr, p, (r-p)*sizeof(char)); - ptr += r-p; - std::memcpy(ptr, replaceString.m_sharedString->string, replaceString.m_sharedString->size*sizeof(char)); - ptr += replaceString.m_sharedString->size; - p = r+oldString.m_sharedString->size; - pos += oldString.m_sharedString->size; - - count++; - } - - std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; -} - -unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags) -{ - ///FIXME: Ne gère pas l'UTF-8 - if (!oldCharacters || !oldCharacters[0]) - return 0; - - /*if (replaceCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe - return ReplaceAny(NzString(oldCharacters), NzString(), start);*/ - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - unsigned int count = 0; - char* ptr = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - do - { - const char* c = oldCharacters; - char character = nzToLower(*ptr); - bool found = false; - do - { - if (character == nzToLower(*c)) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = replaceCharacter; - ++count; - break; - } - } - while (*++c); - } - while (*++ptr); - } - else - { - bool found = false; - while ((ptr = std::strpbrk(ptr, oldCharacters))) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr++ = replaceCharacter; - ++count; - } - } - - return count; -} -/* - unsigned int NzString::ReplaceAny(const char* oldCharacters, const char* replaceString, int start, nzUInt32 flags) - { - if (start < 0) - { - start = m_sharedString->size+start; - if (start < 0) - start = 0; - } - - unsigned int pos = static_cast(start); - unsigned int oSize = (oldCharacters) ? std::strlen(oldCharacters) : 0; - unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; - - if (pos >= m_sharedString->size || m_sharedString->size == 0 || oSize == 0) - return 0; - - unsigned int count = 0; - - if (rSize == 1) // On utilise un algorithme optimisé - { - EnsureOwnership(); - - f or (; pos < m_sharedString->size; ++pos) - { - for (unsigned int i = 0; i < oSize; ++i) - { - if (m_sharedString->string[pos] == oldCharacters[i]) - { - m_sharedString->string[pos] = replaceString[0]; - ++count; - - break; - } - } - } - } - else - { - unsigned int newSize; - { - unsigned int count = CountAny(oldCharacters); - newSize = m_sharedString->size - count + count*rSize; - } - char* newString = new char[newSize+1]; - - unsigned int j = 0; - for (unsigned int i = 0; i < m_sharedString->size; ++i) - { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier - newString[j++] = m_sharedString->string[i]; - else - { - bool found = false; - for (unsigned int l = 0; l < oSize; ++l) - { - if (m_sharedString->string[i] == oldCharacters[l]) - { - for (unsigned int k = 0; k < rSize; ++k) - newString[j++] = replaceString[k]; - - ++count; - found = true; - break; // Simple façon d'éviter la ligne après la boucle - } - } - - if (!found) - newString[j++] = m_sharedString->string[i]; - } - } - newString[newSize] = '\0'; - - ReleaseString(); - - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; - } - - unsigned int NzString::ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start, nzUInt32 flags) - { - if (start < 0) - { - start = m_sharedString->size+start; - if (start < 0) - start = 0; - } - - unsigned int pos = static_cast(start); - - if (pos >= m_sharedString->size || m_sharedString->size == 0 || oldCharacters.m_sharedString->size == 0) - return 0; - - unsigned int count = 0; - - if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé - { - EnsureOwnership(); - - char character = replaceString[0]; - for (; pos < m_sharedString->size; ++pos) - { - for (unsigned int i = 0; i < oldCharacters.m_sharedString->size; ++i) - { - if (m_sharedString->string[pos] == oldCharacters[i]) - { - m_sharedString->string[pos] = character; - ++count; - break; - } - } - } - } - else - { - unsigned int newSize; - { - unsigned int count = CountAny(oldCharacters); - newSize = m_sharedString->size - count + count*replaceString.m_sharedString->size; - } - char* newString = new char[newSize+1]; - - unsigned int j = 0; - for (unsigned int i = 0; i < m_sharedString->size; ++i) - { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier - newString[j++] = m_sharedString->string[i]; - else - { - bool found = false; - for (unsigned int l = 0; l < oldCharacters.m_sharedString->size; ++l) - { - if (m_sharedString->string[i] == oldCharacters[l]) - { - for (unsigned int k = 0; k < replaceString.m_sharedString->size; ++k) - newString[j++] = replaceString[k]; - - ++count; - found = true; - break; // Simple façon d'éviter la ligne après la boucle - } - } - - if (!found) - newString[j++] = m_sharedString->string[i]; - } - } - newString[newSize] = '\0'; - - ReleaseString(); - - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; - } -*/ -void NzString::Reserve(unsigned int bufferSize) -{ - if (m_sharedString->capacity >= bufferSize) - return; - - char* ptr = new char[bufferSize+1]; - if (m_sharedString->size > 0) - std::strcpy(ptr, m_sharedString->string); - - unsigned int size = m_sharedString->size; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = size; - m_sharedString->string = ptr; -} - -NzString& NzString::Resize(int size, char character) -{ - if (size == 0) - { - Clear(true); - return *this; - } - - if (size < 0) - size = std::max(static_cast(m_sharedString->size + size), 0); - - unsigned int newSize = static_cast(size); - - if (m_sharedString->capacity >= newSize) - { - EnsureOwnership(); - - // Nous avons déjà la place requise, contentons-nous de remplir le buffer - if (character != '\0' && newSize > m_sharedString->size) - { - char* ptr = &m_sharedString->string[m_sharedString->size]; - char* limit = &m_sharedString->string[newSize]; - while (ptr != limit) - *ptr++ = character; - } - - m_sharedString->size = newSize; - m_sharedString->string[newSize] = '\0'; - } - else // On veut forcément agrandir la chaine - { - char* newString = new char[newSize+1]; - if (m_sharedString->size != 0) - std::memcpy(newString, m_sharedString->string, newSize*sizeof(char)); - - char* ptr = &newString[m_sharedString->size]; - char* limit = &newString[newSize]; - while (ptr != limit) - *ptr++ = character; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -NzString NzString::Resized(int size, char character) const -{ - if (size < 0) - size = m_sharedString->size + size; - - if (size <= 0) - return NzString(); - - unsigned int newSize = static_cast(size); - if (newSize == m_sharedString->size) - return *this; - - char* str = new char[newSize+1]; - if (newSize > m_sharedString->size) - { - std::memcpy(str, m_sharedString->string, m_sharedString->size); - if (character != '\0') - { - char* ptr = &str[m_sharedString->size]; - char* limit = &str[newSize]; - while (ptr != limit) - *ptr++ = character; - } - } - else - std::memcpy(str, m_sharedString->string, newSize); - - str[newSize] = '\0'; - - return NzString(new SharedString(1, newSize, newSize, str)); -} - -NzString& NzString::Reverse() -{ - if (m_sharedString->size != 0) - { - unsigned int i = 0; - unsigned int j = m_sharedString->size-1; - - while (i < j) - std::swap(m_sharedString->string[i++], m_sharedString->string[j--]); - } - - return *this; -} - -NzString NzString::Reversed() const -{ - if (m_sharedString->size == 0) - return NzString(); - - char* str = new char[m_sharedString->size+1]; - - char* ptr = &str[m_sharedString->size-1]; - char* p = m_sharedString->string; - - do - *ptr-- = *p; - while (*(++p)); - - str[m_sharedString->size] = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); -} - -NzString NzString::Simplified(nzUInt32 flags) const -{ - char* str = new char[m_sharedString->size+1]; - char* p = str; - - const char* ptr = m_sharedString->string; - bool inword = false; - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - { - if (inword) - { - *p++ = ' '; - inword = false; - } - } - else - { - p = utf8::append(*it, p); - inword = true; - } - } - while (*++it); - } - else - { - const char* limit = &m_sharedString->string[m_sharedString->size]; - do - { - if (std::isspace(*ptr)) - { - if (inword) - { - *p++ = ' '; - inword = false; - } - } - else - { - *p++ = *ptr; - inword = true; - } - } - while (++ptr != limit); - } - - if (!inword) - p--; - - *p = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, p-str, str)); -} - -NzString& NzString::Simplify(nzUInt32 flags) -{ - return operator=(Simplified(flags)); -} - -unsigned int NzString::Split(std::vector& result, char separation, int start, nzUInt32 flags) const -{ - if (separation == '\0' || m_sharedString->size == 0) - return 0; - - unsigned int lastSep = Find(separation, start, flags); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - while (true) - { - unsigned int sep = Find(separation, lastSep+1, flags); - if (sep == npos) - break; - - if (sep-lastSep > 1) - result.push_back(Substr(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(Substr(lastSep+1)); - - return result.size(); -} - -unsigned int NzString::Split(std::vector& result, const char* separation, int start, nzUInt32 flags) const -{ - unsigned int size = (separation) ? std::strlen(separation) : 0; - if (m_sharedString->size == 0) - return 0; - else if (size == 0) - { - result.reserve(m_sharedString->size); - for (unsigned int i = 0; i < m_sharedString->size; ++i) - result.push_back(NzString(m_sharedString->string[i])); - - return m_sharedString->size; - } - else if (size > m_sharedString->size) - { - result.push_back(*this); - return 1; - } - - unsigned int lastSep = Find(separation, start, flags); - unsigned int oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = Find(separation, lastSep+size, flags)) != npos) - { - if (sep-lastSep > size) - result.push_back(Substr(lastSep+size, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-size) - result.push_back(Substr(lastSep+size)); - - return result.size()-oldSize; -} - -unsigned int NzString::Split(std::vector& result, const NzString& separation, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - else if (separation.m_sharedString->size == 0) - { - result.reserve(m_sharedString->size); - for (unsigned int i = 0; i < m_sharedString->size; ++i) - result.push_back(NzString(m_sharedString->string[i])); - - return m_sharedString->size; - } - else if (separation.m_sharedString->size > m_sharedString->size) - { - result.push_back(*this); - return 1; - } - - unsigned int lastSep = Find(separation, start, flags); - unsigned int oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = Find(separation, lastSep+separation.m_sharedString->size, flags)) != npos) - { - if (sep-lastSep > separation.m_sharedString->size) - result.push_back(Substr(lastSep+separation.m_sharedString->size, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-separation.m_sharedString->size) - result.push_back(Substr(lastSep+separation.m_sharedString->size)); - - return result.size()-oldSize; -} - -unsigned int NzString::SplitAny(std::vector& result, const char* separations, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - - unsigned int oldSize = result.size(); - - unsigned int lastSep = FindAny(separations, start, flags); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = FindAny(separations, lastSep+1, flags)) != npos) - { - if (sep-lastSep > 1) - result.push_back(Substr(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(Substr(lastSep+1)); - - return result.size()-oldSize; -} - -unsigned int NzString::SplitAny(std::vector& result, const NzString& separations, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - - unsigned int lastSep = FindAny(separations, start, flags); - unsigned int oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = FindAny(separations, lastSep+1, flags)) != npos) - { - if (sep-lastSep > 1) - result.push_back(Substr(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(Substr(lastSep+1)); - - return result.size()-oldSize; -} - -bool NzString::StartsWith(char character, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return false; - - if (flags & CaseInsensitive) - return nzToLower(m_sharedString->string[0]) == nzToLower(character); - else - return m_sharedString->string[0] == character; -} - -bool NzString::StartsWith(const char* string, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(m_sharedString->string); - utf8::unchecked::iterator it2(string); - do - { - if (*it2 == '\0') - return true; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - return false; - - ++it2; - } - while (*it++); - } - else - { - char* ptr = m_sharedString->string; - const char* s = string; - do - { - if (*s == '\0') - return true; - - if (nzToLower(*ptr) != nzToLower(*s)) - return false; - - s++; - } - while (*ptr++); - } - } - else - { - char* ptr = m_sharedString->string; - const char* s = string; - do - { - if (*s == '\0') - return true; - - if (*ptr != *s) - return false; - - s++; - } - while (*ptr++); - } - - return false; -} - -bool NzString::StartsWith(const NzString& string, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0) - return false; - - if (m_sharedString->size < string.m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(m_sharedString->string); - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it2 == '\0') - return true; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - return false; - - ++it2; - } - while (*it++); - } - else - { - char* ptr = m_sharedString->string; - const char* s = string.m_sharedString->string; - do - { - if (*s == '\0') - return true; - - if (nzToLower(*ptr) != nzToLower(*s)) - return false; - - s++; - } - while (*ptr++); - } - } - else - return std::memcmp(m_sharedString->string, string.m_sharedString->string, string.m_sharedString->size*sizeof(char)) == 0; - - return false; -} - -NzString NzString::Substr(int startPos, int endPos) const -{ - if (startPos < 0) - startPos = std::max(m_sharedString->size+startPos, 0U); - - unsigned int start = static_cast(startPos); - - if (endPos < 0) - { - endPos = m_sharedString->size+endPos; - if (endPos < 0) - return NzString(); - } - - unsigned int minEnd = std::min(static_cast(endPos), m_sharedString->size-1); - - if (start > minEnd || start >= m_sharedString->size) - return NzString(); - - unsigned int size = minEnd-start+1; - char* str = new char[size+1]; - std::memcpy(str, &m_sharedString->string[start], size*sizeof(char)); - str[size] = '\0'; - - return NzString(new SharedString(1, size, size, str)); -} - -NzString NzString::SubstrFrom(char character, int startPos, bool fromLast, bool include, nzUInt32 flags) const -{ - if (character == '\0') - return *this; - - unsigned int pos; - if (fromLast) - pos = FindLast(character, startPos, flags); - else - pos = Find(character, startPos, flags); - - if (pos == 0 and include) - return *this; - else if (pos == npos) - return NzString(); - - return Substr(pos+((include) ? 0 : 1)); -} - -NzString NzString::SubstrFrom(const char* string, int startPos, bool fromLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (fromLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0 && include) - return *this; - else if (pos == npos) - return NzString(); - - return Substr(pos+((include) ? 0 : std::strlen(string))); -} - -NzString NzString::SubstrFrom(const NzString& string, int startPos, bool fromLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (fromLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0 && include) - return *this; - else if (pos == npos) - return NzString(); - - return Substr(pos+((include) ? 0 : string.m_sharedString->size)); -} - -NzString NzString::SubstrTo(char character, int startPos, bool toLast, bool include, nzUInt32 flags) const -{ - if (character == '\0') - return *this; - - unsigned int pos; - if (toLast) - pos = FindLast(character, startPos); - else - pos = Find(character, startPos, flags); - - if (pos == 0) - return (include) ? character : NzString(); - else if (pos == npos) - return *this; - - return Substr(0, pos+((include) ? 1 : 0)-1); -} - -NzString NzString::SubstrTo(const char* string, int startPos, bool toLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (toLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0) - return (include) ? string : NzString(); - else if (pos == npos) - return *this; - - return Substr(0, pos+((include) ? std::strlen(string) : 0)-1); -} - -NzString NzString::SubstrTo(const NzString& string, int startPos, bool toLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (toLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0) - return (include) ? string : NzString(); - else if (pos == npos) - return *this; - - return Substr(0, pos+((include) ? string.m_sharedString->size : 0)-1); -} - -void NzString::Swap(NzString& str) -{ - std::swap(m_sharedString, str.m_sharedString); -} - -bool NzString::ToBool(bool* value, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return false; - - NzString word = GetWord(0); - - if (word[0] == '1') - { - if (value) - *value = true; - } - else if (word[0] == '0') - { - if (value) - *value = false; - } - else - { - if (flags & CaseInsensitive) - word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode - - if (word == "true") - { - if (value) - *value = true; - } - else if (word == "false") - { - if (value) - *value = false; - } - else - return false; - } - - return true; -} - -bool NzString::ToDouble(double* value) const -{ - if (m_sharedString->size == 0) - return false; - - if (value) - *value = std::atof(m_sharedString->string); - - return true; -} - -bool NzString::ToInteger(long long* value, nzUInt8 base) const -{ - if (value) - { - bool ok; - *value = NzStringToNumber(*this, base, &ok); - - return ok; - } - else - return IsNumber(base); -} - -NzString NzString::ToLower(nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - if (flags & HandleUtf8) - { - NzString lower; - lower.Reserve(m_sharedString->size); - utf8::unchecked::iterator it(m_sharedString->string); - do - utf8::append(NzUnicode::GetLowercase(*it), std::back_inserter(lower)); - while (*++it); - - return lower; - } - else - { - char* str = new char[m_sharedString->size+1]; - - char* ptr = m_sharedString->string; - char* s = str; - do - *s++ = nzToLower(*ptr); - while (*++ptr); - - *s = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); - } -} - -NzString NzString::ToUpper(nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - if (flags & HandleUtf8) - { - NzString upper; - upper.Reserve(m_sharedString->size); - utf8::unchecked::iterator it(m_sharedString->string); - do - utf8::append(NzUnicode::GetUppercase(*it), std::back_inserter(upper)); - while (*++it); - - return upper; - } - else - { - char* str = new char[m_sharedString->size+1]; - - char* ptr = m_sharedString->string; - char* s = str; - do - *s++ = nzToUpper(*ptr); - while (*++ptr); - - *s = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); - } -} - -NzString& NzString::Trim(nzUInt32 flags) -{ - return operator=(Trimmed(flags)); -} - -NzString& NzString::Trim(char character, nzUInt32 flags) -{ - return operator=(Trimmed(character, flags)); -} - -NzString NzString::Trimmed(nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - unsigned int startPos; - unsigned int endPos; - if (flags & HandleUtf8) - { - if ((flags & TrimOnlyRight) == 0) - { - utf8::unchecked::iterator it(m_sharedString->string); - do - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - break; - } - while (*++it); - - startPos = it.base() - m_sharedString->string; - } - else - startPos = 0; - - if ((flags & TrimOnlyLeft) == 0) - { - utf8::unchecked::iterator it(&m_sharedString->string[m_sharedString->size]); - while ((it--).base() != m_sharedString->string) - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - break; - } - - endPos = it.base() - m_sharedString->string; - } - else - endPos = m_sharedString->size-1; - } - else - { - startPos = 0; - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (!std::isspace(m_sharedString->string[startPos])) - break; - } - } - - endPos = m_sharedString->size-1; - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (!std::isspace(m_sharedString->string[endPos])) - break; - } - } - } - - return Substr(startPos, endPos); -} - -NzString NzString::Trimmed(char character, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - unsigned int startPos = 0; - unsigned int endPos = m_sharedString->size-1; - if (flags & CaseInsensitive) - { - char ch = nzToLower(character); - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (nzToLower(m_sharedString->string[startPos]) != ch) - break; - } - } - - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (nzToLower(m_sharedString->string[startPos]) != ch) - break; - } - } - } - else - { - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (m_sharedString->string[startPos] != character) - break; - } - } - - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (m_sharedString->string[startPos] != character) - break; - } - } - } - - return Substr(startPos, endPos); -} - -char* NzString::begin() -{ - return m_sharedString->string; -} - -const char* NzString::begin() const -{ - return m_sharedString->string; -} - -char* NzString::end() -{ - return &m_sharedString->string[m_sharedString->size]; -} - -const char* NzString::end() const -{ - return &m_sharedString->string[m_sharedString->size]; -} - -void NzString::push_front(char c) -{ - operator=(c + *this); -} - -void NzString::push_back(char c) -{ - operator+=(c); -} -/* -char* NzString::rbegin() -{ - return &m_sharedString->string[m_sharedString->size-1]; -} - -const char* NzString::rbegin() const -{ - return &m_sharedString->string[m_sharedString->size-1]; -} - -char* NzString::rend() -{ - return &m_sharedString->string[-1]; -} - -const char* NzString::rend() const -{ - return &m_sharedString->string[-1]; -} -*/ - -NzString::operator std::string() const -{ - return std::string(m_sharedString->string, m_sharedString->size); -} - -char& NzString::operator[](unsigned int pos) -{ - EnsureOwnership(); - - if (pos >= m_sharedString->size) - Resize(pos+1); - - return m_sharedString->string[pos]; -} - -char NzString::operator[](unsigned int pos) const -{ - #if NAZARA_CORE_SAFE - if (pos >= m_sharedString->size) - { - NazaraError("Index out of range (" + Number(pos) + " >= " + Number(m_sharedString->size) + ')'); - return 0; - } - #endif - - return m_sharedString->string[pos]; -} - -NzString& NzString::operator=(char character) -{ - if (character != '\0') - { - if (m_sharedString->capacity >= 1) - EnsureOwnership(); - else - { - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = 1; - m_sharedString->string = new char[2]; - } - - m_sharedString->size = 1; - m_sharedString->string[0] = character; - m_sharedString->string[1] = '\0'; - } - else - ReleaseString(); - - return *this; -} - -NzString& NzString::operator=(const char* string) -{ - if (string && string[0] != '\0') - { - unsigned int size = std::strlen(string); - if (m_sharedString->capacity >= size) - EnsureOwnership(); - else - { - ReleaseString(); - - m_sharedString = new SharedString; - m_sharedString->capacity = size; - m_sharedString->string = new char[size+1]; - } - - m_sharedString->size = size; - std::strcpy(m_sharedString->string, string); - } - else - ReleaseString(); - - return *this; -} - -NzString& NzString::operator=(const std::string& string) -{ - if (string.size() > 0) - { - if (m_sharedString->capacity >= string.size()) - EnsureOwnership(); - else - { - ReleaseString(); - - m_sharedString = new SharedString; - m_sharedString->capacity = string.size(); - m_sharedString->string = new char[string.size()+1]; - } - - m_sharedString->size = string.size(); - std::strcpy(m_sharedString->string, string.c_str()); - } - else - ReleaseString(); - - return *this; -} - -NzString& NzString::operator=(const NzString& string) -{ - ReleaseString(); - - m_sharedString = string.m_sharedString; - if (m_sharedString != &emptyString) - { - NazaraMutexLock(m_sharedString->mutex); - m_sharedString->refCount++; - NazaraMutexUnlock(m_sharedString->mutex); - } - - return *this; -} - -NzString& NzString::operator=(NzString&& string) noexcept -{ - std::swap(m_sharedString, string.m_sharedString); - - return *this; -} - -NzString NzString::operator+(char character) const -{ - if (character == '\0') - return *this; - - unsigned int totalSize = m_sharedString->size+1; - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - - str[m_sharedString->size] = character; - str[totalSize] = '\0'; - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString NzString::operator+(const char* string) const -{ - if (!string || !string[0]) - return *this; - - if (m_sharedString->size == 0) - return string; - - unsigned int length = std::strlen(string); - if (length == 0) - return *this; - - unsigned int totalSize = m_sharedString->size + length; - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string); - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString NzString::operator+(const std::string& string) const -{ - if (string.empty()) - return *this; - - if (m_sharedString->size == 0) - return string; - - unsigned int totalSize = m_sharedString->size + string.size(); - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string.c_str()); - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString NzString::operator+(const NzString& string) const -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0) - return string; - - unsigned int totalSize = m_sharedString->size + string.m_sharedString->size; - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string.m_sharedString->string); - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString& NzString::operator+=(char character) -{ - if (character == '\0') - return *this; - - if (m_sharedString->size == 0) - return operator=(character); - - if (m_sharedString->capacity > m_sharedString->size) - { - EnsureOwnership(); - - m_sharedString->string[m_sharedString->size] = character; - m_sharedString->string[m_sharedString->size+1] = '\0'; - m_sharedString->size++; - } - else - { - unsigned int newSize = m_sharedString->size+1; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - str[m_sharedString->size] = character; - str[newSize] = '\0'; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::operator+=(const char* string) -{ - if (!string || !string[0]) - return *this; - - if (m_sharedString->size == 0) - return operator=(string); - - unsigned int length = std::strlen(string); - if (length == 0) - return *this; - - if (m_sharedString->capacity >= m_sharedString->size + length) - { - EnsureOwnership(); - - std::strcpy(&m_sharedString->string[m_sharedString->size], string); - m_sharedString->size += length; - } - else - { - unsigned int newSize = m_sharedString->size + length; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::operator+=(const std::string& string) -{ - if (string.empty()) - return *this; - - if (m_sharedString->size == 0) - return operator=(string); - - if (m_sharedString->capacity >= m_sharedString->size + string.size()) - { - EnsureOwnership(); - - std::strcpy(&m_sharedString->string[m_sharedString->size], string.c_str()); - m_sharedString->size += string.size(); - } - else - { - unsigned int newSize = m_sharedString->size + string.size(); - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string.c_str()); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::operator+=(const NzString& string) -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0) - return operator=(string); - - if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) - { - EnsureOwnership(); - - std::strcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string); - m_sharedString->size += string.m_sharedString->size; - } - else - { - unsigned int newSize = m_sharedString->size + string.m_sharedString->size; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size*sizeof(char)); - std::strcpy(&str[m_sharedString->size], string.m_sharedString->string); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -bool NzString::operator==(char character) const -{ - if (m_sharedString->size == 0) - return character == '\0'; - - if (m_sharedString->size > 1) - return false; - - return m_sharedString->string[0] == character; -} - -bool NzString::operator==(const char* string) const -{ - if (m_sharedString->size == 0) - return !string || !string[0]; - - if (!string || !string[0]) - return false; - - return std::strcmp(m_sharedString->string, string) == 0; -} - -bool NzString::operator==(const std::string& string) const -{ - if (m_sharedString->size == 0 || string.empty()) - return m_sharedString->size == string.size(); - - if (m_sharedString->size != string.size()) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) == 0; -} - -bool NzString::operator!=(char character) const -{ - if (m_sharedString->size == 0) - return character != '\0'; - - if (character == '\0' || m_sharedString->size != 1) - return true; - - if (m_sharedString->size != 1) - return true; - - return m_sharedString->string[0] != character; -} - -bool NzString::operator!=(const char* string) const -{ - if (m_sharedString->size == 0) - return string && string[0]; - - if (!string || !string[0]) - return true; - - return std::strcmp(m_sharedString->string, string) != 0; -} - -bool NzString::operator!=(const std::string& string) const -{ - if (m_sharedString->size == 0 || string.empty()) - return m_sharedString->size == string.size(); - - if (m_sharedString->size != string.size()) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) != 0; -} - -bool NzString::operator<(char character) const -{ - if (character == '\0') - return false; - - if (m_sharedString->size == 0) - return true; - - return m_sharedString->string[0] < character; -} - -bool NzString::operator<(const char* string) const -{ - if (!string || !string[0]) - return false; - - if (m_sharedString->size == 0) - return true; - - return std::strcmp(m_sharedString->string, string) < 0; -} - -bool NzString::operator<(const std::string& string) const -{ - if (string.empty()) - return false; - - if (m_sharedString->size == 0) - return true; - - return std::strcmp(m_sharedString->string, string.c_str()) < 0; -} - -bool NzString::operator<=(char character) const -{ - if (m_sharedString->size == 0) - return true; - - if (character == '\0') - return false; - - return m_sharedString->string[0] < character || (m_sharedString->string[0] == character && m_sharedString->size == 1); -} - -bool NzString::operator<=(const char* string) const -{ - if (m_sharedString->size == 0) - return true; - - if (!string || !string[0]) - return false; - - return std::strcmp(m_sharedString->string, string) <= 0; -} - -bool NzString::operator<=(const std::string& string) const -{ - if (m_sharedString->size == 0) - return true; - - if (string.empty()) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) <= 0; -} - -bool NzString::operator>(char character) const -{ - if (m_sharedString->size == 0) - return false; - - if (character == '\0') - return true; - - return m_sharedString->string[0] > character; -} - -bool NzString::operator>(const char* string) const -{ - if (m_sharedString->size == 0) - return false; - - if (!string || !string[0]) - return true; - - return std::strcmp(m_sharedString->string, string) > 0; -} - -bool NzString::operator>(const std::string& string) const -{ - if (m_sharedString->size == 0) - return false; - - if (string.empty()) - return true; - - return std::strcmp(m_sharedString->string, string.c_str()) > 0; -} - -bool NzString::operator>=(char character) const -{ - if (character == '\0') - return true; - - if (m_sharedString->size == 0) - return false; - - return m_sharedString->string[0] > character || (m_sharedString->string[0] == character && m_sharedString->size == 1); -} - -bool NzString::operator>=(const char* string) const -{ - if (!string || !string[0]) - return true; - - if (m_sharedString->size == 0) - return false; - - return std::strcmp(m_sharedString->string, string) >= 0; -} - -bool NzString::operator>=(const std::string& string) const -{ - if (string.empty()) - return true; - - if (m_sharedString->size == 0) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) >= 0; -} - -NzString NzString::Boolean(bool boolean) -{ - unsigned int size = (boolean) ? 4 : 5; - char* str = new char[size+1]; - std::strcpy(str, (boolean) ? "true" : "false"); - - return NzString(new SharedString(1, size, size, str)); -} - -int NzString::Compare(const NzString& first, const NzString& second) -{ - if (first.m_sharedString->size == 0) - return (second.m_sharedString->size == 0) ? 0 : -1; - - if (second.m_sharedString->size == 0) - return 1; - - return std::strcmp(first.m_sharedString->string, second.m_sharedString->string); -} - -NzString NzString::Number(float number) -{ - std::ostringstream oss; - oss.precision(NAZARA_CORE_REAL_PRECISION); - oss << number; - - return NzString(oss.str()); -} - -NzString NzString::Number(double number) -{ - std::ostringstream oss; - oss.precision(NAZARA_CORE_REAL_PRECISION); - oss << number; - - return NzString(oss.str()); -} - -NzString NzString::Number(long double number) -{ - std::ostringstream oss; - oss.precision(NAZARA_CORE_REAL_PRECISION); - oss << number; - - return NzString(oss.str()); -} - -NzString NzString::Number(signed char number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned char number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(short number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned short number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(int number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned int number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(long long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned long long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Pointer(const void* ptr) -{ - unsigned int size = sizeof(ptr)*2+2; - char* str = new char[size+1]; - std::sprintf(str, "0x%p", ptr); - - return NzString(new SharedString(1, size, size, str)); -} - -NzString NzString::Unicode(char32_t character) -{ - if (character == '\0') - return NzString(); - - unsigned int count = 0; - if (character < 0x80) - count = 1; - else if (character < 0x800) - count = 2; - else if (character < 0x10000) - count = 3; - else - count = 4; - - char* str = new char[count+1]; - utf8::append(character, str); - str[count] = '\0'; - - return NzString(new SharedString(1, count, count, str)); -} - -NzString NzString::Unicode(const char* u8String) -{ - return NzString(u8String); -} - -NzString NzString::Unicode(const char16_t* u16String) -{ - if (!u16String || !u16String[0]) - return NzString(); - - const char16_t* ptr = u16String; - unsigned int count = 0; - do - count++; - while (*++ptr); - - count *= 2; // On s'assure d'avoir la place suffisante - - char* str = new char[count+1]; - char* r = utf8::utf16to8(u16String, ptr, str); - *r = '\0'; - - return NzString(new SharedString(1, count, r-str, str)); -} - -NzString NzString::Unicode(const char32_t* u32String) -{ - if (!u32String || !u32String[0]) - return NzString(); - - const char32_t* ptr = u32String; - unsigned int count = 0; - do - { - char32_t cp = *ptr; - if (cp < 0x80) - count += 1; - else if (cp < 0x800) - count += 2; - else if (cp < 0x10000) - count += 3; - else - count += 4; - } - while (*++ptr); - - char* str = new char[count+1]; - char* r = utf8::utf32to8(u32String, ptr, str); - *r = '\0'; - - return NzString(new SharedString(1, count, count, str)); -} - -NzString NzString::Unicode(const wchar_t* wString) -{ - if (!wString || !wString[0]) - return NzString(); - - const wchar_t* ptr = wString; - unsigned int count = 0; - do - { - char32_t cp = *ptr; - if (cp < 0x80) - count += 1; - else if (cp < 0x800) - count += 2; - else if (cp < 0x10000) - count += 3; - else - count += 4; - } - while (*++ptr); - - char* str = new char[count+1]; - char* r = utf8::utf32to8(wString, ptr, str); - *r = '\0'; - - return NzString(new SharedString(1, count, count, str)); -} - -std::istream& operator>>(std::istream& is, NzString& str) -{ - str.Clear(); - - char c; - do - { - is.get(c); - if (c == '\0') - break; - else if (std::isspace(c)) - { - if (str.IsNull()) - continue; - else - break; - } - else - str += c; - } - while (true); - - return is; -} - -std::ostream& operator<<(std::ostream& os, const NzString& str) -{ - if (str.IsEmpty()) - return os; - - return operator<<(os, str.m_sharedString->string); -} - -NzString operator+(char character, const NzString& string) -{ - if (character == '\0') - return string; - - if (string.IsEmpty()) - return character; - - unsigned int totalSize = string.m_sharedString->size+1; - char* str = new char[totalSize+1]; - str[0] = character; - std::strcpy(str, string.m_sharedString->string); - - return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); -} - -NzString operator+(const char* string, const NzString& nstring) -{ - if (!string || !string[0]) - return nstring; - - if (nstring.IsEmpty()) - return string; - - unsigned int size = std::strlen(string); - unsigned int totalSize = size + nstring.m_sharedString->size; - char* str = new char[totalSize+1]; - std::memcpy(str, string, size*sizeof(char)); - std::strcpy(&str[size], nstring.m_sharedString->string); - - return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); -} - -NzString operator+(const std::string& string, const NzString& nstring) -{ - if (string.empty()) - return nstring; - - if (nstring.m_sharedString->size == 0) - return string; - - unsigned int totalSize = string.size() + nstring.m_sharedString->size; - char* str = new char[totalSize+1]; - std::memcpy(str, string.c_str(), string.size()*sizeof(char)); - std::strcpy(&str[string.size()], nstring.m_sharedString->string); - - return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); -} - -bool operator==(const NzString& first, const NzString& second) -{ - if (first.m_sharedString->size == 0 || second.m_sharedString->size == 0) - return first.m_sharedString->size == second.m_sharedString->size; - - if (first.m_sharedString->size != second.m_sharedString->size) - return false; - - return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) == 0; -} - -bool operator!=(const NzString& first, const NzString& second) -{ - return !operator==(first, second); -} - -bool operator<(const NzString& first, const NzString& second) -{ - if (second.m_sharedString->size == 0) - return false; - - if (first.m_sharedString->size == 0) - return true; - - return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) < 0; -} - -bool operator<=(const NzString& first, const NzString& second) -{ - return !operator<(second, first); -} - -bool operator>(const NzString& first, const NzString& second) -{ - return second < first; -} - -bool operator>=(const NzString& first, const NzString& second) -{ - return !operator<(first, second); -} - -bool operator==(char character, const NzString& nstring) -{ - return nstring == character; -} - -bool operator==(const char* string, const NzString& nstring) -{ - return nstring == string; -} - -bool operator==(const std::string& string, const NzString& nstring) -{ - return nstring == string; -} - -bool operator!=(char character, const NzString& nstring) -{ - return !operator==(character, nstring); -} - -bool operator!=(const char* string, const NzString& nstring) -{ - return !operator==(string, nstring); -} - -bool operator!=(const std::string& string, const NzString& nstring) -{ - return !operator==(string, nstring); -} - -bool operator<(char character, const NzString& nstring) -{ - return nstring > character; -} - -bool operator<(const char* string, const NzString& nstring) -{ - return nstring > string; -} - -bool operator<(const std::string& string, const NzString& nstring) -{ - return nstring > string; -} - -bool operator<=(char character, const NzString& nstring) -{ - return !operator<(nstring, character); -} - -bool operator<=(const char* string, const NzString& nstring) -{ - return !operator<(nstring, string); -} - -bool operator<=(const std::string& string, const NzString& nstring) -{ - return !operator<(nstring, string); -} - -bool operator>(char character, const NzString& nstring) -{ - return nstring < character; -} - -bool operator>(const char* string, const NzString& nstring) -{ - return nstring < string; -} - -bool operator>(const std::string& string, const NzString& nstring) -{ - return nstring < string; -} - -bool operator>=(char character, const NzString& nstring) -{ - return !operator<(character, nstring); -} - -bool operator>=(const char* string, const NzString& nstring) -{ - return !operator<(string, nstring); -} - -bool operator>=(const std::string& string, const NzString& nstring) -{ - return !operator<(string, nstring); -} - -void NzString::EnsureOwnership() -{ - if (m_sharedString == &emptyString) - return; - - NazaraLock(m_sharedString->mutex); - if (m_sharedString->refCount > 1) - { - m_sharedString->refCount--; - - char* string = new char[m_sharedString->capacity+1]; - std::strcpy(string, m_sharedString->string); - - m_sharedString = new SharedString(1, m_sharedString->capacity, m_sharedString->size, string); - } -} - -bool NzString::FillHash(NzHashImpl* hazh) const -{ - hazh->Append(reinterpret_cast(m_sharedString->string), m_sharedString->size); - - return true; -} - -void NzString::ReleaseString() -{ - if (m_sharedString == &emptyString) - return; - - NazaraMutexLock(m_sharedString->mutex); - bool freeSharedString = (--m_sharedString->refCount == 0); - NazaraMutexUnlock(m_sharedString->mutex); - - if (freeSharedString) - { - delete[] m_sharedString->string; - delete m_sharedString; - } - - m_sharedString = &emptyString; -} - -NzString::SharedString NzString::emptyString(0, 0, 0, nullptr); -unsigned int NzString::npos(static_cast(-1)); - -namespace std -{ - istream& getline(istream& is, NzString& str) - { - str.Clear(); - - char c; - do - { - is.get(c); - if (c != '\n' && c != '\0') - str += c; - else - break; - } - while (true); - - return is; - } - - istream& getline(istream& is, NzString& str, char delim) - { - str.Clear(); - - char c; - do - { - is.get(c); - if (c != delim && c != '\0') - str += c; - else - break; - } - while (true); - - return is; - } - - void swap(NzString& lhs, NzString& rhs) - { - lhs.Swap(rhs); - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +inline unsigned int nzPow2(unsigned int n) +{ + unsigned int x = 1; + + // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux + while(x <= n) + x <<= 1; + + return x; +} +// Cet algorithme est inspiré de la documentation de Qt +inline unsigned int nzGetNewSize(unsigned int newSize) +{ + if (newSize < 20) + return newSize+4; + else + { + if (newSize < (1 << 12)-12) + return nzPow2(newSize << 1)-12; + else + return newSize + (1 << 11); + } +} + +inline char nzToLower(char character) +{ + if (character >= 'A' && character <= 'Z') + return character + ('a' - 'A'); + else + return character; +} + +inline char nzToUpper(char character) +{ + if (character >= 'a' && character <= 'z') + return character + ('A' - 'a'); + else + return character; +} + +inline int nzStrcasecmp(const char* s1, const char* s2) +{ + int ret = 0; + + while (!(ret = static_cast(nzToLower(*s1)) - static_cast(nzToLower(*s2))) && *s2) + ++s1, ++s2; + + return ret != 0 ? (ret > 0 ? 1 : -1) : 0; +} + +inline int nzUnicodecasecmp(const char* s1, const char* s2) +{ + int ret = 0; + utf8::unchecked::iterator it1(s1); + utf8::unchecked::iterator it2(s2); + + while (!(ret = NzUnicode::GetLowercase(*it1) - NzUnicode::GetLowercase(*it2)) && *it2) + ++it1, ++it2; + + return ret != 0 ? (ret > 0 ? 1 : -1) : 0; +} + +NzString::NzString() : +m_sharedString(&emptyString) +{ +} + +NzString::NzString(char character) +{ + if (character == '\0') + m_sharedString = &emptyString; + else + { + m_sharedString = new SharedString; + m_sharedString->capacity = 1; + m_sharedString->size = 1; + m_sharedString->string = new char[2]; + m_sharedString->string[0] = character; + m_sharedString->string[1] = '\0'; + } +} + +NzString::NzString(const char* string) +{ + if (string) + { + unsigned int size = std::strlen(string); + if (size > 0) + { + m_sharedString = new SharedString; + m_sharedString->capacity = size; + m_sharedString->size = size; + m_sharedString->string = new char[size+1]; + std::memcpy(m_sharedString->string, string, size+1); + } + else + m_sharedString = &emptyString; + } + else + m_sharedString = &emptyString; +} + +NzString::NzString(const std::string& string) +{ + if (string.size() > 0) + { + m_sharedString = new SharedString; + m_sharedString->capacity = string.capacity(); + m_sharedString->size = string.size(); + m_sharedString->string = new char[string.capacity()+1]; + std::memcpy(m_sharedString->string, string.c_str(), string.size()+1); + } + else + m_sharedString = &emptyString; +} + +NzString::NzString(const NzString& string) : +m_sharedString(string.m_sharedString) +{ + if (m_sharedString != &emptyString) + { + NazaraMutexLock(m_sharedString->mutex); + m_sharedString->refCount++; + NazaraMutexUnlock(m_sharedString->mutex); + } +} + +NzString::NzString(NzString&& string) noexcept : +m_sharedString(string.m_sharedString) +{ + string.m_sharedString = &emptyString; +} + +NzString::NzString(SharedString* sharedString) : +m_sharedString(sharedString) +{ +} + +NzString::~NzString() +{ + ReleaseString(); +} + +NzString& NzString::Append(char character) +{ + if (character == '\0') + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity == 0) + return operator=(character); + + if (m_sharedString->capacity > m_sharedString->size) + { + EnsureOwnership(); + + m_sharedString->string[m_sharedString->size] = character; + m_sharedString->string[m_sharedString->size+1] = '\0'; + m_sharedString->size++; + } + else + { + unsigned int newSize = m_sharedString->size+1; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + str[m_sharedString->size] = character; + str[newSize] = '\0'; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::Append(const char* string) +{ + if (!string || !string[0]) + return *this; + + unsigned int length = std::strlen(string); + if (length == 0) + return *this; + + if (m_sharedString->capacity >= m_sharedString->size + length) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string, length+1); + m_sharedString->size += length; + } + else + { + unsigned int newSize = m_sharedString->size + length; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string, length+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::Append(const NzString& string) +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) + return operator=(string); + + if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + m_sharedString->size += string.m_sharedString->size; + } + else + { + unsigned int newSize = m_sharedString->size + string.m_sharedString->size; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +void NzString::Clear(bool keepBuffer) +{ + if (keepBuffer) + { + EnsureOwnership(); + m_sharedString->size = 0; + } + else + ReleaseString(); +} + +bool NzString::Contains(char character, int start, nzUInt32 flags) const +{ + return Find(character, start, flags) != npos; +} + +bool NzString::Contains(const char* string, int start, nzUInt32 flags) const +{ + return Find(string, start, flags) != npos; +} + +bool NzString::Contains(const NzString& string, int start, nzUInt32 flags) const +{ + return Find(string, start, flags) != npos; +} + +unsigned int NzString::Count(char character, int start, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & CaseInsensitive) + { + char character_lower = nzToLower(character); + char character_upper = nzToUpper(character); + do + { + if (*str == character_lower || *str == character_upper) + count++; + } + while (*++str); + } + else + { + while ((str = std::strchr(str, character))) + { + count++; + str++; + } + } + + return count; +} + +unsigned int NzString::Count(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + { + count++; + break; + } + + if (*it == '\0') + return count; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*str) == c) + { + str++; + + const char* ptr = &string[1]; + while (true) + { + if (*ptr == '\0') + { + count++; + break; + } + + if (*str == '\0') + return count; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + while ((str = std::strstr(str, string))) + { + count++; + str++; + } + } + + return count; +} + +unsigned int NzString::Count(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string.m_sharedString->string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + { + count++; + break; + } + + if (*it == '\0') + return count; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string.m_sharedString->string[0]); + do + { + if (nzToLower(*str) == c) + { + str++; + + const char* ptr = &string.m_sharedString->string[1]; + while (true) + { + if (*ptr == '\0') + { + count++; + break; + } + + if (*str == '\0') + return count; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + while ((str = std::strstr(str, string.m_sharedString->string))) + { + count++; + str++; + } + } + + return count; +} + +unsigned int NzString::CountAny(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + else + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (*it == *it2) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string; + do + { + if (nzToLower(*str) == nzToLower(*c)) + { + count++; + break; + } + } + while (*++c); + } + while (*++str); + } + else + { + while ((str = std::strpbrk(str, string))) + { + count++; + str++; + } + } + } + + return count; +} + +unsigned int NzString::CountAny(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + else + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it == *it2) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string.m_sharedString->string; + do + { + if (nzToLower(*str) == nzToLower(*c)) + { + count++; + break; + } + } + while (*++c); + } + while (*++str); + } + else + { + while ((str = std::strpbrk(str, string.m_sharedString->string))) + { + count++; + str++; + } + } + } + + return count; +} + +bool NzString::EndsWith(char character, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + + if (flags & CaseInsensitive) + return nzToLower(m_sharedString->string[m_sharedString->size-1]) == nzToLower(character); + else + return m_sharedString->string[m_sharedString->size-1] == character; // character == '\0' sera toujours faux +} + +bool NzString::EndsWith(const char* string, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return false; + + unsigned int len = std::strlen(string); + if (len > m_sharedString->size) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; + else + return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; + } + else + return std::strcmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; +} + +bool NzString::EndsWith(const NzString& string, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; + else + return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; + } + else + return std::strcmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; +} + +unsigned int NzString::Find(char character, int start, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + if (flags & CaseInsensitive) + { + char ch = nzToLower(character); + const char* str = m_sharedString->string; + do + { + if (nzToLower(*str) == ch) + return static_cast(str - m_sharedString->string); + } + while (*++str); + + return npos; + } + else + { + char* ch = std::strchr(&m_sharedString->string[pos], character); + if (ch) + return static_cast(ch - m_sharedString->string); + else + return npos; + } +} + +unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + const char* ptrPos = it.base(); + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*it == '\0') + return npos; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*str) == c) + { + char* ptrPos = str; + str++; + + const char* ptr = &string[1]; + while (true) + { + if (*ptr == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*str == '\0') + return npos; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + char* ch = std::strstr(&m_sharedString->string[pos], string); + if (ch) + return static_cast(ch - m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string.m_sharedString->string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + const char* ptrPos = it.base(); + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*it == '\0') + return npos; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string.m_sharedString->string[0]); + do + { + if (nzToLower(*str) == c) + { + char* ptrPos = str; + str++; + + const char* ptr = &string.m_sharedString->string[1]; + while (true) + { + if (*ptr == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*str == '\0') + return npos; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + char* ch = std::strstr(&m_sharedString->string[pos], string.m_sharedString->string); + if (ch) + return static_cast(ch - m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::FindAny(const char* string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || !string || !string[0]) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + else + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (*++str); + } + else + { + str = std::strpbrk(str, string); + if (str) + return str - m_sharedString->string; + } + } + + return npos; +} + +unsigned int NzString::FindAny(const NzString& string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || string.m_sharedString->size == 0) + return npos; + + if (string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + else + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string.m_sharedString->string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (*++str); + } + else + { + str = std::strpbrk(str, string.m_sharedString->string); + if (str) + return str - m_sharedString->string; + } + } + + return npos; +} + +unsigned int NzString::FindLast(char character, int start, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* ptr = &m_sharedString->string[m_sharedString->size-1]; + + if (flags & CaseInsensitive) + { + character = nzToLower(character); + do + { + if (nzToLower(*ptr) == character) + return static_cast(ptr - m_sharedString->string); + } + while (ptr-- != m_sharedString->string); + } + else + { + // strrchr ? + do + { + if (*ptr == character) + return static_cast(ptr - m_sharedString->string); + } + while (ptr-- != m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::FindLast(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] ||m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + ///Algo 1.FindLast#3 (Taille du pattern inconnue) + const char* ptr = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + const char* t = string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + utf8::unchecked::iterator it2(t); + utf8::unchecked::iterator tIt(it); + ++tIt; + + while (true) + { + if (*it2 == '\0') + return it.base() - m_sharedString->string; + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) + break; + + ++it2; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + else + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*ptr) == c) + { + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + return ptr - m_sharedString->string; + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + } + else + { + do + { + if (*ptr == string[0]) + { + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + return ptr - m_sharedString->string; + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (*tPtr != *p) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::FindLast(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size || string.m_sharedString->size > m_sharedString->size) + return npos; + + const char* ptr = &m_sharedString->string[pos]; + const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + ///Algo 1.FindLast#3 (Itérateur non-adapté) + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + const char* t = string.m_sharedString->string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + utf8::unchecked::iterator it2(t); + utf8::unchecked::iterator tIt(it); + ++tIt; + + while (true) + { + if (*it2 == '\0') + return it.base() - m_sharedString->string; + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) + break; + + ++it2; + ++tIt; + } + } + } + while (it--.base() != limit); + } + else + { + ///Algo 1.FindLast#4 (Taille du pattern connue) + char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); + while (true) + { + if (nzToLower(*ptr) == c) + { + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (nzToLower(*ptr) != nzToLower(*p)) + break; + + if (p == &string.m_sharedString->string[0]) + return ptr-m_sharedString->string; + + if (ptr == m_sharedString->string) + return npos; + } + } + else if (ptr-- <= limit) + break; + } + } + } + else + { + ///Algo 1.FindLast#4 (Taille du pattern connue) + while (true) + { + if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) + { + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (*ptr != *p) + break; + + if (p == &string.m_sharedString->string[0]) + return ptr-m_sharedString->string; + + if (ptr == m_sharedString->string) + return npos; + } + } + else if (ptr-- <= limit) + break; + } + } + + return npos; +} + +unsigned int NzString::FindLastAny(const char* string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || !string || !string[0]) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + else + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + else + { + do + { + const char* c = string; + do + { + if (*str == *c) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + } + + return npos; +} + +unsigned int NzString::FindLastAny(const NzString& string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || string.m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + else + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string.m_sharedString->string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + else + { + do + { + const char* c = string.m_sharedString->string; + do + { + if (*str == *c) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + } + + return npos; +} + +unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + ///Algo 2.FindLastWord#1 (Taille du pattern inconnue) + const char* ptr = &m_sharedString->string[pos]; + + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + else + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = utf8::unchecked::next(t); + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (*tIt != *p) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + } + else + { + if (flags & CaseInsensitive) + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*ptr) == c) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr-m_sharedString->string; + else + break; + } + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + else + { + do + { + if (*ptr == string[0]) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr-m_sharedString->string; + else + break; + } + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (*tPtr != *p) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + } + + return npos; +} + +unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + const char* ptr = &m_sharedString->string[pos]; + const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; + + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + else + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = utf8::unchecked::next(t); + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (*tIt != *p) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + } + else + { + ///Algo 2.FindLastWord#2 (Taille du pattern connue) + if (flags & CaseInsensitive) + { + char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); + do + { + if (nzToLower(*ptr) == c) + { + if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) + continue; + + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (nzToLower(*ptr) != nzToLower(*p)) + break; + + if (p == &string.m_sharedString->string[0]) + { + if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) + return ptr-m_sharedString->string; + else + break; + } + + if (ptr == m_sharedString->string) + return npos; + } + } + } + while (ptr-- > limit); + } + else + { + do + { + if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) + { + if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) + continue; + + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (*ptr != *p) + break; + + if (p == &string.m_sharedString->string[0]) + { + if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) + return ptr-m_sharedString->string; + else + break; + } + + if (ptr == m_sharedString->string) + return npos; + } + } + } + while (ptr-- > limit); + } + } + + return npos; +} + +unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + ///Algo 3.FindWord#3 (Taille du pattern inconnue) + const char* ptr = m_sharedString->string; + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + else + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (*tIt != *p) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + } + else + { + if (flags & CaseInsensitive) + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*ptr) == c) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr - m_sharedString->string; + else + break; + } + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (*++ptr); + } + else + { + do + { + if (*ptr == string[0]) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr - m_sharedString->string; + else + break; + } + + if (*tPtr != *p) + break; + + p++; + tPtr++; + } + } + } + while (*++ptr); + } + } + + return npos; +} + +unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* ptr = m_sharedString->string; + if (flags & HandleUtf8) + { + ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + else + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (*tIt != *p) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + } + else + { + ///Algo 3.FindWord#2 (Taille du pattern connue) + if (flags & CaseInsensitive) + { + char c = nzToLower(string.m_sharedString->string[0]); + do + { + if (nzToLower(*ptr) == c) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string.m_sharedString->string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr - m_sharedString->string; + else + break; + } + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (*++ptr); + } + else + { + while ((ptr = std::strstr(ptr, string.m_sharedString->string))) + { + // Si le mot est bien isolé + if ((ptr == m_sharedString->string || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) + return ptr - m_sharedString->string; + + ptr++; + } + } + } + + return npos; +} + +char* NzString::GetBuffer() +{ + EnsureOwnership(); + + return m_sharedString->string; +} + +unsigned int NzString::GetCapacity() const +{ + return m_sharedString->capacity; +} + +const char* NzString::GetConstBuffer() const +{ + return m_sharedString->string; +} + +unsigned int NzString::GetLength() const +{ + #if NAZARA_CORE_SAFE + try + { + #endif + return utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return 0; + } + #endif +} + +unsigned int NzString::GetSize() const +{ + return m_sharedString->size; +} + +char* NzString::GetUtf8Buffer(unsigned int* size) const +{ + if (m_sharedString->size == 0) + return nullptr; + + char* buffer = new char[m_sharedString->size+1]; + std::memcpy(buffer, m_sharedString->string, m_sharedString->size+1); + + if (size) + *size = m_sharedString->size; + + return buffer; +} + +char16_t* NzString::GetUtf16Buffer(unsigned int* size) const +{ + if (m_sharedString->size == 0) + return nullptr; + + std::vector utf16; + utf16.reserve(m_sharedString->size); + #if NAZARA_CORE_SAFE + try + { + #endif + utf8::utf8to16(m_sharedString->string, &m_sharedString->string[m_sharedString->size], std::back_inserter(utf16)); + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return nullptr; + } + #endif + + unsigned int bufferSize = utf16.size(); + if (bufferSize == 0) + return nullptr; + + char16_t* buffer = new char16_t[bufferSize+1]; + std::memcpy(buffer, &utf16[0], bufferSize*sizeof(char16_t)); + buffer[bufferSize] ='\0'; + + if (size) + *size = bufferSize; + + return buffer; +} + +char32_t* NzString::GetUtf32Buffer(unsigned int* size) const +{ + if (m_sharedString->size == 0) + return nullptr; + + #if NAZARA_CORE_SAFE + try + { + #endif + unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); + if (bufferSize == 0) + return nullptr; + + char32_t* buffer = new char32_t[bufferSize+1]; + utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); + buffer[bufferSize] ='\0'; + + if (size) + *size = bufferSize; + + return buffer; + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return nullptr; + } + #endif +} + +wchar_t* NzString::GetWideBuffer(unsigned int* size) const +{ + static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t size is not supported"); + if (m_sharedString->size == 0) + return nullptr; + + #if NAZARA_CORE_SAFE + try + { + #endif + unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); + if (bufferSize == 0) + return nullptr; + + wchar_t* buffer = new wchar_t[bufferSize+1]; + if (sizeof(wchar_t) == 4) + utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); + else + { + wchar_t* ptr = buffer; + + utf8::unchecked::iterator it(m_sharedString->string); + do + { + char32_t cp = *it; + if (cp <= 0xFFFF && (cp < 0xD800 || cp > 0xDFFF)) // @Laurent Gomila + *ptr++ = static_cast(cp); + else + *ptr++ = L'?'; + } + while (*it++); + } + + if (size) + *size = bufferSize; + + return buffer; + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return nullptr; + } + #endif +} + +NzString NzString::GetWord(unsigned int index, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return NzString(); + + NzString temp = Simplified(flags); // Évitons les mauvaises surprises + if (temp.IsEmpty()) + return NzString(); + + unsigned int foundPos = temp.Find(' '); // Simplified nous assure que nous n'avons plus que des espaces comme séparation + unsigned int lastPos = 0; + for (; index > 0; --index) + { + if (foundPos == npos) + return NzString(); + + lastPos = foundPos; + foundPos = temp.Find(' ', foundPos+1); + } + return temp.Substr((lastPos == 0) ? 0 : lastPos+1, (foundPos == npos) ? -1 : static_cast(foundPos-1)); +} + +unsigned int NzString::GetWordPosition(unsigned int index, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return npos; + + unsigned int currentWord = 0; + bool inWord = false; + + const char* ptr = m_sharedString->string; + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(ptr); + do + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + inWord = false; + else + { + if (!inWord) + { + inWord = true; + if (++currentWord > index) + return static_cast(it.base() - m_sharedString->string); + } + } + } + while (*++it); + } + else + { + while (ptr != &m_sharedString->string[m_sharedString->size]) + { + if (!std::isspace(*ptr++)) + { + if (!inWord) + { + inWord = true; + if (++currentWord > index) + return ptr-m_sharedString->string; + } + } + else + inWord = false; + } + } + + return npos; +} + +NzString& NzString::Insert(int pos, char character) +{ + if (character == '\0') + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity == 0) + return operator=(character); + + if (pos < 0) + pos = std::max(static_cast(m_sharedString->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedString->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedString->capacity >= m_sharedString->size+1) + { + EnsureOwnership(); + + std::memmove(&m_sharedString->string[start+1], &m_sharedString->string[start], m_sharedString->size); + m_sharedString->string[start] = character; + + m_sharedString->size += 1; + } + else + { + unsigned int newSize = m_sharedString->size+1; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedString->string; + while (ptr != &newString[start]) + *ptr++ = *s++; + + *ptr++ = character; + + std::strcpy(ptr, s); + + ReleaseString(); + + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +NzString& NzString::Insert(int pos, const char* string) +{ + if (!string || !string[0]) + return *this; + + if (pos < 0) + pos = std::max(static_cast(m_sharedString->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedString->size); + + // Si le buffer est déjà suffisamment grand + unsigned int len = std::strlen(string); + if (m_sharedString->capacity >= m_sharedString->size+len) + { + EnsureOwnership(); + + std::memmove(&m_sharedString->string[start+len], &m_sharedString->string[start], m_sharedString->size); + std::memcpy(&m_sharedString->string[start], string, len+1); + + m_sharedString->size += len; + } + else + { + unsigned int newSize = m_sharedString->size+len; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedString->string; + + while (ptr != &newString[start]) + *ptr++ = *s++; + + const char* p = string; + while (ptr != &newString[start+len]) + *ptr++ = *p++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +NzString& NzString::Insert(int pos, const NzString& string) +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) + return operator=(string); + + if (pos < 0) + pos = std::max(static_cast(m_sharedString->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedString->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) + { + EnsureOwnership(); + + std::memmove(&m_sharedString->string[start+string.m_sharedString->size], &m_sharedString->string[start], m_sharedString->size); + std::memcpy(&m_sharedString->string[start], string.m_sharedString->string, string.m_sharedString->size+1); + + m_sharedString->size += string.m_sharedString->size; + } + else + { + unsigned int newSize = m_sharedString->size+string.m_sharedString->size; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedString->string; + + while (ptr != &newString[start]) + *ptr++ = *s++; + + const char* p = string.m_sharedString->string; + while (ptr != &newString[start+string.m_sharedString->size]) + *ptr++ = *p++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +bool NzString::IsEmpty() const +{ + return m_sharedString->size == 0; +} + +bool NzString::IsNull() const +{ + return m_sharedString == &emptyString; +} + +bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const +{ + #if NAZARA_CORE_SAFE + if (base < 2 || base > 36) + { + NazaraError("Base must be between 2 and 36"); + return false; + } + #endif + + if (m_sharedString->size == 0) + return false; + + NzString check = Simplified(); + if (check.m_sharedString->size) + return false; + + char* ptr = (check.m_sharedString->string[0] == '-') ? &check.m_sharedString->string[1] : check.m_sharedString->string; + + if (base > 10) + { + if (flags & CaseInsensitive) + { + do + { + char c = *ptr; + if (c != ' ' && (c < '0' || (c > '9' && c < 'A') || (c > 'A'+base-1 && c < 'a') || c > 'a'+base-1)) + return false; + } + while (*++ptr); + } + else + { + do + { + char c = *ptr; + if (c != ' ' && (c < '0' || (c > '9' && c < 'a') || c > 'a'+base-1)) + return false; + } + while (*++ptr); + } + } + else + { + do + { + char c = *ptr; + if (c != ' ' && (c < '0' || c > '0'+base-1)) + return false; + } + while (*++ptr); + } + + return true; +} + +bool NzString::Match(const char* pattern) const +{ + if (m_sharedString->size == 0 || !pattern) + return false; + + // Par Jack Handy - akkhandy@hotmail.com + // From : http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing + const char* str = m_sharedString->string; + while (*str && *pattern != '*') + { + if (*pattern != *str && *pattern != '?') + return false; + + pattern++; + str++; + } + + const char* cp = nullptr; + const char* mp = nullptr; + while (*str) + { + if (*pattern == '*') + { + if (!*++pattern) + return true; + + mp = pattern; + cp = str+1; + } + else if (*pattern == *str || *pattern == '?') + { + pattern++; + str++; + } + else + { + pattern = mp; + str = cp++; + } + } + + while (*pattern == '*') + pattern++; + + return !*pattern; +} + +bool NzString::Match(const NzString& pattern) const +{ + return Match(pattern.m_sharedString->string); +} + +NzString& NzString::Prepend(char character) +{ + return Insert(0, character); +} + +NzString& NzString::Prepend(const char* string) +{ + return Insert(0, string); +} + +NzString& NzString::Prepend(const NzString& string) +{ + return Insert(0, string); +} + +unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start, nzUInt32 flags) +{ + if (oldCharacter == '\0' || oldCharacter == newCharacter) + return 0; + + if (newCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe + return Replace(NzString(oldCharacter), NzString(), start); + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + unsigned int count = 0; + char* ptr = &m_sharedString->string[pos]; + bool found = false; + if (flags & CaseInsensitive) + { + char character_lower = nzToLower(oldCharacter); + char character_upper = nzToUpper(oldCharacter); + do + { + if (*ptr == character_lower || *ptr == character_upper) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr = newCharacter; + ++count; + } + } + while (*++ptr); + } + else + { + while ((ptr = std::strchr(ptr, oldCharacter))) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr = newCharacter; + ++count; + } + } + + return count; +} + +unsigned int NzString::Replace(const char* oldString, const char* replaceString, int start, nzUInt32 flags) +{ + if (!oldString || !oldString[0]) + return 0; + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + unsigned int oSize = std::strlen(oldString); + if (oSize == 0) + return 0; + + unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; + + unsigned int count = 0; + if (oSize == rSize) + { + bool found = false; + + // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + while ((pos = Find(oldString, pos, flags)) != npos) + { + if (!found) + { + EnsureOwnership(); + found = true; + } + + std::memcpy(&m_sharedString->string[pos], replaceString, oSize); + pos += oSize; + + ++count; + } + } + else ///TODO: Algorithme de remplacement sans changement de buffer (si rSize < oSize) + { + unsigned int newSize = m_sharedString->size + Count(oldString)*(rSize - oSize); + if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 + return 0; + + char* newString = new char[newSize+1]; + + ///Algo 4.Replace#2 + char* ptr = newString; + const char* p = m_sharedString->string; + + while ((pos = Find(oldString, pos, flags)) != npos) + { + const char* r = &m_sharedString->string[pos]; + + std::memcpy(ptr, p, r-p); + ptr += r-p; + std::memcpy(ptr, replaceString, rSize); + ptr += rSize; + p = r+oSize; + pos += oSize; + + count++; + } + + std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; +} + +unsigned int NzString::Replace(const NzString& oldString, const NzString& replaceString, int start, nzUInt32 flags) +{ + if (oldString.m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size || oldString.m_sharedString->size == 0) + return 0; + + unsigned int count = 0; + if (oldString.m_sharedString->size == replaceString.m_sharedString->size) + { + bool found = false; + + // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + while ((pos = Find(oldString, pos, flags)) != npos) + { + if (!found) + { + EnsureOwnership(); + found = true; + } + + std::memcpy(&m_sharedString->string[pos], replaceString.m_sharedString->string, oldString.m_sharedString->size); + pos += oldString.m_sharedString->size; + + ++count; + } + } + else + { + unsigned int newSize = m_sharedString->size + Count(oldString)*(replaceString.m_sharedString->size - oldString.m_sharedString->size); + if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 + return 0; + + char* newString = new char[newSize+1]; + + ///Algo 4.Replace#2 + char* ptr = newString; + const char* p = m_sharedString->string; + + while ((pos = Find(oldString, pos, flags)) != npos) + { + const char* r = &m_sharedString->string[pos]; + + std::memcpy(ptr, p, r-p); + ptr += r-p; + std::memcpy(ptr, replaceString.m_sharedString->string, replaceString.m_sharedString->size); + ptr += replaceString.m_sharedString->size; + p = r+oldString.m_sharedString->size; + pos += oldString.m_sharedString->size; + + count++; + } + + std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; +} + +unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags) +{ + ///FIXME: Ne gère pas l'UTF-8 + if (!oldCharacters || !oldCharacters[0]) + return 0; + + /*if (replaceCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe + return ReplaceAny(NzString(oldCharacters), NzString(), start);*/ + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + unsigned int count = 0; + char* ptr = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + do + { + const char* c = oldCharacters; + char character = nzToLower(*ptr); + bool found = false; + do + { + if (character == nzToLower(*c)) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr = replaceCharacter; + ++count; + break; + } + } + while (*++c); + } + while (*++ptr); + } + else + { + bool found = false; + while ((ptr = std::strpbrk(ptr, oldCharacters))) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr++ = replaceCharacter; + ++count; + } + } + + return count; +} +/* + unsigned int NzString::ReplaceAny(const char* oldCharacters, const char* replaceString, int start, nzUInt32 flags) + { + if (start < 0) + { + start = m_sharedString->size+start; + if (start < 0) + start = 0; + } + + unsigned int pos = static_cast(start); + unsigned int oSize = (oldCharacters) ? std::strlen(oldCharacters) : 0; + unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; + + if (pos >= m_sharedString->size || m_sharedString->size == 0 || oSize == 0) + return 0; + + unsigned int count = 0; + + if (rSize == 1) // On utilise un algorithme optimisé + { + EnsureOwnership(); + + f or (; pos < m_sharedString->size; ++pos) + { + for (unsigned int i = 0; i < oSize; ++i) + { + if (m_sharedString->string[pos] == oldCharacters[i]) + { + m_sharedString->string[pos] = replaceString[0]; + ++count; + + break; + } + } + } + } + else + { + unsigned int newSize; + { + unsigned int count = CountAny(oldCharacters); + newSize = m_sharedString->size - count + count*rSize; + } + char* newString = new char[newSize+1]; + + unsigned int j = 0; + for (unsigned int i = 0; i < m_sharedString->size; ++i) + { + if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier + newString[j++] = m_sharedString->string[i]; + else + { + bool found = false; + for (unsigned int l = 0; l < oSize; ++l) + { + if (m_sharedString->string[i] == oldCharacters[l]) + { + for (unsigned int k = 0; k < rSize; ++k) + newString[j++] = replaceString[k]; + + ++count; + found = true; + break; // Simple façon d'éviter la ligne après la boucle + } + } + + if (!found) + newString[j++] = m_sharedString->string[i]; + } + } + newString[newSize] = '\0'; + + ReleaseString(); + + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; + } + + unsigned int NzString::ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start, nzUInt32 flags) + { + if (start < 0) + { + start = m_sharedString->size+start; + if (start < 0) + start = 0; + } + + unsigned int pos = static_cast(start); + + if (pos >= m_sharedString->size || m_sharedString->size == 0 || oldCharacters.m_sharedString->size == 0) + return 0; + + unsigned int count = 0; + + if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé + { + EnsureOwnership(); + + char character = replaceString[0]; + for (; pos < m_sharedString->size; ++pos) + { + for (unsigned int i = 0; i < oldCharacters.m_sharedString->size; ++i) + { + if (m_sharedString->string[pos] == oldCharacters[i]) + { + m_sharedString->string[pos] = character; + ++count; + break; + } + } + } + } + else + { + unsigned int newSize; + { + unsigned int count = CountAny(oldCharacters); + newSize = m_sharedString->size - count + count*replaceString.m_sharedString->size; + } + char* newString = new char[newSize+1]; + + unsigned int j = 0; + for (unsigned int i = 0; i < m_sharedString->size; ++i) + { + if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier + newString[j++] = m_sharedString->string[i]; + else + { + bool found = false; + for (unsigned int l = 0; l < oldCharacters.m_sharedString->size; ++l) + { + if (m_sharedString->string[i] == oldCharacters[l]) + { + for (unsigned int k = 0; k < replaceString.m_sharedString->size; ++k) + newString[j++] = replaceString[k]; + + ++count; + found = true; + break; // Simple façon d'éviter la ligne après la boucle + } + } + + if (!found) + newString[j++] = m_sharedString->string[i]; + } + } + newString[newSize] = '\0'; + + ReleaseString(); + + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; + } +*/ +void NzString::Reserve(unsigned int bufferSize) +{ + if (m_sharedString->capacity >= bufferSize) + return; + + char* ptr = new char[bufferSize+1]; + if (m_sharedString->size > 0) + std::memcpy(ptr, m_sharedString->string, m_sharedString->size+1); + + unsigned int size = m_sharedString->size; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = size; + m_sharedString->string = ptr; +} + +NzString& NzString::Resize(int size, char character) +{ + if (size == 0) + { + Clear(true); + return *this; + } + + if (size < 0) + size = std::max(static_cast(m_sharedString->size + size), 0); + + unsigned int newSize = static_cast(size); + + if (m_sharedString->capacity >= newSize) + { + EnsureOwnership(); + + // Nous avons déjà la place requise, contentons-nous de remplir le buffer + if (character != '\0' && newSize > m_sharedString->size) + { + char* ptr = &m_sharedString->string[m_sharedString->size]; + char* limit = &m_sharedString->string[newSize]; + while (ptr != limit) + *ptr++ = character; + } + + m_sharedString->size = newSize; + m_sharedString->string[newSize] = '\0'; + } + else // On veut forcément agrandir la chaine + { + char* newString = new char[newSize+1]; + if (m_sharedString->size != 0) + std::memcpy(newString, m_sharedString->string, newSize); + + char* ptr = &newString[m_sharedString->size]; + char* limit = &newString[newSize]; + while (ptr != limit) + *ptr++ = character; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +NzString NzString::Resized(int size, char character) const +{ + if (size < 0) + size = m_sharedString->size + size; + + if (size <= 0) + return NzString(); + + unsigned int newSize = static_cast(size); + if (newSize == m_sharedString->size) + return *this; + + char* str = new char[newSize+1]; + if (newSize > m_sharedString->size) + { + std::memcpy(str, m_sharedString->string, m_sharedString->size); + if (character != '\0') + { + char* ptr = &str[m_sharedString->size]; + char* limit = &str[newSize]; + while (ptr != limit) + *ptr++ = character; + } + } + else + std::memcpy(str, m_sharedString->string, newSize); + + str[newSize] = '\0'; + + return NzString(new SharedString(1, newSize, newSize, str)); +} + +NzString& NzString::Reverse() +{ + if (m_sharedString->size != 0) + { + unsigned int i = 0; + unsigned int j = m_sharedString->size-1; + + while (i < j) + std::swap(m_sharedString->string[i++], m_sharedString->string[j--]); + } + + return *this; +} + +NzString NzString::Reversed() const +{ + if (m_sharedString->size == 0) + return NzString(); + + char* str = new char[m_sharedString->size+1]; + + char* ptr = &str[m_sharedString->size-1]; + char* p = m_sharedString->string; + + do + *ptr-- = *p; + while (*(++p)); + + str[m_sharedString->size] = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); +} + +NzString NzString::Simplified(nzUInt32 flags) const +{ + char* str = new char[m_sharedString->size+1]; + char* p = str; + + const char* ptr = m_sharedString->string; + bool inword = false; + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(ptr); + do + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + { + if (inword) + { + *p++ = ' '; + inword = false; + } + } + else + { + p = utf8::append(*it, p); + inword = true; + } + } + while (*++it); + } + else + { + const char* limit = &m_sharedString->string[m_sharedString->size]; + do + { + if (std::isspace(*ptr)) + { + if (inword) + { + *p++ = ' '; + inword = false; + } + } + else + { + *p++ = *ptr; + inword = true; + } + } + while (++ptr != limit); + } + + if (!inword) + p--; + + *p = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, p-str, str)); +} + +NzString& NzString::Simplify(nzUInt32 flags) +{ + return operator=(Simplified(flags)); +} + +unsigned int NzString::Split(std::vector& result, char separation, int start, nzUInt32 flags) const +{ + if (separation == '\0' || m_sharedString->size == 0) + return 0; + + unsigned int lastSep = Find(separation, start, flags); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + while (true) + { + unsigned int sep = Find(separation, lastSep+1, flags); + if (sep == npos) + break; + + if (sep-lastSep > 1) + result.push_back(Substr(lastSep+1, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-1) + result.push_back(Substr(lastSep+1)); + + return result.size(); +} + +unsigned int NzString::Split(std::vector& result, const char* separation, int start, nzUInt32 flags) const +{ + unsigned int size = (separation) ? std::strlen(separation) : 0; + if (m_sharedString->size == 0) + return 0; + else if (size == 0) + { + result.reserve(m_sharedString->size); + for (unsigned int i = 0; i < m_sharedString->size; ++i) + result.push_back(NzString(m_sharedString->string[i])); + + return m_sharedString->size; + } + else if (size > m_sharedString->size) + { + result.push_back(*this); + return 1; + } + + unsigned int lastSep = Find(separation, start, flags); + unsigned int oldSize = result.size(); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = Find(separation, lastSep+size, flags)) != npos) + { + if (sep-lastSep > size) + result.push_back(Substr(lastSep+size, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-size) + result.push_back(Substr(lastSep+size)); + + return result.size()-oldSize; +} + +unsigned int NzString::Split(std::vector& result, const NzString& separation, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + else if (separation.m_sharedString->size == 0) + { + result.reserve(m_sharedString->size); + for (unsigned int i = 0; i < m_sharedString->size; ++i) + result.push_back(NzString(m_sharedString->string[i])); + + return m_sharedString->size; + } + else if (separation.m_sharedString->size > m_sharedString->size) + { + result.push_back(*this); + return 1; + } + + unsigned int lastSep = Find(separation, start, flags); + unsigned int oldSize = result.size(); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = Find(separation, lastSep+separation.m_sharedString->size, flags)) != npos) + { + if (sep-lastSep > separation.m_sharedString->size) + result.push_back(Substr(lastSep+separation.m_sharedString->size, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-separation.m_sharedString->size) + result.push_back(Substr(lastSep+separation.m_sharedString->size)); + + return result.size()-oldSize; +} + +unsigned int NzString::SplitAny(std::vector& result, const char* separations, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + + unsigned int oldSize = result.size(); + + unsigned int lastSep = FindAny(separations, start, flags); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = FindAny(separations, lastSep+1, flags)) != npos) + { + if (sep-lastSep > 1) + result.push_back(Substr(lastSep+1, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-1) + result.push_back(Substr(lastSep+1)); + + return result.size()-oldSize; +} + +unsigned int NzString::SplitAny(std::vector& result, const NzString& separations, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + + unsigned int lastSep = FindAny(separations, start, flags); + unsigned int oldSize = result.size(); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = FindAny(separations, lastSep+1, flags)) != npos) + { + if (sep-lastSep > 1) + result.push_back(Substr(lastSep+1, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-1) + result.push_back(Substr(lastSep+1)); + + return result.size()-oldSize; +} + +bool NzString::StartsWith(char character, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return false; + + if (flags & CaseInsensitive) + return nzToLower(m_sharedString->string[0]) == nzToLower(character); + else + return m_sharedString->string[0] == character; +} + +bool NzString::StartsWith(const char* string, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(m_sharedString->string); + utf8::unchecked::iterator it2(string); + do + { + if (*it2 == '\0') + return true; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + return false; + + ++it2; + } + while (*it++); + } + else + { + char* ptr = m_sharedString->string; + const char* s = string; + do + { + if (*s == '\0') + return true; + + if (nzToLower(*ptr) != nzToLower(*s)) + return false; + + s++; + } + while (*ptr++); + } + } + else + { + char* ptr = m_sharedString->string; + const char* s = string; + do + { + if (*s == '\0') + return true; + + if (*ptr != *s) + return false; + + s++; + } + while (*ptr++); + } + + return false; +} + +bool NzString::StartsWith(const NzString& string, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0) + return false; + + if (m_sharedString->size < string.m_sharedString->size) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(m_sharedString->string); + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it2 == '\0') + return true; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + return false; + + ++it2; + } + while (*it++); + } + else + { + char* ptr = m_sharedString->string; + const char* s = string.m_sharedString->string; + do + { + if (*s == '\0') + return true; + + if (nzToLower(*ptr) != nzToLower(*s)) + return false; + + s++; + } + while (*ptr++); + } + } + else + return std::memcmp(m_sharedString->string, string.m_sharedString->string, string.m_sharedString->size) == 0; + + return false; +} + +NzString NzString::Substr(int startPos, int endPos) const +{ + if (startPos < 0) + startPos = std::max(m_sharedString->size+startPos, 0U); + + unsigned int start = static_cast(startPos); + + if (endPos < 0) + { + endPos = m_sharedString->size+endPos; + if (endPos < 0) + return NzString(); + } + + unsigned int minEnd = std::min(static_cast(endPos), m_sharedString->size-1); + + if (start > minEnd || start >= m_sharedString->size) + return NzString(); + + unsigned int size = minEnd-start+1; + char* str = new char[size+1]; + std::memcpy(str, &m_sharedString->string[start], size); + str[size] = '\0'; + + return NzString(new SharedString(1, size, size, str)); +} + +NzString NzString::SubstrFrom(char character, int startPos, bool fromLast, bool include, nzUInt32 flags) const +{ + if (character == '\0') + return *this; + + unsigned int pos; + if (fromLast) + pos = FindLast(character, startPos, flags); + else + pos = Find(character, startPos, flags); + + if (pos == 0 and include) + return *this; + else if (pos == npos) + return NzString(); + + return Substr(pos+((include) ? 0 : 1)); +} + +NzString NzString::SubstrFrom(const char* string, int startPos, bool fromLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (fromLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0 && include) + return *this; + else if (pos == npos) + return NzString(); + + return Substr(pos+((include) ? 0 : std::strlen(string))); +} + +NzString NzString::SubstrFrom(const NzString& string, int startPos, bool fromLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (fromLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0 && include) + return *this; + else if (pos == npos) + return NzString(); + + return Substr(pos+((include) ? 0 : string.m_sharedString->size)); +} + +NzString NzString::SubstrTo(char character, int startPos, bool toLast, bool include, nzUInt32 flags) const +{ + if (character == '\0') + return *this; + + unsigned int pos; + if (toLast) + pos = FindLast(character, startPos); + else + pos = Find(character, startPos, flags); + + if (pos == 0) + return (include) ? character : NzString(); + else if (pos == npos) + return *this; + + return Substr(0, pos+((include) ? 1 : 0)-1); +} + +NzString NzString::SubstrTo(const char* string, int startPos, bool toLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (toLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0) + return (include) ? string : NzString(); + else if (pos == npos) + return *this; + + return Substr(0, pos+((include) ? std::strlen(string) : 0)-1); +} + +NzString NzString::SubstrTo(const NzString& string, int startPos, bool toLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (toLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0) + return (include) ? string : NzString(); + else if (pos == npos) + return *this; + + return Substr(0, pos+((include) ? string.m_sharedString->size : 0)-1); +} + +void NzString::Swap(NzString& str) +{ + std::swap(m_sharedString, str.m_sharedString); +} + +bool NzString::ToBool(bool* value, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return false; + + NzString word = GetWord(0); + + if (word[0] == '1') + { + if (value) + *value = true; + } + else if (word[0] == '0') + { + if (value) + *value = false; + } + else + { + if (flags & CaseInsensitive) + word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode + + if (word == "true") + { + if (value) + *value = true; + } + else if (word == "false") + { + if (value) + *value = false; + } + else + return false; + } + + return true; +} + +bool NzString::ToDouble(double* value) const +{ + if (m_sharedString->size == 0) + return false; + + if (value) + *value = std::atof(m_sharedString->string); + + return true; +} + +bool NzString::ToInteger(long long* value, nzUInt8 base) const +{ + if (value) + { + bool ok; + *value = NzStringToNumber(*this, base, &ok); + + return ok; + } + else + return IsNumber(base); +} + +NzString NzString::ToLower(nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + if (flags & HandleUtf8) + { + NzString lower; + lower.Reserve(m_sharedString->size); + utf8::unchecked::iterator it(m_sharedString->string); + do + utf8::append(NzUnicode::GetLowercase(*it), std::back_inserter(lower)); + while (*++it); + + return lower; + } + else + { + char* str = new char[m_sharedString->size+1]; + + char* ptr = m_sharedString->string; + char* s = str; + do + *s++ = nzToLower(*ptr); + while (*++ptr); + + *s = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); + } +} + +NzString NzString::ToUpper(nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + if (flags & HandleUtf8) + { + NzString upper; + upper.Reserve(m_sharedString->size); + utf8::unchecked::iterator it(m_sharedString->string); + do + utf8::append(NzUnicode::GetUppercase(*it), std::back_inserter(upper)); + while (*++it); + + return upper; + } + else + { + char* str = new char[m_sharedString->size+1]; + + char* ptr = m_sharedString->string; + char* s = str; + do + *s++ = nzToUpper(*ptr); + while (*++ptr); + + *s = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); + } +} + +NzString& NzString::Trim(nzUInt32 flags) +{ + return operator=(Trimmed(flags)); +} + +NzString& NzString::Trim(char character, nzUInt32 flags) +{ + return operator=(Trimmed(character, flags)); +} + +NzString NzString::Trimmed(nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + unsigned int startPos; + unsigned int endPos; + if (flags & HandleUtf8) + { + if ((flags & TrimOnlyRight) == 0) + { + utf8::unchecked::iterator it(m_sharedString->string); + do + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + break; + } + while (*++it); + + startPos = it.base() - m_sharedString->string; + } + else + startPos = 0; + + if ((flags & TrimOnlyLeft) == 0) + { + utf8::unchecked::iterator it(&m_sharedString->string[m_sharedString->size]); + while ((it--).base() != m_sharedString->string) + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + break; + } + + endPos = it.base() - m_sharedString->string; + } + else + endPos = m_sharedString->size-1; + } + else + { + startPos = 0; + if ((flags & TrimOnlyRight) == 0) + { + for (; startPos < m_sharedString->size; ++startPos) + { + if (!std::isspace(m_sharedString->string[startPos])) + break; + } + } + + endPos = m_sharedString->size-1; + if ((flags & TrimOnlyLeft) == 0) + { + for (; endPos > 0; --endPos) + { + if (!std::isspace(m_sharedString->string[endPos])) + break; + } + } + } + + return Substr(startPos, endPos); +} + +NzString NzString::Trimmed(char character, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + unsigned int startPos = 0; + unsigned int endPos = m_sharedString->size-1; + if (flags & CaseInsensitive) + { + char ch = nzToLower(character); + if ((flags & TrimOnlyRight) == 0) + { + for (; startPos < m_sharedString->size; ++startPos) + { + if (nzToLower(m_sharedString->string[startPos]) != ch) + break; + } + } + + if ((flags & TrimOnlyLeft) == 0) + { + for (; endPos > 0; --endPos) + { + if (nzToLower(m_sharedString->string[startPos]) != ch) + break; + } + } + } + else + { + if ((flags & TrimOnlyRight) == 0) + { + for (; startPos < m_sharedString->size; ++startPos) + { + if (m_sharedString->string[startPos] != character) + break; + } + } + + if ((flags & TrimOnlyLeft) == 0) + { + for (; endPos > 0; --endPos) + { + if (m_sharedString->string[startPos] != character) + break; + } + } + } + + return Substr(startPos, endPos); +} + +char* NzString::begin() +{ + return m_sharedString->string; +} + +const char* NzString::begin() const +{ + return m_sharedString->string; +} + +char* NzString::end() +{ + return &m_sharedString->string[m_sharedString->size]; +} + +const char* NzString::end() const +{ + return &m_sharedString->string[m_sharedString->size]; +} + +void NzString::push_front(char c) +{ + operator=(c + *this); +} + +void NzString::push_back(char c) +{ + operator+=(c); +} +/* +char* NzString::rbegin() +{ + return &m_sharedString->string[m_sharedString->size-1]; +} + +const char* NzString::rbegin() const +{ + return &m_sharedString->string[m_sharedString->size-1]; +} + +char* NzString::rend() +{ + return &m_sharedString->string[-1]; +} + +const char* NzString::rend() const +{ + return &m_sharedString->string[-1]; +} +*/ + +NzString::operator std::string() const +{ + return std::string(m_sharedString->string, m_sharedString->size); +} + +char& NzString::operator[](unsigned int pos) +{ + EnsureOwnership(); + + if (pos >= m_sharedString->size) + Resize(pos+1); + + return m_sharedString->string[pos]; +} + +char NzString::operator[](unsigned int pos) const +{ + #if NAZARA_CORE_SAFE + if (pos >= m_sharedString->size) + { + NazaraError("Index out of range (" + Number(pos) + " >= " + Number(m_sharedString->size) + ')'); + return 0; + } + #endif + + return m_sharedString->string[pos]; +} + +NzString& NzString::operator=(char character) +{ + if (character != '\0') + { + if (m_sharedString->capacity >= 1) + EnsureOwnership(); + else + { + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = 1; + m_sharedString->string = new char[2]; + } + + m_sharedString->size = 1; + m_sharedString->string[0] = character; + m_sharedString->string[1] = '\0'; + } + else + ReleaseString(); + + return *this; +} + +NzString& NzString::operator=(const char* string) +{ + if (string && string[0] != '\0') + { + unsigned int size = std::strlen(string); + if (m_sharedString->capacity >= size) + EnsureOwnership(); + else + { + ReleaseString(); + + m_sharedString = new SharedString; + m_sharedString->capacity = size; + m_sharedString->string = new char[size+1]; + } + + m_sharedString->size = size; + std::memcpy(m_sharedString->string, string, size+1); + } + else + ReleaseString(); + + return *this; +} + +NzString& NzString::operator=(const std::string& string) +{ + if (string.size() > 0) + { + if (m_sharedString->capacity >= string.size()) + EnsureOwnership(); + else + { + ReleaseString(); + + m_sharedString = new SharedString; + m_sharedString->capacity = string.size(); + m_sharedString->string = new char[string.size()+1]; + } + + m_sharedString->size = string.size(); + std::memcpy(m_sharedString->string, string.c_str(), string.size()+1); + } + else + ReleaseString(); + + return *this; +} + +NzString& NzString::operator=(const NzString& string) +{ + ReleaseString(); + + m_sharedString = string.m_sharedString; + if (m_sharedString != &emptyString) + { + NazaraMutexLock(m_sharedString->mutex); + m_sharedString->refCount++; + NazaraMutexUnlock(m_sharedString->mutex); + } + + return *this; +} + +NzString& NzString::operator=(NzString&& string) noexcept +{ + std::swap(m_sharedString, string.m_sharedString); + + return *this; +} + +NzString NzString::operator+(char character) const +{ + if (character == '\0') + return *this; + + unsigned int totalSize = m_sharedString->size+1; + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + + str[m_sharedString->size] = character; + str[totalSize] = '\0'; + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString NzString::operator+(const char* string) const +{ + if (!string || !string[0]) + return *this; + + if (m_sharedString->size == 0) + return string; + + unsigned int length = std::strlen(string); + if (length == 0) + return *this; + + unsigned int totalSize = m_sharedString->size + length; + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string, length+1); + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString NzString::operator+(const std::string& string) const +{ + if (string.empty()) + return *this; + + if (m_sharedString->size == 0) + return string; + + unsigned int totalSize = m_sharedString->size + string.size(); + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.c_str(), string.size()+1); + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString NzString::operator+(const NzString& string) const +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0) + return string; + + unsigned int totalSize = m_sharedString->size + string.m_sharedString->size; + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString& NzString::operator+=(char character) +{ + if (character == '\0') + return *this; + + if (m_sharedString->size == 0) + return operator=(character); + + if (m_sharedString->capacity > m_sharedString->size) + { + EnsureOwnership(); + + m_sharedString->string[m_sharedString->size] = character; + m_sharedString->string[m_sharedString->size+1] = '\0'; + m_sharedString->size++; + } + else + { + unsigned int newSize = m_sharedString->size+1; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + str[m_sharedString->size] = character; + str[newSize] = '\0'; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::operator+=(const char* string) +{ + if (!string || !string[0]) + return *this; + + if (m_sharedString->size == 0) + return operator=(string); + + unsigned int size = std::strlen(string); + if (size == 0) + return *this; + + if (m_sharedString->capacity >= m_sharedString->size + size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string, size+1); + m_sharedString->size += size; + } + else + { + unsigned int newSize = m_sharedString->size + size; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string, size+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::operator+=(const std::string& string) +{ + if (string.empty()) + return *this; + + if (m_sharedString->size == 0) + return operator=(string); + + if (m_sharedString->capacity >= m_sharedString->size + string.size()) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string.c_str(), string.size()+1); + m_sharedString->size += string.size(); + } + else + { + unsigned int newSize = m_sharedString->size + string.size(); + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.c_str(), string.size()+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::operator+=(const NzString& string) +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0) + return operator=(string); + + if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + m_sharedString->size += string.m_sharedString->size; + } + else + { + unsigned int newSize = m_sharedString->size + string.m_sharedString->size; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +bool NzString::operator==(char character) const +{ + if (m_sharedString->size == 0) + return character == '\0'; + + if (m_sharedString->size > 1) + return false; + + return m_sharedString->string[0] == character; +} + +bool NzString::operator==(const char* string) const +{ + if (m_sharedString->size == 0) + return !string || !string[0]; + + if (!string || !string[0]) + return false; + + return std::strcmp(m_sharedString->string, string) == 0; +} + +bool NzString::operator==(const std::string& string) const +{ + if (m_sharedString->size == 0 || string.empty()) + return m_sharedString->size == string.size(); + + if (m_sharedString->size != string.size()) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) == 0; +} + +bool NzString::operator!=(char character) const +{ + if (m_sharedString->size == 0) + return character != '\0'; + + if (character == '\0' || m_sharedString->size != 1) + return true; + + if (m_sharedString->size != 1) + return true; + + return m_sharedString->string[0] != character; +} + +bool NzString::operator!=(const char* string) const +{ + if (m_sharedString->size == 0) + return string && string[0]; + + if (!string || !string[0]) + return true; + + return std::strcmp(m_sharedString->string, string) != 0; +} + +bool NzString::operator!=(const std::string& string) const +{ + if (m_sharedString->size == 0 || string.empty()) + return m_sharedString->size == string.size(); + + if (m_sharedString->size != string.size()) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) != 0; +} + +bool NzString::operator<(char character) const +{ + if (character == '\0') + return false; + + if (m_sharedString->size == 0) + return true; + + return m_sharedString->string[0] < character; +} + +bool NzString::operator<(const char* string) const +{ + if (!string || !string[0]) + return false; + + if (m_sharedString->size == 0) + return true; + + return std::strcmp(m_sharedString->string, string) < 0; +} + +bool NzString::operator<(const std::string& string) const +{ + if (string.empty()) + return false; + + if (m_sharedString->size == 0) + return true; + + return std::strcmp(m_sharedString->string, string.c_str()) < 0; +} + +bool NzString::operator<=(char character) const +{ + if (m_sharedString->size == 0) + return true; + + if (character == '\0') + return false; + + return m_sharedString->string[0] < character || (m_sharedString->string[0] == character && m_sharedString->size == 1); +} + +bool NzString::operator<=(const char* string) const +{ + if (m_sharedString->size == 0) + return true; + + if (!string || !string[0]) + return false; + + return std::strcmp(m_sharedString->string, string) <= 0; +} + +bool NzString::operator<=(const std::string& string) const +{ + if (m_sharedString->size == 0) + return true; + + if (string.empty()) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) <= 0; +} + +bool NzString::operator>(char character) const +{ + if (m_sharedString->size == 0) + return false; + + if (character == '\0') + return true; + + return m_sharedString->string[0] > character; +} + +bool NzString::operator>(const char* string) const +{ + if (m_sharedString->size == 0) + return false; + + if (!string || !string[0]) + return true; + + return std::strcmp(m_sharedString->string, string) > 0; +} + +bool NzString::operator>(const std::string& string) const +{ + if (m_sharedString->size == 0) + return false; + + if (string.empty()) + return true; + + return std::strcmp(m_sharedString->string, string.c_str()) > 0; +} + +bool NzString::operator>=(char character) const +{ + if (character == '\0') + return true; + + if (m_sharedString->size == 0) + return false; + + return m_sharedString->string[0] > character || (m_sharedString->string[0] == character && m_sharedString->size == 1); +} + +bool NzString::operator>=(const char* string) const +{ + if (!string || !string[0]) + return true; + + if (m_sharedString->size == 0) + return false; + + return std::strcmp(m_sharedString->string, string) >= 0; +} + +bool NzString::operator>=(const std::string& string) const +{ + if (string.empty()) + return true; + + if (m_sharedString->size == 0) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) >= 0; +} + +NzString NzString::Boolean(bool boolean) +{ + unsigned int size = (boolean) ? 4 : 5; + char* str = new char[size+1]; + std::strcpy(str, (boolean) ? "true" : "false"); + + return NzString(new SharedString(1, size, size, str)); +} + +int NzString::Compare(const NzString& first, const NzString& second) +{ + if (first.m_sharedString->size == 0) + return (second.m_sharedString->size == 0) ? 0 : -1; + + if (second.m_sharedString->size == 0) + return 1; + + return std::strcmp(first.m_sharedString->string, second.m_sharedString->string); +} + +NzString NzString::Number(float number) +{ + std::ostringstream oss; + oss.precision(NAZARA_CORE_REAL_PRECISION); + oss << number; + + return NzString(oss.str()); +} + +NzString NzString::Number(double number) +{ + std::ostringstream oss; + oss.precision(NAZARA_CORE_REAL_PRECISION); + oss << number; + + return NzString(oss.str()); +} + +NzString NzString::Number(long double number) +{ + std::ostringstream oss; + oss.precision(NAZARA_CORE_REAL_PRECISION); + oss << number; + + return NzString(oss.str()); +} + +NzString NzString::Number(signed char number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned char number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(short number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned short number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(int number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned int number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(long long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned long long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Pointer(const void* ptr) +{ + unsigned int size = sizeof(ptr)*2+2; + char* str = new char[size+1]; + std::sprintf(str, "0x%p", ptr); + + return NzString(new SharedString(1, size, size, str)); +} + +NzString NzString::Unicode(char32_t character) +{ + if (character == '\0') + return NzString(); + + unsigned int count = 0; + if (character < 0x80) + count = 1; + else if (character < 0x800) + count = 2; + else if (character < 0x10000) + count = 3; + else + count = 4; + + char* str = new char[count+1]; + utf8::append(character, str); + str[count] = '\0'; + + return NzString(new SharedString(1, count, count, str)); +} + +NzString NzString::Unicode(const char* u8String) +{ + return NzString(u8String); +} + +NzString NzString::Unicode(const char16_t* u16String) +{ + if (!u16String || !u16String[0]) + return NzString(); + + const char16_t* ptr = u16String; + unsigned int count = 0; + do + count++; + while (*++ptr); + + count *= 2; // On s'assure d'avoir la place suffisante + + char* str = new char[count+1]; + char* r = utf8::utf16to8(u16String, ptr, str); + *r = '\0'; + + return NzString(new SharedString(1, count, r-str, str)); +} + +NzString NzString::Unicode(const char32_t* u32String) +{ + if (!u32String || !u32String[0]) + return NzString(); + + const char32_t* ptr = u32String; + unsigned int count = 0; + do + { + char32_t cp = *ptr; + if (cp < 0x80) + count += 1; + else if (cp < 0x800) + count += 2; + else if (cp < 0x10000) + count += 3; + else + count += 4; + } + while (*++ptr); + + char* str = new char[count+1]; + char* r = utf8::utf32to8(u32String, ptr, str); + *r = '\0'; + + return NzString(new SharedString(1, count, count, str)); +} + +NzString NzString::Unicode(const wchar_t* wString) +{ + if (!wString || !wString[0]) + return NzString(); + + const wchar_t* ptr = wString; + unsigned int count = 0; + do + { + char32_t cp = *ptr; + if (cp < 0x80) + count += 1; + else if (cp < 0x800) + count += 2; + else if (cp < 0x10000) + count += 3; + else + count += 4; + } + while (*++ptr); + + char* str = new char[count+1]; + char* r = utf8::utf32to8(wString, ptr, str); + *r = '\0'; + + return NzString(new SharedString(1, count, count, str)); +} + +std::istream& operator>>(std::istream& is, NzString& str) +{ + str.Clear(); + + char c; + do + { + is.get(c); + if (c == '\0') + break; + else if (std::isspace(c)) + { + if (str.IsNull()) + continue; + else + break; + } + else + str += c; + } + while (true); + + return is; +} + +std::ostream& operator<<(std::ostream& os, const NzString& str) +{ + if (str.IsEmpty()) + return os; + + return operator<<(os, str.m_sharedString->string); +} + +NzString operator+(char character, const NzString& string) +{ + if (character == '\0') + return string; + + if (string.IsEmpty()) + return character; + + unsigned int totalSize = string.m_sharedString->size+1; + char* str = new char[totalSize+1]; + str[0] = character; + std::memcpy(str, string.m_sharedString->string, string.m_sharedString->size+1); + + return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); +} + +NzString operator+(const char* string, const NzString& nstring) +{ + if (!string || !string[0]) + return nstring; + + if (nstring.IsEmpty()) + return string; + + unsigned int size = std::strlen(string); + unsigned int totalSize = size + nstring.m_sharedString->size; + char* str = new char[totalSize+1]; + std::memcpy(str, string, size); + std::memcpy(&str[size], nstring.m_sharedString->string, nstring.m_sharedString->size+1); + + return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); +} + +NzString operator+(const std::string& string, const NzString& nstring) +{ + if (string.empty()) + return nstring; + + if (nstring.m_sharedString->size == 0) + return string; + + unsigned int totalSize = string.size() + nstring.m_sharedString->size; + char* str = new char[totalSize+1]; + std::memcpy(str, string.c_str(), string.size()); + std::memcpy(&str[string.size()], nstring.m_sharedString->string, nstring.m_sharedString->size+1); + + return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); +} + +bool operator==(const NzString& first, const NzString& second) +{ + if (first.m_sharedString->size == 0 || second.m_sharedString->size == 0) + return first.m_sharedString->size == second.m_sharedString->size; + + if (first.m_sharedString->size != second.m_sharedString->size) + return false; + + return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) == 0; +} + +bool operator!=(const NzString& first, const NzString& second) +{ + return !operator==(first, second); +} + +bool operator<(const NzString& first, const NzString& second) +{ + if (second.m_sharedString->size == 0) + return false; + + if (first.m_sharedString->size == 0) + return true; + + return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) < 0; +} + +bool operator<=(const NzString& first, const NzString& second) +{ + return !operator<(second, first); +} + +bool operator>(const NzString& first, const NzString& second) +{ + return second < first; +} + +bool operator>=(const NzString& first, const NzString& second) +{ + return !operator<(first, second); +} + +bool operator==(char character, const NzString& nstring) +{ + return nstring == character; +} + +bool operator==(const char* string, const NzString& nstring) +{ + return nstring == string; +} + +bool operator==(const std::string& string, const NzString& nstring) +{ + return nstring == string; +} + +bool operator!=(char character, const NzString& nstring) +{ + return !operator==(character, nstring); +} + +bool operator!=(const char* string, const NzString& nstring) +{ + return !operator==(string, nstring); +} + +bool operator!=(const std::string& string, const NzString& nstring) +{ + return !operator==(string, nstring); +} + +bool operator<(char character, const NzString& nstring) +{ + return nstring > character; +} + +bool operator<(const char* string, const NzString& nstring) +{ + return nstring > string; +} + +bool operator<(const std::string& string, const NzString& nstring) +{ + return nstring > string; +} + +bool operator<=(char character, const NzString& nstring) +{ + return !operator<(nstring, character); +} + +bool operator<=(const char* string, const NzString& nstring) +{ + return !operator<(nstring, string); +} + +bool operator<=(const std::string& string, const NzString& nstring) +{ + return !operator<(nstring, string); +} + +bool operator>(char character, const NzString& nstring) +{ + return nstring < character; +} + +bool operator>(const char* string, const NzString& nstring) +{ + return nstring < string; +} + +bool operator>(const std::string& string, const NzString& nstring) +{ + return nstring < string; +} + +bool operator>=(char character, const NzString& nstring) +{ + return !operator<(character, nstring); +} + +bool operator>=(const char* string, const NzString& nstring) +{ + return !operator<(string, nstring); +} + +bool operator>=(const std::string& string, const NzString& nstring) +{ + return !operator<(string, nstring); +} + +void NzString::EnsureOwnership() +{ + if (m_sharedString == &emptyString) + return; + + NazaraLock(m_sharedString->mutex); + if (m_sharedString->refCount > 1) + { + m_sharedString->refCount--; + + char* string = new char[m_sharedString->capacity+1]; + std::memcpy(string, m_sharedString->string, m_sharedString->size+1); + + m_sharedString = new SharedString(1, m_sharedString->capacity, m_sharedString->size, string); + } +} + +bool NzString::FillHash(NzHashImpl* hazh) const +{ + hazh->Append(reinterpret_cast(m_sharedString->string), m_sharedString->size); + + return true; +} + +void NzString::ReleaseString() +{ + if (m_sharedString == &emptyString) + return; + + NazaraMutexLock(m_sharedString->mutex); + bool freeSharedString = (--m_sharedString->refCount == 0); + NazaraMutexUnlock(m_sharedString->mutex); + + if (freeSharedString) + { + delete[] m_sharedString->string; + delete m_sharedString; + } + + m_sharedString = &emptyString; +} + +NzString::SharedString NzString::emptyString(0, 0, 0, nullptr); +const unsigned int NzString::npos(std::numeric_limits::max()); + +namespace std +{ + istream& getline(istream& is, NzString& str) + { + str.Clear(); + + char c; + do + { + is.get(c); + if (c != '\n' && c != '\0') + str += c; + else + break; + } + while (true); + + return is; + } + + istream& getline(istream& is, NzString& str, char delim) + { + str.Clear(); + + char c; + do + { + is.get(c); + if (c != delim && c != '\0') + str += c; + else + break; + } + while (true); + + return is; + } + + void swap(NzString& lhs, NzString& rhs) + { + lhs.Swap(rhs); + } +} diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index 1dfc9787e..e10588943 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -1,355 +1,359 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) - #include -#elif defined(NAZARA_PLATFORM_LINUX) - #include -#else - #error Lack of implementation: Context -#endif - -#include - -namespace -{ - NAZARA_THREADLOCAL NzContext* currentContext = nullptr; - NAZARA_THREADLOCAL NzContext* threadContext = nullptr; - - std::vector contexts; - - void CALLBACK DebugCallback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, void* userParam) - { - NazaraUnused(length); - - NzStringStream ss; - ss << "OpenGL debug message (ID: 0x" << NzString::Number(id, 16) << "):\n"; - ss << "Sent by context: " << userParam; - ss << "\n-Source: "; - switch (source) - { - case GL_DEBUG_SOURCE_API_ARB: - ss << "OpenGL"; - break; - - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: - ss << "Operating system"; - break; - - case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: - ss << "Shader compiler"; - break; - - case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: - ss << "Shader compiler"; - break; - - case GL_DEBUG_SOURCE_APPLICATION_ARB: - ss << "Application"; - break; - - case GL_DEBUG_SOURCE_OTHER_ARB: - ss << "Other"; - break; - - default: - // Peut être rajouté par une extension - ss << "Unknown"; - break; - } - ss << '\n'; - - ss << "-Type: "; - switch (type) - { - case GL_DEBUG_TYPE_ERROR_ARB: - ss << "Error"; - break; - - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: - ss << "Deprecated behavior"; - break; - - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: - ss << "Undefined behavior"; - break; - - case GL_DEBUG_TYPE_PORTABILITY_ARB: - ss << "Portability"; - break; - - case GL_DEBUG_TYPE_PERFORMANCE_ARB: - ss << "Performance"; - break; - - case GL_DEBUG_TYPE_OTHER_ARB: - ss << "Other"; - break; - - default: - // Peut être rajouté par une extension - ss << "Unknown"; - break; - } - ss << '\n'; - - ss << "-Severity: "; - switch (severity) - { - case GL_DEBUG_SEVERITY_HIGH_ARB: - ss << "High"; - break; - - case GL_DEBUG_SEVERITY_MEDIUM_ARB: - ss << "Medium"; - break; - - case GL_DEBUG_SEVERITY_LOW_ARB: - ss << "Low"; - break; - - default: - // Peut être rajouté par une extension - ss << "Unknown"; - break; - } - ss << '\n'; - - ss << "Message: " << message << '\n'; - - NazaraNotice(ss); - } -} - -NzContext::NzContext() : -m_impl(nullptr) -{ -} - -NzContext::~NzContext() -{ - Destroy(); -} - -bool NzContext::Create(const NzContextParameters& parameters) -{ - Destroy(); - - m_parameters = parameters; - if (m_parameters.shared && !m_parameters.shareContext) - m_parameters.shareContext = s_reference; - - m_impl = new NzContextImpl; - if (!m_impl->Create(m_parameters)) - { - NazaraError("Failed to create context implementation"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - if (!m_impl->Activate()) - { - NazaraError("Failed to activate context"); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - - return false; - } - - if (m_parameters.antialiasingLevel > 0) - glEnable(GL_MULTISAMPLE); - - if (NzOpenGL::IsSupported(NzOpenGL::DebugOutput) && m_parameters.debugMode) - { - glDebugMessageCallback(&DebugCallback, this); - - #ifdef NAZARA_DEBUG - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); - #endif - } - - return true; -} - -void NzContext::Destroy() -{ - if (m_impl) - { - if (currentContext == this) - NzContextImpl::Desactivate(); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - } -} - -const NzContextParameters& NzContext::GetParameters() const -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - NazaraError("No context has been created"); - #endif - - return m_parameters; -} - -bool NzContext::IsActive() const -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("No context has been created"); - return false; - } - #endif - - return currentContext == this; -} - -bool NzContext::SetActive(bool active) -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("No context has been created"); - return false; - } - #endif - - // Si le contexte est déjà activé/désactivé - if ((currentContext == this) == active) - return true; - - if (active) - { - if (!m_impl->Activate()) - return false; - - currentContext = this; - } - else - { - if (!NzContextImpl::Desactivate()) - return false; - - currentContext = nullptr; - } - - return true; -} - -void NzContext::SwapBuffers() -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("No context has been created"); - return; - } - - if (!m_parameters.doubleBuffered) - { - NazaraError("Context is not double buffered"); - return; - } - #endif - - m_impl->SwapBuffers(); -} - -bool NzContext::EnsureContext() -{ - if (!currentContext) - { - if (!threadContext) - { - NzContext* context = new NzContext; - if (!context->Create()) - { - NazaraError("Failed to create context"); - delete context; - - return false; - } - - contexts.push_back(context); - - threadContext = context; - } - - if (!threadContext->SetActive(true)) - { - NazaraError("Failed to active thread context"); - return false; - } - } - - return true; -} - -NzContext* NzContext::GetCurrent() -{ - return currentContext; -} - -const NzContext* NzContext::GetReference() -{ - return s_reference; -} - -NzContext* NzContext::GetThreadContext() -{ - EnsureContext(); - - return threadContext; -} - -bool NzContext::Initialize() -{ - NzContextParameters parameters; -// parameters.compatibilityProfile = true; - parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même - - s_reference = new NzContext; - if (!s_reference->Create(parameters)) - { - delete s_reference; - s_reference = nullptr; - - return false; - } - - // Le contexte de référence doit rester désactivé pour le partage - s_reference->SetActive(false); - - NzContextParameters::defaultShareContext = s_reference; - - return true; -} - -void NzContext::Uninitialize() -{ - for (NzContext* context : contexts) - delete context; - - contexts.clear(); // On supprime tous les contextes créés - - delete s_reference; - s_reference = nullptr; -} - -NzContext* NzContext::s_reference = nullptr; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) + #include +#elif defined(NAZARA_PLATFORM_LINUX) + #include +#else + #error Lack of implementation: Context +#endif + +#include + +namespace +{ + NAZARA_THREADLOCAL NzContext* currentContext = nullptr; + NAZARA_THREADLOCAL NzContext* threadContext = nullptr; + + std::vector contexts; + + void CALLBACK DebugCallback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, void* userParam) + { + NazaraUnused(length); + + NzStringStream ss; + ss << "OpenGL debug message (ID: 0x" << NzString::Number(id, 16) << "):\n"; + ss << "Sent by context: " << userParam; + ss << "\n-Source: "; + switch (source) + { + case GL_DEBUG_SOURCE_API_ARB: + ss << "OpenGL"; + break; + + case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: + ss << "Operating system"; + break; + + case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: + ss << "Shader compiler"; + break; + + case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: + ss << "Shader compiler"; + break; + + case GL_DEBUG_SOURCE_APPLICATION_ARB: + ss << "Application"; + break; + + case GL_DEBUG_SOURCE_OTHER_ARB: + ss << "Other"; + break; + + default: + // Peut être rajouté par une extension + ss << "Unknown"; + break; + } + ss << '\n'; + + ss << "-Type: "; + switch (type) + { + case GL_DEBUG_TYPE_ERROR_ARB: + ss << "Error"; + break; + + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: + ss << "Deprecated behavior"; + break; + + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: + ss << "Undefined behavior"; + break; + + case GL_DEBUG_TYPE_PORTABILITY_ARB: + ss << "Portability"; + break; + + case GL_DEBUG_TYPE_PERFORMANCE_ARB: + ss << "Performance"; + break; + + case GL_DEBUG_TYPE_OTHER_ARB: + ss << "Other"; + break; + + default: + // Peut être rajouté par une extension + ss << "Unknown"; + break; + } + ss << '\n'; + + ss << "-Severity: "; + switch (severity) + { + case GL_DEBUG_SEVERITY_HIGH_ARB: + ss << "High"; + break; + + case GL_DEBUG_SEVERITY_MEDIUM_ARB: + ss << "Medium"; + break; + + case GL_DEBUG_SEVERITY_LOW_ARB: + ss << "Low"; + break; + + default: + // Peut être rajouté par une extension + ss << "Unknown"; + break; + } + ss << '\n'; + + ss << "Message: " << message << '\n'; + + NazaraNotice(ss); + } +} + +NzContext::NzContext() : +m_impl(nullptr) +{ +} + +NzContext::~NzContext() +{ + Destroy(); +} + +bool NzContext::Create(const NzContextParameters& parameters) +{ + Destroy(); + + m_parameters = parameters; + if (m_parameters.shared && !m_parameters.shareContext) + m_parameters.shareContext = s_reference; + + m_impl = new NzContextImpl; + if (!m_impl->Create(m_parameters)) + { + NazaraError("Failed to create context implementation"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + if (!m_impl->Activate()) + { + NazaraError("Failed to activate context"); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + + return false; + } + + if (m_parameters.antialiasingLevel > 0) + glEnable(GL_MULTISAMPLE); + + if (NzOpenGL::IsSupported(nzOpenGLExtension_DebugOutput) && m_parameters.debugMode) + { + glDebugMessageCallback(&DebugCallback, this); + + #ifdef NAZARA_DEBUG + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + #endif + } + + NotifyCreated(); + + return true; +} + +void NzContext::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + if (currentContext == this) + NzContextImpl::Desactivate(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + } +} + +const NzContextParameters& NzContext::GetParameters() const +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + NazaraError("No context has been created"); + #endif + + return m_parameters; +} + +bool NzContext::IsActive() const +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("No context has been created"); + return false; + } + #endif + + return currentContext == this; +} + +bool NzContext::SetActive(bool active) +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("No context has been created"); + return false; + } + #endif + + // Si le contexte est déjà activé/désactivé + if ((currentContext == this) == active) + return true; + + if (active) + { + if (!m_impl->Activate()) + return false; + + currentContext = this; + } + else + { + if (!NzContextImpl::Desactivate()) + return false; + + currentContext = nullptr; + } + + return true; +} + +void NzContext::SwapBuffers() +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("No context has been created"); + return; + } + + if (!m_parameters.doubleBuffered) + { + NazaraError("Context is not double buffered"); + return; + } + #endif + + m_impl->SwapBuffers(); +} + +bool NzContext::EnsureContext() +{ + if (!currentContext) + { + if (!threadContext) + { + NzContext* context = new NzContext; + if (!context->Create()) + { + NazaraError("Failed to create context"); + delete context; + + return false; + } + + contexts.push_back(context); + + threadContext = context; + } + + if (!threadContext->SetActive(true)) + { + NazaraError("Failed to active thread context"); + return false; + } + } + + return true; +} + +NzContext* NzContext::GetCurrent() +{ + return currentContext; +} + +const NzContext* NzContext::GetReference() +{ + return s_reference; +} + +NzContext* NzContext::GetThreadContext() +{ + EnsureContext(); + + return threadContext; +} + +bool NzContext::Initialize() +{ + NzContextParameters parameters; +// parameters.compatibilityProfile = true; + parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même + + s_reference = new NzContext; + if (!s_reference->Create(parameters)) + { + delete s_reference; + s_reference = nullptr; + + return false; + } + + // Le contexte de référence doit rester désactivé pour le partage + s_reference->SetActive(false); + + NzContextParameters::defaultShareContext = s_reference; + + return true; +} + +void NzContext::Uninitialize() +{ + for (NzContext* context : contexts) + delete context; + + contexts.clear(); // On supprime tous les contextes créés + + delete s_reference; + s_reference = nullptr; +} + +NzContext* NzContext::s_reference = nullptr; diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLShader.cpp index 22ebcc6fe..ecc0e6199 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLShader.cpp @@ -1,578 +1,712 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - ///FIXME: Déclaré deux fois (ici et dans Renderer.cpp) - const nzUInt8 attribIndex[] = - { - 2, // nzElementUsage_Diffuse - 1, // nzElementUsage_Normal - 0, // nzElementUsage_Position - 3, // nzElementUsage_Tangent - 4 // nzElementUsage_TexCoord - }; - - const GLenum shaderType[nzShaderType_Max+1] = { - GL_FRAGMENT_SHADER, // nzShaderType_Fragment - GL_GEOMETRY_SHADER, // nzShaderType_Geometry - GL_VERTEX_SHADER // nzShaderType_Vertex - }; - - GLuint lockedPrevious = 0; - nzUInt8 lockedLevel = 0; -} - -NzGLSLShader::NzGLSLShader(NzShader* parent) : -m_parent(parent) -{ -} - -NzGLSLShader::~NzGLSLShader() -{ -} - -bool NzGLSLShader::Bind() -{ - #if NAZARA_RENDERER_SAFE - if (lockedLevel > 0) - { - NazaraError("Cannot bind shader while a shader is locked"); - return false; - } - #endif - - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return false; - } - #endif - - glUseProgram(m_program); - - return true; -} - -bool NzGLSLShader::BindTextures() -{ - for (auto it = m_textures.begin(); it != m_textures.end(); ++it) - { - TextureSlot& slot = it->second; - if (!slot.updated) - { - glActiveTexture(GL_TEXTURE0 + slot.unit); - if (!slot.texture->Bind()) - NazaraWarning("Failed to bind texture"); - - slot.updated = true; - } - } - - return true; -} - -bool NzGLSLShader::Compile() -{ - NzContext::EnsureContext(); - - m_idCache.clear(); - m_textures.clear(); - - glLinkProgram(m_program); - - GLint success; - glGetProgramiv(m_program, GL_LINK_STATUS, &success); - - if (success == GL_TRUE) - { - static NzString successStr("Linkage successful"); - m_log = successStr; - - return true; - } - else - { - // On remplit le log avec l'erreur de compilation - GLint length = 0; - glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length); - if (length > 1) - { - m_log.Clear(true); - m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) - m_log.Prepend("Linkage error: "); - m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log - - glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]); - } - else - m_log = "Linkage failed but no info log found"; - - NazaraError(m_log); - - return false; - } -} - -bool NzGLSLShader::Create() -{ - NzContext::EnsureContext(); - - m_program = glCreateProgram(); - if (!m_program) - { - NazaraError("Failed to create program"); - return false; - } - - glBindAttribLocation(m_program, attribIndex[nzElementUsage_Position], "Position"); - glBindAttribLocation(m_program, attribIndex[nzElementUsage_Normal], "Normal"); - glBindAttribLocation(m_program, attribIndex[nzElementUsage_Diffuse], "Diffuse"); - glBindAttribLocation(m_program, attribIndex[nzElementUsage_Tangent], "Tangent"); - - NzString uniform = "TexCoord"; - unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits(); - for (unsigned int i = 0; i < maxTexCoords; ++i) - { - NzString uniformName = uniform + NzString::Number(i); - glBindAttribLocation(m_program, attribIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer()); - } - - for (int i = 0; i <= nzShaderType_Max; ++i) - m_shaders[i] = 0; - - return true; -} - -void NzGLSLShader::Destroy() -{ - NzContext::EnsureContext(); - - for (auto it = m_textures.begin(); it != m_textures.end(); ++it) - it->second.texture->RemoveResourceReference(); - - for (GLuint shader : m_shaders) - if (shader) - glDeleteShader(shader); - - if (m_program) - glDeleteProgram(m_program); -} - -NzString NzGLSLShader::GetLog() const -{ - return m_log; -} - -nzShaderLanguage NzGLSLShader::GetLanguage() const -{ - return nzShaderLanguage_GLSL; -} - -NzString NzGLSLShader::GetSourceCode(nzShaderType type) const -{ - NzContext::EnsureContext(); - - NzString source; - - GLint length; - glGetShaderiv(m_shaders[type], GL_SHADER_SOURCE_LENGTH, &length); - if (length > 1) - { - source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin) - glGetShaderSource(m_shaders[type], length, nullptr, &source[0]); - } - - return source; -} - -int NzGLSLShader::GetUniformLocation(const NzString& name) const -{ - std::map::const_iterator it = m_idCache.find(name); - GLint id; - if (it == m_idCache.end()) - { - NzContext::EnsureContext(); - - id = glGetUniformLocation(m_program, name.GetConstBuffer()); - m_idCache[name] = id; - } - else - id = it->second; - - return id; -} - -bool NzGLSLShader::IsLoaded(nzShaderType type) const -{ - return m_shaders[type] != 0; -} - -bool NzGLSLShader::Load(nzShaderType type, const NzString& source) -{ - NzContext::EnsureContext(); - - GLuint shader = glCreateShader(shaderType[type]); - if (!shader) - { - m_log = "Failed to create shader object"; - NazaraError(m_log); - - return false; - } - - const char* tmp = source.GetConstBuffer(); - GLint length = source.GetSize(); - glShaderSource(shader, 1, &tmp, &length); - - glCompileShader(shader); - - GLint success; - glGetShaderiv(shader, GL_COMPILE_STATUS, &success); - - if (success == GL_TRUE) - { - glAttachShader(m_program, shader); - m_shaders[type] = shader; - - static NzString successStr("Compilation successful"); - m_log = successStr; - - return true; - } - else - { - // On remplit le log avec l'erreur de compilation - length = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); - if (length > 1) - { - m_log.Clear(true); - m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) - m_log.Prepend("Compilation error: "); - m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log - - glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]); - } - else - m_log = "Compilation failed but no info log found"; - - NazaraError(m_log); - - glDeleteShader(shader); - - return false; - } -} - -bool NzGLSLShader::Lock() -{ - if (lockedLevel++ == 0) - { - NzContext::EnsureContext(); - - GLint previous; - glGetIntegerv(GL_CURRENT_PROGRAM, &previous); - - lockedPrevious = previous; - - if (lockedPrevious != m_program) - glUseProgram(m_program); - } - - return true; -} - -bool NzGLSLShader::SendBoolean(int location, bool value) -{ - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, value); - else - { - Lock(); - glUniform1i(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendDouble(int location, double value) -{ - if (glProgramUniform1d) - glProgramUniform1d(m_program, location, value); - else - { - Lock(); - glUniform1d(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendFloat(int location, float value) -{ - if (glProgramUniform1f) - glProgramUniform1f(m_program, location, value); - else - { - Lock(); - glUniform1f(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendInteger(int location, int value) -{ - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, value); - else - { - Lock(); - glUniform1i(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) -{ - if (glProgramUniformMatrix4dv) - glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix); - else - { - Lock(); - glUniformMatrix4dv(location, 1, GL_FALSE, matrix); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) -{ - if (glProgramUniformMatrix4fv) - glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix); - else - { - Lock(); - glUniformMatrix4fv(location, 1, GL_FALSE, matrix); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) -{ - auto it = m_textures.find(location); - if (it != m_textures.end()) - { - // Slot déjà utilisé - TextureSlot& slot = it->second; - if (slot.texture != texture) - { - slot.texture->RemoveResourceReference(); - - if (texture) - { - slot.texture = texture; - slot.texture->AddResourceReference(); - - slot.updated = false; - } - else - m_textures.erase(it); // On supprime le slot - } - } - else - { - static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits(); - - unsigned int unitUsed = m_textures.size(); - if (unitUsed >= maxUnits) - { - NazaraError("Unable to use texture for shader: all available texture units are used"); - return false; - } - - // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre - nzUInt8 unit; - if (unitUsed == 0) - // Pas d'unité utilisée, la tâche est simple - unit = 0; - else - { - auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map - unit = it2->second.unit; - if (unit == maxUnits-1) - { - // Il y a une place libre, mais pas à la fin - for (; it2 != m_textures.rend(); ++it2) - { - if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre - { - unit--; - break; - } - } - } - else - // Il y a une place libre à la fin - unit++; - } - - TextureSlot slot; - slot.unit = unit; - slot.texture = texture; - texture->AddResourceReference(); - - m_textures[location] = slot; - - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, unit); - else - { - Lock(); - glUniform1i(location, unit); - Unlock(); - } - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) -{ - if (glProgramUniform2dv) - glProgramUniform2dv(m_program, location, 1, vector); - else - { - Lock(); - glUniform2dv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) -{ - if (glProgramUniform2fv) - glProgramUniform2fv(m_program, location, 1, vector); - else - { - Lock(); - glUniform2fv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) -{ - if (glProgramUniform3dv) - glProgramUniform3dv(m_program, location, 1, vector); - else - { - Lock(); - glUniform3dv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) -{ - if (glProgramUniform3fv) - glProgramUniform3fv(m_program, location, 1, vector); - else - { - Lock(); - glUniform3fv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) -{ - if (glProgramUniform4dv) - glProgramUniform4dv(m_program, location, 1, vector); - else - { - Lock(); - glUniform4dv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) -{ - if (glProgramUniform4fv) - glProgramUniform4fv(m_program, location, 1, vector); - else - { - Lock(); - glUniform4fv(location, 1, vector); - Unlock(); - } - - return true; -} - -void NzGLSLShader::Unbind() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glUseProgram(0); -} - -void NzGLSLShader::Unlock() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (lockedLevel == 0) - { - NazaraWarning("Unlock called on non-locked texture"); - return; - } - #endif - - if (--lockedLevel == 0 && lockedPrevious != m_program) - glUseProgram(lockedPrevious); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + GLuint lockedPrevious = 0; + nzUInt8 lockedLevel = 0; +} + +NzGLSLShader::NzGLSLShader(NzShader* parent) : +m_parent(parent) +{ +} + +NzGLSLShader::~NzGLSLShader() +{ + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + it->second.texture->RemoveResourceListener(this); +} + +bool NzGLSLShader::Bind() +{ + #if NAZARA_RENDERER_SAFE + if (lockedLevel > 0) + { + NazaraError("Cannot bind shader while a shader is locked"); + return false; + } + #endif + + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return false; + } + #endif + + glUseProgram(m_program); + + return true; +} + +bool NzGLSLShader::BindTextures() +{ + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + { + TextureSlot& slot = it->second; + if (slot.enabled && !slot.updated) + { + glActiveTexture(GL_TEXTURE0 + slot.unit); + if (!slot.texture->Prepare()) + NazaraWarning("Failed to prepare texture"); + + slot.updated = true; + } + } + + return true; +} + +bool NzGLSLShader::Compile() +{ + NzContext::EnsureContext(); + + m_idCache.clear(); + m_textures.clear(); + + glLinkProgram(m_program); + + GLint success; + glGetProgramiv(m_program, GL_LINK_STATUS, &success); + + if (success == GL_TRUE) + { + static NzString successStr("Linkage successful"); + m_log = successStr; + + return true; + } + else + { + // On remplit le log avec l'erreur de compilation + GLint length = 0; + glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length); + if (length > 1) + { + m_log.Clear(true); + m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) + m_log.Prepend("Linkage error: "); + m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log + + glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]); + } + else + m_log = "Linkage failed but no info log found"; + + NazaraError(m_log); + + return false; + } +} + +bool NzGLSLShader::Create() +{ + NzContext::EnsureContext(); + + m_program = glCreateProgram(); + if (!m_program) + { + NazaraError("Failed to create program"); + return false; + } + + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Position], "Position"); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Normal], "Normal"); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Diffuse], "Diffuse"); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Tangent], "Tangent"); + + NzString uniform; + + static const unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits(); + + uniform.Reserve(10); // 8 + 2 + uniform = "TexCoord"; + for (unsigned int i = 0; i < maxTexCoords; ++i) + { + NzString uniformName = uniform + NzString::Number(i); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer()); + } + + static const bool mrtSupported = NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets); + if (mrtSupported) + { + static const unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets(); + + uniform.Reserve(14); // 12 + 2 + uniform = "RenderTarget"; + for (unsigned int i = 0; i < maxRenderTargets; ++i) + { + NzString uniformName = uniform + NzString::Number(i); + glBindFragDataLocation(m_program, i, uniformName.GetConstBuffer()); + } + } + + for (int i = 0; i <= nzShaderType_Max; ++i) + m_shaders[i] = 0; + + return true; +} + +void NzGLSLShader::Destroy() +{ + NzContext::EnsureContext(); + + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + it->second.texture->RemoveResourceReference(); + + for (GLuint shader : m_shaders) + if (shader) + glDeleteShader(shader); + + if (m_program) + glDeleteProgram(m_program); +} + +NzString NzGLSLShader::GetLog() const +{ + return m_log; +} + +nzShaderLanguage NzGLSLShader::GetLanguage() const +{ + return nzShaderLanguage_GLSL; +} + +NzString NzGLSLShader::GetSourceCode(nzShaderType type) const +{ + NzContext::EnsureContext(); + + NzString source; + + GLint length; + glGetShaderiv(m_shaders[type], GL_SHADER_SOURCE_LENGTH, &length); + if (length > 1) + { + source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin) + glGetShaderSource(m_shaders[type], length, nullptr, &source[0]); + } + + return source; +} + +int NzGLSLShader::GetUniformLocation(const NzString& name) const +{ + std::map::const_iterator it = m_idCache.find(name); + GLint id; + if (it == m_idCache.end()) + { + NzContext::EnsureContext(); + + id = glGetUniformLocation(m_program, name.GetConstBuffer()); + m_idCache[name] = id; + } + else + id = it->second; + + return id; +} + +bool NzGLSLShader::IsLoaded(nzShaderType type) const +{ + return m_shaders[type] != 0; +} + +bool NzGLSLShader::Load(nzShaderType type, const NzString& source) +{ + NzContext::EnsureContext(); + + GLuint shader = glCreateShader(NzOpenGL::ShaderType[type]); + if (!shader) + { + m_log = "Failed to create shader object"; + NazaraError(m_log); + + return false; + } + + const char* tmp = source.GetConstBuffer(); + GLint length = source.GetSize(); + glShaderSource(shader, 1, &tmp, &length); + + glCompileShader(shader); + + GLint success; + glGetShaderiv(shader, GL_COMPILE_STATUS, &success); + + if (success == GL_TRUE) + { + glAttachShader(m_program, shader); + m_shaders[type] = shader; + + static NzString successStr("Compilation successful"); + m_log = successStr; + + return true; + } + else + { + // On remplit le log avec l'erreur de compilation + length = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); + if (length > 1) + { + m_log.Clear(true); + m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) + m_log.Prepend("Compilation error: "); + m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log + + glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]); + } + else + m_log = "Compilation failed but no info log found"; + + NazaraError(m_log); + + glDeleteShader(shader); + + return false; + } +} + +bool NzGLSLShader::Lock() +{ + if (lockedLevel++ == 0) + { + NzContext::EnsureContext(); + + GLint previous; + glGetIntegerv(GL_CURRENT_PROGRAM, &previous); + + lockedPrevious = previous; + + if (lockedPrevious != m_program) + glUseProgram(m_program); + } + + return true; +} + +bool NzGLSLShader::SendBoolean(int location, bool value) +{ + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1i(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendDouble(int location, double value) +{ + if (glProgramUniform1d) + glProgramUniform1d(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1d(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendFloat(int location, float value) +{ + if (glProgramUniform1f) + glProgramUniform1f(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1f(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendInteger(int location, int value) +{ + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1i(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) +{ + if (glProgramUniformMatrix4dv) + glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniformMatrix4dv(location, 1, GL_FALSE, matrix); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) +{ + if (glProgramUniformMatrix4fv) + glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniformMatrix4fv(location, 1, GL_FALSE, matrix); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) +{ + auto it = m_textures.find(location); + if (it != m_textures.end()) + { + // Slot déjà utilisé + TextureSlot& slot = it->second; + if (slot.texture != texture) + { + slot.texture->RemoveResourceListener(this); + + if (texture) + { + slot.texture = texture; + slot.texture->AddResourceListener(this, location); + + slot.updated = false; + } + else + m_textures.erase(it); // On supprime le slot + } + } + else + { + static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits(); + + unsigned int unitUsed = m_textures.size(); + if (unitUsed >= maxUnits) + { + NazaraError("Unable to use texture for shader: all available texture units are used"); + return false; + } + + // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre + nzUInt8 unit; + if (unitUsed == 0) + // Pas d'unité utilisée, la tâche est simple + unit = 0; + else + { + auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map + unit = it2->second.unit; + if (unit == maxUnits-1) + { + // Il y a une place libre, mais pas à la fin + for (; it2 != m_textures.rend(); ++it2) + { + if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre + { + unit--; + break; + } + } + } + else + // Il y a une place libre à la fin + unit++; + } + + TextureSlot slot; + slot.enabled = texture->IsValid(); + slot.unit = unit; + slot.texture = texture; + texture->AddResourceListener(this, location); + + m_textures[location] = slot; + + if (slot.enabled) + { + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, unit); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1i(location, unit); + Unlock(); + } + } + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) +{ + if (glProgramUniform2dv) + glProgramUniform2dv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform2dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) +{ + if (glProgramUniform2fv) + glProgramUniform2fv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform2fv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) +{ + if (glProgramUniform3dv) + glProgramUniform3dv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform3dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) +{ + if (glProgramUniform3fv) + glProgramUniform3fv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform3fv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) +{ + if (glProgramUniform4dv) + glProgramUniform4dv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform4dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) +{ + if (glProgramUniform4fv) + glProgramUniform4fv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform4fv(location, 1, vector); + Unlock(); + } + + return true; +} + +void NzGLSLShader::Unbind() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glUseProgram(0); +} + +void NzGLSLShader::Unlock() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (lockedLevel == 0) + { + NazaraWarning("Unlock called on non-locked texture"); + return; + } + #endif + + if (--lockedLevel == 0 && lockedPrevious != m_program) + glUseProgram(lockedPrevious); +} + +void NzGLSLShader::OnResourceCreated(const NzResource* resource, int index) +{ + NazaraUnused(resource); + + auto it = m_textures.find(index); + + #ifdef NAZARA_DEBUG + if (it == m_textures.end()) + { + NazaraInternalError("Invalid index (" + NzString::Number(index) + ')'); + return; + } + #endif + + TextureSlot& slot = it->second; + + #ifdef NAZARA_DEBUG + if (slot.texture != resource) + { + NazaraInternalError("Wrong texture at location #" + NzString::Number(index)); + return; + } + #endif + + slot.enabled = true; + slot.updated = false; +} + +void NzGLSLShader::OnResourceDestroy(const NzResource* resource, int index) +{ + NazaraUnused(resource); + + auto it = m_textures.find(index); + + #ifdef NAZARA_DEBUG + if (it == m_textures.end()) + { + NazaraInternalError("Invalid index (" + NzString::Number(index) + ')'); + return; + } + #endif + + TextureSlot& slot = it->second; + + #ifdef NAZARA_DEBUG + if (slot.texture != resource) + { + NazaraInternalError("Wrong texture at location #" + NzString::Number(index)); + return; + } + #endif + + slot.enabled = false; +} + +void NzGLSLShader::OnResourceReleased(const NzResource* resource, int index) +{ + if (m_textures.erase(index) == 0) + NazaraInternalError("Texture " + NzString::Pointer(resource) + " not found"); +} diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLShader.hpp index 4cfb4d269..33ce45aff 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLShader.hpp @@ -1,73 +1,81 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_GLSLSHADER_HPP -#define NAZARA_GLSLSHADER_HPP - -#include -#include -#include -#include -#include - -class NzGLSLShader : public NzShaderImpl -{ - public: - NzGLSLShader(NzShader* parent); - ~NzGLSLShader(); - - bool Bind(); - bool BindTextures(); - - bool Compile(); - - bool Create(); - void Destroy(); - - NzString GetLog() const; - nzShaderLanguage GetLanguage() const; - NzString GetSourceCode(nzShaderType type) const; - int GetUniformLocation(const NzString& name) const; - - bool IsLoaded(nzShaderType type) const; - - bool Load(nzShaderType type, const NzString& source); - bool Lock(); - - bool SendBoolean(int location, bool value); - bool SendDouble(int location, double value); - bool SendFloat(int location, float value); - bool SendInteger(int location, int value); - bool SendMatrix(int location, const NzMatrix4d& matrix); - bool SendMatrix(int location, const NzMatrix4f& matrix); - bool SendTexture(int location, const NzTexture* texture); - bool SendVector(int location, const NzVector2d& vector); - bool SendVector(int location, const NzVector2f& vector); - bool SendVector(int location, const NzVector3d& vector); - bool SendVector(int location, const NzVector3f& vector); - bool SendVector(int location, const NzVector4d& vector); - bool SendVector(int location, const NzVector4f& vector); - - void Unbind(); - void Unlock(); - - private: - struct TextureSlot - { - bool updated = false; - nzUInt8 unit; - const NzTexture* texture; - }; - - mutable std::map m_idCache; - std::map m_textures; - GLuint m_program; - GLuint m_shaders[nzShaderType_Max+1]; - NzShader* m_parent; - NzString m_log; -}; - -#endif // NAZARA_GLSLSHADER_HPPs +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_GLSLSHADER_HPP +#define NAZARA_GLSLSHADER_HPP + +#include +#include +#include +#include +#include +#include + +class NzResource; + +class NzGLSLShader : public NzShaderImpl, NzResourceListener +{ + public: + NzGLSLShader(NzShader* parent); + ~NzGLSLShader(); + + bool Bind(); + bool BindTextures(); + + bool Compile(); + + bool Create(); + void Destroy(); + + NzString GetLog() const; + nzShaderLanguage GetLanguage() const; + NzString GetSourceCode(nzShaderType type) const; + int GetUniformLocation(const NzString& name) const; + + bool IsLoaded(nzShaderType type) const; + + bool Load(nzShaderType type, const NzString& source); + bool Lock(); + + bool SendBoolean(int location, bool value); + bool SendDouble(int location, double value); + bool SendFloat(int location, float value); + bool SendInteger(int location, int value); + bool SendMatrix(int location, const NzMatrix4d& matrix); + bool SendMatrix(int location, const NzMatrix4f& matrix); + bool SendTexture(int location, const NzTexture* texture); + bool SendVector(int location, const NzVector2d& vector); + bool SendVector(int location, const NzVector2f& vector); + bool SendVector(int location, const NzVector3d& vector); + bool SendVector(int location, const NzVector3f& vector); + bool SendVector(int location, const NzVector4d& vector); + bool SendVector(int location, const NzVector4f& vector); + + void Unbind(); + void Unlock(); + + private: + void OnResourceCreated(const NzResource* resource, int index) override; + void OnResourceDestroy(const NzResource* resource, int index) override; + void OnResourceReleased(const NzResource* resource, int index) override; + + struct TextureSlot + { + bool enabled; + bool updated = false; + nzUInt8 unit; + const NzTexture* texture; + }; + + mutable std::map m_idCache; + std::map m_textures; + GLuint m_program; + GLuint m_shaders[nzShaderType_Max+1]; + NzShader* m_parent; + NzString m_log; +}; + +#endif // NAZARA_GLSLSHADER_HPPs diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index ce3f2c7e7..404382c7d 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -1,250 +1,218 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - GLenum bufferLock[] = { - GL_WRITE_ONLY, // nzBufferAccess_DiscardAndWrite - GL_READ_ONLY, // nzBufferAccess_ReadOnly - GL_READ_WRITE, // nzBufferAccess_ReadWrite - GL_WRITE_ONLY // nzBufferAccess_WriteOnly - }; - - GLenum bufferLockRange[] = { - GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_DiscardAndWrite - GL_MAP_READ_BIT, // nzBufferAccess_ReadOnly - GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_ReadWrite - GL_MAP_WRITE_BIT // nzBufferAccess_WriteOnly - }; - - GLenum bufferTarget[] = { - GL_ELEMENT_ARRAY_BUFFER, // nzBufferType_Index, - GL_ARRAY_BUFFER, // nzBufferType_Vertex - }; - - GLenum bufferTargetBinding[] = { - GL_ELEMENT_ARRAY_BUFFER_BINDING, // nzBufferType_Index, - GL_ARRAY_BUFFER_BINDING, // nzBufferType_Vertex - }; - - GLenum bufferUsage[] = { - // J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus" - // Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?) - // Source: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=160839 - GL_DYNAMIC_DRAW, // nzBufferUsage_Dynamic - GL_STATIC_DRAW // nzBufferUsage_Static - }; - - using LockRoutine = nzUInt8* (*)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); - - nzUInt8* LockBuffer(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) - { - NazaraUnused(size); - - if (access == nzBufferAccess_DiscardAndWrite) - { - GLint bufSize; - glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize); - - GLint bufUsage; - glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage); - - // On discard le buffer - glBufferData(bufferTargetBinding[type], bufSize, nullptr, bufUsage); - } - - void* ptr = glMapBuffer(bufferTarget[type], bufferLock[access]); - if (ptr) - return reinterpret_cast(ptr) + offset; - else - return nullptr; - } - - nzUInt8* LockBufferRange(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) - { - return reinterpret_cast(glMapBufferRange(bufferTarget[type], offset, size, bufferLockRange[access])); - } - - nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); - - LockRoutine mapBuffer = LockBufferFirstRun; - - nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) - { - if (glMapBufferRange) - mapBuffer = LockBufferRange; - else - mapBuffer = LockBuffer; - - return mapBuffer(type, access, offset, size); - } -} - -NzHardwareBuffer::NzHardwareBuffer(NzBuffer* parent, nzBufferType type) : -m_type(type), -m_parent(parent) -{ -} - -NzHardwareBuffer::~NzHardwareBuffer() -{ -} - -void NzHardwareBuffer::Bind() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBindBuffer(bufferTarget[m_type], m_buffer); -} - -bool NzHardwareBuffer::Create(unsigned int size, nzBufferUsage usage) -{ - NzContext::EnsureContext(); - - m_buffer = 0; - glGenBuffers(1, &m_buffer); - - GLint previous; - glGetIntegerv(bufferTargetBinding[m_type], &previous); - - glBindBuffer(bufferTarget[m_type], m_buffer); - glBufferData(bufferTarget[m_type], size, nullptr, bufferUsage[usage]); - - // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent - if (previous != 0) - glBindBuffer(bufferTarget[m_type], previous); - - return true; -} - -void NzHardwareBuffer::Destroy() -{ - NzContext::EnsureContext(); - - glDeleteBuffers(1, &m_buffer); -} - -bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size) -{ - NzContext::EnsureContext(); - - GLuint previous; - glGetIntegerv(bufferTargetBinding[m_type], reinterpret_cast(&previous)); - - if (previous != m_buffer) - glBindBuffer(bufferTarget[m_type], m_buffer); - - // Il semblerait que glBuffer(Sub)Data soit plus performant que glMapBuffer(Range) en dessous d'un certain seuil - // http://www.stevestreeting.com/2007/03/17/glmapbuffer-vs-glbuffersubdata-the-return/ - if (size < 32*1024) - { - // http://www.opengl.org/wiki/Vertex_Specification_Best_Practices - if (size == m_parent->GetSize()) - glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetUsage()]); // Discard - - glBufferSubData(bufferTarget[m_type], offset, size, data); - } - else - { - nzUInt8* ptr = mapBuffer(m_type, (size == m_parent->GetSize()) ? nzBufferAccess_DiscardAndWrite : nzBufferAccess_WriteOnly, offset, size); - if (!ptr) - { - NazaraError("Failed to map buffer"); - return false; - } - - std::memcpy(ptr, data, size); - - if (glUnmapBuffer(bufferTarget[m_type]) != GL_TRUE) - { - // Une erreur rare est survenue, nous devons réinitialiser le buffer - NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); - - glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetStorage()]); - - return false; - } - } - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(bufferTarget[m_type], previous); - - return true; -} - -void* NzHardwareBuffer::GetPointer() -{ - return nullptr; -} - -bool NzHardwareBuffer::IsHardware() const -{ - return true; -} - -void* NzHardwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int size) -{ - NzContext::EnsureContext(); - - // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent - GLuint previous; - glGetIntegerv(bufferTargetBinding[m_type], reinterpret_cast(&previous)); - - if (previous != m_buffer) - glBindBuffer(bufferTarget[m_type], m_buffer); - - void* ptr = mapBuffer(m_type, access, offset, size); - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérrations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(bufferTarget[m_type], previous); - - return ptr; -} - -bool NzHardwareBuffer::Unmap() -{ - NzContext::EnsureContext(); - - GLuint previous; - glGetIntegerv(bufferTargetBinding[m_type], reinterpret_cast(&previous)); - - if (previous != m_buffer) - glBindBuffer(bufferTarget[m_type], m_buffer); - - if (glUnmapBuffer(bufferTarget[m_type]) != GL_TRUE) - { - // Une erreur rare est survenue, nous devons réinitialiser le buffer - NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); - - glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetStorage()]); - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(bufferTarget[m_type], previous); - - return false; - } - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(bufferTarget[m_type], previous); - - return true; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + using LockRoutine = nzUInt8* (*)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); + + nzUInt8* LockBuffer(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) + { + NazaraUnused(size); + + if (access == nzBufferAccess_DiscardAndWrite) + { + GLint bufSize; + glGetBufferParameteriv(NzOpenGL::BufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize); + + GLint bufUsage; + glGetBufferParameteriv(NzOpenGL::BufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage); + + // On discard le buffer + glBufferData(NzOpenGL::BufferTargetBinding[type], bufSize, nullptr, bufUsage); + } + + void* ptr = glMapBuffer(NzOpenGL::BufferTarget[type], NzOpenGL::BufferLock[access]); + if (ptr) + return reinterpret_cast(ptr) + offset; + else + return nullptr; + } + + nzUInt8* LockBufferRange(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) + { + return reinterpret_cast(glMapBufferRange(NzOpenGL::BufferTarget[type], offset, size, NzOpenGL::BufferLockRange[access])); + } + + nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); + + LockRoutine mapBuffer = LockBufferFirstRun; + + nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) + { + if (glMapBufferRange) + mapBuffer = LockBufferRange; + else + mapBuffer = LockBuffer; + + return mapBuffer(type, access, offset, size); + } +} + +NzHardwareBuffer::NzHardwareBuffer(NzBuffer* parent, nzBufferType type) : +m_type(type), +m_parent(parent) +{ +} + +NzHardwareBuffer::~NzHardwareBuffer() +{ +} + +void NzHardwareBuffer::Bind() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); +} + +bool NzHardwareBuffer::Create(unsigned int size, nzBufferUsage usage) +{ + NzContext::EnsureContext(); + + m_buffer = 0; + glGenBuffers(1, &m_buffer); + + GLint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], &previous); + + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + glBufferData(NzOpenGL::BufferTarget[m_type], size, nullptr, NzOpenGL::BufferUsage[usage]); + + // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent + if (previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return true; +} + +void NzHardwareBuffer::Destroy() +{ + NzContext::EnsureContext(); + + glDeleteBuffers(1, &m_buffer); +} + +bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size) +{ + NzContext::EnsureContext(); + + GLuint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); + + if (previous != m_buffer) + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + + // Il semblerait que glBuffer(Sub)Data soit plus performant que glMapBuffer(Range) en dessous d'un certain seuil + // http://www.stevestreeting.com/2007/03/17/glmapbuffer-vs-glbuffersubdata-the-return/ + if (size < 32*1024) + { + // http://www.opengl.org/wiki/Vertex_Specification_Best_Practices + if (size == m_parent->GetSize()) + glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetUsage()]); // Discard + + glBufferSubData(NzOpenGL::BufferTarget[m_type], offset, size, data); + } + else + { + nzUInt8* ptr = mapBuffer(m_type, (size == m_parent->GetSize()) ? nzBufferAccess_DiscardAndWrite : nzBufferAccess_WriteOnly, offset, size); + if (!ptr) + { + NazaraError("Failed to map buffer"); + return false; + } + + std::memcpy(ptr, data, size); + + if (glUnmapBuffer(NzOpenGL::BufferTarget[m_type]) != GL_TRUE) + { + // Une erreur rare est survenue, nous devons réinitialiser le buffer + NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); + + glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetStorage()]); + + return false; + } + } + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return true; +} + +void* NzHardwareBuffer::GetPointer() +{ + return nullptr; +} + +bool NzHardwareBuffer::IsHardware() const +{ + return true; +} + +void* NzHardwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int size) +{ + NzContext::EnsureContext(); + + // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent + GLuint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); + + if (previous != m_buffer) + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + + void* ptr = mapBuffer(m_type, access, offset, size); + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérrations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return ptr; +} + +bool NzHardwareBuffer::Unmap() +{ + NzContext::EnsureContext(); + + GLuint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); + + if (previous != m_buffer) + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + + if (glUnmapBuffer(NzOpenGL::BufferTarget[m_type]) != GL_TRUE) + { + // Une erreur rare est survenue, nous devons réinitialiser le buffer + NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); + + glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetStorage()]); + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return false; + } + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return true; +} diff --git a/src/Nazara/Renderer/OcclusionQuery.cpp b/src/Nazara/Renderer/OcclusionQuery.cpp index de2c7a660..228caab8f 100644 --- a/src/Nazara/Renderer/OcclusionQuery.cpp +++ b/src/Nazara/Renderer/OcclusionQuery.cpp @@ -1,102 +1,98 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -NzOcclusionQuery::NzOcclusionQuery() : -m_id(0) -{ - #if NAZARA_RENDERER_SAFE - if (IsSupported()) - { - #endif - NzContext::EnsureContext(); - - glGenQueries(1, reinterpret_cast(&m_id)); - #if NAZARA_RENDERER_SAFE - } - else - { - NazaraError("Occlusion queries not supported"); - return; - } - #endif - - #ifdef NAZARA_DEBUG - if (!m_id) - { - NazaraError("Failed to create occlusion query"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzOcclusionQuery::~NzOcclusionQuery() -{ - if (m_id) - { - NzContext::EnsureContext(); - - GLuint query = static_cast(m_id); - glDeleteQueries(1, &query); - } -} - -void NzOcclusionQuery::Begin() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBeginQuery(GL_SAMPLES_PASSED, m_id); -} - -void NzOcclusionQuery::End() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glEndQuery(GL_SAMPLES_PASSED); -} - -unsigned int NzOcclusionQuery::GetResult() const -{ - NzContext::EnsureContext(); - - GLuint result; - glGetQueryObjectuiv(m_id, GL_QUERY_RESULT, &result); - - return result; -} - -bool NzOcclusionQuery::IsResultAvailable() const -{ - NzContext::EnsureContext(); - - GLint available; - glGetQueryObjectiv(m_id, GL_QUERY_RESULT_AVAILABLE, &available); - - return available == GL_TRUE; -} - -bool NzOcclusionQuery::IsSupported() -{ - return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +NzOcclusionQuery::NzOcclusionQuery() : +m_id(0) +{ + if (IsSupported()) + { + NzContext::EnsureContext(); + + glGenQueries(1, reinterpret_cast(&m_id)); + } + else + { + NazaraError("Occlusion queries not supported"); + return; + } + + #ifdef NAZARA_DEBUG + if (!m_id) + { + NazaraError("Failed to create occlusion query"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzOcclusionQuery::~NzOcclusionQuery() +{ + if (m_id) + { + NzContext::EnsureContext(); + + GLuint query = static_cast(m_id); + glDeleteQueries(1, &query); + } +} + +void NzOcclusionQuery::Begin() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glBeginQuery(GL_SAMPLES_PASSED, m_id); +} + +void NzOcclusionQuery::End() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glEndQuery(GL_SAMPLES_PASSED); +} + +unsigned int NzOcclusionQuery::GetResult() const +{ + NzContext::EnsureContext(); + + GLuint result; + glGetQueryObjectuiv(m_id, GL_QUERY_RESULT, &result); + + return result; +} + +bool NzOcclusionQuery::IsResultAvailable() const +{ + NzContext::EnsureContext(); + + GLint available; + glGetQueryObjectiv(m_id, GL_QUERY_RESULT_AVAILABLE, &available); + + return available == GL_TRUE; +} + +bool NzOcclusionQuery::IsSupported() +{ + return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery); +} diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 3871b7169..452db653b 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1,703 +1,1014 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - #ifdef NAZARA_PLATFORM_WINDOWS - HMODULE openGLlibrary; - #endif - - NzOpenGLFunc LoadEntry(const char* name, bool launchException = true) - { - #if defined(NAZARA_PLATFORM_WINDOWS) - NzOpenGLFunc entry = reinterpret_cast(wglGetProcAddress(name)); - if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 - entry = reinterpret_cast(GetProcAddress(openGLlibrary, name)); - #elif defined(NAZARA_PLATFORM_LINUX) - NzOpenGLFunc entry = reinterpret_cast(glXGetProcAddress(name)); - #else - #error OS not handled - #endif - - if (!entry && launchException) - { - std::ostringstream oss; - oss << "failed to load \"" << name << '"'; - - throw std::runtime_error(oss.str()); - } - - return entry; - } - - bool LoadLibrary() - { - #ifdef NAZARA_PLATFORM_WINDOWS - openGLlibrary = ::LoadLibraryA("opengl32.dll"); - - return openGLlibrary != nullptr; - #else - return true; - #endif - } - - void UnloadLibrary() - { - #ifdef NAZARA_PLATFORM_WINDOWS - FreeLibrary(openGLlibrary); - #endif - } - - std::set openGLextensionSet; - bool openGLextensions[NzOpenGL::Max+1] = {false}; - unsigned int openGLversion = 0; - - bool LoadExtensionsString(const NzString& extensionString) - { - if (extensionString.IsEmpty()) - { - NazaraError("Unable to get extension string"); - return false; - } - - // On peut sûrement faire plus rapide mais comme ça ne se fait qu'une fois et que NzString implémente le COW... - std::vector ext; - extensionString.Split(ext); - - for (std::vector::iterator it = ext.begin(); it != ext.end(); ++it) - openGLextensionSet.insert(*it); - - return true; - } - - bool LoadExtensions3() - { - GLint extensionCount = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); - - if (extensionCount <= 0) - { - NazaraError("Unable to get extension count"); - return false; - } - - for (int i = 0; i < extensionCount; ++i) - { - NzString extension(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); - if (extension.IsEmpty()) - { - NazaraWarning("Unable to get extension #" + NzString::Number(i)); - continue; - } - - openGLextensionSet.insert(extension); - } - - return true; - } -} - -NzOpenGLFunc NzOpenGL::GetEntry(const NzString& entryPoint) -{ - return LoadEntry(entryPoint.GetConstBuffer(), false); -} - -unsigned int NzOpenGL::GetVersion() -{ - return openGLversion; -} - -bool NzOpenGL::Initialize() -{ - if (!LoadLibrary()) - { - NazaraError("Failed to load OpenGL library"); - return false; - } - - // Le chargement des fonctions OpenGL nécessite un contexte OpenGL - NzContextParameters parameters; - parameters.majorVersion = 2; - parameters.minorVersion = 0; - parameters.shared = false; - - /* - Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser - Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant - de créer le second avec les bons paramètres. - - Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise - */ - - /****************************************Initialisation****************************************/ - - NzContext loadContext; - if (!loadContext.Create(parameters)) - { - NazaraError("Failed to create load context"); - Uninitialize(); - - return false; - } - - #if defined(NAZARA_PLATFORM_WINDOWS) - wglCreateContextAttribs = reinterpret_cast(LoadEntry("wglCreateContextAttribsARB", false)); - wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatARB", false)); - if (!wglChoosePixelFormat) - wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatEXT", false)); - #elif defined(NAZARA_PLATFORM_LINUX) - glXCreateContextAttribs = reinterpret_cast(LoadEntry("glXCreateContextAttribsARB", false)); - #endif - - // Récupération de la version d'OpenGL - // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée - // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... - glGetString = reinterpret_cast(LoadEntry("glGetString", false)); - if (!glGetString) - { - NazaraError("Unable to load OpenGL: failed to load glGetString"); - Uninitialize(); - - return false; - } - - const GLubyte* version = glGetString(GL_VERSION); - if (!version) - { - NazaraError("Unable to retrieve OpenGL version"); - Uninitialize(); - - return false; - } - - unsigned int major = version[0] - '0'; - unsigned int minor = version[2] - '0'; - - if (major == 0 || major > 9) - { - NazaraError("Unable to retrieve OpenGL major version"); - return false; - } - - if (minor > 9) - { - NazaraWarning("Unable to retrieve OpenGL minor version (using 0)"); - minor = 0; - } - - openGLversion = major*100 + minor*10; - if (openGLversion < 200) - { - NazaraError("OpenGL version is too low, please upgrade your drivers or your graphics card"); - Uninitialize(); - - return false; - } - - parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output) - parameters.majorVersion = NzContextParameters::defaultMajorVersion = major; - parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor; - - // Destruction implicite du premier contexte - if (!loadContext.Create(parameters)) - { - NazaraError("Failed to create load context"); - Uninitialize(); - - return false; - } - - /****************************************Noyau****************************************/ - - try - { - glActiveTexture = reinterpret_cast(LoadEntry("glActiveTexture")); - glAttachShader = reinterpret_cast(LoadEntry("glAttachShader")); - glBeginQuery = reinterpret_cast(LoadEntry("glBeginQuery")); - glBindAttribLocation = reinterpret_cast(LoadEntry("glBindAttribLocation")); - glBindBuffer = reinterpret_cast(LoadEntry("glBindBuffer")); - glBindTexture = reinterpret_cast(LoadEntry("glBindTexture")); - glBlendFunc = reinterpret_cast(LoadEntry("glBlendFunc")); - glBufferData = reinterpret_cast(LoadEntry("glBufferData")); - glBufferSubData = reinterpret_cast(LoadEntry("glBufferSubData")); - glClear = reinterpret_cast(LoadEntry("glClear")); - glClearColor = reinterpret_cast(LoadEntry("glClearColor")); - glClearDepth = reinterpret_cast(LoadEntry("glClearDepth")); - glClearStencil = reinterpret_cast(LoadEntry("glClearStencil")); - glCreateProgram = reinterpret_cast(LoadEntry("glCreateProgram")); - glCreateShader = reinterpret_cast(LoadEntry("glCreateShader")); - glColorMask = reinterpret_cast(LoadEntry("glColorMask")); - glCullFace = reinterpret_cast(LoadEntry("glCullFace")); - glCompileShader = reinterpret_cast(LoadEntry("glCompileShader")); - glCopyTexSubImage2D = reinterpret_cast(LoadEntry("glCopyTexSubImage2D")); - glDeleteBuffers = reinterpret_cast(LoadEntry("glDeleteBuffers")); - glDeleteQueries = reinterpret_cast(LoadEntry("glDeleteQueries")); - glDeleteProgram = reinterpret_cast(LoadEntry("glDeleteProgram")); - glDeleteShader = reinterpret_cast(LoadEntry("glDeleteShader")); - glDeleteTextures = reinterpret_cast(LoadEntry("glDeleteTextures")); - glDepthFunc = reinterpret_cast(LoadEntry("glDepthFunc")); - glDepthMask = reinterpret_cast(LoadEntry("glDepthMask")); - glDisable = reinterpret_cast(LoadEntry("glDisable")); - glDisableVertexAttribArray = reinterpret_cast(LoadEntry("glDisableVertexAttribArray")); - glDrawArrays = reinterpret_cast(LoadEntry("glDrawArrays")); - glDrawBuffer = reinterpret_cast(LoadEntry("glDrawBuffer")); - glDrawBuffers = reinterpret_cast(LoadEntry("glDrawBuffers")); - glDrawElements = reinterpret_cast(LoadEntry("glDrawElements")); - glFlush = reinterpret_cast(LoadEntry("glFlush")); - glEnable = reinterpret_cast(LoadEntry("glEnable")); - glEnableVertexAttribArray = reinterpret_cast(LoadEntry("glEnableVertexAttribArray")); - glEndQuery = reinterpret_cast(LoadEntry("glEndQuery")); - glGenBuffers = reinterpret_cast(LoadEntry("glGenBuffers")); - glGenQueries = reinterpret_cast(LoadEntry("glGenQueries")); - glGenTextures = reinterpret_cast(LoadEntry("glGenTextures")); - glGetBufferParameteriv = reinterpret_cast(LoadEntry("glGetBufferParameteriv")); - glGetError = reinterpret_cast(LoadEntry("glGetError")); - glGetQueryiv = reinterpret_cast(LoadEntry("glGetQueryiv")); - glGetQueryObjectiv = reinterpret_cast(LoadEntry("glGetQueryObjectiv")); - glGetQueryObjectuiv = reinterpret_cast(LoadEntry("glGetQueryObjectuiv")); - glGetIntegerv = reinterpret_cast(LoadEntry("glGetIntegerv")); - glGetProgramiv = reinterpret_cast(LoadEntry("glGetProgramiv")); - glGetProgramInfoLog = reinterpret_cast(LoadEntry("glGetProgramInfoLog")); - glGetShaderInfoLog = reinterpret_cast(LoadEntry("glGetShaderInfoLog")); - glGetShaderiv = reinterpret_cast(LoadEntry("glGetShaderiv")); - glGetShaderSource = reinterpret_cast(LoadEntry("glGetShaderSource")); - glGetTexImage = reinterpret_cast(LoadEntry("glGetTexImage")); - glGetTexLevelParameterfv = reinterpret_cast(LoadEntry("glGetTexLevelParameterfv")); - glGetTexLevelParameteriv = reinterpret_cast(LoadEntry("glGetTexLevelParameteriv")); - glGetTexParameterfv = reinterpret_cast(LoadEntry("glGetTexParameterfv")); - glGetTexParameteriv = reinterpret_cast(LoadEntry("glGetTexParameteriv")); - glGetUniformLocation = reinterpret_cast(LoadEntry("glGetUniformLocation")); - glLinkProgram = reinterpret_cast(LoadEntry("glLinkProgram")); - glMapBuffer = reinterpret_cast(LoadEntry("glMapBuffer")); - glPixelStorei = reinterpret_cast(LoadEntry("glPixelStorei")); - glPolygonMode = reinterpret_cast(LoadEntry("glPolygonMode")); - glReadPixels = reinterpret_cast(LoadEntry("glReadPixels")); - glScissor = reinterpret_cast(LoadEntry("glScissor")); - glShaderSource = reinterpret_cast(LoadEntry("glShaderSource")); - glStencilFunc = reinterpret_cast(LoadEntry("glStencilFunc")); - glStencilOp = reinterpret_cast(LoadEntry("glStencilOp")); - glTexImage2D = reinterpret_cast(LoadEntry("glTexImage2D")); - glTexParameterf = reinterpret_cast(LoadEntry("glTexParameterf")); - glTexParameteri = reinterpret_cast(LoadEntry("glTexParameteri")); - glTexSubImage2D = reinterpret_cast(LoadEntry("glTexSubImage2D")); - glUniform1f = reinterpret_cast(LoadEntry("glUniform1f")); - glUniform1i = reinterpret_cast(LoadEntry("glUniform1i")); - glUniform2fv = reinterpret_cast(LoadEntry("glUniform2fv")); - glUniform3fv = reinterpret_cast(LoadEntry("glUniform3fv")); - glUniform4fv = reinterpret_cast(LoadEntry("glUniform4fv")); - glUniformMatrix4fv = reinterpret_cast(LoadEntry("glUniformMatrix4fv")); - glUnmapBuffer = reinterpret_cast(LoadEntry("glUnmapBuffer")); - glUseProgram = reinterpret_cast(LoadEntry("glUseProgram")); - glVertexAttrib4f = reinterpret_cast(LoadEntry("glVertexAttrib4f")); - glVertexAttribPointer = reinterpret_cast(LoadEntry("glVertexAttribPointer")); - glViewport = reinterpret_cast(LoadEntry("glViewport")); - } - catch (const std::exception& e) - { - NazaraError("Unable to load OpenGL: " + NzString(e.what())); - Uninitialize(); - - return false; - } - - /****************************************Extensions****************************************/ - - glGetStringi = reinterpret_cast(LoadEntry("glGetStringi", false)); - glMapBufferRange = reinterpret_cast(LoadEntry("glMapBufferRange", false)); - - #if defined(NAZARA_PLATFORM_WINDOWS) - wglGetExtensionsStringARB = reinterpret_cast(LoadEntry("wglGetExtensionsStringARB", false)); - wglGetExtensionsStringEXT = reinterpret_cast(LoadEntry("wglGetExtensionsStringEXT", false)); - wglSwapInterval = reinterpret_cast(LoadEntry("wglSwapIntervalEXT", false)); - #elif defined(NAZARA_PLATFORM_LINUX) - glXSwapInterval = reinterpret_cast(LoadEntry("glXSwapIntervalSGI", false)); - #endif - - if (!glGetStringi || !LoadExtensions3()) - { - if (openGLversion >= 300) // Dans le cas contraire c'est normal - NazaraWarning("Failed to load OpenGL 3 extension system, switching to OpenGL 2 extension system..."); - - if (!LoadExtensionsString(reinterpret_cast(glGetString(GL_EXTENSIONS)))) - NazaraWarning("Failed to load extension system"); - } - - #ifdef NAZARA_PLATFORM_WINDOWS - { - bool loaded; - if (wglGetExtensionsStringARB) - loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringARB(wglGetCurrentDC()))); - else if (wglGetExtensionsStringEXT) - loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringEXT())); - else - loaded = false; - - if (!loaded) - NazaraWarning("Failed to load wgl extension string"); - } - #endif - - // AnisotropicFilter - openGLextensions[NzOpenGL::AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic"); - - // DebugOutput - if (openGLversion >= 430 || IsSupported("GL_KHR_debug")) - { - try - { - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); - glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); - glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); - glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); - - openGLextensions[NzOpenGL::DebugOutput] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load GL_KHR_debug: " + NzString(e.what())); - } - } - - if (!openGLextensions[NzOpenGL::DebugOutput] && IsSupported("GL_ARB_debug_output")) - { - try - { - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); - glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControlARB")); - glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsertARB")); - glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLogARB")); - - openGLextensions[NzOpenGL::DebugOutput] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load GL_ARB_debug_output: " + NzString(e.what())); - } - } - - // FP64 - if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) - { - try - { - glUniform1d = reinterpret_cast(LoadEntry("glUniform1d")); - glUniform2dv = reinterpret_cast(LoadEntry("glUniform2dv")); - glUniform3dv = reinterpret_cast(LoadEntry("glUniform3dv")); - glUniform4dv = reinterpret_cast(LoadEntry("glUniform4dv")); - - openGLextensions[NzOpenGL::FP64] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_gpu_shader_fp64: " + NzString(e.what())); - } - } - - // FrameBufferObject - if (openGLversion >= 300 || IsSupported("GL_ARB_framebuffer_object")) - { - try - { - glBindFramebuffer = reinterpret_cast(LoadEntry("glBindFramebuffer")); - glBindRenderbuffer = reinterpret_cast(LoadEntry("glBindRenderbuffer")); - glCheckFramebufferStatus = reinterpret_cast(LoadEntry("glCheckFramebufferStatus")); - glDeleteFramebuffers = reinterpret_cast(LoadEntry("glDeleteFramebuffers")); - glDeleteRenderbuffers = reinterpret_cast(LoadEntry("glDeleteRenderbuffers")); - glFramebufferRenderbuffer = reinterpret_cast(LoadEntry("glFramebufferRenderbuffer")); - glFramebufferTexture2D = reinterpret_cast(LoadEntry("glFramebufferTexture2D")); - glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmap")); - glGenFramebuffers = reinterpret_cast(LoadEntry("glGenFramebuffers")); - glGenRenderbuffers = reinterpret_cast(LoadEntry("glGenRenderbuffers")); - glRenderbufferStorage = reinterpret_cast(LoadEntry("glRenderbufferStorage")); - - openGLextensions[NzOpenGL::FrameBufferObject] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")"); - } - } - - // PixelBufferObject - openGLextensions[NzOpenGL::PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object")); - - // SeparateShaderObjects - if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects")) - { - glProgramUniform1f = reinterpret_cast(LoadEntry("glProgramUniform1f")); - glProgramUniform1i = reinterpret_cast(LoadEntry("glProgramUniform1i")); - glProgramUniform2fv = reinterpret_cast(LoadEntry("glProgramUniform2fv")); - glProgramUniform3fv = reinterpret_cast(LoadEntry("glProgramUniform3fv")); - glProgramUniform4fv = reinterpret_cast(LoadEntry("glProgramUniform4fv")); - glProgramUniformMatrix4fv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4fv")); - - // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double - if (openGLextensions[NzOpenGL::FP64]) - { - glProgramUniform1d = reinterpret_cast(LoadEntry("glProgramUniform1d")); - glProgramUniform2dv = reinterpret_cast(LoadEntry("glProgramUniform2dv")); - glProgramUniform3dv = reinterpret_cast(LoadEntry("glProgramUniform3dv")); - glProgramUniform4dv = reinterpret_cast(LoadEntry("glProgramUniform4dv")); - glProgramUniformMatrix4dv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4dv")); - } - - openGLextensions[NzOpenGL::SeparateShaderObjects] = true; - } - - // Texture3D - try - { - glTexImage3D = reinterpret_cast(LoadEntry("glTexImage3D")); - glTexSubImage3D = reinterpret_cast(LoadEntry("glTexSubImage3D")); - - openGLextensions[NzOpenGL::Texture3D] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")"); - - if (IsSupported("GL_EXT_texture3D")) - { - try - { - // Hacky: Normalement incompatible à cause du internalFormat, GLenum pour l'extension et GLint pour le noyau - // Mais la taille du type étant la même (GLenum est un typedef équivalent à GLint) et Nazara n'utilisant pas - // Ce qui cause l'incompatibilité (les paramètres 1,2,3,4), je prends cette liberté - glTexImage3D = reinterpret_cast(LoadEntry("glTexImage3DEXT")); - glTexSubImage3D = reinterpret_cast(LoadEntry("glTexSubImage3DEXT")); - - openGLextensions[NzOpenGL::Texture3D] = true; - } - catch (const std::exception& e2) - { - NazaraWarning("Failed to load EXT_texture3D: " + NzString(e2.what())); - } - } - } - - // TextureArray - openGLextensions[NzOpenGL::TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array")); - - // TextureCompression_s3tc - openGLextensions[NzOpenGL::TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc"); - - // TextureStorage - if (openGLversion >= 420 || IsSupported("GL_ARB_texture_storage")) - { - try - { - glTexStorage1D = reinterpret_cast(LoadEntry("glTexStorage1D")); - glTexStorage2D = reinterpret_cast(LoadEntry("glTexStorage2D")); - glTexStorage3D = reinterpret_cast(LoadEntry("glTexStorage3D")); - - openGLextensions[NzOpenGL::TextureStorage] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_texture_storage: " + NzString(e.what())); - } - } - - // VertexArrayObject - if (openGLversion >= 300 || IsSupported("GL_ARB_vertex_array_object")) - { - try - { - glBindVertexArray = reinterpret_cast(LoadEntry("glBindVertexArray")); - glDeleteVertexArrays = reinterpret_cast(LoadEntry("glDeleteVertexArrays")); - glGenVertexArrays = reinterpret_cast(LoadEntry("glGenVertexArrays")); - - openGLextensions[NzOpenGL::VertexArrayObject] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_vertex_array_object: " + NzString(e.what())); - } - } - - // Fonctions de substitut - if (!glGenerateMipmap) - glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmapEXT", false)); - - /****************************************Contexte de référence****************************************/ - - ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) - if (!NzContext::Initialize()) - { - NazaraError("Failed to initialize contexts"); - Uninitialize(); - - return false; - } - - NzContextParameters::defaultShareContext = NzContext::GetReference(); - - return true; -} - -bool NzOpenGL::IsSupported(Extension extension) -{ - return openGLextensions[extension]; -} - -bool NzOpenGL::IsSupported(const NzString& string) -{ - return openGLextensionSet.find(string) != openGLextensionSet.end(); -} - -void NzOpenGL::Uninitialize() -{ - NzContext::Uninitialize(); - - for (bool& ext : openGLextensions) - ext = false; - - openGLextensionSet.clear(); - openGLversion = 0; - - UnloadLibrary(); -} - -PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; -PFNGLATTACHSHADERPROC glAttachShader = nullptr; -PFNGLBEGINQUERYPROC glBeginQuery = nullptr; -PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; -PFNGLBINDBUFFERPROC glBindBuffer = nullptr; -PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; -PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; -PFNGLBINDTEXTUREPROC glBindTexture = nullptr; -PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; -PFNGLBLENDFUNCPROC glBlendFunc = nullptr; -PFNGLBUFFERDATAPROC glBufferData = nullptr; -PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; -PFNGLCLEARPROC glClear = nullptr; -PFNGLCLEARCOLORPROC glClearColor = nullptr; -PFNGLCLEARDEPTHPROC glClearDepth = nullptr; -PFNGLCLEARSTENCILPROC glClearStencil = nullptr; -PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; -PFNGLCREATESHADERPROC glCreateShader = nullptr; -PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; -PFNGLCOLORMASKPROC glColorMask = nullptr; -PFNGLCULLFACEPROC glCullFace = nullptr; -PFNGLCOMPILESHADERPROC glCompileShader = nullptr; -PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; -PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; -PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; -PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; -PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; -PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; -PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; -PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; -PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; -PFNGLDELETESHADERPROC glDeleteShader = nullptr; -PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; -PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; -PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; -PFNGLDEPTHMASKPROC glDepthMask = nullptr; -PFNGLDISABLEPROC glDisable = nullptr; -PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; -PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; -PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; -PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; -PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; -PFNGLENDQUERYPROC glEndQuery = nullptr; -PFNGLFLUSHPROC glFlush = nullptr; -PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; -PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; -PFNGLENABLEPROC glEnable = nullptr; -PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; -PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; -PFNGLGENBUFFERSPROC glGenBuffers = nullptr; -PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; -PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; -PFNGLGENQUERIESPROC glGenQueries = nullptr; -PFNGLGENTEXTURESPROC glGenTextures = nullptr; -PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; -PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; -PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; -PFNGLGETERRORPROC glGetError = nullptr; -PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; -PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; -PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; -PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; -PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; -PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; -PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; -PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; -PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; -PFNGLGETSTRINGPROC glGetString = nullptr; -PFNGLGETSTRINGIPROC glGetStringi = nullptr; -PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; -PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; -PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; -PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; -PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; -PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; -PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; -PFNGLMAPBUFFERPROC glMapBuffer = nullptr; -PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; -PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; -PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; -PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; -PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; -PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; -PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; -PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; -PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; -PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; -PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; -PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; -PFNGLREADPIXELSPROC glReadPixels = nullptr; -PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; -PFNGLSCISSORPROC glScissor = nullptr; -PFNGLSHADERSOURCEPROC glShaderSource = nullptr; -PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; -PFNGLSTENCILOPPROC glStencilOp = nullptr; -PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; -PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; -PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; -PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; -PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; -PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; -PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; -PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; -PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; -PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; -PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; -PFNGLUNIFORM1DPROC glUniform1d = nullptr; -PFNGLUNIFORM1FPROC glUniform1f = nullptr; -PFNGLUNIFORM1IPROC glUniform1i = nullptr; -PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; -PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; -PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; -PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; -PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; -PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; -PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; -PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; -PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; -PFNGLUSEPROGRAMPROC glUseProgram = nullptr; -PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; -PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; -PFNGLVIEWPORTPROC glViewport = nullptr; -#if defined(NAZARA_PLATFORM_WINDOWS) -PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; -PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; -PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; -PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; -PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; -#elif defined(NAZARA_PLATFORM_LINUX) -PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; -PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = nullptr; -#endif +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + #ifdef NAZARA_PLATFORM_WINDOWS + HMODULE openGLlibrary; + #endif + + NzOpenGLFunc LoadEntry(const char* name, bool launchException = true) + { + #if defined(NAZARA_PLATFORM_WINDOWS) + NzOpenGLFunc entry = reinterpret_cast(wglGetProcAddress(name)); + if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 + entry = reinterpret_cast(GetProcAddress(openGLlibrary, name)); + #elif defined(NAZARA_PLATFORM_LINUX) + NzOpenGLFunc entry = reinterpret_cast(glXGetProcAddress(name)); + #else + #error OS not handled + #endif + + if (!entry && launchException) + { + std::ostringstream oss; + oss << "failed to load \"" << name << '"'; + + throw std::runtime_error(oss.str()); + } + + return entry; + } + + bool LoadLibrary() + { + #ifdef NAZARA_PLATFORM_WINDOWS + openGLlibrary = ::LoadLibraryA("opengl32.dll"); + + return openGLlibrary != nullptr; + #else + return true; + #endif + } + + void UnloadLibrary() + { + #ifdef NAZARA_PLATFORM_WINDOWS + FreeLibrary(openGLlibrary); + #endif + } + + std::set openGLextensionSet; + bool openGLextensions[nzOpenGLExtension_Max+1] = {false}; + unsigned int openGLversion = 0; + + bool LoadExtensionsString(const NzString& extensionString) + { + if (extensionString.IsEmpty()) + { + NazaraError("Unable to get extension string"); + return false; + } + + // On peut sûrement faire plus rapide mais comme ça ne se fait qu'une fois et que NzString implémente le COW... + std::vector ext; + extensionString.Split(ext); + + for (std::vector::iterator it = ext.begin(); it != ext.end(); ++it) + openGLextensionSet.insert(*it); + + return true; + } + + bool LoadExtensions3() + { + GLint extensionCount = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); + + if (extensionCount <= 0) + { + NazaraError("Unable to get extension count"); + return false; + } + + for (int i = 0; i < extensionCount; ++i) + { + NzString extension(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); + if (extension.IsEmpty()) + { + NazaraWarning("Unable to get extension #" + NzString::Number(i)); + continue; + } + + openGLextensionSet.insert(extension); + } + + return true; + } +} + +namespace NzOpenGL +{ + NzOpenGLFunc GetEntry(const NzString& entryPoint) + { + return LoadEntry(entryPoint.GetConstBuffer(), false); + } + + unsigned int GetVersion() + { + return openGLversion; + } + + bool Initialize() + { + if (!LoadLibrary()) + { + NazaraError("Failed to load OpenGL library"); + return false; + } + + // Le chargement des fonctions OpenGL nécessite un contexte OpenGL + NzContextParameters parameters; + parameters.majorVersion = 2; + parameters.minorVersion = 0; + parameters.shared = false; + + /* + Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser + Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant + de créer le second avec les bons paramètres. + + Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise. + */ + + /****************************************Initialisation****************************************/ + + NzContext loadContext; + if (!loadContext.Create(parameters)) + { + NazaraError("Failed to create load context"); + Uninitialize(); + + return false; + } + + #if defined(NAZARA_PLATFORM_WINDOWS) + wglCreateContextAttribs = reinterpret_cast(LoadEntry("wglCreateContextAttribsARB", false)); + wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatARB", false)); + if (!wglChoosePixelFormat) + wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatEXT", false)); + #elif defined(NAZARA_PLATFORM_LINUX) + glXCreateContextAttribs = reinterpret_cast(LoadEntry("glXCreateContextAttribsARB", false)); + #endif + + // Récupération de la version d'OpenGL + // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée + // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... + glGetString = reinterpret_cast(LoadEntry("glGetString", false)); + if (!glGetString) + { + NazaraError("Unable to load OpenGL: failed to load glGetString"); + Uninitialize(); + + return false; + } + + const GLubyte* version = glGetString(GL_VERSION); + if (!version) + { + NazaraError("Unable to retrieve OpenGL version"); + Uninitialize(); + + return false; + } + + unsigned int major = version[0] - '0'; + unsigned int minor = version[2] - '0'; + + if (major == 0 || major > 9) + { + NazaraError("Unable to retrieve OpenGL major version"); + return false; + } + + if (minor > 9) + { + NazaraWarning("Unable to retrieve OpenGL minor version (using 0)"); + minor = 0; + } + + openGLversion = major*100 + minor*10; + if (openGLversion < 200) + { + NazaraError("OpenGL version is too low, please upgrade your drivers or your video card"); + Uninitialize(); + + return false; + } + + parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output) + parameters.majorVersion = NzContextParameters::defaultMajorVersion = major; + parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor; + + if (!loadContext.Create(parameters)) // Destruction implicite du premier contexte + { + NazaraError("Failed to create load context"); + Uninitialize(); + + return false; + } + + /****************************************Noyau****************************************/ + + try + { + glActiveTexture = reinterpret_cast(LoadEntry("glActiveTexture")); + glAttachShader = reinterpret_cast(LoadEntry("glAttachShader")); + glBeginQuery = reinterpret_cast(LoadEntry("glBeginQuery")); + glBindAttribLocation = reinterpret_cast(LoadEntry("glBindAttribLocation")); + glBindBuffer = reinterpret_cast(LoadEntry("glBindBuffer")); + glBindTexture = reinterpret_cast(LoadEntry("glBindTexture")); + glBlendFunc = reinterpret_cast(LoadEntry("glBlendFunc")); + glBufferData = reinterpret_cast(LoadEntry("glBufferData")); + glBufferSubData = reinterpret_cast(LoadEntry("glBufferSubData")); + glClear = reinterpret_cast(LoadEntry("glClear")); + glClearColor = reinterpret_cast(LoadEntry("glClearColor")); + glClearDepth = reinterpret_cast(LoadEntry("glClearDepth")); + glClearStencil = reinterpret_cast(LoadEntry("glClearStencil")); + glCreateProgram = reinterpret_cast(LoadEntry("glCreateProgram")); + glCreateShader = reinterpret_cast(LoadEntry("glCreateShader")); + glColorMask = reinterpret_cast(LoadEntry("glColorMask")); + glCullFace = reinterpret_cast(LoadEntry("glCullFace")); + glCompileShader = reinterpret_cast(LoadEntry("glCompileShader")); + glCopyTexSubImage2D = reinterpret_cast(LoadEntry("glCopyTexSubImage2D")); + glDeleteBuffers = reinterpret_cast(LoadEntry("glDeleteBuffers")); + glDeleteQueries = reinterpret_cast(LoadEntry("glDeleteQueries")); + glDeleteProgram = reinterpret_cast(LoadEntry("glDeleteProgram")); + glDeleteShader = reinterpret_cast(LoadEntry("glDeleteShader")); + glDeleteTextures = reinterpret_cast(LoadEntry("glDeleteTextures")); + glDepthFunc = reinterpret_cast(LoadEntry("glDepthFunc")); + glDepthMask = reinterpret_cast(LoadEntry("glDepthMask")); + glDisable = reinterpret_cast(LoadEntry("glDisable")); + glDisableVertexAttribArray = reinterpret_cast(LoadEntry("glDisableVertexAttribArray")); + glDrawArrays = reinterpret_cast(LoadEntry("glDrawArrays")); + glDrawBuffer = reinterpret_cast(LoadEntry("glDrawBuffer")); + glDrawBuffers = reinterpret_cast(LoadEntry("glDrawBuffers")); + glDrawElements = reinterpret_cast(LoadEntry("glDrawElements")); + glFlush = reinterpret_cast(LoadEntry("glFlush")); + glEnable = reinterpret_cast(LoadEntry("glEnable")); + glEnableVertexAttribArray = reinterpret_cast(LoadEntry("glEnableVertexAttribArray")); + glEndQuery = reinterpret_cast(LoadEntry("glEndQuery")); + glGenBuffers = reinterpret_cast(LoadEntry("glGenBuffers")); + glGenQueries = reinterpret_cast(LoadEntry("glGenQueries")); + glGenTextures = reinterpret_cast(LoadEntry("glGenTextures")); + glGetBufferParameteriv = reinterpret_cast(LoadEntry("glGetBufferParameteriv")); + glGetError = reinterpret_cast(LoadEntry("glGetError")); + glGetQueryiv = reinterpret_cast(LoadEntry("glGetQueryiv")); + glGetQueryObjectiv = reinterpret_cast(LoadEntry("glGetQueryObjectiv")); + glGetQueryObjectuiv = reinterpret_cast(LoadEntry("glGetQueryObjectuiv")); + glGetIntegerv = reinterpret_cast(LoadEntry("glGetIntegerv")); + glGetProgramiv = reinterpret_cast(LoadEntry("glGetProgramiv")); + glGetProgramInfoLog = reinterpret_cast(LoadEntry("glGetProgramInfoLog")); + glGetShaderInfoLog = reinterpret_cast(LoadEntry("glGetShaderInfoLog")); + glGetShaderiv = reinterpret_cast(LoadEntry("glGetShaderiv")); + glGetShaderSource = reinterpret_cast(LoadEntry("glGetShaderSource")); + glGetTexImage = reinterpret_cast(LoadEntry("glGetTexImage")); + glGetTexLevelParameterfv = reinterpret_cast(LoadEntry("glGetTexLevelParameterfv")); + glGetTexLevelParameteriv = reinterpret_cast(LoadEntry("glGetTexLevelParameteriv")); + glGetTexParameterfv = reinterpret_cast(LoadEntry("glGetTexParameterfv")); + glGetTexParameteriv = reinterpret_cast(LoadEntry("glGetTexParameteriv")); + glGetUniformLocation = reinterpret_cast(LoadEntry("glGetUniformLocation")); + glLinkProgram = reinterpret_cast(LoadEntry("glLinkProgram")); + glMapBuffer = reinterpret_cast(LoadEntry("glMapBuffer")); + glPixelStorei = reinterpret_cast(LoadEntry("glPixelStorei")); + glPolygonMode = reinterpret_cast(LoadEntry("glPolygonMode")); + glReadPixels = reinterpret_cast(LoadEntry("glReadPixels")); + glScissor = reinterpret_cast(LoadEntry("glScissor")); + glShaderSource = reinterpret_cast(LoadEntry("glShaderSource")); + glStencilFunc = reinterpret_cast(LoadEntry("glStencilFunc")); + glStencilOp = reinterpret_cast(LoadEntry("glStencilOp")); + glTexImage2D = reinterpret_cast(LoadEntry("glTexImage2D")); + glTexImage3D = reinterpret_cast(LoadEntry("glTexImage3D")); + glTexParameterf = reinterpret_cast(LoadEntry("glTexParameterf")); + glTexParameteri = reinterpret_cast(LoadEntry("glTexParameteri")); + glTexSubImage2D = reinterpret_cast(LoadEntry("glTexSubImage2D")); + glTexSubImage3D = reinterpret_cast(LoadEntry("glTexSubImage3D")); + glUniform1f = reinterpret_cast(LoadEntry("glUniform1f")); + glUniform1i = reinterpret_cast(LoadEntry("glUniform1i")); + glUniform2fv = reinterpret_cast(LoadEntry("glUniform2fv")); + glUniform3fv = reinterpret_cast(LoadEntry("glUniform3fv")); + glUniform4fv = reinterpret_cast(LoadEntry("glUniform4fv")); + glUniformMatrix4fv = reinterpret_cast(LoadEntry("glUniformMatrix4fv")); + glUnmapBuffer = reinterpret_cast(LoadEntry("glUnmapBuffer")); + glUseProgram = reinterpret_cast(LoadEntry("glUseProgram")); + glVertexAttrib4f = reinterpret_cast(LoadEntry("glVertexAttrib4f")); + glVertexAttribPointer = reinterpret_cast(LoadEntry("glVertexAttribPointer")); + glViewport = reinterpret_cast(LoadEntry("glViewport")); + } + catch (const std::exception& e) + { + NazaraError("Unable to load OpenGL: " + NzString(e.what())); + Uninitialize(); + + return false; + } + + /****************************************Extensions****************************************/ + + // Fonctions optionnelles + glBindFragDataLocation = reinterpret_cast(LoadEntry("glBindFragDataLocation", false)); + if (!glBindFragDataLocation) + glBindFragDataLocation = reinterpret_cast(LoadEntry("glBindFragDataLocationEXT", false)); + + glGetStringi = reinterpret_cast(LoadEntry("glGetStringi", false)); + glMapBufferRange = reinterpret_cast(LoadEntry("glMapBufferRange", false)); + + #if defined(NAZARA_PLATFORM_WINDOWS) + wglGetExtensionsStringARB = reinterpret_cast(LoadEntry("wglGetExtensionsStringARB", false)); + wglGetExtensionsStringEXT = reinterpret_cast(LoadEntry("wglGetExtensionsStringEXT", false)); + wglSwapInterval = reinterpret_cast(LoadEntry("wglSwapIntervalEXT", false)); + #elif defined(NAZARA_PLATFORM_LINUX) + glXSwapInterval = reinterpret_cast(LoadEntry("glXSwapIntervalSGI", false)); + #endif + + if (!glGetStringi || !LoadExtensions3()) + { + if (openGLversion >= 300) // Dans le cas contraire c'est normal + NazaraWarning("Failed to load OpenGL 3 extension system, switching to OpenGL 2 extension system..."); + + if (!LoadExtensionsString(reinterpret_cast(glGetString(GL_EXTENSIONS)))) + NazaraWarning("Failed to load extension system"); + } + + #ifdef NAZARA_PLATFORM_WINDOWS + { + bool loaded; + if (wglGetExtensionsStringARB) + loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringARB(wglGetCurrentDC()))); + else if (wglGetExtensionsStringEXT) + loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringEXT())); + else + loaded = false; + + if (!loaded) + NazaraWarning("Failed to load wgl extension string"); + } + #endif + + // AnisotropicFilter + openGLextensions[nzOpenGLExtension_AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic"); + + // DebugOutput + if (openGLversion >= 430 || IsSupported("GL_KHR_debug")) + { + try + { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); + glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); + glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); + glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); + + openGLextensions[nzOpenGLExtension_DebugOutput] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load GL_KHR_debug: " + NzString(e.what())); + } + } + + if (!openGLextensions[nzOpenGLExtension_DebugOutput] && IsSupported("GL_ARB_debug_output")) + { + try + { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); + glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControlARB")); + glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsertARB")); + glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLogARB")); + + openGLextensions[nzOpenGLExtension_DebugOutput] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load GL_ARB_debug_output: " + NzString(e.what())); + } + } + + // FP64 + if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) + { + try + { + glUniform1d = reinterpret_cast(LoadEntry("glUniform1d")); + glUniform2dv = reinterpret_cast(LoadEntry("glUniform2dv")); + glUniform3dv = reinterpret_cast(LoadEntry("glUniform3dv")); + glUniform4dv = reinterpret_cast(LoadEntry("glUniform4dv")); + + openGLextensions[nzOpenGLExtension_FP64] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_gpu_shader_fp64: " + NzString(e.what())); + } + } + + // FrameBufferObject + if (openGLversion >= 300 || IsSupported("GL_ARB_framebuffer_object")) + { + try + { + glBindFramebuffer = reinterpret_cast(LoadEntry("glBindFramebuffer")); + glBindRenderbuffer = reinterpret_cast(LoadEntry("glBindRenderbuffer")); + glCheckFramebufferStatus = reinterpret_cast(LoadEntry("glCheckFramebufferStatus")); + glDeleteFramebuffers = reinterpret_cast(LoadEntry("glDeleteFramebuffers")); + glDeleteRenderbuffers = reinterpret_cast(LoadEntry("glDeleteRenderbuffers")); + glFramebufferRenderbuffer = reinterpret_cast(LoadEntry("glFramebufferRenderbuffer")); + glFramebufferTexture = reinterpret_cast(LoadEntry("glFramebufferTexture")); + glFramebufferTexture1D = reinterpret_cast(LoadEntry("glFramebufferTexture1D")); + glFramebufferTexture2D = reinterpret_cast(LoadEntry("glFramebufferTexture2D")); + glFramebufferTexture3D = reinterpret_cast(LoadEntry("glFramebufferTexture3D")); + glFramebufferTextureLayer = reinterpret_cast(LoadEntry("glFramebufferTextureLayer")); + glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmap")); + glGenFramebuffers = reinterpret_cast(LoadEntry("glGenFramebuffers")); + glGenRenderbuffers = reinterpret_cast(LoadEntry("glGenRenderbuffers")); + glRenderbufferStorage = reinterpret_cast(LoadEntry("glRenderbufferStorage")); + + openGLextensions[nzOpenGLExtension_FrameBufferObject] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")"); + } + } + + // PixelBufferObject + openGLextensions[nzOpenGLExtension_PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object")); + + // SeparateShaderObjects + if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects")) + { + glProgramUniform1f = reinterpret_cast(LoadEntry("glProgramUniform1f")); + glProgramUniform1i = reinterpret_cast(LoadEntry("glProgramUniform1i")); + glProgramUniform2fv = reinterpret_cast(LoadEntry("glProgramUniform2fv")); + glProgramUniform3fv = reinterpret_cast(LoadEntry("glProgramUniform3fv")); + glProgramUniform4fv = reinterpret_cast(LoadEntry("glProgramUniform4fv")); + glProgramUniformMatrix4fv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4fv")); + + // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double + if (openGLextensions[nzOpenGLExtension_FP64]) + { + glProgramUniform1d = reinterpret_cast(LoadEntry("glProgramUniform1d")); + glProgramUniform2dv = reinterpret_cast(LoadEntry("glProgramUniform2dv")); + glProgramUniform3dv = reinterpret_cast(LoadEntry("glProgramUniform3dv")); + glProgramUniform4dv = reinterpret_cast(LoadEntry("glProgramUniform4dv")); + glProgramUniformMatrix4dv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4dv")); + } + + openGLextensions[nzOpenGLExtension_SeparateShaderObjects] = true; + } + + // TextureArray + openGLextensions[nzOpenGLExtension_TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array")); + + // TextureCompression_s3tc + openGLextensions[nzOpenGLExtension_TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc"); + + // TextureStorage + if (openGLversion >= 420 || IsSupported("GL_ARB_texture_storage")) + { + try + { + glTexStorage1D = reinterpret_cast(LoadEntry("glTexStorage1D")); + glTexStorage2D = reinterpret_cast(LoadEntry("glTexStorage2D")); + glTexStorage3D = reinterpret_cast(LoadEntry("glTexStorage3D")); + + openGLextensions[nzOpenGLExtension_TextureStorage] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_texture_storage: " + NzString(e.what())); + } + } + + // VertexArrayObject + if (openGLversion >= 300 || IsSupported("GL_ARB_vertex_array_object")) + { + try + { + glBindVertexArray = reinterpret_cast(LoadEntry("glBindVertexArray")); + glDeleteVertexArrays = reinterpret_cast(LoadEntry("glDeleteVertexArrays")); + glGenVertexArrays = reinterpret_cast(LoadEntry("glGenVertexArrays")); + + openGLextensions[nzOpenGLExtension_VertexArrayObject] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_vertex_array_object: " + NzString(e.what())); + } + } + + // Fonctions de substitut + if (!glGenerateMipmap) + glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmapEXT", false)); + + /****************************************Contexte de référence****************************************/ + + ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) + if (!NzContext::Initialize()) + { + NazaraError("Failed to initialize contexts"); + Uninitialize(); + + return false; + } + + NzContextParameters::defaultShareContext = NzContext::GetReference(); + + return true; + } + + bool IsSupported(nzOpenGLExtension extension) + { + return openGLextensions[extension]; + } + + bool IsSupported(const NzString& string) + { + return openGLextensionSet.find(string) != openGLextensionSet.end(); + } + + bool TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType type) + { + switch (pixelFormat) + { + case nzPixelFormat_BGR8: + format->dataFormat = GL_BGR; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGB8; + return true; + + case nzPixelFormat_BGRA8: + format->dataFormat = GL_BGRA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGBA8; + return true; + + case nzPixelFormat_DXT1: + format->dataFormat = GL_RGB; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return true; + + case nzPixelFormat_DXT3: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + return true; + + case nzPixelFormat_DXT5: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return true; + + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + return false; + + case nzPixelFormat_RGB5A1: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_SHORT_5_5_5_1; + format->internalFormat = GL_RGB5_A1; + return true; + + case nzPixelFormat_RGB8: + format->dataFormat = GL_RGB; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGB8; + return true; + + case nzPixelFormat_RGBA4: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_SHORT_4_4_4_4; + format->internalFormat = GL_RGBA4; + return true; + + case nzPixelFormat_RGBA8: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGBA8; + return true; + + case nzPixelFormat_Depth16: + format->dataFormat = GL_DEPTH_COMPONENT; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH_COMPONENT16; + return true; + + case nzPixelFormat_Depth24: + format->dataFormat = GL_DEPTH_COMPONENT; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH_COMPONENT24; + return true; + + case nzPixelFormat_Depth24Stencil8: + format->dataFormat = GL_DEPTH_STENCIL; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH24_STENCIL8; + return true; + + case nzPixelFormat_Depth32: + format->dataFormat = GL_DEPTH_COMPONENT; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH_COMPONENT32; + return true; + + case nzPixelFormat_Stencil1: + if (type == FormatType_Texture) // Les formats de stencil ne sont pas supportés par les textures + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX1; + return true; + } + + case nzPixelFormat_Stencil4: + if (type == FormatType_Texture) + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX4; + return true; + } + + case nzPixelFormat_Stencil8: + if (type == FormatType_Texture) + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX8; + return true; + } + + case nzPixelFormat_Stencil16: + if (type == FormatType_Texture) + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX16; + return true; + } + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return false; + } + + void Uninitialize() + { + NzContext::Uninitialize(); + + for (bool& ext : openGLextensions) + ext = false; + + openGLextensionSet.clear(); + openGLversion = 0; + + UnloadLibrary(); + } + + GLenum Attachment[nzAttachmentPoint_Max+1] = + { + GL_COLOR_ATTACHMENT0, // nzAttachmentPoint_Color + GL_DEPTH_ATTACHMENT, // nzAttachmentPoint_Depth + GL_DEPTH_STENCIL_ATTACHMENT, // nzAttachmentPoint_DepthStencil + GL_STENCIL_ATTACHMENT // nzAttachmentPoint_Stencil + }; + + nzUInt8 AttributeIndex[nzElementUsage_Max+1] = + { + 2, // nzElementUsage_Diffuse + 1, // nzElementUsage_Normal + 0, // nzElementUsage_Position + 3, // nzElementUsage_Tangent + + 4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible) + }; + + GLenum BlendFunc[nzBlendFunc_Max+1] = + { + GL_DST_ALPHA, // nzBlendFunc_DestAlpha + GL_DST_COLOR, // nzBlendFunc_DestColor + GL_SRC_ALPHA, // nzBlendFunc_SrcAlpha + GL_SRC_COLOR, // nzBlendFunc_SrcColor + GL_ONE_MINUS_DST_ALPHA, // nzBlendFunc_InvDestAlpha + GL_ONE_MINUS_DST_COLOR, // nzBlendFunc_InvDestColor + GL_ONE_MINUS_SRC_ALPHA, // nzBlendFunc_InvSrcAlpha + GL_ONE_MINUS_SRC_COLOR, // nzBlendFunc_InvSrcColor + GL_ONE, // nzBlendFunc_One + GL_ZERO // nzBlendFunc_Zero + }; + + GLenum BufferLock[nzBufferAccess_Max+1] = + { + GL_WRITE_ONLY, // nzBufferAccess_DiscardAndWrite + GL_READ_ONLY, // nzBufferAccess_ReadOnly + GL_READ_WRITE, // nzBufferAccess_ReadWrite + GL_WRITE_ONLY // nzBufferAccess_WriteOnly + }; + + GLenum BufferLockRange[nzBufferAccess_Max+1] = + { + GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_DiscardAndWrite + GL_MAP_READ_BIT, // nzBufferAccess_ReadOnly + GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_ReadWrite + GL_MAP_WRITE_BIT // nzBufferAccess_WriteOnly + }; + + GLenum BufferTarget[nzBufferType_Max+1] = + { + GL_ELEMENT_ARRAY_BUFFER, // nzBufferType_Index, + GL_ARRAY_BUFFER, // nzBufferType_Vertex + }; + + GLenum BufferTargetBinding[nzBufferType_Max+1] = + { + GL_ELEMENT_ARRAY_BUFFER_BINDING, // nzBufferType_Index, + GL_ARRAY_BUFFER_BINDING, // nzBufferType_Vertex + }; + + GLenum BufferUsage[nzBufferUsage_Max+1] = + { + // J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus" + // Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?) + // Source: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=160839 + GL_DYNAMIC_DRAW, // nzBufferUsage_Dynamic + GL_STATIC_DRAW // nzBufferUsage_Static + }; + + GLenum CubemapFace[6] = + { + GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, // nzCubemapFace_NegativeX + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // nzCubemapFace_PositiveY + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // nzCubemapFace_NegativeY + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, // nzCubemapFace_PositiveZ + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z // nzCubemapFace_NegativeZ + }; + + GLenum ElementType[nzElementType_Max+1] = + { + GL_UNSIGNED_BYTE, // nzElementType_Color + GL_DOUBLE, // nzElementType_Double1 + GL_DOUBLE, // nzElementType_Double2 + GL_DOUBLE, // nzElementType_Double3 + GL_DOUBLE, // nzElementType_Double4 + GL_FLOAT, // nzElementType_Float1 + GL_FLOAT, // nzElementType_Float2 + GL_FLOAT, // nzElementType_Float3 + GL_FLOAT // nzElementType_Float4 + }; + + GLenum FaceCulling[nzFaceCulling_Max+1] = + { + GL_BACK, // nzFaceCulling_Back + GL_FRONT, // nzFaceCulling_Front + GL_FRONT_AND_BACK // nzFaceCulling_FrontAndBack + }; + + GLenum FaceFilling[nzFaceFilling_Max+1] = + { + GL_POINT, // nzFaceFilling_Point + GL_LINE, // nzFaceFilling_Line + GL_FILL // nzFaceFilling_Fill + }; + + GLenum PrimitiveType[nzPrimitiveType_Max+1] = + { + GL_LINES, // nzPrimitiveType_LineList, + GL_LINE_STRIP, // nzPrimitiveType_LineStrip, + GL_POINTS, // nzPrimitiveType_PointList, + GL_TRIANGLES, // nzPrimitiveType_TriangleList, + GL_TRIANGLE_STRIP, // nzPrimitiveType_TriangleStrip, + GL_TRIANGLE_FAN // nzPrimitiveType_TriangleFan + }; + + GLenum RendererComparison[nzRendererComparison_Max+1] = + { + GL_ALWAYS, // nzRendererComparison_Always + GL_EQUAL, // nzRendererComparison_Equal + GL_GREATER, // nzRendererComparison_Greater + GL_GEQUAL, // nzRendererComparison_GreaterOrEqual + GL_LESS, // nzRendererComparison_Less + GL_LEQUAL, // nzRendererComparison_LessOrEqual + GL_NEVER // nzRendererComparison_Never + }; + + GLenum RendererParameter[nzRendererParameter_Max+1] = + { + GL_BLEND, // nzRendererParameter_Blend + GL_NONE, // nzRendererParameter_ColorWrite + GL_DEPTH_TEST, // nzRendererParameter_DepthTest + GL_NONE, // nzRendererParameter_DepthWrite + GL_CULL_FACE, // nzRendererParameter_FaceCulling + GL_STENCIL_TEST // nzRendererParameter_Stencil + }; + + GLenum ShaderType[nzShaderType_Max+1] = + { + GL_FRAGMENT_SHADER, // nzShaderType_Fragment + GL_GEOMETRY_SHADER, // nzShaderType_Geometry + GL_VERTEX_SHADER // nzShaderType_Vertex + }; + + GLenum StencilOperation[nzStencilOperation_Max+1] = + { + GL_DECR, // nzStencilOperation_Decrement + GL_DECR_WRAP, // nzStencilOperation_DecrementToSaturation + GL_INCR, // nzStencilOperation_Increment + GL_INCR_WRAP, // nzStencilOperation_IncrementToSaturation + GL_INVERT, // nzStencilOperation_Invert + GL_KEEP, // nzStencilOperation_Keep + GL_REPLACE, // nzStencilOperation_Replace + GL_ZERO // nzStencilOperation_Zero + }; + + GLenum TextureTarget[nzImageType_Max+1] + { + GL_TEXTURE_1D, // nzImageType_1D + GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array + GL_TEXTURE_2D, // nzImageType_2D + GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array + GL_TEXTURE_3D, // nzImageType_3D + GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap + }; + + GLenum TextureTargetBinding[nzImageType_Max+1] + { + GL_TEXTURE_BINDING_1D, // nzImageType_1D + GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D_Array + GL_TEXTURE_BINDING_2D, // nzImageType_2D + GL_TEXTURE_BINDING_2D_ARRAY, // nzImageType_2D_Array + GL_TEXTURE_BINDING_3D, // nzImageType_3D + GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap + }; + + GLenum TextureTargetProxy[nzImageType_Max+1] + { + GL_PROXY_TEXTURE_1D, // nzImageType_1D + GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array + GL_PROXY_TEXTURE_2D, // nzImageType_2D + GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array + GL_PROXY_TEXTURE_3D, // nzImageType_3D + GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap + }; +} + +PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; +PFNGLATTACHSHADERPROC glAttachShader = nullptr; +PFNGLBEGINQUERYPROC glBeginQuery = nullptr; +PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; +PFNGLBINDBUFFERPROC glBindBuffer = nullptr; +PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; +PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr; +PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; +PFNGLBINDTEXTUREPROC glBindTexture = nullptr; +PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; +PFNGLBLENDFUNCPROC glBlendFunc = nullptr; +PFNGLBUFFERDATAPROC glBufferData = nullptr; +PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; +PFNGLCLEARPROC glClear = nullptr; +PFNGLCLEARCOLORPROC glClearColor = nullptr; +PFNGLCLEARDEPTHPROC glClearDepth = nullptr; +PFNGLCLEARSTENCILPROC glClearStencil = nullptr; +PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; +PFNGLCREATESHADERPROC glCreateShader = nullptr; +PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; +PFNGLCOLORMASKPROC glColorMask = nullptr; +PFNGLCULLFACEPROC glCullFace = nullptr; +PFNGLCOMPILESHADERPROC glCompileShader = nullptr; +PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; +PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; +PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; +PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; +PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; +PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; +PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; +PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; +PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; +PFNGLDELETESHADERPROC glDeleteShader = nullptr; +PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; +PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; +PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; +PFNGLDEPTHMASKPROC glDepthMask = nullptr; +PFNGLDISABLEPROC glDisable = nullptr; +PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; +PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; +PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; +PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; +PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; +PFNGLENDQUERYPROC glEndQuery = nullptr; +PFNGLFLUSHPROC glFlush = nullptr; +PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; +PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture = nullptr; +PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = nullptr; +PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; +PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = nullptr; +PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = nullptr; +PFNGLENABLEPROC glEnable = nullptr; +PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; +PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; +PFNGLGENBUFFERSPROC glGenBuffers = nullptr; +PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; +PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; +PFNGLGENQUERIESPROC glGenQueries = nullptr; +PFNGLGENTEXTURESPROC glGenTextures = nullptr; +PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; +PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; +PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; +PFNGLGETERRORPROC glGetError = nullptr; +PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; +PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; +PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; +PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; +PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; +PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; +PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; +PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; +PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; +PFNGLGETSTRINGPROC glGetString = nullptr; +PFNGLGETSTRINGIPROC glGetStringi = nullptr; +PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; +PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; +PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; +PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; +PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; +PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; +PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; +PFNGLMAPBUFFERPROC glMapBuffer = nullptr; +PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; +PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; +PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; +PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; +PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; +PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; +PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; +PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; +PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; +PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; +PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; +PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; +PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; +PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; +PFNGLREADPIXELSPROC glReadPixels = nullptr; +PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; +PFNGLSCISSORPROC glScissor = nullptr; +PFNGLSHADERSOURCEPROC glShaderSource = nullptr; +PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; +PFNGLSTENCILOPPROC glStencilOp = nullptr; +PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; +PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; +PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; +PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; +PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; +PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; +PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; +PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; +PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; +PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; +PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; +PFNGLUNIFORM1DPROC glUniform1d = nullptr; +PFNGLUNIFORM1FPROC glUniform1f = nullptr; +PFNGLUNIFORM1IPROC glUniform1i = nullptr; +PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; +PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; +PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; +PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; +PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; +PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; +PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; +PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; +PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; +PFNGLUSEPROGRAMPROC glUseProgram = nullptr; +PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; +PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; +PFNGLVIEWPORTPROC glViewport = nullptr; +#if defined(NAZARA_PLATFORM_WINDOWS) +PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; +PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; +PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; +PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; +PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; +#elif defined(NAZARA_PLATFORM_LINUX) +PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; +PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = nullptr; +#endif diff --git a/src/Nazara/Renderer/RenderTexture.cpp b/src/Nazara/Renderer/RenderTexture.cpp new file mode 100644 index 000000000..8d5bf552f --- /dev/null +++ b/src/Nazara/Renderer/RenderTexture.cpp @@ -0,0 +1,728 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + struct Attachment + { + union + { + GLuint buffer; + NzTexture* texture; + }; + + bool isBuffer; + bool isUsed = false; + }; + + unsigned int attachmentIndex[nzAttachmentPoint_Max+1] = + { + 2, // nzAttachmentPoint_Color + 0, // nzAttachmentPoint_Depth + 0, // nzAttachmentPoint_DepthStencil + 1 // nzAttachmentPoint_Stencil + }; + + nzAttachmentPoint formatTypeToAttachment[nzPixelFormatType_Max+1] = + { + nzAttachmentPoint_Color, // nzPixelFormatType_Color + nzAttachmentPoint_Depth, // nzPixelFormatType_Depth + nzAttachmentPoint_DepthStencil, // nzPixelFormatType_DepthStencil + nzAttachmentPoint_Stencil // nzPixelFormatType_Stencil + }; + + GLuint lockedPrevious = 0; + nzUInt8 lockedLevel = 0; +} + +struct NzRenderTextureImpl +{ + GLuint fbo; + std::vector attachements; + std::vector drawBuffers; + NzContext* context; + bool checked = false; + bool complete = false; + bool drawBuffersUpdated = true; + unsigned int height; + unsigned int width; +}; + +NzRenderTexture::~NzRenderTexture() +{ + Destroy(); +} + +bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return false; + } + + unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; + if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && + m_impl->attachements[depthStencilIndex].isUsed) + { + NazaraError("Stencil target already attached by DepthStencil attachment"); + return false; + } + + if (formatTypeToAttachment[NzPixelFormat::GetType(format)] != attachmentPoint) + { + NazaraError("Pixel format type does not match attachment point type"); + return false; + } + #endif + + NzOpenGL::Format openglFormat; + if (!NzOpenGL::TranslateFormat(format, &openglFormat, NzOpenGL::FormatType_RenderBuffer)) + { + NazaraError("Failed to translate pixel format into OpenGL format"); + return false; + } + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + // Détachement de l'attache précédente (Si il y a) + Detach(attachmentPoint, index); + + GLuint renderBuffer = 0; + + glGenRenderbuffers(1, &renderBuffer); + if (!renderBuffer) + { + NazaraError("Failed to create renderbuffer"); + return false; + } + + GLint previous; + glGetIntegerv(GL_RENDERBUFFER_BINDING, &previous); + + glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); + glRenderbufferStorage(GL_RENDERBUFFER, openglFormat.internalFormat, m_impl->width, m_impl->height); + + if (previous != 0) + glBindRenderbuffer(GL_RENDERBUFFER, previous); + + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, renderBuffer); + Unlock(); + + unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; + if (m_impl->attachements.size() < minSize) + m_impl->attachements.resize(minSize); + + Attachment& attachment = m_impl->attachements[minSize-1]; + attachment.isBuffer = true; + attachment.isUsed = true; + attachment.buffer = renderBuffer; + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + + return true; +} + +bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return false; + } + + unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; + if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && + m_impl->attachements[depthStencilIndex].isUsed) + { + NazaraError("Stencil target already attached by DepthStencil attachment"); + return false; + } + + if (!texture || !texture->IsValid()) + { + NazaraError("Invalid texture"); + return false; + } + + if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height) + { + NazaraError("Texture cannot be smaller than render texture"); + return false; + } + + if (texture->GetRenderTexture() != nullptr) + { + NazaraError("Texture already used by another render texture"); + return false; + } + + if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint) + { + NazaraError("Pixel format type does not match attachment point type"); + return false; + } + #endif + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + // Détachement de l'attache précédente (Si il y a) + Detach(attachmentPoint, index); + + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0); + Unlock(); + + unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; + if (m_impl->attachements.size() < minSize) + m_impl->attachements.resize(minSize); + + Attachment& attachment = m_impl->attachements[minSize-1]; + attachment.isBuffer = true; + attachment.isUsed = true; + attachment.texture = texture; + + texture->AddResourceListener(this, minSize-1); + texture->SetRenderTexture(this); + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + + return true; +} + +bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return false; + } + + if (attachmentPoint == nzAttachmentPoint_Stencil) + { + NazaraError("Targeting stencil-only textures is not supported"); + return false; + } + + unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; + if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && + m_impl->attachements[depthStencilIndex].isUsed) + { + NazaraError("Stencil target already attached by DepthStencil attachment"); + return false; + } + + if (!texture || !texture->IsValid()) + { + NazaraError("Invalid texture"); + return false; + } + + if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height) + { + NazaraError("Texture cannot be smaller than render texture"); + return false; + } + + unsigned int depth = (texture->GetType() == nzImageType_Cubemap) ? 6 : texture->GetDepth(); + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return false; + } + + if (texture->GetRenderTexture() != nullptr) + { + NazaraError("Texture already used by another render texture"); + return false; + } + + if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint) + { + NazaraError("Pixel format type does not match attachment point type"); + return false; + } + #endif + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + // Détachement de l'attache précédente (Si il y a) + Detach(attachmentPoint, index); + + switch (texture->GetType()) + { + case nzImageType_1D: + glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_1D, texture->GetOpenGLID(), 0); + break; + + case nzImageType_1D_Array: + case nzImageType_2D_Array: + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0, z); + break; + + case nzImageType_2D: + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::TextureTarget[texture->GetType()], texture->GetOpenGLID(), 0); + break; + + case nzImageType_3D: + glFramebufferTexture3D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_3D, texture->GetOpenGLID(), 0, z); + break; + + case nzImageType_Cubemap: + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::CubemapFace[z], texture->GetOpenGLID(), 0); + break; + } + Unlock(); + + unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; + if (m_impl->attachements.size() < minSize) + m_impl->attachements.resize(minSize); + + Attachment& attachment = m_impl->attachements[minSize-1]; + attachment.isBuffer = true; + attachment.isUsed = true; + attachment.texture = texture; + + texture->AddResourceListener(this); + texture->SetRenderTexture(this); + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + + return true; +} + +bool NzRenderTexture::Create(unsigned int width, unsigned int height, bool lock) +{ + if (!IsSupported()) + { + NazaraError("Render textures not supported"); + return false; + } + + Destroy(); + + #if NAZARA_RENDERER_SAFE + if (width == 0) + { + NazaraError("Width must be at least 1 (0)"); + return false; + } + + if (height == 0) + { + NazaraError("Height must be at least 1 (0)"); + return false; + } + + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return false; + } + #endif + + NzRenderTextureImpl* impl = new NzRenderTextureImpl; + impl->width = width; + impl->height = height; + + impl->context = NzContext::GetCurrent(); + impl->context->AddResourceListener(this); + + impl->fbo = 0; + glGenFramebuffers(1, &impl->fbo); + + if (!impl->fbo) + { + NazaraError("Failed to create framebuffer"); + delete impl; + + return false; + } + + m_impl = impl; + + if (lock && !Lock()) + { + NazaraError("Failed to lock render texture"); + delete impl; + m_impl = nullptr; + + return false; + } + + return true; +} + +void NzRenderTexture::Destroy() +{ + if (m_impl) + { + #if NAZARA_RENDERER_SAFE + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture can only be used with it's creation context"); + return; + } + #endif + + m_impl->context->RemoveResourceListener(this); + + for (Attachment& attachment : m_impl->attachements) + { + if (attachment.isUsed) + { + if (attachment.isBuffer) + glDeleteRenderbuffers(1, &attachment.buffer); + else + { + attachment.texture->RemoveResourceListener(this); + attachment.texture->SetRenderTexture(nullptr); + } + } + } + + glDeleteFramebuffers(1, &m_impl->fbo); + + delete m_impl; + m_impl = nullptr; + } +} + +void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return; + } + #endif + + unsigned int attachIndex = attachmentIndex[attachmentPoint]+index; + if (attachIndex >= m_impl->attachements.size()) + return; + + Attachment& attachement = m_impl->attachements[attachIndex]; + if (!attachement.isUsed) + return; + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return; + } + + attachement.isUsed = false; + + if (attachement.isBuffer) + { + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0); + glDeleteRenderbuffers(1, &attachement.buffer); + } + else + { + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0); + attachement.texture->RemoveResourceListener(this); + attachement.texture->SetRenderTexture(nullptr); + } + + Unlock(); + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + +} + +unsigned int NzRenderTexture::GetHeight() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return 0; + } + #endif + + return m_impl->height; +} + +NzRenderTargetParameters NzRenderTexture::GetParameters() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return NzRenderTargetParameters(); + } + #endif + + return NzRenderTargetParameters(); +} + +unsigned int NzRenderTexture::GetWidth() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return 0; + } + #endif + + return m_impl->width; +} + +bool NzRenderTexture::IsComplete() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + #endif + + if (!m_impl->checked) + { + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); + Unlock(); + + m_impl->complete = false; + + switch (status) + { + case GL_FRAMEBUFFER_COMPLETE: + m_impl->complete = true; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + NazaraError("Incomplete attachment"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + NazaraInternalError("Incomplete draw buffer"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + NazaraInternalError("Incomplete read buffer"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + NazaraError("Incomplete missing attachment"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: + NazaraError("Incomplete multisample"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: + NazaraError("Incomplete layer targets"); + break; + + case GL_FRAMEBUFFER_UNSUPPORTED: + NazaraError("Render texture has unsupported attachments"); + break; + + default: + NazaraInternalError("Unknown error"); + } + + m_impl->checked = true; + } + + return m_impl->complete; +} + +bool NzRenderTexture::IsRenderable() const +{ + return IsComplete(); +} + +bool NzRenderTexture::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzRenderTexture::Lock() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return false; + } + #endif + + if (lockedLevel++ == 0) + { + GLint previous; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previous); + + lockedPrevious = previous; + + if (lockedPrevious != m_impl->fbo) + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo); + } + + return true; +} + +void NzRenderTexture::Unlock() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return; + } + + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return; + } + + if (lockedLevel == 0) + { + NazaraWarning("Unlock called on non-locked texture"); + return; + } + #endif + + if (--lockedLevel == 0 && lockedPrevious != m_impl->fbo) // Ici, il est important qu'un FBO soit débindé si l'ancien était 0 + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, lockedPrevious); +} + +bool NzRenderTexture::HasContext() const +{ + return false; +} + +bool NzRenderTexture::IsSupported() +{ + return NzRenderer::HasCapability(nzRendererCap_RenderTexture); +} + +bool NzRenderTexture::Activate() +{ + #if NAZARA_RENDERER_SAFE + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return false; + } + #endif + + if (!m_impl->drawBuffersUpdated) + { + m_impl->drawBuffers.clear(); + m_impl->drawBuffers.reserve(m_impl->attachements.size()); + for (unsigned int i = attachmentIndex[nzAttachmentPoint_Color]; i < m_impl->attachements.size(); ++i) + { + if (m_impl->attachements[i].isUsed) + m_impl->drawBuffers.push_back(GL_COLOR_ATTACHMENT0 + i - attachmentIndex[nzAttachmentPoint_Color]); + } + + m_impl->drawBuffersUpdated = true; + } + + glDrawBuffers(m_impl->drawBuffers.size(), &m_impl->drawBuffers[0]); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo); + + return true; +} + +void NzRenderTexture::Desactivate() +{ + #if NAZARA_RENDERER_SAFE + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return; + } + #endif + + glFlush(); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); +} + +void NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index) +{ + if (resource == m_impl->context) + // Notre context a été détruit, libérons la RenderTexture pour éviter un leak + Destroy(); + else + { + // Sinon, c'est une texture + + // La ressource n'est plus, du coup nous mettons à jour + Attachment& attachement = m_impl->attachements[index]; + attachement.isUsed = false; + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + } +} diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index ffdbc21cc..a3fb37653 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -1,278 +1,276 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) -{ - Create(mode, title, style, parameters); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create render window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) -{ - Create(handle, parameters); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create render window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzRenderWindow::~NzRenderWindow() -{ - // Nécessaire si NzWindow::Destroy est appelé par son destructeur - OnWindowDestroying(); -} - -bool NzRenderWindow::CopyToImage(NzImage* image) -{ - #if NAZARA_RENDERER_SAFE - if (!m_context) - { - NazaraError("Window has not been created"); - return false; - } - - if (!image) - { - NazaraError("Image must be valid"); - return false; - } - #endif - - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return false; - } - - NzVector2ui size = GetSize(); - - if (!image->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1)) - { - NazaraError("Failed to create image"); - return false; - } - - nzUInt8* pixels = image->GetPixels(); - glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - image->FlipVertically(); - - return true; -} - -bool NzRenderWindow::CopyToTexture(NzTexture* texture) -{ - #if NAZARA_RENDERER_SAFE - if (!m_context) - { - NazaraError("Window has not been created"); - return false; - } - - if (!texture) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return false; - } - - NzVector2ui size = GetSize(); - - if (!texture->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1, true)) - { - NazaraError("Failed to create texture"); - return false; - } - - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.x, size.y); - - texture->Unlock(); - - return true; -} - -bool NzRenderWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) -{ - m_parameters = parameters; - return NzWindow::Create(mode, title, style); -} - -bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& parameters) -{ - m_parameters = parameters; - return NzWindow::Create(handle); -} - -void NzRenderWindow::Display() -{ - if (m_framerateLimit > 0) - { - int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds(); - if (remainingTime > 0) - NzThread::Sleep(remainingTime); - - m_clock.Restart(); - } - - if (m_context && m_parameters.doubleBuffered) - m_context->SwapBuffers(); -} - -void NzRenderWindow::EnableVerticalSync(bool enabled) -{ - if (m_context) - { - #if defined(NAZARA_PLATFORM_WINDOWS) - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return; - } - - if (wglSwapInterval) - wglSwapInterval(enabled ? 1 : 0); - else - #elif defined(NAZARA_PLATFORM_LINUX) - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return; - } - - if (glXSwapInterval) - glXSwapInterval(enabled ? 1 : 0); - else - #else - #error Vertical Sync is not supported on this platform - #endif - NazaraError("Vertical Sync is not supported on this platform"); - } - else - NazaraError("No context"); -} - -NzContextParameters NzRenderWindow::GetContextParameters() const -{ - if (m_context) - return m_context->GetParameters(); - else - { - NazaraError("Window not created/context not initialized"); - return NzContextParameters(); - } -} - -unsigned int NzRenderWindow::GetHeight() const -{ - return NzWindow::GetHeight(); -} - -NzRenderTargetParameters NzRenderWindow::GetParameters() const -{ - if (m_context) - { - const NzContextParameters& parameters = m_context->GetParameters(); - return NzRenderTargetParameters(parameters.antialiasingLevel, parameters.depthBits, parameters.stencilBits); - } - else - { - NazaraError("Window not created/context not initialized"); - return NzRenderTargetParameters(); - } -} - -unsigned int NzRenderWindow::GetWidth() const -{ - return NzWindow::GetWidth(); -} - -bool NzRenderWindow::HasContext() const -{ - return true; -} - -bool NzRenderWindow::IsValid() const -{ - return m_impl != nullptr && m_context != nullptr; -} - -void NzRenderWindow::SetFramerateLimit(unsigned int limit) -{ - m_framerateLimit = limit; -} - -bool NzRenderWindow::Activate() -{ - if (m_context->SetActive(true)) - { - glDrawBuffer((m_parameters.doubleBuffered) ? GL_BACK : GL_FRONT); - return true; - } - else - { - NazaraError("Failed to activate window's context"); - return false; - } -} - -void NzRenderWindow::OnWindowDestroying() -{ - if (m_context) - { - delete m_context; - m_context = nullptr; - } -} - -bool NzRenderWindow::OnWindowCreated() -{ - m_parameters.doubleBuffered = true; - m_parameters.window = GetHandle(); - - m_context = new NzContext; - if (!m_context->Create(m_parameters)) - { - NazaraError("Failed not create context"); - delete m_context; - - return false; - } - - EnableVerticalSync(false); - - #if NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION - if (!SetActive(true)) // Les fenêtres s'activent à la création - NazaraWarning("Failed to activate window"); - #endif - - m_clock.Restart(); - - return true; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) +{ + Create(mode, title, style, parameters); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create render window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) +{ + Create(handle, parameters); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create render window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzRenderWindow::~NzRenderWindow() +{ + // Nécessaire si NzWindow::Destroy est appelé par son destructeur + OnWindowDestroy(); +} + +bool NzRenderWindow::CopyToImage(NzImage* image) +{ + #if NAZARA_RENDERER_SAFE + if (!m_context) + { + NazaraError("Window has not been created"); + return false; + } + + if (!image) + { + NazaraError("Image must be valid"); + return false; + } + #endif + + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return false; + } + + NzVector2ui size = GetSize(); + + if (!image->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1)) + { + NazaraError("Failed to create image"); + return false; + } + + nzUInt8* pixels = image->GetPixels(); + glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + image->FlipVertically(); + + return true; +} + +bool NzRenderWindow::CopyToTexture(NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_context) + { + NazaraError("Window has not been created"); + return false; + } + + if (!texture) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return false; + } + + NzVector2ui size = GetSize(); + + if (!texture->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1, true)) + { + NazaraError("Failed to create texture"); + return false; + } + + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.x, size.y); + + texture->Unlock(); + + return true; +} + +bool NzRenderWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) +{ + m_parameters = parameters; + return NzWindow::Create(mode, title, style); +} + +bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& parameters) +{ + m_parameters = parameters; + return NzWindow::Create(handle); +} + +void NzRenderWindow::Display() +{ + if (m_framerateLimit > 0) + { + int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds(); + if (remainingTime > 0) + NzThread::Sleep(remainingTime); + + m_clock.Restart(); + } + + if (m_context && m_parameters.doubleBuffered) + m_context->SwapBuffers(); +} + +void NzRenderWindow::EnableVerticalSync(bool enabled) +{ + if (m_context) + { + #if defined(NAZARA_PLATFORM_WINDOWS) + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return; + } + + if (wglSwapInterval) + wglSwapInterval(enabled ? 1 : 0); + else + #elif defined(NAZARA_PLATFORM_LINUX) + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return; + } + + if (glXSwapInterval) + glXSwapInterval(enabled ? 1 : 0); + else + #else + #error Vertical Sync is not supported on this platform + #endif + NazaraError("Vertical Sync is not supported on this platform"); + } + else + NazaraError("No context"); +} + +unsigned int NzRenderWindow::GetHeight() const +{ + return NzWindow::GetHeight(); +} + +NzRenderTargetParameters NzRenderWindow::GetParameters() const +{ + if (m_context) + { + const NzContextParameters& parameters = m_context->GetParameters(); + return NzRenderTargetParameters(parameters.antialiasingLevel, parameters.depthBits, parameters.stencilBits); + } + else + { + NazaraError("Window not created/context not initialized"); + return NzRenderTargetParameters(); + } +} + +unsigned int NzRenderWindow::GetWidth() const +{ + return NzWindow::GetWidth(); +} + +bool NzRenderWindow::IsRenderable() const +{ + return m_impl != nullptr; // Si m_impl est valide, alors m_context l'est aussi +} + +void NzRenderWindow::SetFramerateLimit(unsigned int limit) +{ + m_framerateLimit = limit; +} + +NzContextParameters NzRenderWindow::GetContextParameters() const +{ + if (m_context) + return m_context->GetParameters(); + else + { + NazaraError("Window not created/context not initialized"); + return NzContextParameters(); + } +} + +bool NzRenderWindow::HasContext() const +{ + return true; +} + +bool NzRenderWindow::Activate() +{ + if (m_context->SetActive(true)) + { + glDrawBuffer((m_parameters.doubleBuffered) ? GL_BACK : GL_FRONT); + return true; + } + else + { + NazaraError("Failed to activate window's context"); + return false; + } +} + +bool NzRenderWindow::OnWindowCreated() +{ + m_parameters.doubleBuffered = true; + m_parameters.window = GetHandle(); + + m_context = new NzContext; + if (!m_context->Create(m_parameters)) + { + NazaraError("Failed not create context"); + delete m_context; + + return false; + } + + EnableVerticalSync(false); + + if (!SetActive(true)) // Les fenêtres s'activent à la création + NazaraWarning("Failed to activate window"); + + m_clock.Restart(); + + return true; +} + +void NzRenderWindow::OnWindowDestroy() +{ + if (m_context) + { + delete m_context; + m_context = nullptr; + } +} diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index a186fe518..a30725bbd 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -1,1008 +1,902 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include // Pour éviter une redéfinition de WIN32_LEAN_AND_MEAN -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - const nzUInt8 attribIndex[] = - { - 2, // nzElementUsage_Diffuse - 1, // nzElementUsage_Normal - 0, // nzElementUsage_Position - 3, // nzElementUsage_Tangent - - 4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible) - }; - - - const GLenum blendFunc[] = - { - GL_DST_ALPHA, // nzBlendFunc_DestAlpha - GL_DST_COLOR, // nzBlendFunc_DestColor - GL_SRC_ALPHA, // nzBlendFunc_SrcAlpha - GL_SRC_COLOR, // nzBlendFunc_SrcColor - GL_ONE_MINUS_DST_ALPHA, // nzBlendFunc_InvDestAlpha - GL_ONE_MINUS_DST_COLOR, // nzBlendFunc_InvDestColor - GL_ONE_MINUS_SRC_ALPHA, // nzBlendFunc_InvSrcAlpha - GL_ONE_MINUS_SRC_COLOR, // nzBlendFunc_InvSrcColor - GL_ONE, // nzBlendFunc_One - GL_ZERO // nzBlendFunc_Zero - }; - - const GLenum faceCullingMode[] = - { - GL_BACK, // nzFaceCulling_Back - GL_FRONT, // nzFaceCulling_Front - GL_FRONT_AND_BACK // nzFaceCulling_FrontAndBack - }; - - const GLenum faceFillingMode[] = - { - GL_POINT, // nzFaceFilling_Point - GL_LINE, // nzFaceFilling_Line - GL_FILL // nzFaceFilling_Fill - }; - - const GLenum openglPrimitive[] = - { - GL_LINES, // nzPrimitiveType_LineList, - GL_LINE_STRIP, // nzPrimitiveType_LineStrip, - GL_POINTS, // nzPrimitiveType_PointList, - GL_TRIANGLES, // nzPrimitiveType_TriangleList, - GL_TRIANGLE_STRIP, // nzPrimitiveType_TriangleStrip, - GL_TRIANGLE_FAN // nzPrimitiveType_TriangleFan - }; - - const nzUInt8 openglSize[] = - { - 4, // nzElementType_Color - 1, // nzElementType_Double1 - 2, // nzElementType_Double2 - 3, // nzElementType_Double3 - 4, // nzElementType_Double4 - 1, // nzElementType_Float1 - 2, // nzElementType_Float2 - 3, // nzElementType_Float3 - 4 // nzElementType_Float4 - }; - - const GLenum openglType[] = - { - GL_UNSIGNED_BYTE, // nzElementType_Color - GL_DOUBLE, // nzElementType_Double1 - GL_DOUBLE, // nzElementType_Double2 - GL_DOUBLE, // nzElementType_Double3 - GL_DOUBLE, // nzElementType_Double4 - GL_FLOAT, // nzElementType_Float1 - GL_FLOAT, // nzElementType_Float2 - GL_FLOAT, // nzElementType_Float3 - GL_FLOAT // nzElementType_Float4 - }; - - const GLenum rendererComparison[] = - { - GL_ALWAYS, // nzRendererComparison_Always - GL_EQUAL, // nzRendererComparison_Equal - GL_GREATER, // nzRendererComparison_Greater - GL_GEQUAL, // nzRendererComparison_GreaterOrEqual - GL_LESS, // nzRendererComparison_Less - GL_LEQUAL, // nzRendererComparison_LessOrEqual - GL_NEVER // nzRendererComparison_Never - }; - - const GLenum rendererParameter[] = - { - GL_BLEND, // nzRendererParameter_Blend - GL_NONE, // nzRendererParameter_ColorWrite - GL_DEPTH_TEST, // nzRendererParameter_DepthTest - GL_NONE, // nzRendererParameter_DepthWrite - GL_CULL_FACE, // nzRendererParameter_FaceCulling - GL_STENCIL_TEST // nzRendererParameter_Stencil - }; - - const GLenum stencilOperation[] = - { - GL_DECR, // nzStencilOperation_Decrement - GL_DECR_WRAP, // nzStencilOperation_DecrementToSaturation - GL_INCR, // nzStencilOperation_Increment - GL_INCR_WRAP, // nzStencilOperation_IncrementToSaturation - GL_INVERT, // nzStencilOperation_Invert - GL_KEEP, // nzStencilOperation_Keep - GL_REPLACE, // nzStencilOperation_Replace - GL_ZERO // nzStencilOperation_Zero - }; - - ///FIXME: Solution temporaire pour plus de facilité - enum nzMatrixCombination - { - nzMatrixCombination_ViewProj = nzMatrixType_Max+1, - nzMatrixCombination_WorldView, - nzMatrixCombination_WorldViewProj, - - nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj - }; - - NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type) - { - return new NzHardwareBuffer(parent, type); - } - - constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; - - using VAO_Key = std::tuple; - - std::map s_vaos; - NzMatrix4f s_matrix[totalMatrixCount]; - int s_matrixLocation[totalMatrixCount]; - bool s_matrixUpdated[totalMatrixCount]; - nzRendererComparison s_stencilCompare; - nzStencilOperation s_stencilFail; - nzStencilOperation s_stencilPass; - nzStencilOperation s_stencilZFail; - nzUInt32 s_stencilMask; - const NzIndexBuffer* s_indexBuffer; - NzRenderTarget* s_target; - NzShader* s_shader; - const NzVertexBuffer* s_vertexBuffer; - const NzVertexDeclaration* s_vertexDeclaration; - bool s_vaoUpdated; - bool s_capabilities[nzRendererCap_Max+1]; - bool s_stencilFuncUpdated; - bool s_stencilOpUpdated; - unsigned int s_maxAnisotropyLevel; - unsigned int s_maxRenderTarget; - unsigned int s_maxTextureUnit; - unsigned int s_stencilReference; -} - -void NzRenderer::Clear(unsigned long flags) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - if (flags) - { - GLenum mask = 0; - - if (flags & nzRendererClear_Color) - mask |= GL_COLOR_BUFFER_BIT; - - if (flags & nzRendererClear_Depth) - mask |= GL_DEPTH_BUFFER_BIT; - - if (flags & nzRendererClear_Stencil) - mask |= GL_STENCIL_BUFFER_BIT; - - glClear(mask); - } -} - -void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (!s_indexBuffer) - { - NazaraError("No index buffer"); - return; - } - #endif - - if (!EnsureStateUpdate()) - { - NazaraError("Failed to update states"); - return; - } - - if (s_indexBuffer->IsSequential()) - glDrawArrays(openglPrimitive[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount()); - else - { - nzUInt8 indexSize = s_indexBuffer->GetIndexSize(); - - GLenum type; - switch (indexSize) - { - case 1: - type = GL_UNSIGNED_BYTE; - break; - - case 2: - type = GL_UNSIGNED_SHORT; - break; - - case 4: - type = GL_UNSIGNED_INT; - break; - - default: - NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')'); - return; - } - - glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast(s_indexBuffer->GetPointer()) + firstIndex*indexSize); - } -} - -void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - if (!EnsureStateUpdate()) - { - NazaraError("Failed to update states"); - return; - } - - glDrawArrays(openglPrimitive[primitive], firstVertex, vertexCount); -} - -void NzRenderer::Enable(nzRendererParameter parameter, bool enable) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - switch (parameter) - { - case nzRendererParameter_ColorWrite: - glColorMask(enable, enable, enable, enable); - break; - - case nzRendererParameter_DepthWrite: - glDepthMask(enable); - break; - - default: - if (enable) - glEnable(rendererParameter[parameter]); - else - glDisable(rendererParameter[parameter]); - - break; - } -} -/* -NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination) -{ - switch (combination) - { - case nzMatrixCombination_ViewProj: - if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) - { - s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; - s_matrixUpdated[nzMatrixCombination_ViewProj] = true; - } - break; - - case nzMatrixCombination_WorldView: - if (!s_matrixUpdated[nzMatrixCombination_WorldView]) - { - s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); - s_matrixUpdated[nzMatrixCombination_WorldView] = true; - } - break; - - case nzMatrixCombination_WorldViewProj: - if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) - { - s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; - s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; - } - break; - } - - return m_matrix[combination]; -} -*/ -NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type) -{ - return s_matrix[type]; -} - -unsigned int NzRenderer::GetMaxAnisotropyLevel() -{ - return s_maxAnisotropyLevel; -} - -unsigned int NzRenderer::GetMaxRenderTargets() -{ - return s_maxRenderTarget; -} - -unsigned int NzRenderer::GetMaxTextureUnits() -{ - return s_maxTextureUnit; -} - -NzShader* NzRenderer::GetShader() -{ - return s_shader; -} - -NzRenderTarget* NzRenderer::GetTarget() -{ - return s_target; -} - -NzRectui NzRenderer::GetViewport() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return NzRectui(); - } - #endif - - GLint params[4]; - glGetIntegerv(GL_VIEWPORT, ¶ms[0]); - - return NzRectui(params[0], params[1], params[2], params[3]); -} - -bool NzRenderer::HasCapability(nzRendererCap capability) -{ - return s_capabilities[capability]; -} - -bool NzRenderer::Initialize() -{ - if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé - - // Initialisation des dépendances - if (!NzUtility::Initialize()) - { - NazaraError("Failed to initialize utility module"); - return false; - } - - // Initialisation du module - if (!NzOpenGL::Initialize()) - { - NazaraError("Failed to initialize OpenGL"); - return false; - } - - NzContext::EnsureContext(); - - for (unsigned int i = 0; i < totalMatrixCount; ++i) - { - s_matrix[i].MakeIdentity(); - s_matrixLocation[i] = -1; - s_matrixUpdated[i] = false; - } - - s_indexBuffer = nullptr; - s_shader = nullptr; - s_stencilCompare = nzRendererComparison_Always; - s_stencilFail = nzStencilOperation_Keep; - s_stencilFuncUpdated = true; - s_stencilMask = 0xFFFFFFFF; - s_stencilOpUpdated = true; - s_stencilPass = nzStencilOperation_Keep; - s_stencilReference = 0; - s_stencilZFail = nzStencilOperation_Keep; - s_target = nullptr; - s_vaoUpdated = false; - s_vertexBuffer = nullptr; - s_vertexDeclaration = nullptr; - - // Récupération des capacités - s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter); - s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64); - s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 - s_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0 - s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 - s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject); - s_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D); - s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 - s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 - s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0 - - if (s_capabilities[nzRendererCap_AnisotropicFilter]) - { - GLint maxAnisotropy; - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); - - s_maxAnisotropyLevel = static_cast(maxAnisotropy); - } - else - s_maxAnisotropyLevel = 1; - - if (s_capabilities[nzRendererCap_MultipleRenderTargets]) - { - GLint maxDrawBuffers; - glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); - - s_maxRenderTarget = static_cast(maxDrawBuffers); - } - else - s_maxRenderTarget = 1; - - if (s_capabilities[nzRendererCap_TextureMulti]) - { - GLint maxTextureUnits; - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); - - GLint maxVertexAttribs; - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); - - // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) - s_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord])); - } - else - s_maxTextureUnit = 1; - - NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); - - NazaraNotice("Initialized: Renderer module"); - - return true; -} - -bool NzRenderer::IsInitialized() -{ - return s_moduleReferenceCouter != 0; -} - -void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBlendFunc(blendFunc[src], blendFunc[dest]); -} - -void NzRenderer::SetClearColor(const NzColor& color) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearColor(color.r/255.f, color.g/255.f, color.b/255.f, color.a/255.f); -} - -void NzRenderer::SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearColor(r/255.f, g/255.f, b/255.f, a/255.f); -} - -void NzRenderer::SetClearDepth(double depth) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearDepth(depth); -} - -void NzRenderer::SetClearStencil(unsigned int value) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearStencil(value); -} - -void NzRenderer::SetFaceCulling(nzFaceCulling cullingMode) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glCullFace(faceCullingMode[cullingMode]); -} - -void NzRenderer::SetFaceFilling(nzFaceFilling fillingMode) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glPolygonMode(GL_FRONT_AND_BACK, faceFillingMode[fillingMode]); -} - -bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer) -{ - #if NAZARA_RENDERER_SAFE - if (indexBuffer && !indexBuffer->IsHardware() && !indexBuffer->IsSequential()) - { - NazaraError("Buffer must be hardware"); - return false; - } - #endif - - if (s_indexBuffer != indexBuffer) - { - s_indexBuffer = indexBuffer; - s_vaoUpdated = false; - } - - return true; -} - -void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix) -{ - s_matrix[type] = matrix; - - // Cas particulier, la matrice projection doit être inversée sur l'axe Y à cause des conventions d'OpenGL - if (type == nzMatrixType_Projection) - s_matrix[type] *= NzMatrix4f::Scale(NzVector3f(1.f, -1.f, 1.f)); - - // Invalidation des combinaisons - switch (type) - { - case nzMatrixType_View: - case nzMatrixType_World: - s_matrixUpdated[nzMatrixCombination_WorldView] = false; - case nzMatrixType_Projection: - s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false; - s_matrixUpdated[nzMatrixCombination_ViewProj] = false; - break; - } -} - -bool NzRenderer::SetShader(NzShader* shader) -{ - if (s_shader == shader) - return true; - - if (s_shader) - s_shader->m_impl->Unbind(); - - if (shader) - { - #if NAZARA_RENDERER_SAFE - if (!shader->IsCompiled()) - { - NazaraError("Shader is not compiled"); - shader = nullptr; - - return false; - } - #endif - - if (!shader->m_impl->Bind()) - { - NazaraError("Failed to bind shader"); - shader = nullptr; - - return false; - } - - // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) - s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix"); - s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix"); - s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix"); - - s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix"); - s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix"); - s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix"); - } - - s_shader = shader; - - return true; -} - -void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc) -{ - if (compareFunc != s_stencilCompare) - { - s_stencilCompare = compareFunc; - s_stencilFuncUpdated = false; - } -} - -void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation) -{ - if (failOperation != s_stencilFail) - { - s_stencilFail = failOperation; - s_stencilOpUpdated = false; - } -} - -void NzRenderer::SetStencilMask(nzUInt32 mask) -{ - if (mask != s_stencilMask) - { - s_stencilMask = mask; - s_stencilFuncUpdated = false; - } -} - -void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation) -{ - if (passOperation != s_stencilPass) - { - s_stencilPass = passOperation; - s_stencilOpUpdated = false; - } -} - -void NzRenderer::SetStencilReferenceValue(unsigned int refValue) -{ - if (refValue != s_stencilReference) - { - s_stencilReference = refValue; - s_stencilFuncUpdated = false; - } -} - -void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation) -{ - if (zfailOperation != s_stencilZFail) - { - s_stencilZFail = zfailOperation; - s_stencilOpUpdated = false; - } -} - -bool NzRenderer::SetTarget(NzRenderTarget* target) -{ - if (s_target == target) - return true; - - if (s_target && !target->HasContext()) - s_target->Desactivate(); - - if (target) - { - #if NAZARA_RENDERER_SAFE - if (!target->IsValid()) - { - NazaraError("Target not valid"); - return false; - } - #endif - - if (target->Activate()) - s_target = target; - else - { - NazaraError("Failed to activate target"); - s_target = nullptr; - - return false; - } - } - else - s_target = nullptr; - - return true; -} - -bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) -{ - #if NAZARA_RENDERER_SAFE - if (vertexBuffer && !vertexBuffer->IsHardware()) - { - NazaraError("Buffer must be hardware"); - return false; - } - #endif - - if (s_vertexBuffer != vertexBuffer) - { - s_vertexBuffer = vertexBuffer; - s_vaoUpdated = false; - } - - return true; -} - -bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration) -{ - if (s_vertexDeclaration != vertexDeclaration) - { - s_vertexDeclaration = vertexDeclaration; - s_vaoUpdated = false; - } - - return true; -} - -void NzRenderer::SetViewport(const NzRectui& viewport) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - unsigned int height = s_target->GetHeight(); - - #if NAZARA_RENDERER_SAFE - if (!s_target) - { - NazaraError("Renderer has no target"); - return; - } - - unsigned int width = s_target->GetWidth(); - if (viewport.x+viewport.width > width || viewport.y+viewport.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return; - } - #endif - - glViewport(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); - glScissor(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); -} - -void NzRenderer::Uninitialize() -{ - if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé - - // Libération du module - NzContext::EnsureContext(); - - // Libération des VAOs - for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it) - { - GLuint vao = static_cast(it->second); - glDeleteVertexArrays(1, &vao); - } - - NzOpenGL::Uninitialize(); - - NazaraNotice("Uninitialized: Renderer module"); - - // Libération des dépendances - NzUtility::Uninitialize(); -} - -bool NzRenderer::EnsureStateUpdate() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return false; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (!s_shader) - { - NazaraError("No shader"); - return false; - } - #endif - - // Il est plus rapide d'opérer sur l'implémentation du shader directement - NzShaderImpl* shaderImpl = s_shader->m_impl; - - if (!shaderImpl->BindTextures()) - NazaraWarning("Failed to bind textures"); - - for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) - { - if (!s_matrixUpdated[i]) - { - shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]); - s_matrixUpdated[i] = true; - } - } - - // Cas spéciaux car il faut recalculer la matrice - if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) - { - s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; - - shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]); - s_matrixUpdated[nzMatrixCombination_ViewProj] = true; - } - - if (!s_matrixUpdated[nzMatrixCombination_WorldView]) - { - s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); - - shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]); - s_matrixUpdated[nzMatrixCombination_WorldView] = true; - } - - if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) - { - s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; - - shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]); - s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; - } - - if (!s_stencilFuncUpdated) - { - glStencilFunc(rendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask); - s_stencilFuncUpdated = true; - } - - if (!s_stencilOpUpdated) - { - glStencilOp(stencilOperation[s_stencilFail], stencilOperation[s_stencilZFail], stencilOperation[s_stencilPass]); - s_stencilOpUpdated = true; - } - - if (!s_vaoUpdated) - { - #if NAZARA_RENDERER_SAFE - if (!s_vertexBuffer) - { - NazaraError("No vertex buffer"); - return false; - } - - if (!s_vertexDeclaration) - { - NazaraError("No vertex declaration"); - return false; - } - #endif - - static const bool vaoSupported = NzOpenGL::IsSupported(NzOpenGL::VertexArrayObject); - bool update; - GLuint vao; - - // Si les VAOs sont supportés, on entoure nos appels par ceux-ci - if (vaoSupported) - { - // On recherche si un VAO existe déjà avec notre configuration - // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration - - auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration); - auto it = s_vaos.find(key); - if (it == s_vaos.end()) - { - // On créé notre VAO - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - // On l'ajoute à notre liste - s_vaos.insert(std::make_pair(key, static_cast(vao))); - - // Et on indique qu'on veut le programmer - update = true; - } - else - { - // Notre VAO existe déjà, il est donc inutile de le reprogrammer - vao = it->second; - - update = false; - } - } - else - update = true; // Fallback si les VAOs ne sont pas supportés - - if (update) - { - NzHardwareBuffer* vertexBufferImpl = static_cast(s_vertexBuffer->GetBuffer()->GetImpl()); - vertexBufferImpl->Bind(); - - const nzUInt8* buffer = reinterpret_cast(s_vertexBuffer->GetPointer()); - - unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData); - for (unsigned int i = 0; i <= nzElementUsage_Max; ++i) - { - const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast(i)); - - if (element) - { - glEnableVertexAttribArray(attribIndex[i]); - glVertexAttribPointer(attribIndex[i], - openglSize[element->type], - openglType[element->type], - (element->type == nzElementType_Color) ? GL_TRUE : GL_FALSE, - stride, - &buffer[element->offset]); - } - else - glDisableVertexAttribArray(attribIndex[i]); - } - - if (s_indexBuffer) - { - NzHardwareBuffer* indexBufferImpl = static_cast(s_indexBuffer->GetBuffer()->GetImpl()); - indexBufferImpl->Bind(); - } - } - - if (vaoSupported) - { - // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction - if (update) - glBindVertexArray(0); - - // Nous (re)bindons le VAO pour définir les attributs de vertice - glBindVertexArray(vao); - } - - s_vaoUpdated = true; - } - - return true; -} - -unsigned int NzRenderer::s_moduleReferenceCouter = 0; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include // Pour éviter une redéfinition de WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + ///FIXME: Solution temporaire pour plus de facilité + enum nzMatrixCombination + { + nzMatrixCombination_ViewProj = nzMatrixType_Max+1, + nzMatrixCombination_WorldView, + nzMatrixCombination_WorldViewProj, + + nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj + }; + + NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type) + { + return new NzHardwareBuffer(parent, type); + } + + constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; + + using VAO_Key = std::tuple; + + std::map s_vaos; + NzMatrix4f s_matrix[totalMatrixCount]; + int s_matrixLocation[totalMatrixCount]; + bool s_matrixUpdated[totalMatrixCount]; + nzRendererComparison s_stencilCompare; + nzStencilOperation s_stencilFail; + nzStencilOperation s_stencilPass; + nzStencilOperation s_stencilZFail; + nzUInt32 s_stencilMask; + const NzIndexBuffer* s_indexBuffer; + NzRenderTarget* s_target; + NzShader* s_shader; + const NzVertexBuffer* s_vertexBuffer; + const NzVertexDeclaration* s_vertexDeclaration; + bool s_vaoUpdated; + bool s_capabilities[nzRendererCap_Max+1]; + bool s_stencilFuncUpdated; + bool s_stencilOpUpdated; + unsigned int s_maxAnisotropyLevel; + unsigned int s_maxRenderTarget; + unsigned int s_maxTextureUnit; + unsigned int s_stencilReference; +} + +void NzRenderer::Clear(unsigned long flags) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + if (flags) + { + GLenum mask = 0; + + if (flags & nzRendererClear_Color) + mask |= GL_COLOR_BUFFER_BIT; + + if (flags & nzRendererClear_Depth) + mask |= GL_DEPTH_BUFFER_BIT; + + if (flags & nzRendererClear_Stencil) + mask |= GL_STENCIL_BUFFER_BIT; + + glClear(mask); + } +} + +void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (!s_indexBuffer) + { + NazaraError("No index buffer"); + return; + } + #endif + + if (!EnsureStateUpdate()) + { + NazaraError("Failed to update states"); + return; + } + + if (s_indexBuffer->IsSequential()) + glDrawArrays(NzOpenGL::PrimitiveType[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount()); + else + { + nzUInt8 indexSize = s_indexBuffer->GetIndexSize(); + + GLenum type; + switch (indexSize) + { + case 1: + type = GL_UNSIGNED_BYTE; + break; + + case 2: + type = GL_UNSIGNED_SHORT; + break; + + case 4: + type = GL_UNSIGNED_INT; + break; + + default: + NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')'); + return; + } + + glDrawElements(NzOpenGL::PrimitiveType[primitive], indexCount, type, reinterpret_cast(s_indexBuffer->GetPointer()) + firstIndex*indexSize); + } +} + +void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + if (!EnsureStateUpdate()) + { + NazaraError("Failed to update states"); + return; + } + + glDrawArrays(NzOpenGL::PrimitiveType[primitive], firstVertex, vertexCount); +} + +void NzRenderer::Enable(nzRendererParameter parameter, bool enable) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + switch (parameter) + { + case nzRendererParameter_ColorWrite: + glColorMask(enable, enable, enable, enable); + break; + + case nzRendererParameter_DepthWrite: + glDepthMask(enable); + break; + + default: + if (enable) + glEnable(NzOpenGL::RendererParameter[parameter]); + else + glDisable(NzOpenGL::RendererParameter[parameter]); + + break; + } +} +/* +NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination) +{ + ///FIXME: Duplication + switch (combination) + { + case nzMatrixCombination_ViewProj: + if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) + { + s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; + s_matrixUpdated[nzMatrixCombination_ViewProj] = true; + } + break; + + case nzMatrixCombination_WorldView: + if (!s_matrixUpdated[nzMatrixCombination_WorldView]) + { + s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); + s_matrixUpdated[nzMatrixCombination_WorldView] = true; + } + break; + + case nzMatrixCombination_WorldViewProj: + if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) + { + s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; + } + break; + } + + return m_matrix[combination]; +} +*/ +NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type) +{ + return s_matrix[type]; +} + +unsigned int NzRenderer::GetMaxAnisotropyLevel() +{ + return s_maxAnisotropyLevel; +} + +unsigned int NzRenderer::GetMaxRenderTargets() +{ + return s_maxRenderTarget; +} + +unsigned int NzRenderer::GetMaxTextureUnits() +{ + return s_maxTextureUnit; +} + +NzShader* NzRenderer::GetShader() +{ + return s_shader; +} + +NzRenderTarget* NzRenderer::GetTarget() +{ + return s_target; +} + +NzRectui NzRenderer::GetViewport() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return NzRectui(); + } + #endif + + GLint params[4]; + glGetIntegerv(GL_VIEWPORT, ¶ms[0]); + + return NzRectui(params[0], params[1], params[2], params[3]); +} + +bool NzRenderer::HasCapability(nzRendererCap capability) +{ + return s_capabilities[capability]; +} + +bool NzRenderer::Initialize() +{ + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation des dépendances + if (!NzUtility::Initialize()) + { + NazaraError("Failed to initialize utility module"); + return false; + } + + // Initialisation du module + if (!NzOpenGL::Initialize()) + { + NazaraError("Failed to initialize OpenGL"); + return false; + } + + NzContext::EnsureContext(); + + for (unsigned int i = 0; i < totalMatrixCount; ++i) + { + s_matrix[i].MakeIdentity(); + s_matrixLocation[i] = -1; + s_matrixUpdated[i] = false; + } + + s_indexBuffer = nullptr; + s_shader = nullptr; + s_stencilCompare = nzRendererComparison_Always; + s_stencilFail = nzStencilOperation_Keep; + s_stencilFuncUpdated = true; + s_stencilMask = 0xFFFFFFFF; + s_stencilOpUpdated = true; + s_stencilPass = nzStencilOperation_Keep; + s_stencilReference = 0; + s_stencilZFail = nzStencilOperation_Keep; + s_target = nullptr; + s_vaoUpdated = false; + s_vertexBuffer = nullptr; + s_vertexDeclaration = nullptr; + + // Récupération des capacités d'OpenGL + s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter); + s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(nzOpenGLExtension_FP64); + s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 + // MultipleRenderTargets (Techniquement natif depuis OpenGL 2.0 mais inutile sans glBindFragDataLocation) + s_capabilities[nzRendererCap_MultipleRenderTargets] = (glBindFragDataLocation != nullptr); + s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 + s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(nzOpenGLExtension_PixelBufferObject); + s_capabilities[nzRendererCap_RenderTexture] = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); + s_capabilities[nzRendererCap_Texture3D] = true; // Natif depuis OpenGL 1.2 + s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 + s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 + s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0 + + if (s_capabilities[nzRendererCap_AnisotropicFilter]) + { + GLint maxAnisotropy; + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); + + s_maxAnisotropyLevel = static_cast(maxAnisotropy); + } + else + s_maxAnisotropyLevel = 1; + + if (s_capabilities[nzRendererCap_MultipleRenderTargets]) + { + GLint maxDrawBuffers; + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); + + GLint maxColorAttachments; + glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); + + s_maxRenderTarget = static_cast(std::min(maxColorAttachments, maxDrawBuffers)); + } + else + s_maxRenderTarget = 1; + + if (s_capabilities[nzRendererCap_TextureMulti]) + { + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + + GLint maxVertexAttribs; + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); + + // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) + s_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-NzOpenGL::AttributeIndex[nzElementUsage_TexCoord])); + } + else + s_maxTextureUnit = 1; + + NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); + + NazaraNotice("Initialized: Renderer module"); + + return true; +} + +bool NzRenderer::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + +void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glBlendFunc(NzOpenGL::BlendFunc[src], NzOpenGL::BlendFunc[dest]); +} + +void NzRenderer::SetClearColor(const NzColor& color) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearColor(color.r/255.f, color.g/255.f, color.b/255.f, color.a/255.f); +} + +void NzRenderer::SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearColor(r/255.f, g/255.f, b/255.f, a/255.f); +} + +void NzRenderer::SetClearDepth(double depth) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearDepth(depth); +} + +void NzRenderer::SetClearStencil(unsigned int value) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearStencil(value); +} + +void NzRenderer::SetFaceCulling(nzFaceCulling cullingMode) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glCullFace(NzOpenGL::FaceCulling[cullingMode]); +} + +void NzRenderer::SetFaceFilling(nzFaceFilling fillingMode) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glPolygonMode(GL_FRONT_AND_BACK, NzOpenGL::FaceFilling[fillingMode]); +} + +bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer) +{ + #if NAZARA_RENDERER_SAFE + if (indexBuffer && !indexBuffer->IsHardware() && !indexBuffer->IsSequential()) + { + NazaraError("Buffer must be hardware"); + return false; + } + #endif + + if (s_indexBuffer != indexBuffer) + { + s_indexBuffer = indexBuffer; + s_vaoUpdated = false; + } + + return true; +} + +void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix) +{ + s_matrix[type] = matrix; + + // Invalidation des combinaisons + switch (type) + { + case nzMatrixType_View: + case nzMatrixType_World: + s_matrixUpdated[nzMatrixCombination_WorldView] = false; + case nzMatrixType_Projection: + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false; + s_matrixUpdated[nzMatrixCombination_ViewProj] = false; + break; + } +} + +bool NzRenderer::SetShader(NzShader* shader) +{ + if (s_shader == shader) + return true; + + if (s_shader) + s_shader->m_impl->Unbind(); + + if (shader) + { + #if NAZARA_RENDERER_SAFE + if (!shader->IsCompiled()) + { + NazaraError("Shader is not compiled"); + shader = nullptr; + + return false; + } + #endif + + if (!shader->m_impl->Bind()) + { + NazaraError("Failed to bind shader"); + shader = nullptr; + + return false; + } + + // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) + s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix"); + s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix"); + s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix"); + + s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix"); + s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix"); + s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix"); + } + + s_shader = shader; + + return true; +} + +void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc) +{ + if (compareFunc != s_stencilCompare) + { + s_stencilCompare = compareFunc; + s_stencilFuncUpdated = false; + } +} + +void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation) +{ + if (failOperation != s_stencilFail) + { + s_stencilFail = failOperation; + s_stencilOpUpdated = false; + } +} + +void NzRenderer::SetStencilMask(nzUInt32 mask) +{ + if (mask != s_stencilMask) + { + s_stencilMask = mask; + s_stencilFuncUpdated = false; + } +} + +void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation) +{ + if (passOperation != s_stencilPass) + { + s_stencilPass = passOperation; + s_stencilOpUpdated = false; + } +} + +void NzRenderer::SetStencilReferenceValue(unsigned int refValue) +{ + if (refValue != s_stencilReference) + { + s_stencilReference = refValue; + s_stencilFuncUpdated = false; + } +} + +void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation) +{ + if (zfailOperation != s_stencilZFail) + { + s_stencilZFail = zfailOperation; + s_stencilOpUpdated = false; + } +} + +bool NzRenderer::SetTarget(NzRenderTarget* target) +{ + if (s_target == target) + return true; + + if (s_target && !s_target->HasContext()) + s_target->Desactivate(); + + if (target) + { + #if NAZARA_RENDERER_SAFE + if (!target->IsRenderable()) + { + NazaraError("Target not renderable"); + return false; + } + #endif + + if (target->Activate()) + s_target = target; + else + { + NazaraError("Failed to activate target"); + s_target = nullptr; + + return false; + } + } + else + s_target = nullptr; + + return true; +} + +bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) +{ + #if NAZARA_RENDERER_SAFE + if (vertexBuffer && !vertexBuffer->IsHardware()) + { + NazaraError("Buffer must be hardware"); + return false; + } + #endif + + if (s_vertexBuffer != vertexBuffer) + { + s_vertexBuffer = vertexBuffer; + s_vaoUpdated = false; + } + + return true; +} + +bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration) +{ + if (s_vertexDeclaration != vertexDeclaration) + { + s_vertexDeclaration = vertexDeclaration; + s_vaoUpdated = false; + } + + return true; +} + +void NzRenderer::SetViewport(const NzRectui& viewport) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + unsigned int height = s_target->GetHeight(); + + #if NAZARA_RENDERER_SAFE + if (!s_target) + { + NazaraError("Renderer has no target"); + return; + } + + unsigned int width = s_target->GetWidth(); + if (viewport.x+viewport.width > width || viewport.y+viewport.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return; + } + #endif + + glViewport(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); + glScissor(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); +} + +void NzRenderer::Uninitialize() +{ + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé + + // Libération du module + NzContext::EnsureContext(); + + // Libération des VAOs + for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it) + { + GLuint vao = static_cast(it->second); + glDeleteVertexArrays(1, &vao); + } + + NzOpenGL::Uninitialize(); + + NazaraNotice("Uninitialized: Renderer module"); + + // Libération des dépendances + NzUtility::Uninitialize(); +} + +bool NzRenderer::EnsureStateUpdate() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return false; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (!s_shader) + { + NazaraError("No shader"); + return false; + } + #endif + + // Il est plus rapide d'opérer sur l'implémentation du shader directement + NzShaderImpl* shaderImpl = s_shader->m_impl; + + if (!shaderImpl->BindTextures()) + NazaraWarning("Failed to bind textures"); + + for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) + { + if (!s_matrixUpdated[i]) + { + shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]); + s_matrixUpdated[i] = true; + } + } + + // Cas spéciaux car il faut recalculer la matrice + if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) + { + s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]); + s_matrixUpdated[nzMatrixCombination_ViewProj] = true; + } + + if (!s_matrixUpdated[nzMatrixCombination_WorldView]) + { + s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]); + s_matrixUpdated[nzMatrixCombination_WorldView] = true; + } + + if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) + { + s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]); + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; + } + + if (!s_stencilFuncUpdated) + { + glStencilFunc(NzOpenGL::RendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask); + s_stencilFuncUpdated = true; + } + + if (!s_stencilOpUpdated) + { + glStencilOp(NzOpenGL::StencilOperation[s_stencilFail], NzOpenGL::StencilOperation[s_stencilZFail], NzOpenGL::StencilOperation[s_stencilPass]); + s_stencilOpUpdated = true; + } + + if (!s_vaoUpdated) + { + #if NAZARA_RENDERER_SAFE + if (!s_vertexBuffer) + { + NazaraError("No vertex buffer"); + return false; + } + + if (!s_vertexDeclaration) + { + NazaraError("No vertex declaration"); + return false; + } + #endif + + static const bool vaoSupported = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObject); + bool update; + GLuint vao; + + // Si les VAOs sont supportés, on entoure nos appels par ceux-ci + if (vaoSupported) + { + // On recherche si un VAO existe déjà avec notre configuration + // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration + + auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration); + auto it = s_vaos.find(key); + if (it == s_vaos.end()) + { + // On créé notre VAO + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + // On l'ajoute à notre liste + s_vaos.insert(std::make_pair(key, static_cast(vao))); + + // Et on indique qu'on veut le programmer + update = true; + } + else + { + // Notre VAO existe déjà, il est donc inutile de le reprogrammer + vao = it->second; + + update = false; + } + } + else + update = true; // Fallback si les VAOs ne sont pas supportés + + if (update) + { + NzHardwareBuffer* vertexBufferImpl = static_cast(s_vertexBuffer->GetBuffer()->GetImpl()); + vertexBufferImpl->Bind(); + + const nzUInt8* buffer = reinterpret_cast(s_vertexBuffer->GetPointer()); + + unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData); + for (unsigned int i = 0; i <= nzElementUsage_Max; ++i) + { + const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast(i)); + + if (element) + { + glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + glVertexAttribPointer(NzOpenGL::AttributeIndex[i], + NzVertexDeclaration::GetElementCount(element->type), + NzOpenGL::ElementType[element->type], + (element->type == nzElementType_Color) ? GL_TRUE : GL_FALSE, + stride, + &buffer[element->offset]); + } + else + glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + } + + if (s_indexBuffer) + { + NzHardwareBuffer* indexBufferImpl = static_cast(s_indexBuffer->GetBuffer()->GetImpl()); + indexBufferImpl->Bind(); + } + } + + if (vaoSupported) + { + // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction + if (update) + glBindVertexArray(0); + + // Nous (re)bindons le VAO pour définir les attributs de vertice + glBindVertexArray(vao); + } + + s_vaoUpdated = true; + } + + return true; +} + +unsigned int NzRenderer::s_moduleReferenceCouter = 0; diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index fff9f9fd7..a6be23090 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -1,624 +1,627 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -NzShader::NzShader(nzShaderLanguage language) -{ - Create(language); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create shader"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzShader::~NzShader() -{ - Destroy(); -} - -bool NzShader::Create(nzShaderLanguage language) -{ - Destroy(); - - switch (language) - { - case nzShaderLanguage_Cg: - NazaraError("Cg support is not implemented yet"); - return false; - - case nzShaderLanguage_GLSL: - m_impl = new NzGLSLShader(this); - break; - - default: - NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); - return false; - } - - if (!m_impl->Create()) - { - NazaraError("Failed to create shader"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - return true; -} - -bool NzShader::Compile() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - if (m_impl->Compile()) - { - m_compiled = true; - return true; - } - else - return false; -} - -void NzShader::Destroy() -{ - if (m_impl) - { - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - } -} - -NzString NzShader::GetLog() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NzString error = "Shader not created"; - NazaraError(error); - - return error; - } - #endif - - return m_impl->GetLog(); -} - -nzShaderLanguage NzShader::GetLanguage() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NzString error = "Shader not created"; - NazaraError(error); - - return nzShaderLanguage_Unknown; - } - #endif - - return m_impl->GetLanguage(); -} - -NzString NzShader::GetSourceCode(nzShaderType type) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NzString error = "Shader not created"; - NazaraError(error); - - return error; - } - - if (!IsTypeSupported(type)) - { - NzString error = "Shader type not supported"; - NazaraError(error); - - return error; - } - - if (!m_impl->IsLoaded(type)) - { - NzString error = "Shader not loaded"; - NazaraError(error); - - return error; - } - #endif - - return m_impl->GetSourceCode(type); -} - -int NzShader::GetUniformLocation(const NzString& name) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_impl->GetUniformLocation(name); -} - -bool NzShader::HasUniform(const NzString& name) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_impl->GetUniformLocation(name) != -1; -} - -bool NzShader::IsCompiled() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_compiled; -} - -bool NzShader::IsLoaded(nzShaderType type) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!IsTypeSupported(type)) - { - NazaraError("Shader type not supported"); - return false; - } - #endif - - return m_impl->IsLoaded(type); -} - -bool NzShader::Load(nzShaderType type, const NzString& source) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!IsTypeSupported(type)) - { - NazaraError("Shader type not supported"); - return false; - } - - if (source.IsEmpty()) - { - NazaraError("Empty source code"); - return false; - } - - if (m_impl->IsLoaded(type)) - { - NazaraError("Shader already loaded"); - return false; - } - #endif - - return m_impl->Load(type, source); -} - -bool NzShader::LoadFromFile(nzShaderType type, const NzString& filePath) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!IsTypeSupported(type)) - { - NazaraError("Shader type not supported"); - return false; - } - - if (m_impl->IsLoaded(type)) - { - NazaraError("Shader already loaded"); - return false; - } - #endif - - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly | NzFile::Text)) - { - NazaraError("Failed to open \"" + filePath + '"'); - return false; - } - - unsigned int length = file.GetSize(); - - NzString source; - source.Resize(length); - - if (file.Read(&source[0], length) != length) - { - NazaraError("Failed to read shader file"); - return false; - } - - file.Close(); - - return m_impl->Load(type, source); -} - -bool NzShader::Lock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_impl->Lock(); -} - -bool NzShader::SendBoolean(int location, bool value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendBoolean(location, value); -} - -bool NzShader::SendDouble(int location, double value) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendDouble(location, value); -} - -bool NzShader::SendFloat(int location, float value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendFloat(location, value); -} - -bool NzShader::SendInteger(int location, int value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendInteger(location, value); -} - -bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendMatrix(location, matrix); -} - -bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendMatrix(location, matrix); -} - -bool NzShader::SendTexture(int location, const NzTexture* texture) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendTexture(location, texture); -} - -bool NzShader::SendVector(int location, const NzVector2d& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector2f& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector3d& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector3f& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector4d& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector4f& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -void NzShader::Unlock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return; - } - #endif - - return m_impl->Unlock(); -} - -bool NzShader::IsLanguageSupported(nzShaderLanguage language) -{ - switch (language) - { - case nzShaderLanguage_Cg: - return false; // ?? - - case nzShaderLanguage_GLSL: - return true; - - default: - NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); - return false; - } -} - -bool NzShader::IsTypeSupported(nzShaderType type) -{ - switch (type) - { - case nzShaderType_Fragment: - case nzShaderType_Vertex: - return true; - - case nzShaderType_Geometry: - return false; // ?? - - default: - NazaraError("Shader type not handled (0x" + NzString::Number(type, 16) + ')'); - return false; - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +NzShader::NzShader(nzShaderLanguage language) +{ + Create(language); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create shader"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzShader::~NzShader() +{ + Destroy(); +} + +bool NzShader::Create(nzShaderLanguage language) +{ + Destroy(); + + switch (language) + { + case nzShaderLanguage_Cg: + NazaraError("Cg support is not implemented yet"); + return false; + + case nzShaderLanguage_GLSL: + m_impl = new NzGLSLShader(this); + break; + + default: + NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); + return false; + } + + if (!m_impl->Create()) + { + NazaraError("Failed to create shader"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + NotifyCreated(); + return true; +} + +bool NzShader::Compile() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + if (m_impl->Compile()) + { + m_compiled = true; + return true; + } + else + return false; +} + +void NzShader::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + } +} + +NzString NzShader::GetLog() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NzString error = "Shader not created"; + NazaraError(error); + + return error; + } + #endif + + return m_impl->GetLog(); +} + +nzShaderLanguage NzShader::GetLanguage() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NzString error = "Shader not created"; + NazaraError(error); + + return nzShaderLanguage_Unknown; + } + #endif + + return m_impl->GetLanguage(); +} + +NzString NzShader::GetSourceCode(nzShaderType type) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NzString error = "Shader not created"; + NazaraError(error); + + return error; + } + + if (!IsTypeSupported(type)) + { + NzString error = "Shader type not supported"; + NazaraError(error); + + return error; + } + + if (!m_impl->IsLoaded(type)) + { + NzString error = "Shader not loaded"; + NazaraError(error); + + return error; + } + #endif + + return m_impl->GetSourceCode(type); +} + +int NzShader::GetUniformLocation(const NzString& name) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->GetUniformLocation(name); +} + +bool NzShader::HasUniform(const NzString& name) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->GetUniformLocation(name) != -1; +} + +bool NzShader::IsCompiled() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_compiled; +} + +bool NzShader::IsLoaded(nzShaderType type) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (!IsTypeSupported(type)) + { + NazaraError("Shader type not supported"); + return false; + } + #endif + + return m_impl->IsLoaded(type); +} + +bool NzShader::Load(nzShaderType type, const NzString& source) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (!IsTypeSupported(type)) + { + NazaraError("Shader type not supported"); + return false; + } + + if (source.IsEmpty()) + { + NazaraError("Empty source code"); + return false; + } + + if (m_impl->IsLoaded(type)) + { + NazaraError("Shader already loaded"); + return false; + } + #endif + + return m_impl->Load(type, source); +} + +bool NzShader::LoadFromFile(nzShaderType type, const NzString& filePath) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (!IsTypeSupported(type)) + { + NazaraError("Shader type not supported"); + return false; + } + + if (m_impl->IsLoaded(type)) + { + NazaraError("Shader already loaded"); + return false; + } + #endif + + NzFile file(filePath); + if (!file.Open(NzFile::ReadOnly | NzFile::Text)) + { + NazaraError("Failed to open \"" + filePath + '"'); + return false; + } + + unsigned int length = file.GetSize(); + + NzString source; + source.Resize(length); + + if (file.Read(&source[0], length) != length) + { + NazaraError("Failed to read shader file"); + return false; + } + + file.Close(); + + return m_impl->Load(type, source); +} + +bool NzShader::Lock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->Lock(); +} + +bool NzShader::SendBoolean(int location, bool value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendBoolean(location, value); +} + +bool NzShader::SendDouble(int location, double value) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendDouble(location, value); +} + +bool NzShader::SendFloat(int location, float value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendFloat(location, value); +} + +bool NzShader::SendInteger(int location, int value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendInteger(location, value); +} + +bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendMatrix(location, matrix); +} + +bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendMatrix(location, matrix); +} + +bool NzShader::SendTexture(int location, const NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendTexture(location, texture); +} + +bool NzShader::SendVector(int location, const NzVector2d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector2f& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector3d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector3f& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector4d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector4f& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +void NzShader::Unlock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return; + } + #endif + + return m_impl->Unlock(); +} + +bool NzShader::IsLanguageSupported(nzShaderLanguage language) +{ + switch (language) + { + case nzShaderLanguage_Cg: + return false; //FIXME: ?? + + case nzShaderLanguage_GLSL: + return true; + + default: + NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); + return false; + } +} + +bool NzShader::IsTypeSupported(nzShaderType type) +{ + switch (type) + { + case nzShaderType_Fragment: + case nzShaderType_Vertex: + return true; + + case nzShaderType_Geometry: + return false; // ?? + + default: + NazaraError("Shader type not handled (0x" + NzString::Number(type, 16) + ')'); + return false; + } +} diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 7c829ff44..792990f6d 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -1,1630 +1,1556 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -struct NzTextureImpl -{ - GLuint id; - nzImageType type; - nzPixelFormat format; - nzUInt8 levelCount; - bool isTarget = false; - bool mipmapping = false; - bool mipmapsUpdated = true; - unsigned int depth; - unsigned int height; - unsigned int width; -}; - -namespace -{ - GLenum cubemapFace[] = - { - GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX - GL_TEXTURE_CUBE_MAP_NEGATIVE_X, // nzCubemapFace_NegativeX - GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // nzCubemapFace_PositiveY - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // nzCubemapFace_NegativeY - GL_TEXTURE_CUBE_MAP_POSITIVE_Z, // nzCubemapFace_PositiveZ - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z // nzCubemapFace_NegativeZ - }; - - GLenum openglTarget[] = - { - GL_TEXTURE_1D, // nzImageType_1D - GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array - GL_TEXTURE_2D, // nzImageType_2D - GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array - GL_TEXTURE_3D, // nzImageType_3D - GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap - }; - - GLenum openglTargetBinding[] = - { - GL_TEXTURE_BINDING_1D, // nzImageType_1D - GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D - GL_TEXTURE_BINDING_2D, // nzImageType_2D - GL_TEXTURE_BINDING_3D, // nzImageType_3D - GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap - }; - - GLenum openglTargetProxy[] = - { - GL_PROXY_TEXTURE_1D, // nzImageType_1D - GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array - GL_PROXY_TEXTURE_2D, // nzImageType_2D - GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array - GL_PROXY_TEXTURE_3D, // nzImageType_3D - GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap - }; - - struct OpenGLFormat - { - GLint internalFormat; - GLenum dataFormat; - GLenum dataType; - }; - - bool GetOpenGLFormat(nzPixelFormat pixelFormat, OpenGLFormat* format) - { - switch (pixelFormat) - { - case nzPixelFormat_BGR8: - format->dataFormat = GL_BGR; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGB8; - return true; - - case nzPixelFormat_BGRA8: - format->dataFormat = GL_BGRA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGBA8; - return true; - - case nzPixelFormat_DXT1: - format->dataFormat = GL_RGB; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - return true; - - case nzPixelFormat_DXT3: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - return true; - - case nzPixelFormat_DXT5: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - return true; - - case nzPixelFormat_L8: - case nzPixelFormat_LA8: - NazaraError("Pixel format not supported"); - return false; - - case nzPixelFormat_RGB5A1: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_SHORT_5_5_5_1; - format->internalFormat = GL_RGB5_A1; - return true; - - case nzPixelFormat_RGB8: - format->dataFormat = GL_RGB; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGB8; - return true; - - case nzPixelFormat_RGBA4: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_SHORT_4_4_4_4; - format->internalFormat = GL_RGBA4; - return true; - - case nzPixelFormat_RGBA8: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGBA8; - return true; - - case nzPixelFormat_Undefined: - NazaraInternalError("Invalid pixel format"); - return false; - } - - NazaraError("Pixel format not handled"); - - return false; - } - - bool CreateTexture(NzTextureImpl* impl, bool proxy) - { - OpenGLFormat openGLFormat; - if (!GetOpenGLFormat(impl->format, &openGLFormat)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - GLenum target = (proxy) ? openglTargetProxy[impl->type] : openglTarget[impl->type]; - GLint previous; - glGetIntegerv(openglTargetBinding[impl->type], &previous); - switch (impl->type) - { - case nzImageType_1D: - { - if (glTexStorage1D) - glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width); - else - { - unsigned int w = impl->width; - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - glTexImage1D(target, level, openGLFormat.internalFormat, w, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - if (w > 1U) - w >>= 1; - } - } - break; - } - - case nzImageType_1D_Array: - case nzImageType_2D: - { - if (glTexStorage2D) - glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); - else - { - unsigned int w = impl->width; - unsigned int h = impl->height; - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - glTexImage2D(target, level, openGLFormat.internalFormat, w, h, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - if (w > 1U) - w >>= 1; - - if (h > 1U) - h >>= 1; - } - } - break; - } - - case nzImageType_2D_Array: - case nzImageType_3D: - { - if (glTexStorage3D) - glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth); - else - { - unsigned int w = impl->width; - unsigned int h = impl->height; - unsigned int d = impl->depth; - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - glTexImage3D(target, level, openGLFormat.internalFormat, w, h, d, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - if (w > 1U) - w >>= 1; - - if (h > 1U) - h >>= 1; - - if (d > 1U) - d >>= 1; - } - } - break; - } - - case nzImageType_Cubemap: - { - if (glTexStorage2D) - glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); - else - { - unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - for (GLenum face : cubemapFace) - glTexImage2D(face, level, openGLFormat.internalFormat, size, size, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - - if (size > 1U) - size >>= 1; - } - } - break; - } - } - - if (proxy) - { - GLint internalFormat = 0; - glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); - if (internalFormat == 0) - return false; - } - - return true; - } - - static unsigned short lockedLevel[nzImageType_Max+1] = {0}; - static GLuint lockedPrevious[nzImageType_Max+1] = {0}; - - void LockTexture(NzTextureImpl* impl) - { - if (lockedLevel[impl->type]++ == 0) - { - NzContext::EnsureContext(); - - GLint previous; - glGetIntegerv(openglTargetBinding[impl->type], &previous); - - lockedPrevious[impl->type] = static_cast(previous); - - if (lockedPrevious[impl->type] != impl->id) - glBindTexture(openglTarget[impl->type], impl->id); - } - } - - inline void SetUnpackAlignement(nzUInt8 bpp) - { - if (bpp % 8 == 0) - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - else if (bpp % 4 == 0) - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - else if (bpp % 2 == 0) - glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - else - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - } - - void UnlockTexture(NzTextureImpl* impl) - { - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (lockedLevel[impl->type] == 0) - { - NazaraError("Unlock called on non-locked texture"); - return; - } - #endif - - if (--lockedLevel[impl->type] == 0 && lockedPrevious[impl->type] != impl->id) - glBindTexture(openglTarget[impl->type], lockedPrevious[impl->type]); - } -} - -NzTexture::NzTexture() : -m_impl(nullptr) -{ -} - -NzTexture::NzTexture(const NzImage& image) : -m_impl(nullptr) -{ - LoadFromImage(image); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create texture"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzTexture::~NzTexture() -{ - Destroy(); -} - -bool NzTexture::Bind() const -{ - #if NAZARA_RENDERER_SAFE - if (lockedLevel[m_impl->type] > 0) - { - NazaraError("Cannot bind texture while a texture is locked"); - return false; - } - #endif - - glBindTexture(openglTarget[m_impl->type], m_impl->id); - - if (m_impl->mipmapping && !m_impl->mipmapsUpdated) - { - glGenerateMipmap(openglTarget[m_impl->type]); - m_impl->mipmapsUpdated = true; - } - - return true; -} - -bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount, bool lock) -{ - #if NAZARA_RENDERER_SAFE - if (m_impl && m_impl->isTarget) - { - NazaraError("Texture is a target, it cannot be recreated"); - return false; - } - #endif - - Destroy(); - - if (width == 0 || height == 0 || depth == 0) - return true; - - #if NAZARA_RENDERER_SAFE - if (!IsTypeSupported(type)) - { - NazaraError("Texture's type not supported"); - return false; - } - - if (!NzPixelFormat::IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - - if (!IsFormatSupported(format)) - { - NazaraError("Texture's format not supported"); - return false; - } - - switch (type) - { - case nzImageType_1D: - if (height > 1) - { - NazaraError("One dimensional texture's height must be 1"); - return false; - } - - if (depth > 1) - { - NazaraError("1D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - if (depth > 1) - { - NazaraError("2D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - break; - - case nzImageType_Cubemap: - if (depth > 1) - { - NazaraError("Cubemaps must be 1 depth"); - return false; - } - - if (width != height) - { - NazaraError("Cubemaps must have square dimensions"); - return false; - } - break; - } - #endif - - NzContext::EnsureContext(); - - if (IsMipmappingSupported()) - levelCount = std::min(levelCount, NzImage::GetMaxLevel(width, height, depth)); - else if (levelCount > 1) - { - NazaraWarning("Mipmapping not supported, reducing level count to 1"); - levelCount = 1; - } - - NzTextureImpl* impl = new NzTextureImpl; - glGenTextures(1, &impl->id); - - impl->depth = GetValidSize(depth); - impl->format = format; - impl->height = GetValidSize(height); - impl->levelCount = levelCount; - impl->type = type; - impl->width = GetValidSize(width); - - LockTexture(impl); - - // Vérification du support par la carte graphique - /*if (!CreateTexture(impl, true)) - { - NazaraError("Texture's parameters not supported by driver"); - UnlockTexture(impl); - glDeleteTextures(1, &impl->id); - delete impl; - - return false; - }*/ - - // Création de la texture - if (!CreateTexture(impl, false)) - { - NazaraError("Failed to create texture"); - UnlockTexture(impl); - glDeleteTextures(1, &impl->id); - delete impl; - - return false; - } - - m_impl = impl; - - // Paramètres par défaut - SetFilterMode(nzTextureFilter_Nearest); - SetMipmapRange(0, m_impl->levelCount); - SetWrapMode(nzTextureWrap_Repeat); - - if (m_impl->levelCount > 1U) - EnableMipmapping(true); - - if (!lock) - UnlockTexture(impl); - - return true; -} - -void NzTexture::Destroy() -{ - if (m_impl) - { - #if NAZARA_RENDERER_SAFE - if (m_impl->isTarget) - { - NazaraError("Texture is a target, it cannot be destroyed"); - return; - } - #endif - - NzContext::EnsureContext(); - - glDeleteTextures(1, &m_impl->id); - delete m_impl; - m_impl = nullptr; - } -} - -bool NzTexture::Download(NzImage* image) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (!image) - { - NazaraError("Image must be valid"); - return false; - } - #endif - - OpenGLFormat format; - if (!GetOpenGLFormat(m_impl->format, &format)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - if (!image->Create(m_impl->type, m_impl->format, m_impl->width, m_impl->height, m_impl->depth, m_impl->levelCount)) - { - NazaraError("Failed to create image"); - return false; - } - - LockTexture(m_impl); - - unsigned int width = m_impl->width; - unsigned int height = m_impl->height; - unsigned int depth = m_impl->depth; - - // Téléchargement... - for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) - { - glGetTexImage(openglTarget[m_impl->type], level, format.dataFormat, format.dataType, image->GetPixels(level)); - - if (width > 1) - width >>= 1; - - if (height > 1) - height >>= 1; - - if (depth > 1) - depth >>= 1; - } - - UnlockTexture(m_impl); - - // Inversion de la texture pour le repère d'OpenGL - if (!image->FlipVertically()) - NazaraWarning("Failed to flip image"); - - return true; -} - -bool NzTexture::EnableMipmapping(bool enable) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (m_impl->levelCount == 1) - return true; - - if (!IsMipmappingSupported()) - { - NazaraError("Mipmapping not supported"); - return false; - } - - if (!m_impl->mipmapping && enable) - m_impl->mipmapsUpdated = false; - - m_impl->mipmapping = enable; - - return true; -} - -unsigned int NzTexture::GetAnisotropyLevel() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter)) - return 1; - - LockTexture(m_impl); - - GLint anisotropyLevel; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropyLevel); - - UnlockTexture(m_impl); - - return anisotropyLevel; -} - -nzUInt8 NzTexture::GetBPP() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return NzPixelFormat::GetBPP(m_impl->format); -} - -unsigned int NzTexture::GetDepth() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->depth; -} - -nzTextureFilter NzTexture::GetFilterMode() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzTextureFilter_Unknown; - } - #endif - - LockTexture(m_impl); - - GLint value; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &value); - - UnlockTexture(m_impl); - - GLenum filterMode = static_cast(value); - switch (filterMode) - { - case GL_LINEAR: - case GL_LINEAR_MIPMAP_NEAREST: - return nzTextureFilter_Bilinear; - - case GL_NEAREST: - case GL_NEAREST_MIPMAP_NEAREST: - return nzTextureFilter_Nearest; - - case GL_LINEAR_MIPMAP_LINEAR: - return nzTextureFilter_Trilinear; - - default: - NazaraInternalError("OpenGL filter mode not handled (0x" + NzString::Number(filterMode, 16) + ')'); - return nzTextureFilter_Unknown; - } -} - -nzPixelFormat NzTexture::GetFormat() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzPixelFormat_Undefined; - } - #endif - - return m_impl->format; -} - -unsigned int NzTexture::GetHeight() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->height; -} - -nzImageType NzTexture::GetType() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzImageType_2D; - } - #endif - - return m_impl->type; -} - -unsigned int NzTexture::GetWidth() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->width; -} - -nzTextureWrap NzTexture::GetWrapMode() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzTextureWrap_Unknown; - } - #endif - - LockTexture(m_impl); - - GLint value; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &value); - - UnlockTexture(m_impl); - - GLenum wrapMode = static_cast(value); - switch (wrapMode) - { - case GL_CLAMP_TO_EDGE: - return nzTextureWrap_Clamp; - - case GL_REPEAT: - return nzTextureWrap_Repeat; - - default: - NazaraInternalError("OpenGL wrap mode not handled (0x" + NzString::Number(wrapMode, 16) + ')'); - return nzTextureWrap_Unknown; - } -} - -bool NzTexture::IsCompressed() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return NzPixelFormat::IsCompressed(m_impl->format); -} - -bool NzTexture::IsCubemap() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return m_impl->type == nzImageType_Cubemap; -} - -bool NzTexture::IsTarget() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return m_impl->isTarget; -} - -bool NzTexture::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzTexture::LoadFromFile(const NzString& filePath, const NzImageParams& params) -{ - NzImage image; - if (!image.LoadFromFile(filePath, params)) - { - NazaraError("Failed to load image"); - return false; - } - - return LoadFromImage(image); -} - -bool NzTexture::LoadFromImage(const NzImage& image) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - #endif - - // Vive le Copy-On-Write - NzImage newImage(image); - - nzPixelFormat format = newImage.GetFormat(); - if (!IsFormatSupported(format)) - { - nzPixelFormat newFormat = (NzPixelFormat::HasAlpha(format)) ? nzPixelFormat_BGRA8 : nzPixelFormat_BGR8; - NazaraWarning("Format not supported, trying to convert it to " + NzPixelFormat::ToString(newFormat) + "..."); - - if (NzPixelFormat::IsConversionSupported(format, newFormat)) - { - if (newImage.Convert(newFormat)) - { - NazaraWarning("Conversion succeed"); - format = newFormat; - } - else - { - NazaraError("Conversion failed"); - return false; - } - } - else - { - NazaraError("Conversion not supported"); - return false; - } - } - - nzImageType type = newImage.GetType(); - if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), newImage.GetLevelCount(), true)) - { - NazaraError("Failed to create texture"); - return false; - } - - for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) - { - if (!Update(newImage.GetConstPixels(level), level)) - { - NazaraError("Failed to update texture"); - Destroy(); - - return false; - } - } - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) -{ - NzImage image; - if (!image.LoadFromMemory(data, size, params)) - { - NazaraError("Failed to load image"); - return false; - } - - return LoadFromImage(image); -} - -bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& params) -{ - NzImage image; - if (!image.LoadFromStream(stream, params)) - { - NazaraError("Failed to load image"); - return false; - } - - return LoadFromImage(image); -} - -bool NzTexture::Lock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - LockTexture(m_impl); - - return true; -} - -bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter) && anistropyLevel > 1) - { - NazaraError("Anisotropic filter not supported"); - return false; - } - - LockTexture(m_impl); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anistropyLevel); - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::SetFilterMode(nzTextureFilter filter) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (filter == nzTextureFilter_Trilinear && m_impl->levelCount == 1) - { - NazaraError("Trilinear filter set wihout mipmaps"); - return false; - } - #endif - - LockTexture(m_impl); - - GLenum target = openglTarget[m_impl->type]; - switch (filter) - { - case nzTextureFilter_Bilinear: - if (m_impl->mipmapping > 1) - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - else - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - break; - - case nzTextureFilter_Nearest: - if (m_impl->mipmapping > 1) - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - else - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - break; - - case nzTextureFilter_Trilinear: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - break; - - default: - NazaraError("Texture filter not handled (0x" + NzString::Number(filter, 16) + ')'); - } - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (minLevel >= m_impl->levelCount) - { - NazaraError("Minimum level cannot be greater or equal than level count (" + NzString::Number(minLevel) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - - if (maxLevel < minLevel) - { - NazaraError("Minimum level cannot be greater than maximum level (" + NzString::Number(minLevel) + " < " + NzString::Number(maxLevel) + ')'); - return false; - } - #endif - - LockTexture(m_impl); - glTexParameteri(openglTarget[m_impl->type], GL_TEXTURE_BASE_LEVEL, minLevel); - glTexParameteri(openglTarget[m_impl->type], GL_TEXTURE_MAX_LEVEL, std::min(m_impl->levelCount, maxLevel)); - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::SetWrapMode(nzTextureWrap wrap) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - GLenum wrapMode; - switch (wrap) - { - case nzTextureWrap_Clamp: - wrapMode = GL_CLAMP_TO_EDGE; - break; - - case nzTextureWrap_Repeat: - wrapMode = GL_REPEAT; - break; - - default: - NazaraError("Texture wrap mode not handled (0x" + NzString::Number(wrap, 16) + ')'); - return false; - } - - LockTexture(m_impl); - - GLenum target = openglTarget[m_impl->type]; - switch (m_impl->type) - { - // Notez l'absence de "break" ici - case nzImageType_3D: - glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode); - case nzImageType_2D: - case nzImageType_2D_Array: - case nzImageType_Cubemap: - glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode); - case nzImageType_1D: - case nzImageType_1D_Array: - glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode); - break; - - default: - break; - } - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::Update(const NzImage& image, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - return Update(image.GetConstPixels(level), level); -} - -bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int z, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - const nzUInt8* pixels = image.GetConstPixels(level, rect.x, rect.y, z); - if (!pixels) - { - NazaraError("Failed to access image's pixels"); - return false; - } - - glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); - - bool success = Update(pixels, rect, z, level); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - return success; -} - -bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - const nzUInt8* pixels = image.GetConstPixels(level, cube.x, cube.y, cube.z); - if (!pixels) - { - NazaraError("Failed to access image's pixels"); - return false; - } - - glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image.GetHeight(level)); - - bool success = Update(pixels, cube, level); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); - - return success; -} - -bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array) - return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level); - else - return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level); -} - -bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (m_impl->isTarget) - { - NazaraError("Texture is a target, it cannot be updated"); - return false; - } - - if (m_impl->type == nzImageType_Cubemap) - { - NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int height = std::max(m_impl->height >> level, 1U); - - #if NAZARA_RENDERER_SAFE - if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - if (z >= std::max(m_impl->depth >> level, 1U)) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(m_impl->depth) + ')'); - return false; - } - - if (level >= m_impl->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - #endif - - OpenGLFormat format; - if (!GetOpenGLFormat(m_impl->format, &format)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - - // Inversion de la texture pour le repère d'OpenGL - NzImage mirrored; - mirrored.Create(m_impl->type, m_impl->format, rect.width, rect.height); - mirrored.Update(pixels); - - if (!mirrored.FlipVertically()) - NazaraWarning("Failed to flip image"); - - SetUnpackAlignement(bpp); - - LockTexture(m_impl); - switch (m_impl->type) - { - case nzImageType_1D: - glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels()); - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - glTexSubImage2D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels()); - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - glTexSubImage3D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels()); - break; - - case nzImageType_Cubemap: - NazaraError("Update used on a cubemap texture, please enable safe mode"); - break; - } - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (m_impl->isTarget) - { - NazaraError("Texture is a target, it cannot be updated"); - return false; - } - - if (m_impl->type == nzImageType_Cubemap) - { - NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (!cube.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int height = std::max(m_impl->height >> level, 1U); - - #if NAZARA_RENDERER_SAFE - if (cube.x+cube.width > std::max(m_impl->width >> level, 1U) || - cube.y+cube.height > height || - cube.z+cube.depth > std::max(m_impl->depth >> level, 1U)) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - - if (level >= m_impl->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - #endif - - OpenGLFormat format; - if (!GetOpenGLFormat(m_impl->format, &format)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - - // Inversion de la texture pour le repère d'OpenGL - unsigned int size = cube.width*cube.height*cube.depth*bpp; - nzUInt8* mirrored = new nzUInt8[size]; - if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, cube.width, cube.height, cube.depth, pixels, mirrored)) - { - NazaraWarning("Failed to flip image"); - std::memcpy(mirrored, pixels, size); - } - - SetUnpackAlignement(bpp); - - LockTexture(m_impl); - switch (m_impl->type) - { - case nzImageType_1D: - glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored); - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - glTexSubImage2D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored); - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - glTexSubImage3D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored); - break; - - case nzImageType_Cubemap: - NazaraError("Update used on a cubemap texture, please enable safe mode"); - break; - } - UnlockTexture(m_impl); - - delete[] mirrored; - - return true; -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - return UpdateFace(face, image.GetConstPixels(level), NzRectui(0, 0, image.GetWidth(), image.GetHeight()), level); -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); - - bool success = UpdateFace(face, image.GetConstPixels(level), rect, level); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - return success; -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return UpdateFace(face, pixels, NzRectui(0, 0, m_impl->width, m_impl->height), level); -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (m_impl->isTarget) - { - NazaraError("Texture is a target, it cannot be updated"); - return false; - } - - if (m_impl->type != nzImageType_Cubemap) - { - NazaraError("UpdateFace is designed for cubemaps, use Update instead"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int height = std::max(m_impl->height >> level, 1U); - - #if NAZARA_RENDERER_SAFE - if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - if (level >= m_impl->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - #endif - - OpenGLFormat format; - if (!GetOpenGLFormat(m_impl->format, &format)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - - // Inversion de la texture pour le repère d'OpenGL - unsigned int size = rect.width*rect.height*bpp; - nzUInt8* mirrored = new nzUInt8[size]; - if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, rect.width, rect.height, 1, pixels, mirrored)) - { - NazaraWarning("Failed to flip image"); - std::memcpy(mirrored, pixels, size); - } - - SetUnpackAlignement(bpp); - - LockTexture(m_impl); - glTexSubImage2D(cubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored); - UnlockTexture(m_impl); - - - return true; -} - -void NzTexture::Unlock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return; - } - #endif - - UnlockTexture(m_impl); -} - -unsigned int NzTexture::GetValidSize(unsigned int size) -{ - if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT)) - return size; - else - { - unsigned int pot = 1; - while (pot < size) - pot <<= 1; - - return pot; - } -} - -bool NzTexture::IsFormatSupported(nzPixelFormat format) -{ - switch (format) - { - // Formats de base - case nzPixelFormat_BGR8: - case nzPixelFormat_BGRA8: - case nzPixelFormat_RGB8: - case nzPixelFormat_RGBA8: - return true; - - // Packed formats supportés depuis OpenGL 1.2 - case nzPixelFormat_RGB5A1: - case nzPixelFormat_RGBA4: - return true; - - // Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..) - case nzPixelFormat_L8: - case nzPixelFormat_LA8: - return false; - - case nzPixelFormat_DXT1: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - { - static const bool supported = NzOpenGL::IsSupported(NzOpenGL::TextureCompression_s3tc); - return supported; - } - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - - return false; -} - -bool NzTexture::IsMipmappingSupported() -{ - return glGenerateMipmap != nullptr; -} - -bool NzTexture::IsTypeSupported(nzImageType type) -{ - switch (type) - { - case nzImageType_1D: - case nzImageType_2D: - case nzImageType_3D: - case nzImageType_Cubemap: - return true; // Tous supportés nativement dans OpenGL 2 - - case nzImageType_1D_Array: - case nzImageType_2D_Array: - { - static bool supported = NzOpenGL::IsSupported(NzOpenGL::TextureArray); - return supported; - } - } - - NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); - return false; -} - -void NzTexture::SetTarget(bool isTarget) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraInternalError("Texture must be valid"); - return; - } - #endif - - m_impl->isTarget = isTarget; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +struct NzTextureImpl +{ + GLuint id; + nzImageType type; + nzPixelFormat format; + nzUInt8 levelCount; + NzRenderTexture* renderTexture = nullptr; + bool mipmapping = false; + bool mipmapsUpdated = true; + unsigned int depth; + unsigned int height; + unsigned int width; +}; + +namespace +{ + bool CreateTexture(NzTextureImpl* impl, bool proxy) + { + NzOpenGL::Format openGLFormat; + if (!NzOpenGL::TranslateFormat(impl->format, &openGLFormat, NzOpenGL::FormatType_Texture)) + { + NazaraError("Format not supported by OpenGL"); + return false; + } + + GLenum target = (proxy) ? NzOpenGL::TextureTargetProxy[impl->type] : NzOpenGL::TextureTarget[impl->type]; + GLint previous; + glGetIntegerv(NzOpenGL::TextureTargetBinding[impl->type], &previous); + switch (impl->type) + { + case nzImageType_1D: + { + if (glTexStorage1D) + glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width); + else + { + unsigned int w = impl->width; + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + glTexImage1D(target, level, openGLFormat.internalFormat, w, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + if (w > 1U) + w >>= 1; + } + } + break; + } + + case nzImageType_1D_Array: + case nzImageType_2D: + { + if (glTexStorage2D) + glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); + else + { + unsigned int w = impl->width; + unsigned int h = impl->height; + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + glTexImage2D(target, level, openGLFormat.internalFormat, w, h, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + if (w > 1U) + w >>= 1; + + if (h > 1U) + h >>= 1; + } + } + break; + } + + case nzImageType_2D_Array: + case nzImageType_3D: + { + if (glTexStorage3D) + glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth); + else + { + unsigned int w = impl->width; + unsigned int h = impl->height; + unsigned int d = impl->depth; + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + glTexImage3D(target, level, openGLFormat.internalFormat, w, h, d, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + if (w > 1U) + w >>= 1; + + if (h > 1U) + h >>= 1; + + if (d > 1U) + d >>= 1; + } + } + break; + } + + case nzImageType_Cubemap: + { + if (glTexStorage2D) + glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); + else + { + unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + for (GLenum face : NzOpenGL::CubemapFace) + glTexImage2D(face, level, openGLFormat.internalFormat, size, size, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + + if (size > 1U) + size >>= 1; + } + } + break; + } + } + + if (proxy) + { + GLint internalFormat = 0; + glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); + if (internalFormat == 0) + return false; + } + + return true; + } + + static unsigned short lockedLevel[nzImageType_Max+1] = {0}; + static GLuint lockedPrevious[nzImageType_Max+1] = {0}; + + void LockTexture(NzTextureImpl* impl) + { + if (lockedLevel[impl->type]++ == 0) + { + NzContext::EnsureContext(); + + GLint previous; + glGetIntegerv(NzOpenGL::TextureTargetBinding[impl->type], &previous); + + lockedPrevious[impl->type] = static_cast(previous); + + if (lockedPrevious[impl->type] != impl->id) + glBindTexture(NzOpenGL::TextureTarget[impl->type], impl->id); + } + } + + inline void SetUnpackAlignement(nzUInt8 bpp) + { + if (bpp % 8 == 0) + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + else if (bpp % 4 == 0) + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + else if (bpp % 2 == 0) + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + else + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + } + + void UnlockTexture(NzTextureImpl* impl) + { + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (lockedLevel[impl->type] == 0) + { + NazaraError("Unlock called on non-locked texture"); + return; + } + #endif + + if (--lockedLevel[impl->type] == 0 && lockedPrevious[impl->type] != impl->id) + glBindTexture(NzOpenGL::TextureTarget[impl->type], lockedPrevious[impl->type]); + } +} + +NzTexture::NzTexture() : +m_impl(nullptr) +{ +} + +NzTexture::NzTexture(const NzImage& image) : +m_impl(nullptr) +{ + LoadFromImage(image); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create texture"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzTexture::~NzTexture() +{ + Destroy(); +} + +bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount, bool lock) +{ + Destroy(); + + #if NAZARA_RENDERER_SAFE + if (!IsTypeSupported(type)) + { + NazaraError("Texture's type not supported"); + return false; + } + + if (!NzPixelFormat::IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + + if (!IsFormatSupported(format)) + { + NazaraError("Texture's format not supported"); + return false; + } + + if (width == 0) + { + NazaraError("Width must be at least 1 (0)"); + return false; + } + + if (height == 0) + { + NazaraError("Height must be at least 1 (0)"); + return false; + } + + if (depth == 0) + { + NazaraError("Depth must be at least 1 (0)"); + return false; + } + + switch (type) + { + case nzImageType_1D: + if (height > 1) + { + NazaraError("One dimensional texture's height must be 1"); + return false; + } + + if (depth > 1) + { + NazaraError("1D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + if (depth > 1) + { + NazaraError("2D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + break; + + case nzImageType_Cubemap: + if (depth > 1) + { + NazaraError("Cubemaps must be 1 depth"); + return false; + } + + if (width != height) + { + NazaraError("Cubemaps must have square dimensions"); + return false; + } + break; + } + #endif + + NzContext::EnsureContext(); + + if (IsMipmappingSupported()) + levelCount = std::min(levelCount, NzImage::GetMaxLevel(width, height, depth)); + else if (levelCount > 1) + { + NazaraWarning("Mipmapping not supported, reducing level count to 1"); + levelCount = 1; + } + + NzTextureImpl* impl = new NzTextureImpl; + glGenTextures(1, &impl->id); + + impl->depth = GetValidSize(depth); + impl->format = format; + impl->height = GetValidSize(height); + impl->levelCount = levelCount; + impl->type = type; + impl->width = GetValidSize(width); + + LockTexture(impl); + + // Vérification du support par la carte graphique + /*if (!CreateTexture(impl, true)) + { + NazaraError("Texture's parameters not supported by driver"); + UnlockTexture(impl); + glDeleteTextures(1, &impl->id); + delete impl; + + return false; + }*/ + + // Création de la texture + if (!CreateTexture(impl, false)) + { + NazaraError("Failed to create texture"); + UnlockTexture(impl); + glDeleteTextures(1, &impl->id); + delete impl; + + return false; + } + + m_impl = impl; + + // Paramètres par défaut + SetFilterMode(nzTextureFilter_Nearest); + SetMipmapRange(0, m_impl->levelCount); + SetWrapMode(nzTextureWrap_Repeat); + + if (m_impl->levelCount > 1U) + EnableMipmapping(true); + + if (!lock) + UnlockTexture(impl); + + NotifyCreated(); + return true; +} + +void NzTexture::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + NzContext::EnsureContext(); + + glDeleteTextures(1, &m_impl->id); + delete m_impl; + m_impl = nullptr; + } +} + +bool NzTexture::Download(NzImage* image) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (!image) + { + NazaraError("Image must be valid"); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + if (!image->Create(m_impl->type, m_impl->format, m_impl->width, m_impl->height, m_impl->depth, m_impl->levelCount)) + { + NazaraError("Failed to create image"); + return false; + } + + LockTexture(m_impl); + + unsigned int width = m_impl->width; + unsigned int height = m_impl->height; + unsigned int depth = m_impl->depth; + + // Téléchargement... + for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) + { + glGetTexImage(NzOpenGL::TextureTarget[m_impl->type], level, format.dataFormat, format.dataType, image->GetPixels(level)); + + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + if (depth > 1) + depth >>= 1; + } + + UnlockTexture(m_impl); + + // Inversion de la texture pour le repère d'OpenGL + if (!image->FlipVertically()) + NazaraWarning("Failed to flip image"); + + return true; +} + +bool NzTexture::EnableMipmapping(bool enable) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (m_impl->levelCount == 1) + return true; + + if (!IsMipmappingSupported()) + { + NazaraError("Mipmapping not supported"); + return false; + } + + if (!m_impl->mipmapping && enable) + m_impl->mipmapsUpdated = false; + + m_impl->mipmapping = enable; + + return true; +} + +unsigned int NzTexture::GetAnisotropyLevel() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + if (!NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)) + return 1; + + LockTexture(m_impl); + + GLint anisotropyLevel; + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropyLevel); + + UnlockTexture(m_impl); + + return anisotropyLevel; +} + +nzUInt8 NzTexture::GetBPP() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return NzPixelFormat::GetBPP(m_impl->format); +} + +unsigned int NzTexture::GetDepth() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->depth; +} + +nzTextureFilter NzTexture::GetFilterMode() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzTextureFilter_Unknown; + } + #endif + + LockTexture(m_impl); + + GLint value; + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &value); + + UnlockTexture(m_impl); + + GLenum filterMode = static_cast(value); + switch (filterMode) + { + case GL_LINEAR: + case GL_LINEAR_MIPMAP_NEAREST: + return nzTextureFilter_Bilinear; + + case GL_NEAREST: + case GL_NEAREST_MIPMAP_NEAREST: + return nzTextureFilter_Nearest; + + case GL_LINEAR_MIPMAP_LINEAR: + return nzTextureFilter_Trilinear; + + default: + NazaraInternalError("OpenGL filter mode not handled (0x" + NzString::Number(filterMode, 16) + ')'); + return nzTextureFilter_Unknown; + } +} + +nzPixelFormat NzTexture::GetFormat() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzPixelFormat_Undefined; + } + #endif + + return m_impl->format; +} + +unsigned int NzTexture::GetHeight() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->height; +} + +nzImageType NzTexture::GetType() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzImageType_2D; + } + #endif + + return m_impl->type; +} + +unsigned int NzTexture::GetWidth() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->width; +} + +nzTextureWrap NzTexture::GetWrapMode() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzTextureWrap_Unknown; + } + #endif + + LockTexture(m_impl); + + GLint value; + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &value); + + UnlockTexture(m_impl); + + GLenum wrapMode = static_cast(value); + switch (wrapMode) + { + case GL_CLAMP_TO_EDGE: + return nzTextureWrap_Clamp; + + case GL_REPEAT: + return nzTextureWrap_Repeat; + + default: + NazaraInternalError("OpenGL wrap mode not handled (0x" + NzString::Number(wrapMode, 16) + ')'); + return nzTextureWrap_Unknown; + } +} + +bool NzTexture::IsCompressed() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return NzPixelFormat::IsCompressed(m_impl->format); +} + +bool NzTexture::IsCubemap() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return m_impl->type == nzImageType_Cubemap; +} + +bool NzTexture::IsTarget() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return m_impl->renderTexture != nullptr; +} + +bool NzTexture::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzTexture::LoadFromFile(const NzString& filePath, const NzImageParams& params) +{ + NzImage image; + if (!image.LoadFromFile(filePath, params)) + { + NazaraError("Failed to load image"); + return false; + } + + return LoadFromImage(image); +} + +bool NzTexture::LoadFromImage(const NzImage& image) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + #endif + + // Vive le Copy-On-Write + NzImage newImage(image); + + nzPixelFormat format = newImage.GetFormat(); + if (!IsFormatSupported(format)) + { + nzPixelFormat newFormat = (NzPixelFormat::HasAlpha(format)) ? nzPixelFormat_BGRA8 : nzPixelFormat_BGR8; + NazaraWarning("Format not supported, trying to convert it to " + NzPixelFormat::ToString(newFormat) + "..."); + + if (NzPixelFormat::IsConversionSupported(format, newFormat)) + { + if (newImage.Convert(newFormat)) + { + NazaraWarning("Conversion succeed"); + format = newFormat; + } + else + { + NazaraError("Conversion failed"); + return false; + } + } + else + { + NazaraError("Conversion not supported"); + return false; + } + } + + nzImageType type = newImage.GetType(); + if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), newImage.GetLevelCount(), true)) + { + NazaraError("Failed to create texture"); + return false; + } + + for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) + { + if (!Update(newImage.GetConstPixels(level), level)) + { + NazaraError("Failed to update texture"); + Destroy(); + + return false; + } + } + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) +{ + NzImage image; + if (!image.LoadFromMemory(data, size, params)) + { + NazaraError("Failed to load image"); + return false; + } + + return LoadFromImage(image); +} + +bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& params) +{ + NzImage image; + if (!image.LoadFromStream(stream, params)) + { + NazaraError("Failed to load image"); + return false; + } + + return LoadFromImage(image); +} + +bool NzTexture::Lock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + LockTexture(m_impl); + + return true; +} + +bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (anistropyLevel > 1 && !NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)) + { + NazaraError("Anisotropic filter not supported"); + return false; + } + + LockTexture(m_impl); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anistropyLevel); + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::SetFilterMode(nzTextureFilter filter) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (filter == nzTextureFilter_Trilinear && m_impl->levelCount == 1) + { + NazaraError("Trilinear filter set wihout mipmaps"); + return false; + } + #endif + + LockTexture(m_impl); + + GLenum target = NzOpenGL::TextureTarget[m_impl->type]; + switch (filter) + { + case nzTextureFilter_Bilinear: + if (m_impl->mipmapping > 1) + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + else + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + break; + + case nzTextureFilter_Nearest: + if (m_impl->mipmapping > 1) + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + else + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + break; + + case nzTextureFilter_Trilinear: + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + break; + + default: + NazaraError("Texture filter not handled (0x" + NzString::Number(filter, 16) + ')'); + } + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (minLevel >= m_impl->levelCount) + { + NazaraError("Minimum level cannot be greater or equal than level count (" + NzString::Number(minLevel) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + + if (maxLevel < minLevel) + { + NazaraError("Minimum level cannot be greater than maximum level (" + NzString::Number(minLevel) + " < " + NzString::Number(maxLevel) + ')'); + return false; + } + #endif + + LockTexture(m_impl); + glTexParameteri(NzOpenGL::TextureTarget[m_impl->type], GL_TEXTURE_BASE_LEVEL, minLevel); + glTexParameteri(NzOpenGL::TextureTarget[m_impl->type], GL_TEXTURE_MAX_LEVEL, std::min(m_impl->levelCount, maxLevel)); + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::SetWrapMode(nzTextureWrap wrap) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + GLenum wrapMode; + switch (wrap) + { + case nzTextureWrap_Clamp: + wrapMode = GL_CLAMP_TO_EDGE; + break; + + case nzTextureWrap_Repeat: + wrapMode = GL_REPEAT; + break; + + default: + NazaraError("Texture wrap mode not handled (0x" + NzString::Number(wrap, 16) + ')'); + return false; + } + + LockTexture(m_impl); + + GLenum target = NzOpenGL::TextureTarget[m_impl->type]; + switch (m_impl->type) + { + // Notez l'absence de "break" ici + case nzImageType_3D: + glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode); + case nzImageType_2D: + case nzImageType_2D_Array: + case nzImageType_Cubemap: + glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode); + case nzImageType_1D: + case nzImageType_1D_Array: + glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode); + break; + + default: + break; + } + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::Update(const NzImage& image, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + return Update(image.GetConstPixels(level), level); +} + +bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int z, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + const nzUInt8* pixels = image.GetConstPixels(level, rect.x, rect.y, z); + if (!pixels) + { + NazaraError("Failed to access image's pixels"); + return false; + } + + glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); + + bool success = Update(pixels, rect, z, level); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + return success; +} + +bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + const nzUInt8* pixels = image.GetConstPixels(level, cube.x, cube.y, cube.z); + if (!pixels) + { + NazaraError("Failed to access image's pixels"); + return false; + } + + glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image.GetHeight(level)); + + bool success = Update(pixels, cube, level); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); + + return success; +} + +bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array) + return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level); + else + return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level); +} + +bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (m_impl->renderTexture) + { + NazaraError("Texture is a target, it cannot be updated"); + return false; + } + + if (m_impl->type == nzImageType_Cubemap) + { + NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int height = std::max(m_impl->height >> level, 1U); + + #if NAZARA_RENDERER_SAFE + if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + if (z >= std::max(m_impl->depth >> level, 1U)) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(m_impl->depth) + ')'); + return false; + } + + if (level >= m_impl->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + + // Inversion de la texture pour le repère d'OpenGL + NzImage mirrored; + mirrored.Create(m_impl->type, m_impl->format, rect.width, rect.height); + mirrored.Update(pixels); + + if (!mirrored.FlipVertically()) + NazaraWarning("Failed to flip image"); + + SetUnpackAlignement(bpp); + + LockTexture(m_impl); + switch (m_impl->type) + { + case nzImageType_1D: + glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + break; + + case nzImageType_Cubemap: + NazaraError("Update used on a cubemap texture, please enable safe mode"); + break; + } + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (m_impl->renderTexture) + { + NazaraError("Texture is a target, it cannot be updated"); + return false; + } + + if (m_impl->type == nzImageType_Cubemap) + { + NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (!cube.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int height = std::max(m_impl->height >> level, 1U); + + #if NAZARA_RENDERER_SAFE + if (cube.x+cube.width > std::max(m_impl->width >> level, 1U) || + cube.y+cube.height > height || + cube.z+cube.depth > std::max(m_impl->depth >> level, 1U)) + { + NazaraError("Cube dimensions are out of bounds"); + return false; + } + + if (level >= m_impl->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + + // Inversion de la texture pour le repère d'OpenGL + unsigned int size = cube.width*cube.height*cube.depth*bpp; + nzUInt8* mirrored = new nzUInt8[size]; + if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, cube.width, cube.height, cube.depth, pixels, mirrored)) + { + NazaraWarning("Failed to flip image"); + std::memcpy(mirrored, pixels, size); + } + + SetUnpackAlignement(bpp); + + LockTexture(m_impl); + switch (m_impl->type) + { + case nzImageType_1D: + glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored); + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored); + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored); + break; + + case nzImageType_Cubemap: + NazaraError("Update used on a cubemap texture, please enable safe mode"); + break; + } + UnlockTexture(m_impl); + + delete[] mirrored; + + return true; +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + return UpdateFace(face, image.GetConstPixels(level), NzRectui(0, 0, image.GetWidth(), image.GetHeight()), level); +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); + + bool success = UpdateFace(face, image.GetConstPixels(level), rect, level); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + return success; +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return UpdateFace(face, pixels, NzRectui(0, 0, m_impl->width, m_impl->height), level); +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (m_impl->renderTexture) + { + NazaraError("Texture is a target, it cannot be updated"); + return false; + } + + if (m_impl->type != nzImageType_Cubemap) + { + NazaraError("UpdateFace is designed for cubemaps, use Update instead"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int height = std::max(m_impl->height >> level, 1U); + + #if NAZARA_RENDERER_SAFE + if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + if (level >= m_impl->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + + // Inversion de la texture pour le repère d'OpenGL + unsigned int size = rect.width*rect.height*bpp; + nzUInt8* mirrored = new nzUInt8[size]; + if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, rect.width, rect.height, 1, pixels, mirrored)) + { + NazaraWarning("Failed to flip image"); + std::memcpy(mirrored, pixels, size); + } + + SetUnpackAlignement(bpp); + + LockTexture(m_impl); + glTexSubImage2D(NzOpenGL::CubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored); + UnlockTexture(m_impl); + + + return true; +} + +void NzTexture::Unlock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return; + } + #endif + + UnlockTexture(m_impl); +} + +unsigned int NzTexture::GetOpenGLID() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->id; +} + +bool NzTexture::Prepare() const +{ + #if NAZARA_RENDERER_SAFE + if (lockedLevel[m_impl->type] > 0) + { + NazaraError("Cannot bind texture while a texture is locked"); + return false; + } + #endif + + glBindTexture(NzOpenGL::TextureTarget[m_impl->type], m_impl->id); + + if (m_impl->mipmapping && !m_impl->mipmapsUpdated) + { + glGenerateMipmap(NzOpenGL::TextureTarget[m_impl->type]); + m_impl->mipmapsUpdated = true; + } + + return true; +} + +unsigned int NzTexture::GetValidSize(unsigned int size) +{ + if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT)) + return size; + else + { + unsigned int pot = 1; + while (pot < size) + pot <<= 1; + + return pot; + } +} + +bool NzTexture::IsFormatSupported(nzPixelFormat format) +{ + switch (format) + { + // Formats de base + case nzPixelFormat_BGR8: + case nzPixelFormat_BGRA8: + case nzPixelFormat_RGB8: + case nzPixelFormat_RGBA8: + return true; + + // Packed formats supportés depuis OpenGL 1.2 + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGBA4: + return true; + + // Formats de profondeur (Supportés avec les FBOs) + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth32: + case nzPixelFormat_Depth24Stencil8: + { + static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); + return supported; + } + + // Formats de stencil (Non supportés pour les textures) + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return false; + + // Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..) + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + return false; + + case nzPixelFormat_DXT1: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + { + static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc); + return supported; + } + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + + return false; +} + +bool NzTexture::IsMipmappingSupported() +{ + return glGenerateMipmap != nullptr; +} + +bool NzTexture::IsTypeSupported(nzImageType type) +{ + switch (type) + { + case nzImageType_1D: + case nzImageType_2D: + case nzImageType_3D: + case nzImageType_Cubemap: + return true; // Tous supportés nativement dans OpenGL 2 + + case nzImageType_1D_Array: + case nzImageType_2D_Array: + { + static bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray); + return supported; + } + } + + NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); + return false; +} + +NzRenderTexture* NzTexture::GetRenderTexture() const +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Texture must be valid"); + return nullptr; + } + #endif + + return m_impl->renderTexture; +} + +void NzTexture::SetRenderTexture(NzRenderTexture* renderTexture) +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Texture must be valid"); + return; + } + #endif + + m_impl->renderTexture = renderTexture; +} diff --git a/src/Nazara/Renderer/Win32/ContextImpl.cpp b/src/Nazara/Renderer/Win32/ContextImpl.cpp index 5cb657f48..15fd533d2 100644 --- a/src/Nazara/Renderer/Win32/ContextImpl.cpp +++ b/src/Nazara/Renderer/Win32/ContextImpl.cpp @@ -1,231 +1,234 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila - -#include -#include -#include -#include -#include -#include -#include -#include - -NzContextImpl::NzContextImpl() -{ -} - -bool NzContextImpl::Activate() -{ - return wglMakeCurrent(m_deviceContext, m_context); -} - -bool NzContextImpl::Create(NzContextParameters& parameters) -{ - if (parameters.window) - { - m_window = static_cast(parameters.window); - m_ownsWindow = false; - } - else - { - m_window = CreateWindowA("STATIC", nullptr, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); - if (!m_window) - { - NazaraError("Failed to create window"); - return false; - } - - ShowWindow(m_window, SW_HIDE); - m_ownsWindow = true; - } - - m_deviceContext = GetDC(m_window); - if (!m_deviceContext) - { - NazaraError("Failed to get device context"); - Destroy(); - return false; - } - - int pixelFormat = 0; - if (parameters.antialiasingLevel > 0) - { - if (wglChoosePixelFormat) - { - bool valid; - UINT numFormats; - - int attributes[] = { - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_COLOR_BITS_ARB, (parameters.bitsPerPixel == 32) ? 24 : parameters.bitsPerPixel, - WGL_ALPHA_BITS_ARB, (parameters.bitsPerPixel == 32) ? 8 : 0, - WGL_DEPTH_BITS_ARB, parameters.depthBits, - WGL_STENCIL_BITS_ARB, parameters.stencilBits, - WGL_DOUBLE_BUFFER_ARB, (parameters.doubleBuffered) ? GL_TRUE : GL_FALSE, - WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, - WGL_SAMPLES_ARB, parameters.antialiasingLevel, - 0, 0 - }; - - do - { - valid = wglChoosePixelFormat(m_deviceContext, attributes, nullptr, 1, &pixelFormat, &numFormats); - } - while ((!valid || numFormats == 0) && --attributes[19] > 0); - - if (!valid) - { - NazaraWarning("Could not find a format matching requirements, disabling antialiasing..."); - pixelFormat = 0; - } - - parameters.antialiasingLevel = attributes[19]; - } - else - { - NazaraWarning("Antialiasing is not supported"); - parameters.antialiasingLevel = 0; - } - } - - PIXELFORMATDESCRIPTOR descriptor; - ZeroMemory(&descriptor, sizeof(PIXELFORMATDESCRIPTOR)); - descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR); - descriptor.nVersion = 1; - - if (pixelFormat == 0) - { - descriptor.cColorBits = parameters.bitsPerPixel; - descriptor.cDepthBits = parameters.depthBits; - descriptor.cStencilBits = parameters.stencilBits; - descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - descriptor.iPixelType = PFD_TYPE_RGBA; - - if (parameters.bitsPerPixel == 32) - descriptor.cAlphaBits = 8; - - if (parameters.doubleBuffered) - descriptor.dwFlags |= PFD_DOUBLEBUFFER; - - pixelFormat = ChoosePixelFormat(m_deviceContext, &descriptor); - if (pixelFormat == 0) - { - NazaraError("Failed to choose pixel format"); - Destroy(); - - return false; - } - } - - if (!SetPixelFormat(m_deviceContext, pixelFormat, &descriptor)) - { - NazaraError("Failed to set pixel format"); - Destroy(); - return false; - } - - // Arrivé ici, le format de pixel est choisi, nous récupérons donc les paramètres réels du futur contexte - if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0) - { - parameters.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits; - parameters.depthBits = descriptor.cDepthBits; - parameters.stencilBits = descriptor.cDepthBits; - } - else - NazaraWarning("Failed to get context's parameters"); - - HGLRC shareContext = (parameters.shared) ? static_cast(parameters.shareContext->m_impl)->m_context : nullptr; - - m_context = nullptr; - if (wglCreateContextAttribs) - { - int attributes[4*2+1]; - int* attrib = attributes; - - *attrib++ = WGL_CONTEXT_MAJOR_VERSION_ARB; - *attrib++ = parameters.majorVersion; - - *attrib++ = WGL_CONTEXT_MINOR_VERSION_ARB; - *attrib++ = parameters.minorVersion; - - int flags = 0; - - if (parameters.majorVersion >= 3) - { - *attrib++ = WGL_CONTEXT_PROFILE_MASK_ARB; - if (parameters.compatibilityProfile) - *attrib++ = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - else - { - *attrib++ = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; - - flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - } - } - - if (parameters.debugMode) - flags |= WGL_CONTEXT_DEBUG_BIT_ARB; - - if (flags) - { - *attrib++ = WGL_CONTEXT_FLAGS_ARB; - *attrib++ = flags; - } - - *attrib++ = 0; - - m_context = wglCreateContextAttribs(m_deviceContext, shareContext, attributes); - } - - if (!m_context) - { - m_context = wglCreateContext(m_deviceContext); - - if (shareContext) - { - // wglShareLists n'est pas thread-safe (source: SFML) - static NzMutex mutex; - NzLockGuard lock(mutex); - - if (!wglShareLists(shareContext, m_context)) - NazaraWarning("Failed to share the context: " + NzGetLastSystemError()); - } - } - - if (!m_context) - { - NazaraError("Failed to create context"); - Destroy(); - return false; - } - - return true; -} - -void NzContextImpl::Destroy() -{ - if (m_context) - wglDeleteContext(m_context); - - if (m_deviceContext) - ReleaseDC(m_window, m_deviceContext); - - if (m_ownsWindow) - DestroyWindow(m_window); -} - -void NzContextImpl::SwapBuffers() -{ - ::SwapBuffers(m_deviceContext); -} - -bool NzContextImpl::Desactivate() -{ - return wglMakeCurrent(nullptr, nullptr); -} - +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila + +#include +#include +#include +#include +#include +#include +#include +#include + +NzContextImpl::NzContextImpl() +{ +} + +bool NzContextImpl::Activate() +{ + return wglMakeCurrent(m_deviceContext, m_context); +} + +bool NzContextImpl::Create(NzContextParameters& parameters) +{ + if (parameters.window) + { + m_window = static_cast(parameters.window); + m_ownsWindow = false; + } + else + { + m_window = CreateWindowA("STATIC", nullptr, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); + if (!m_window) + { + NazaraError("Failed to create window"); + return false; + } + + ShowWindow(m_window, SW_HIDE); + m_ownsWindow = true; + } + + m_deviceContext = GetDC(m_window); + if (!m_deviceContext) + { + NazaraError("Failed to get device context"); + Destroy(); + return false; + } + + int pixelFormat = 0; + if (parameters.antialiasingLevel > 0) + { + if (wglChoosePixelFormat) + { + bool valid; + UINT numFormats; + + int attributes[] = { + WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, + WGL_SUPPORT_OPENGL_ARB, GL_TRUE, + WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, + WGL_COLOR_BITS_ARB, (parameters.bitsPerPixel == 32) ? 24 : parameters.bitsPerPixel, + WGL_ALPHA_BITS_ARB, (parameters.bitsPerPixel == 32) ? 8 : 0, + WGL_DEPTH_BITS_ARB, parameters.depthBits, + WGL_STENCIL_BITS_ARB, parameters.stencilBits, + WGL_DOUBLE_BUFFER_ARB, (parameters.doubleBuffered) ? GL_TRUE : GL_FALSE, + WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, + WGL_SAMPLES_ARB, parameters.antialiasingLevel, + 0, 0 + }; + + do + { + valid = wglChoosePixelFormat(m_deviceContext, attributes, nullptr, 1, &pixelFormat, &numFormats); + } + while ((!valid || numFormats == 0) && --attributes[19] > 0); + + if (!valid) + { + NazaraWarning("Could not find a format matching requirements, disabling antialiasing..."); + pixelFormat = 0; + } + + parameters.antialiasingLevel = attributes[19]; + } + else + { + NazaraWarning("Antialiasing is not supported"); + parameters.antialiasingLevel = 0; + } + } + + PIXELFORMATDESCRIPTOR descriptor; + ZeroMemory(&descriptor, sizeof(PIXELFORMATDESCRIPTOR)); + descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR); + descriptor.nVersion = 1; + + if (pixelFormat == 0) + { + descriptor.cColorBits = parameters.bitsPerPixel; + descriptor.cDepthBits = parameters.depthBits; + descriptor.cStencilBits = parameters.stencilBits; + descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + descriptor.iPixelType = PFD_TYPE_RGBA; + + if (parameters.bitsPerPixel == 32) + descriptor.cAlphaBits = 8; + + if (parameters.doubleBuffered) + descriptor.dwFlags |= PFD_DOUBLEBUFFER; + + pixelFormat = ChoosePixelFormat(m_deviceContext, &descriptor); + if (pixelFormat == 0) + { + NazaraError("Failed to choose pixel format"); + Destroy(); + + return false; + } + } + + if (!SetPixelFormat(m_deviceContext, pixelFormat, &descriptor)) + { + NazaraError("Failed to set pixel format"); + Destroy(); + return false; + } + + // Arrivé ici, le format de pixel est choisi, nous récupérons donc les paramètres réels du futur contexte + if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0) + { + parameters.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits; + parameters.depthBits = descriptor.cDepthBits; + parameters.stencilBits = descriptor.cDepthBits; + } + else + NazaraWarning("Failed to get context's parameters"); + + HGLRC shareContext = (parameters.shared) ? static_cast(parameters.shareContext->m_impl)->m_context : nullptr; + + m_context = nullptr; + if (wglCreateContextAttribs) + { + int attributes[4*2+1]; + int* attrib = attributes; + + *attrib++ = WGL_CONTEXT_MAJOR_VERSION_ARB; + *attrib++ = parameters.majorVersion; + + *attrib++ = WGL_CONTEXT_MINOR_VERSION_ARB; + *attrib++ = parameters.minorVersion; + + if (parameters.majorVersion >= 3) + { + *attrib++ = WGL_CONTEXT_PROFILE_MASK_ARB; + *attrib++ = (parameters.compatibilityProfile) ? WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB : WGL_CONTEXT_CORE_PROFILE_BIT_ARB; + } + + if (parameters.debugMode) + { + *attrib++ = WGL_CONTEXT_FLAGS_ARB; + *attrib++ = WGL_CONTEXT_DEBUG_BIT_ARB; + + // Les contextes forward-compatible ne sont plus utilisés pour cette raison : + // http://www.opengl.org/discussion_boards/showthread.php/175052-Forward-compatible-vs-Core-profile + } + + *attrib++ = 0; + + m_context = wglCreateContextAttribs(m_deviceContext, shareContext, attributes); + } + + if (!m_context) + { + m_context = wglCreateContext(m_deviceContext); + + if (shareContext) + { + // wglShareLists n'est pas thread-safe (source: SFML) + static NzMutex mutex; + NzLockGuard lock(mutex); + + if (!wglShareLists(shareContext, m_context)) + NazaraWarning("Failed to share the context: " + NzGetLastSystemError()); + } + } + + if (!m_context) + { + NazaraError("Failed to create context"); + Destroy(); + return false; + } + + return true; +} + +void NzContextImpl::Destroy() +{ + if (m_context) + { + if (wglGetCurrentContext() == m_context) + wglMakeCurrent(nullptr, nullptr); + + wglDeleteContext(m_context); + m_context = nullptr; + } + + if (m_deviceContext) + { + ReleaseDC(m_window, m_deviceContext); + m_deviceContext = nullptr; + } + + if (m_ownsWindow) + { + DestroyWindow(m_window); + m_window = nullptr; + } +} + +void NzContextImpl::SwapBuffers() +{ + ::SwapBuffers(m_deviceContext); +} + +bool NzContextImpl::Desactivate() +{ + return wglMakeCurrent(nullptr, nullptr); +} + diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index 48bad22f2..fe9f1c0b2 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -1,317 +1,342 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -struct NzAnimationImpl -{ - std::map sequenceMap; - std::vector sequences; - nzAnimationType type; - unsigned int frameCount; -}; - -bool NzAnimationParams::IsValid() const -{ - if (startFrame > endFrame) - { - NazaraError("Start frame must be lower than end frame"); - return false; - } - - return true; -} - -NzAnimation::~NzAnimation() -{ - Destroy(); -} - -unsigned int NzAnimation::AddSequence(const NzSequence& sequence) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return 0; - } - #endif - - unsigned int index = m_impl->sequences.size(); - - if (!sequence.name.IsEmpty()) - { - #if NAZARA_UTILITY_SAFE - auto it = m_impl->sequenceMap.find(sequence.name); - if (it != m_impl->sequenceMap.end()) - { - NazaraError("Sequence name \"" + sequence.name + "\" is already used"); - return 0; - } - #endif - - m_impl->sequenceMap[sequence.name] = index; - } - - m_impl->sequences.push_back(sequence); - - return index; -} - -bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount) -{ - Destroy(); - - #if NAZARA_UTILITY_SAFE - if (type == nzAnimationType_Static) - { - NazaraError("Invalid type"); - return false; - } - - if (frameCount == 0) - { - NazaraError("Frame count must be over zero"); - return false; - } - #endif - - m_impl = new NzAnimationImpl; - m_impl->frameCount = frameCount; - m_impl->type = type; - - return true; -} - -void NzAnimation::Destroy() -{ - if (m_impl) - { - delete m_impl; - m_impl = nullptr; - } -} - -unsigned int NzAnimation::GetFrameCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - return m_impl->frameCount; -} - -NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - auto it = m_impl->sequenceMap.find(sequenceName); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("Sequence not found"); - return nullptr; - } - - return &m_impl->sequences[it->second]; - #else - return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; - #endif -} - -NzSequence* NzAnimation::GetSequence(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); - return nullptr; - } - #endif - - return &m_impl->sequences[index]; -} - -const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - auto it = m_impl->sequenceMap.find(sequenceName); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("Sequence not found"); - return nullptr; - } - - return &m_impl->sequences[it->second]; - #else - return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; - #endif -} - -const NzSequence* NzAnimation::GetSequence(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); - return nullptr; - } - #endif - - return &m_impl->sequences[index]; -} - -unsigned int NzAnimation::GetSequenceCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return 0; - } - #endif - - return m_impl->sequences.size(); -} - -nzAnimationType NzAnimation::GetType() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nzAnimationType_Static; // Ce qui est une valeur invalide pour NzAnimation - } - #endif - - return m_impl->type; -} - -bool NzAnimation::HasSequence(const NzString& sequenceName) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end(); -} - -bool NzAnimation::HasSequence(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - return index >= m_impl->sequences.size(); -} - -bool NzAnimation::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzAnimation::LoadFromFile(const NzString& filePath, const NzAnimationParams& params) -{ - return NzAnimationLoader::LoadFromFile(this, filePath, params); -} - -bool NzAnimation::LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params) -{ - return NzAnimationLoader::LoadFromMemory(this, data, size, params); -} - -bool NzAnimation::LoadFromStream(NzInputStream& stream, const NzAnimationParams& params) -{ - return NzAnimationLoader::LoadFromStream(this, stream, params); -} - -void NzAnimation::RemoveSequence(const NzString& identifier) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } - - auto it = m_impl->sequenceMap.find(identifier); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("SubMesh not found"); - return; - } - - unsigned int index = it->second; - #else - unsigned int index = m_impl->sequenceMap[identifier]; - #endif - - auto it2 = m_impl->sequences.begin(); - std::advance(it2, index); - - m_impl->sequences.erase(it2); -} - -void NzAnimation::RemoveSequence(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); - return; - } - #endif - - auto it = m_impl->sequences.begin(); - std::advance(it, index); - - m_impl->sequences.erase(it); -} - -NzAnimationLoader::LoaderList NzAnimation::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +struct NzAnimationImpl +{ + std::map sequenceMap; + std::vector sequences; + nzAnimationType type; + unsigned int frameCount; +}; + +bool NzAnimationParams::IsValid() const +{ + if (startFrame > endFrame) + { + NazaraError("Start frame must be lower than end frame"); + return false; + } + + return true; +} + +NzAnimation::~NzAnimation() +{ + Destroy(); +} + +bool NzAnimation::AddSequence(const NzSequence& sequence) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + unsigned int index = m_impl->sequences.size(); + + if (!sequence.name.IsEmpty()) + { + #if NAZARA_UTILITY_SAFE + auto it = m_impl->sequenceMap.find(sequence.name); + if (it != m_impl->sequenceMap.end()) + { + NazaraError("Sequence name \"" + sequence.name + "\" is already used"); + return false; + } + #endif + + m_impl->sequenceMap[sequence.name] = index; + } + + m_impl->sequences.push_back(sequence); + + return true; +} + +bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount) +{ + Destroy(); + + #if NAZARA_UTILITY_SAFE + if (type == nzAnimationType_Static) + { + NazaraError("Invalid type"); + return false; + } + + if (frameCount == 0) + { + NazaraError("Frame count must be over zero"); + return false; + } + #endif + + m_impl = new NzAnimationImpl; + m_impl->frameCount = frameCount; + m_impl->type = type; + + NotifyCreated(); + return true; +} + +void NzAnimation::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + delete m_impl; + m_impl = nullptr; + } +} + +unsigned int NzAnimation::GetFrameCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + return m_impl->frameCount; +} + +NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + auto it = m_impl->sequenceMap.find(sequenceName); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return nullptr; + } + + return &m_impl->sequences[it->second]; + #else + return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; + #endif +} + +NzSequence* NzAnimation::GetSequence(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + if (index >= m_impl->sequences.size()) + { + NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); + return nullptr; + } + #endif + + return &m_impl->sequences[index]; +} + +const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + auto it = m_impl->sequenceMap.find(sequenceName); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return nullptr; + } + + return &m_impl->sequences[it->second]; + #else + return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; + #endif +} + +const NzSequence* NzAnimation::GetSequence(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + if (index >= m_impl->sequences.size()) + { + NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); + return nullptr; + } + #endif + + return &m_impl->sequences[index]; +} + +unsigned int NzAnimation::GetSequenceCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return 0; + } + #endif + + return m_impl->sequences.size(); +} + +int NzAnimation::GetSequenceIndex(const NzString& sequenceName) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return -1; + } + + auto it = m_impl->sequenceMap.find(sequenceName); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return -1; + } + + return it->second; + #else + return m_impl->sequenceMap[sequenceName]; + #endif +} + +nzAnimationType NzAnimation::GetType() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nzAnimationType_Static; // Ce qui est une valeur invalide pour NzAnimation + } + #endif + + return m_impl->type; +} + +bool NzAnimation::HasSequence(const NzString& sequenceName) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end(); +} + +bool NzAnimation::HasSequence(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + return index >= m_impl->sequences.size(); +} + +bool NzAnimation::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzAnimation::LoadFromFile(const NzString& filePath, const NzAnimationParams& params) +{ + return NzAnimationLoader::LoadFromFile(this, filePath, params); +} + +bool NzAnimation::LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params) +{ + return NzAnimationLoader::LoadFromMemory(this, data, size, params); +} + +bool NzAnimation::LoadFromStream(NzInputStream& stream, const NzAnimationParams& params) +{ + return NzAnimationLoader::LoadFromStream(this, stream, params); +} + +void NzAnimation::RemoveSequence(const NzString& identifier) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return; + } + + auto it = m_impl->sequenceMap.find(identifier); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return; + } + + int index = it->second; + #else + int index = m_impl->sequenceMap[identifier]; + #endif + + auto it2 = m_impl->sequences.begin(); + std::advance(it2, index); + + m_impl->sequences.erase(it2); +} + +void NzAnimation::RemoveSequence(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return; + } + + if (index >= m_impl->sequences.size()) + { + NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); + return; + } + #endif + + auto it = m_impl->sequences.begin(); + std::advance(it, index); + + m_impl->sequences.erase(it); +} + +NzAnimationLoader::LoaderList NzAnimation::s_loaders; diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index cebc3e28a..4969b3129 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -1,337 +1,339 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - NzBufferImpl* SoftwareBufferFunction(NzBuffer* parent, nzBufferType type) - { - return new NzSoftwareBuffer(parent, type); - } -} - -NzBuffer::NzBuffer(nzBufferType type) : -m_type(type), -m_typeSize(0), -m_impl(nullptr), -m_length(0) -{ -} - -NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) : -m_type(type), -m_impl(nullptr) -{ - Create(length, typeSize, storage, usage); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create buffer"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzBuffer::~NzBuffer() -{ - Destroy(); -} - -bool NzBuffer::CopyContent(NzBuffer& buffer) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer must be valid"); - return false; - } - - if (!buffer.IsValid()) - { - NazaraError("Source buffer must be valid"); - return false; - } - - if (!buffer.GetTypeSize() != m_typeSize) - { - NazaraError("Source buffer type size does not match buffer type size"); - return false; - } - #endif - - void* ptr = buffer.Map(nzBufferAccess_ReadOnly); - if (!ptr) - { - NazaraError("Failed to map source buffer"); - return false; - } - - bool r = Fill(ptr, 0, buffer.GetLength()); - - if (!buffer.Unmap()) - NazaraWarning("Failed to unmap source buffer"); - - return r; -} - -bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) -{ - Destroy(); - - // On tente d'abord de faire un buffer hardware, si supporté - if (s_bufferFunctions[storage]) - { - NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); - if (!impl->Create(length*typeSize, usage)) - { - NazaraError("Failed to create buffer"); - delete impl; - - return false; - } - - m_impl = impl; - } - else - { - NazaraError("Buffer storage not supported"); - return false; - } - - m_length = length; - m_typeSize = typeSize; - m_storage = storage; - m_usage = usage; - - // Si on arrive ici c'est que tout s'est bien passé. - return true; -} - -void NzBuffer::Destroy() -{ - if (m_impl) - { - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - } -} - -bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return false; - } - - if (offset+length > m_length) - { - NazaraError("Exceeding buffer size"); - return false; - } - #endif - - return m_impl->Fill(data, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); -} - -NzBufferImpl* NzBuffer::GetImpl() const -{ - return m_impl; -} - -unsigned int NzBuffer::GetLength() const -{ - return m_length; -} - -void* NzBuffer::GetPointer() -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return nullptr; - } - #endif - - return m_impl->GetPointer(); -} - -const void* NzBuffer::GetPointer() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return nullptr; - } - #endif - - return m_impl->GetPointer(); -} - -unsigned int NzBuffer::GetSize() const -{ - return m_length*m_typeSize; -} - -nzBufferStorage NzBuffer::GetStorage() const -{ - return m_storage; -} - -nzBufferType NzBuffer::GetType() const -{ - return m_type; -} - -nzUInt8 NzBuffer::GetTypeSize() const -{ - return m_typeSize; -} - -nzBufferUsage NzBuffer::GetUsage() const -{ - return m_usage; -} - -bool NzBuffer::IsHardware() const -{ - return m_storage == nzBufferStorage_Hardware; -} - -bool NzBuffer::IsValid() const -{ - return m_impl != nullptr; -} - -void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return nullptr; - } - - if (offset+length > m_length) - { - NazaraError("Exceeding buffer size"); - return nullptr; - } - #endif - - return m_impl->Map(access, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); -} - -bool NzBuffer::SetStorage(nzBufferStorage storage) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return false; - } - #endif - - if (m_storage == storage) - return true; - - #if NAZARA_UTILITY_SAFE - if (!IsSupported(storage)) - { - NazaraError("Storage not supported"); - return false; - } - #endif - - void* ptr = m_impl->Map(nzBufferAccess_ReadOnly, 0, m_length*m_typeSize); - if (!ptr) - { - NazaraError("Failed to map buffer"); - return false; - } - - NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); - if (!impl->Create(m_length*m_typeSize, m_usage)) - { - NazaraError("Failed to create buffer"); - delete impl; - - if (!m_impl->Unmap()) - NazaraWarning("Failed to unmap buffer"); - - return false; - } - - if (!impl->Fill(ptr, 0, m_length*m_typeSize)) - { - NazaraError("Failed to fill buffer"); - impl->Destroy(); - delete impl; - - if (!m_impl->Unmap()) - NazaraWarning("Failed to unmap buffer"); - - return false; - } - - m_impl->Unmap(); - m_impl->Destroy(); - - delete m_impl; - m_impl = impl; - - m_storage = storage; - - return true; -} - -bool NzBuffer::Unmap() -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return false; - } - #endif - - return m_impl->Unmap(); -} - -bool NzBuffer::IsSupported(nzBufferStorage storage) -{ - return s_bufferFunctions[storage] != nullptr; -} - -void NzBuffer::SetBufferFunction(nzBufferStorage storage, BufferFunction func) -{ - s_bufferFunctions[storage] = func; -} - -bool NzBuffer::Initialize() -{ - s_bufferFunctions[nzBufferStorage_Software] = SoftwareBufferFunction; - - return true; -} - -void NzBuffer::Uninitialize() -{ - std::memset(s_bufferFunctions, 0, (nzBufferStorage_Max+1)*sizeof(NzBuffer::BufferFunction)); -} - -NzBuffer::BufferFunction NzBuffer::s_bufferFunctions[nzBufferStorage_Max+1] = {0}; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + NzBufferImpl* SoftwareBufferFunction(NzBuffer* parent, nzBufferType type) + { + return new NzSoftwareBuffer(parent, type); + } +} + +NzBuffer::NzBuffer(nzBufferType type) : +m_type(type), +m_typeSize(0), +m_impl(nullptr), +m_length(0) +{ +} + +NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) : +m_type(type), +m_impl(nullptr) +{ + Create(length, typeSize, storage, usage); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create buffer"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzBuffer::~NzBuffer() +{ + Destroy(); +} + +bool NzBuffer::CopyContent(NzBuffer& buffer) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer must be valid"); + return false; + } + + if (!buffer.IsValid()) + { + NazaraError("Source buffer must be valid"); + return false; + } + + if (!buffer.GetTypeSize() != m_typeSize) + { + NazaraError("Source buffer type size does not match buffer type size"); + return false; + } + #endif + + void* ptr = buffer.Map(nzBufferAccess_ReadOnly); + if (!ptr) + { + NazaraError("Failed to map source buffer"); + return false; + } + + bool r = Fill(ptr, 0, buffer.GetLength()); + + if (!buffer.Unmap()) + NazaraWarning("Failed to unmap source buffer"); + + return r; +} + +bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) +{ + Destroy(); + + // On tente d'abord de faire un buffer hardware, si supporté + if (s_bufferFunctions[storage]) + { + NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); + if (!impl->Create(length*typeSize, usage)) + { + NazaraError("Failed to create buffer"); + delete impl; + + return false; + } + + m_impl = impl; + } + else + { + NazaraError("Buffer storage not supported"); + return false; + } + + m_length = length; + m_typeSize = typeSize; + m_storage = storage; + m_usage = usage; + + NotifyCreated(); + return true; // Si on arrive ici c'est que tout s'est bien passé. +} + +void NzBuffer::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + } +} + +bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return false; + } + + if (offset+length > m_length) + { + NazaraError("Exceeding buffer size"); + return false; + } + #endif + + return m_impl->Fill(data, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); +} + +NzBufferImpl* NzBuffer::GetImpl() const +{ + return m_impl; +} + +unsigned int NzBuffer::GetLength() const +{ + return m_length; +} + +void* NzBuffer::GetPointer() +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + #endif + + return m_impl->GetPointer(); +} + +const void* NzBuffer::GetPointer() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + #endif + + return m_impl->GetPointer(); +} + +unsigned int NzBuffer::GetSize() const +{ + return m_length*m_typeSize; +} + +nzBufferStorage NzBuffer::GetStorage() const +{ + return m_storage; +} + +nzBufferType NzBuffer::GetType() const +{ + return m_type; +} + +nzUInt8 NzBuffer::GetTypeSize() const +{ + return m_typeSize; +} + +nzBufferUsage NzBuffer::GetUsage() const +{ + return m_usage; +} + +bool NzBuffer::IsHardware() const +{ + return m_storage == nzBufferStorage_Hardware; +} + +bool NzBuffer::IsValid() const +{ + return m_impl != nullptr; +} + +void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + + if (offset+length > m_length) + { + NazaraError("Exceeding buffer size"); + return nullptr; + } + #endif + + return m_impl->Map(access, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); +} + +bool NzBuffer::SetStorage(nzBufferStorage storage) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return false; + } + #endif + + if (m_storage == storage) + return true; + + #if NAZARA_UTILITY_SAFE + if (!IsSupported(storage)) + { + NazaraError("Storage not supported"); + return false; + } + #endif + + void* ptr = m_impl->Map(nzBufferAccess_ReadOnly, 0, m_length*m_typeSize); + if (!ptr) + { + NazaraError("Failed to map buffer"); + return false; + } + + NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); + if (!impl->Create(m_length*m_typeSize, m_usage)) + { + NazaraError("Failed to create buffer"); + delete impl; + + if (!m_impl->Unmap()) + NazaraWarning("Failed to unmap buffer"); + + return false; + } + + if (!impl->Fill(ptr, 0, m_length*m_typeSize)) + { + NazaraError("Failed to fill buffer"); + impl->Destroy(); + delete impl; + + if (!m_impl->Unmap()) + NazaraWarning("Failed to unmap buffer"); + + return false; + } + + m_impl->Unmap(); + m_impl->Destroy(); + + delete m_impl; + m_impl = impl; + + m_storage = storage; + + return true; +} + +bool NzBuffer::Unmap() +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return false; + } + #endif + + return m_impl->Unmap(); +} + +bool NzBuffer::IsSupported(nzBufferStorage storage) +{ + return s_bufferFunctions[storage] != nullptr; +} + +void NzBuffer::SetBufferFunction(nzBufferStorage storage, BufferFunction func) +{ + s_bufferFunctions[storage] = func; +} + +bool NzBuffer::Initialize() +{ + s_bufferFunctions[nzBufferStorage_Software] = SoftwareBufferFunction; + + return true; +} + +void NzBuffer::Uninitialize() +{ + std::memset(s_bufferFunctions, 0, (nzBufferStorage_Max+1)*sizeof(NzBuffer::BufferFunction)); +} + +NzBuffer::BufferFunction NzBuffer::s_bufferFunctions[nzBufferStorage_Max+1] = {0}; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index ebcfa716a..75b66ca2a 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -1,1170 +1,1187 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace -{ - inline unsigned int GetLevelSize(unsigned int size, nzUInt8 level) - { - return std::max(size >> level, 1U); - } - - inline nzUInt8* GetPixelPtr(nzUInt8* base, nzUInt8 bpp, unsigned int x, unsigned int y, unsigned int z, unsigned int width, unsigned int height) - { - return &base[(width*(height*z + y) + x)*bpp]; - } -} - -bool NzImageParams::IsValid() const -{ - return true; -} - -NzImage::NzImage() : -m_sharedImage(&emptyImage) -{ -} - -NzImage::NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) : -m_sharedImage(&emptyImage) -{ - Create(type, format, width, height, depth, levelCount); - - #ifdef NAZARA_DEBUG - if (!m_sharedImage) - { - NazaraError("Failed to create image"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzImage::NzImage(const NzImage& image) : -NzResource(image), -m_sharedImage(image.m_sharedImage) -{ - if (m_sharedImage != &emptyImage) - { - NazaraMutexLock(m_sharedImage->mutex); - m_sharedImage->refCount++; - NazaraMutexUnlock(m_sharedImage->mutex); - } -} - -NzImage::NzImage(NzImage&& image) noexcept : -m_sharedImage(image.m_sharedImage) -{ - image.m_sharedImage = &emptyImage; -} - -NzImage::~NzImage() -{ - ReleaseImage(); -} - -bool NzImage::Convert(nzPixelFormat format) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!NzPixelFormat::IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - - if (!NzPixelFormat::IsConversionSupported(m_sharedImage->format, format)) - { - NazaraError("Conversion from " + NzPixelFormat::ToString(m_sharedImage->format) + " to " + NzPixelFormat::ToString(format) + " is not supported"); - return false; - } - #endif - - if (format == m_sharedImage->format) - return true; - - nzUInt8** levels = new nzUInt8*[m_sharedImage->levelCount]; - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - - // Les images 3D et cubemaps sont stockés de la même façon - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - { - unsigned int pixelsPerFace = width*height; - nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)]; - nzUInt8* pixels = m_sharedImage->pixels[i]; - unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format); - unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format); - - for (unsigned int d = 0; d < depth; ++d) - { - if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr)) - { - NazaraError("Failed to convert image"); - - // Nettoyage de la mémoire - delete[] ptr; // Permet une optimisation de boucle (GCC) - for (unsigned int j = 0; j < i; ++j) - delete[] levels[j]; - - delete[] levels; - - return false; - } - - pixels += srcStride; - ptr += dstStride; - } - - levels[i] = ptr; - - if (width > 1) - width >>= 1; - - if (height > 1) - height >>= 1; - - if (depth > 1 && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - SharedImage* newImage = new SharedImage(1, m_sharedImage->type, format, m_sharedImage->levelCount, levels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); - - ReleaseImage(); - m_sharedImage = newImage; - - return true; -} - -bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos) -{ - #if NAZARA_UTILITY_SAFE - if (!source.IsValid()) - { - NazaraError("Source image must be valid"); - return false; - } - - if (source.GetFormat() != m_sharedImage->format) - { - NazaraError("Source image format does not match destination image format"); - return false; - } - #endif - - const nzUInt8* pixels = source.GetConstPixels(0, srcCube.x, srcCube.y, srcCube.z); - if (!pixels) - { - NazaraError("Failed to access pixels"); - return false; - } - - /* - Correctif temporaire : Update veut de la mémoire contigüe - Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour - - ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) - (Appliquer l'interface à NzTexture également) - */ - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - unsigned int dstLineStride = srcCube.width*bpp; - unsigned int dstFaceStride = dstLineStride*srcCube.height; - unsigned int srcLineStride = m_sharedImage->width*bpp; - unsigned int srcFaceStride = srcLineStride*m_sharedImage->height; - - nzUInt8* cube = new nzUInt8[dstFaceStride*srcCube.depth]; - nzUInt8* ptr = cube; - - for (unsigned int z = 0; z < srcCube.depth; ++z) - { - nzUInt8* facePixels = ptr; - for (unsigned int y = 0; y < srcCube.height; ++y) - { - std::memcpy(facePixels, pixels, dstLineStride); - - facePixels += dstLineStride; - pixels += srcLineStride; - } - - ptr += dstFaceStride; - pixels += srcFaceStride; - } - - bool success = Update(cube, NzCubeui(dstPos.x, dstPos.y, dstPos.z, srcCube.width, srcCube.height, srcCube.depth)); - - delete[] cube; - - return success; -} - -bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) -{ - ReleaseImage(); - - if (width == 0 || height == 0 || depth == 0) - return true; - - #if NAZARA_UTILITY_SAFE - if (!NzPixelFormat::IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - - switch (type) - { - case nzImageType_1D: - if (height > 1) - { - NazaraError("1D textures must be 1 height"); - return false; - } - - if (depth > 1) - { - NazaraError("1D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - if (depth > 1) - { - NazaraError("2D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - break; - - case nzImageType_Cubemap: - if (depth > 1) - { - NazaraError("Cubemaps must be 1 depth"); - return false; - } - - if (width != height) - { - NazaraError("Cubemaps must have square dimensions"); - return false; - } - break; - - default: - NazaraInternalError("Image type not handled"); - return false; - } - #endif - - levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); - - nzUInt8** levels = new nzUInt8*[levelCount]; - - unsigned int w = width; - unsigned int h = height; - unsigned int d = (type == nzImageType_Cubemap) ? 6 : depth; - - for (unsigned int i = 0; i < levelCount; ++i) - { - // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs - try - { - levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBPP(format)]; - - if (w > 1) - w >>= 1; - - if (h > 1) - h >>= 1; - - if (d > 1 && type != nzImageType_Cubemap) - d >>= 1; - } - catch (const std::exception& e) - { - NazaraError("Failed to allocate image's level " + NzString::Number(i) + " (" + NzString(e.what()) + ')'); - - // Nettoyage - delete[] levels[i]; // Permet une optimisation de boucle (GCC) - for (unsigned int j = 0; j < i; ++j) - delete[] levels[j]; - - delete[] levels; - - return false; - } - } - - m_sharedImage = new SharedImage(1, type, format, levelCount, levels, width, height, depth); - - return true; -} - -void NzImage::Destroy() -{ - ReleaseImage(); -} - -bool NzImage::Fill(const NzColor& color) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot access pixels from compressed image"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* pixels = new nzUInt8[bpp]; - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - delete[] pixels; - - return false; - } - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - - for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) - { - nzUInt8* ptr = &m_sharedImage->pixels[level][0]; - nzUInt8* end = &m_sharedImage->pixels[level][width*height*depth*bpp]; - - while (ptr < end) - { - std::memcpy(ptr, pixels, bpp); - ptr += bpp; - } - - if (width > 1U) - width >>= 1; - - if (height > 1U) - height >>= 1; - - if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - delete[] pixels; - - return true; -} - -bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - - if (rect.x+rect.width > m_sharedImage->width || rect.y+rect.height > m_sharedImage->height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* pixels = new nzUInt8[bpp]; - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - delete[] pixels; - - return false; - } - - ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, rect.x, rect.y, z, m_sharedImage->width, m_sharedImage->height); - unsigned int srcStride = rect.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - for (unsigned int y = 0; y < rect.height; ++y) - { - nzUInt8* start = dstPixels; - nzUInt8* end = dstPixels + srcStride; - while (start < end) - { - std::memcpy(start, pixels, bpp); - start += bpp; - } - - dstPixels += dstStride; - } - - delete[] pixels; - - return true; -} - -bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!cube.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - - if (cube.x+cube.width > m_sharedImage->width || cube.y+cube.height > m_sharedImage->height || cube.z+cube.depth > m_sharedImage->depth) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* pixels = new nzUInt8[bpp]; - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - delete[] pixels; - - return false; - } - - ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height); - unsigned int srcStride = cube.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - unsigned int faceSize = dstStride * m_sharedImage->height; - for (unsigned int z = 0; z < cube.depth; ++z) - { - nzUInt8* facePixels = dstPixels; - for (unsigned int y = 0; y < cube.height; ++y) - { - nzUInt8* start = facePixels; - nzUInt8* end = facePixels + srcStride; - while (start < end) - { - std::memcpy(start, pixels, bpp); - start += bpp; - } - - facePixels += dstStride; - } - - dstPixels += faceSize; - } - - delete[] pixels; - - return true; -} - -bool NzImage::FlipHorizontally() -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot flip compressed image"); - return false; - } - #endif - - EnsureOwnership(); - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) - { - NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); - - if (width > 1U) - width >>= 1; - - if (height > 1U) - height >>= 1; - - if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - return true; -} - - -bool NzImage::FlipVertically() -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot flip compressed image"); - return false; - } - #endif - - EnsureOwnership(); - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) - { - NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); - - if (width > 1U) - width >>= 1; - - if (height > 1U) - height >>= 1; - - if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - return true; -} - -nzUInt8 NzImage::GetBPP() const -{ - return NzPixelFormat::GetBPP(m_sharedImage->format); -} - -const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return nullptr; - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return nullptr; - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return nullptr; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return nullptr; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return nullptr; - } - #endif - - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); -} - -unsigned int NzImage::GetDepth(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return GetLevelSize(m_sharedImage->depth, level); -} - -nzPixelFormat NzImage::GetFormat() const -{ - return m_sharedImage->format; -} - -unsigned int NzImage::GetHeight(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return GetLevelSize(m_sharedImage->height, level); -} - -nzUInt8 NzImage::GetLevelCount() const -{ - return m_sharedImage->levelCount; -} - -nzUInt8 NzImage::GetMaxLevel() const -{ - return GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); -} - -NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return NzColor(); - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot access pixels from compressed image"); - return NzColor(); - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return NzColor(); - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return NzColor(); - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return NzColor(); - } - #endif - - const nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); - - NzColor color; - if (!NzPixelFormat::Convert(m_sharedImage->format, nzPixelFormat_RGBA8, pixel, &color.r)) - NazaraError("Failed to convert image's format to RGBA8"); - - return color; -} - -nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return nullptr; - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return nullptr; - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return nullptr; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return nullptr; - } - - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return nullptr; - } - #endif - - EnsureOwnership(); - - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); -} - -unsigned int NzImage::GetSize() const -{ - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = m_sharedImage->depth; - - unsigned int size = 0; - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - { - size += width * height * depth; - - if (width > 1) - width >>= 1; - - if (height > 1) - height >>= 1; - - if (depth > 1) - depth >>= 1; - } - - if (m_sharedImage->type == nzImageType_Cubemap) - size *= 6; - - return size * NzPixelFormat::GetBPP(m_sharedImage->format); -} - -unsigned int NzImage::GetSize(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return (GetLevelSize(m_sharedImage->width, level)) * - (GetLevelSize(m_sharedImage->height, level)) * - ((m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)) * - NzPixelFormat::GetBPP(m_sharedImage->format); -} - -nzImageType NzImage::GetType() const -{ - return m_sharedImage->type; -} - -unsigned int NzImage::GetWidth(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return GetLevelSize(m_sharedImage->width, level); -} - -bool NzImage::IsCompressed() const -{ - return NzPixelFormat::IsCompressed(m_sharedImage->format); -} - -bool NzImage::IsCubemap() const -{ - return m_sharedImage->type == nzImageType_Cubemap; -} - -bool NzImage::IsValid() const -{ - return m_sharedImage != &emptyImage; -} - -bool NzImage::LoadFromFile(const NzString& filePath, const NzImageParams& params) -{ - return NzImageLoader::LoadFromFile(this, filePath, params); -} - -bool NzImage::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) -{ - return NzImageLoader::LoadFromMemory(this, data, size, params); -} - -bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params) -{ - return NzImageLoader::LoadFromStream(this, stream, params); -} - -bool NzImage::SetLevelCount(nzUInt8 levelCount) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (levelCount == 0) - { - NazaraError("Level count must be positive"); - return false; - } - #endif - - levelCount = std::min(levelCount, GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth)); - - if (m_sharedImage->levelCount == levelCount) - return true; - - EnsureOwnership(); - - nzUInt8 oldLevelCount = m_sharedImage->levelCount; - nzUInt8 maxLevelCount = std::max(levelCount, oldLevelCount); - m_sharedImage->levelCount = levelCount; // Pour faire fonctionner GetSize - - nzUInt8** pixels = new nzUInt8*[levelCount]; - for (unsigned int i = 0; i < maxLevelCount; ++i) - { - if (i < oldLevelCount) - pixels[i] = m_sharedImage->pixels[i]; - else if (i < levelCount) - pixels[i] = new nzUInt8[GetSize(i)]; - else - delete[] m_sharedImage->pixels[i]; - } - - delete[] m_sharedImage->pixels; - - m_sharedImage->pixels = pixels; - - return true; -} - -bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y, unsigned int z) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot access pixels from compressed image"); - return false; - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return false; - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return false; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return false; - } - #endif - - nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); - - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixel)) - { - NazaraError("Failed to convert RGBA8 to image's format"); - return false; - } - - return true; -} - -bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return false; - } - #endif - - EnsureOwnership(); - - std::memcpy(m_sharedImage->pixels[level], pixels, GetSize(level)); - - return true; -} - -bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int width = GetLevelSize(m_sharedImage->width, level); - unsigned int height = GetLevelSize(m_sharedImage->height, level); - - #if NAZARA_UTILITY_SAFE - if (rect.x+rect.width > width || rect.y+rect.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= " + NzString::Number(depth) + ')'); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, rect.x, rect.y, z, width, height); - unsigned int srcStride = rect.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - for (unsigned int y = 0; y < rect.height; ++y) - { - std::memcpy(dstPixels, pixels, srcStride); - pixels += srcStride; - dstPixels += dstStride; - } - - return true; -} - -bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) -{ - ///FIXME: Vérifier que ça fonctionne correctement - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return false; - } - #endif - - unsigned int width = GetLevelSize(m_sharedImage->width, level); - unsigned int height = GetLevelSize(m_sharedImage->height, level); - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->height, level); - - #if NAZARA_UTILITY_SAFE - if (!cube.IsValid()) - { - NazaraError("Invalid cube"); - return false; - } - - if (cube.x+cube.width > width || cube.y+cube.height > height || cube.z+cube.depth > depth) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, cube.x, cube.y, cube.z, width, height); - unsigned int srcStride = cube.width * bpp; - unsigned int dstStride = width * bpp; - unsigned int faceSize = dstStride * height; - for (unsigned int z = 0; z < cube.depth; ++z) - { - nzUInt8* facePixels = dstPixels; - for (unsigned int y = 0; y < cube.height; ++y) - { - std::memcpy(facePixels, pixels, srcStride); - pixels += srcStride; - facePixels += dstStride; - } - - dstPixels += faceSize; - } - - return true; -} - -NzImage& NzImage::operator=(const NzImage& image) -{ - ReleaseImage(); - - m_sharedImage = image.m_sharedImage; - if (m_sharedImage != &emptyImage) - { - NazaraMutexLock(m_sharedImage->mutex); - m_sharedImage->refCount++; - NazaraMutexUnlock(m_sharedImage->mutex); - } - - return *this; -} - -NzImage& NzImage::operator=(NzImage&& image) noexcept -{ - std::swap(m_sharedImage, image.m_sharedImage); - - return *this; -} - -nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth) -{ - static const float l2 = std::log(2.f); - - unsigned int widthLevel = std::log(static_cast(width))/l2; - unsigned int heightLevel = std::log(static_cast(height))/l2; - unsigned int depthLevel = std::log(static_cast(depth))/l2; - - return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); -} - -void NzImage::EnsureOwnership() -{ - if (m_sharedImage == &emptyImage) - return; - - NazaraLock(m_sharedImage->mutex); - if (m_sharedImage->refCount > 1) - { - m_sharedImage->refCount--; - - nzUInt8** pixels = new nzUInt8*[m_sharedImage->levelCount]; - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - { - unsigned int size = GetSize(i); - pixels[i] = new nzUInt8[size]; - std::memcpy(pixels[i], m_sharedImage->pixels[i], size); - } - - m_sharedImage = new SharedImage(1, m_sharedImage->type, m_sharedImage->format, m_sharedImage->levelCount, pixels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); - } -} - -void NzImage::ReleaseImage() -{ - if (m_sharedImage == &emptyImage) - return; - - NazaraMutexLock(m_sharedImage->mutex); - bool freeSharedImage = (--m_sharedImage->refCount == 0); - NazaraMutexUnlock(m_sharedImage->mutex); - - if (freeSharedImage) - { - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - delete[] m_sharedImage->pixels[i]; - - delete[] m_sharedImage->pixels; - delete m_sharedImage; - } - - m_sharedImage = &emptyImage; -} - -NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); -NzImageLoader::LoaderList NzImage::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +namespace +{ + inline unsigned int GetLevelSize(unsigned int size, nzUInt8 level) + { + return std::max(size >> level, 1U); + } + + inline nzUInt8* GetPixelPtr(nzUInt8* base, nzUInt8 bpp, unsigned int x, unsigned int y, unsigned int z, unsigned int width, unsigned int height) + { + return &base[(width*(height*z + y) + x)*bpp]; + } +} + +bool NzImageParams::IsValid() const +{ + return true; +} + +NzImage::NzImage() : +m_sharedImage(&emptyImage) +{ +} + +NzImage::NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) : +m_sharedImage(&emptyImage) +{ + Create(type, format, width, height, depth, levelCount); + + #ifdef NAZARA_DEBUG + if (!m_sharedImage) + { + NazaraError("Failed to create image"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzImage::NzImage(const NzImage& image) : +NzResource(image), +m_sharedImage(image.m_sharedImage) +{ + if (m_sharedImage != &emptyImage) + { + NazaraMutexLock(m_sharedImage->mutex); + m_sharedImage->refCount++; + NazaraMutexUnlock(m_sharedImage->mutex); + } +} + +NzImage::NzImage(NzImage&& image) noexcept : +m_sharedImage(image.m_sharedImage) +{ + image.m_sharedImage = &emptyImage; +} + +NzImage::~NzImage() +{ + ReleaseImage(); +} + +bool NzImage::Convert(nzPixelFormat format) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!NzPixelFormat::IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + + if (!NzPixelFormat::IsConversionSupported(m_sharedImage->format, format)) + { + NazaraError("Conversion from " + NzPixelFormat::ToString(m_sharedImage->format) + " to " + NzPixelFormat::ToString(format) + " is not supported"); + return false; + } + #endif + + if (format == m_sharedImage->format) + return true; + + nzUInt8** levels = new nzUInt8*[m_sharedImage->levelCount]; + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + + // Les images 3D et cubemaps sont stockés de la même façon + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + { + unsigned int pixelsPerFace = width*height; + nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)]; + nzUInt8* pixels = m_sharedImage->pixels[i]; + unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format); + unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format); + + for (unsigned int d = 0; d < depth; ++d) + { + if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr)) + { + NazaraError("Failed to convert image"); + + // Nettoyage de la mémoire + delete[] ptr; // Permet une optimisation de boucle (GCC) + for (unsigned int j = 0; j < i; ++j) + delete[] levels[j]; + + delete[] levels; + + return false; + } + + pixels += srcStride; + ptr += dstStride; + } + + levels[i] = ptr; + + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + if (depth > 1 && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + SharedImage* newImage = new SharedImage(1, m_sharedImage->type, format, m_sharedImage->levelCount, levels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); + + ReleaseImage(); + m_sharedImage = newImage; + + return true; +} + +bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos) +{ + #if NAZARA_UTILITY_SAFE + if (!source.IsValid()) + { + NazaraError("Source image must be valid"); + return false; + } + + if (source.GetFormat() != m_sharedImage->format) + { + NazaraError("Source image format does not match destination image format"); + return false; + } + #endif + + const nzUInt8* pixels = source.GetConstPixels(0, srcCube.x, srcCube.y, srcCube.z); + if (!pixels) + { + NazaraError("Failed to access pixels"); + return false; + } + + /* + Correctif temporaire : Update veut de la mémoire contigüe + Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour + + ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) + (Appliquer l'interface à NzTexture également) + */ + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + unsigned int dstLineStride = srcCube.width*bpp; + unsigned int dstFaceStride = dstLineStride*srcCube.height; + unsigned int srcLineStride = m_sharedImage->width*bpp; + unsigned int srcFaceStride = srcLineStride*m_sharedImage->height; + + nzUInt8* cube = new nzUInt8[dstFaceStride*srcCube.depth]; + nzUInt8* ptr = cube; + + for (unsigned int z = 0; z < srcCube.depth; ++z) + { + nzUInt8* facePixels = ptr; + for (unsigned int y = 0; y < srcCube.height; ++y) + { + std::memcpy(facePixels, pixels, dstLineStride); + + facePixels += dstLineStride; + pixels += srcLineStride; + } + + ptr += dstFaceStride; + pixels += srcFaceStride; + } + + bool success = Update(cube, NzCubeui(dstPos.x, dstPos.y, dstPos.z, srcCube.width, srcCube.height, srcCube.depth)); + + delete[] cube; + + return success; +} + +bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) +{ + ReleaseImage(); + + #if NAZARA_UTILITY_SAFE + if (!NzPixelFormat::IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + + if (width == 0) + { + NazaraError("Width must be at least 1 (0)"); + return false; + } + + if (height == 0) + { + NazaraError("Height must be at least 1 (0)"); + return false; + } + + if (depth == 0) + { + NazaraError("Depth must be at least 1 (0)"); + return false; + } + + switch (type) + { + case nzImageType_1D: + if (height > 1) + { + NazaraError("1D textures must be 1 height"); + return false; + } + + if (depth > 1) + { + NazaraError("1D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + if (depth > 1) + { + NazaraError("2D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + break; + + case nzImageType_Cubemap: + if (depth > 1) + { + NazaraError("Cubemaps must be 1 depth"); + return false; + } + + if (width != height) + { + NazaraError("Cubemaps must have square dimensions"); + return false; + } + break; + + default: + NazaraInternalError("Image type not handled"); + return false; + } + #endif + + levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); + + nzUInt8** levels = new nzUInt8*[levelCount]; + + unsigned int w = width; + unsigned int h = height; + unsigned int d = (type == nzImageType_Cubemap) ? 6 : depth; + + for (unsigned int i = 0; i < levelCount; ++i) + { + // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs + try + { + levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBPP(format)]; + + if (w > 1) + w >>= 1; + + if (h > 1) + h >>= 1; + + if (d > 1 && type != nzImageType_Cubemap) + d >>= 1; + } + catch (const std::exception& e) + { + NazaraError("Failed to allocate image's level " + NzString::Number(i) + " (" + NzString(e.what()) + ')'); + + // Nettoyage + delete[] levels[i]; // Permet une optimisation de boucle (GCC) + for (unsigned int j = 0; j < i; ++j) + delete[] levels[j]; + + delete[] levels; + + return false; + } + } + + m_sharedImage = new SharedImage(1, type, format, levelCount, levels, width, height, depth); + + NotifyCreated(); + return true; +} + +void NzImage::Destroy() +{ + NotifyDestroy(); + ReleaseImage(); +} + +bool NzImage::Fill(const NzColor& color) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot access pixels from compressed image"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* pixels = new nzUInt8[bpp]; + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + delete[] pixels; + + return false; + } + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + + for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) + { + nzUInt8* ptr = &m_sharedImage->pixels[level][0]; + nzUInt8* end = &m_sharedImage->pixels[level][width*height*depth*bpp]; + + while (ptr < end) + { + std::memcpy(ptr, pixels, bpp); + ptr += bpp; + } + + if (width > 1U) + width >>= 1; + + if (height > 1U) + height >>= 1; + + if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + delete[] pixels; + + return true; +} + +bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + + if (rect.x+rect.width > m_sharedImage->width || rect.y+rect.height > m_sharedImage->height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* pixels = new nzUInt8[bpp]; + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + delete[] pixels; + + return false; + } + + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, rect.x, rect.y, z, m_sharedImage->width, m_sharedImage->height); + unsigned int srcStride = rect.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + for (unsigned int y = 0; y < rect.height; ++y) + { + nzUInt8* start = dstPixels; + nzUInt8* end = dstPixels + srcStride; + while (start < end) + { + std::memcpy(start, pixels, bpp); + start += bpp; + } + + dstPixels += dstStride; + } + + delete[] pixels; + + return true; +} + +bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!cube.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + + if (cube.x+cube.width > m_sharedImage->width || cube.y+cube.height > m_sharedImage->height || cube.z+cube.depth > m_sharedImage->depth) + { + NazaraError("Cube dimensions are out of bounds"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* pixels = new nzUInt8[bpp]; + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + delete[] pixels; + + return false; + } + + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height); + unsigned int srcStride = cube.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + unsigned int faceSize = dstStride * m_sharedImage->height; + for (unsigned int z = 0; z < cube.depth; ++z) + { + nzUInt8* facePixels = dstPixels; + for (unsigned int y = 0; y < cube.height; ++y) + { + nzUInt8* start = facePixels; + nzUInt8* end = facePixels + srcStride; + while (start < end) + { + std::memcpy(start, pixels, bpp); + start += bpp; + } + + facePixels += dstStride; + } + + dstPixels += faceSize; + } + + delete[] pixels; + + return true; +} + +bool NzImage::FlipHorizontally() +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot flip compressed image"); + return false; + } + #endif + + EnsureOwnership(); + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) + { + NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); + + if (width > 1U) + width >>= 1; + + if (height > 1U) + height >>= 1; + + if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + return true; +} + + +bool NzImage::FlipVertically() +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot flip compressed image"); + return false; + } + #endif + + EnsureOwnership(); + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) + { + NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); + + if (width > 1U) + width >>= 1; + + if (height > 1U) + height >>= 1; + + if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + return true; +} + +nzUInt8 NzImage::GetBPP() const +{ + return NzPixelFormat::GetBPP(m_sharedImage->format); +} + +const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return nullptr; + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return nullptr; + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return nullptr; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return nullptr; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return nullptr; + } + #endif + + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); +} + +unsigned int NzImage::GetDepth(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return GetLevelSize(m_sharedImage->depth, level); +} + +nzPixelFormat NzImage::GetFormat() const +{ + return m_sharedImage->format; +} + +unsigned int NzImage::GetHeight(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return GetLevelSize(m_sharedImage->height, level); +} + +nzUInt8 NzImage::GetLevelCount() const +{ + return m_sharedImage->levelCount; +} + +nzUInt8 NzImage::GetMaxLevel() const +{ + return GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); +} + +NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return NzColor(); + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot access pixels from compressed image"); + return NzColor(); + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return NzColor(); + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return NzColor(); + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return NzColor(); + } + #endif + + const nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + + NzColor color; + if (!NzPixelFormat::Convert(m_sharedImage->format, nzPixelFormat_RGBA8, pixel, &color.r)) + NazaraError("Failed to convert image's format to RGBA8"); + + return color; +} + +nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return nullptr; + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return nullptr; + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return nullptr; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return nullptr; + } + + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return nullptr; + } + #endif + + EnsureOwnership(); + + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); +} + +unsigned int NzImage::GetSize() const +{ + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = m_sharedImage->depth; + + unsigned int size = 0; + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + { + size += width * height * depth; + + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + if (depth > 1) + depth >>= 1; + } + + if (m_sharedImage->type == nzImageType_Cubemap) + size *= 6; + + return size * NzPixelFormat::GetBPP(m_sharedImage->format); +} + +unsigned int NzImage::GetSize(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return (GetLevelSize(m_sharedImage->width, level)) * + (GetLevelSize(m_sharedImage->height, level)) * + ((m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)) * + NzPixelFormat::GetBPP(m_sharedImage->format); +} + +nzImageType NzImage::GetType() const +{ + return m_sharedImage->type; +} + +unsigned int NzImage::GetWidth(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return GetLevelSize(m_sharedImage->width, level); +} + +bool NzImage::IsCompressed() const +{ + return NzPixelFormat::IsCompressed(m_sharedImage->format); +} + +bool NzImage::IsCubemap() const +{ + return m_sharedImage->type == nzImageType_Cubemap; +} + +bool NzImage::IsValid() const +{ + return m_sharedImage != &emptyImage; +} + +bool NzImage::LoadFromFile(const NzString& filePath, const NzImageParams& params) +{ + return NzImageLoader::LoadFromFile(this, filePath, params); +} + +bool NzImage::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) +{ + return NzImageLoader::LoadFromMemory(this, data, size, params); +} + +bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params) +{ + return NzImageLoader::LoadFromStream(this, stream, params); +} + +bool NzImage::SetLevelCount(nzUInt8 levelCount) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (levelCount == 0) + { + NazaraError("Level count must be positive"); + return false; + } + #endif + + levelCount = std::min(levelCount, GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth)); + + if (m_sharedImage->levelCount == levelCount) + return true; + + EnsureOwnership(); + + nzUInt8 oldLevelCount = m_sharedImage->levelCount; + nzUInt8 maxLevelCount = std::max(levelCount, oldLevelCount); + m_sharedImage->levelCount = levelCount; // Pour faire fonctionner GetSize + + nzUInt8** pixels = new nzUInt8*[levelCount]; + for (unsigned int i = 0; i < maxLevelCount; ++i) + { + if (i < oldLevelCount) + pixels[i] = m_sharedImage->pixels[i]; + else if (i < levelCount) + pixels[i] = new nzUInt8[GetSize(i)]; + else + delete[] m_sharedImage->pixels[i]; + } + + delete[] m_sharedImage->pixels; + + m_sharedImage->pixels = pixels; + + return true; +} + +bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y, unsigned int z) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot access pixels from compressed image"); + return false; + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return false; + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return false; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return false; + } + #endif + + nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixel)) + { + NazaraError("Failed to convert RGBA8 to image's format"); + return false; + } + + return true; +} + +bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return false; + } + #endif + + EnsureOwnership(); + + std::memcpy(m_sharedImage->pixels[level], pixels, GetSize(level)); + + return true; +} + +bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int width = GetLevelSize(m_sharedImage->width, level); + unsigned int height = GetLevelSize(m_sharedImage->height, level); + + #if NAZARA_UTILITY_SAFE + if (rect.x+rect.width > width || rect.y+rect.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= " + NzString::Number(depth) + ')'); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, rect.x, rect.y, z, width, height); + unsigned int srcStride = rect.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + for (unsigned int y = 0; y < rect.height; ++y) + { + std::memcpy(dstPixels, pixels, srcStride); + pixels += srcStride; + dstPixels += dstStride; + } + + return true; +} + +bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) +{ + ///FIXME: Vérifier que ça fonctionne correctement + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return false; + } + #endif + + unsigned int width = GetLevelSize(m_sharedImage->width, level); + unsigned int height = GetLevelSize(m_sharedImage->height, level); + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->height, level); + + #if NAZARA_UTILITY_SAFE + if (!cube.IsValid()) + { + NazaraError("Invalid cube"); + return false; + } + + if (cube.x+cube.width > width || cube.y+cube.height > height || cube.z+cube.depth > depth) + { + NazaraError("Cube dimensions are out of bounds"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, cube.x, cube.y, cube.z, width, height); + unsigned int srcStride = cube.width * bpp; + unsigned int dstStride = width * bpp; + unsigned int faceSize = dstStride * height; + for (unsigned int z = 0; z < cube.depth; ++z) + { + nzUInt8* facePixels = dstPixels; + for (unsigned int y = 0; y < cube.height; ++y) + { + std::memcpy(facePixels, pixels, srcStride); + pixels += srcStride; + facePixels += dstStride; + } + + dstPixels += faceSize; + } + + return true; +} + +NzImage& NzImage::operator=(const NzImage& image) +{ + ReleaseImage(); + + m_sharedImage = image.m_sharedImage; + if (m_sharedImage != &emptyImage) + { + NazaraMutexLock(m_sharedImage->mutex); + m_sharedImage->refCount++; + NazaraMutexUnlock(m_sharedImage->mutex); + } + + return *this; +} + +NzImage& NzImage::operator=(NzImage&& image) noexcept +{ + std::swap(m_sharedImage, image.m_sharedImage); + + return *this; +} + +nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth) +{ + static const float l2 = std::log(2.f); + + unsigned int widthLevel = std::log(static_cast(width))/l2; + unsigned int heightLevel = std::log(static_cast(height))/l2; + unsigned int depthLevel = std::log(static_cast(depth))/l2; + + return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); +} + +void NzImage::EnsureOwnership() +{ + if (m_sharedImage == &emptyImage) + return; + + NazaraLock(m_sharedImage->mutex); + if (m_sharedImage->refCount > 1) + { + m_sharedImage->refCount--; + + nzUInt8** pixels = new nzUInt8*[m_sharedImage->levelCount]; + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + { + unsigned int size = GetSize(i); + pixels[i] = new nzUInt8[size]; + std::memcpy(pixels[i], m_sharedImage->pixels[i], size); + } + + m_sharedImage = new SharedImage(1, m_sharedImage->type, m_sharedImage->format, m_sharedImage->levelCount, pixels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); + } +} + +void NzImage::ReleaseImage() +{ + if (m_sharedImage == &emptyImage) + return; + + NazaraMutexLock(m_sharedImage->mutex); + bool freeSharedImage = (--m_sharedImage->refCount == 0); + NazaraMutexUnlock(m_sharedImage->mutex); + + if (freeSharedImage) + { + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + delete[] m_sharedImage->pixels[i]; + + delete[] m_sharedImage->pixels; + delete m_sharedImage; + } + + m_sharedImage = &emptyImage; +} + +NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); +NzImageLoader::LoaderList NzImage::s_loaders; diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index bb30b5832..8af677a6b 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -1,221 +1,200 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters) - { - NazaraUnused(parameters); - - nzUInt32 magic[2]; - if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) - return false; - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&magic[0], sizeof(nzUInt32)); - NzByteSwap(&magic[1], sizeof(nzUInt32)); - #endif - - return magic[0] == md2Ident && magic[1] == 8; - } - - bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) - { - md2_header header; - if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header)) - { - NazaraError("Failed to read header"); - return false; - } - - // Les fichiers MD2 sont en little endian - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&header.ident, sizeof(nzUInt32)); - #endif - - if (header.ident != md2Ident) - { - NazaraError("Invalid MD2 file"); - return false; - } - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&header.version, sizeof(nzUInt32)); - #endif - - if (header.version != 8) - { - NazaraError("Bad version number (" + NzString::Number(header.version) + ')'); - return false; - } - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&header.skinwidth, sizeof(nzUInt32)); - NzByteSwap(&header.skinheight, sizeof(nzUInt32)); - NzByteSwap(&header.framesize, sizeof(nzUInt32)); - NzByteSwap(&header.num_skins, sizeof(nzUInt32)); - NzByteSwap(&header.num_vertices, sizeof(nzUInt32)); - NzByteSwap(&header.num_st, sizeof(nzUInt32)); - NzByteSwap(&header.num_tris, sizeof(nzUInt32)); - NzByteSwap(&header.num_glcmds, sizeof(nzUInt32)); - NzByteSwap(&header.num_frames, sizeof(nzUInt32)); - NzByteSwap(&header.offset_skins, sizeof(nzUInt32)); - NzByteSwap(&header.offset_st, sizeof(nzUInt32)); - NzByteSwap(&header.offset_tris, sizeof(nzUInt32)); - NzByteSwap(&header.offset_frames, sizeof(nzUInt32)); - NzByteSwap(&header.offset_glcmds, sizeof(nzUInt32)); - NzByteSwap(&header.offset_end, sizeof(nzUInt32)); - #endif - - if (stream.GetSize() < header.offset_end) - { - NazaraError("Incomplete MD2 file"); - return false; - } - - /// Création du mesh - // Animé ou statique, c'est la question - bool animated; - unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); - unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); - - if (parameters.loadAnimations && startFrame != endFrame) - animated = true; - else - animated = false; - - if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait pas échouer - { - NazaraInternalError("Failed to create mesh"); - return false; - } - - /// Chargement des skins - if (header.num_skins > 0) - { - stream.SetCursorPos(header.offset_skins); - { - char skin[68]; - for (unsigned int i = 0; i < header.num_skins; ++i) - { - stream.Read(skin, 68*sizeof(char)); - mesh->AddSkin(skin); - } - } - } - - /// Chargement des animmations - if (animated) - { - NzAnimation* animation = new NzAnimation; - if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1)) - { - // Décodage des séquences - NzString frameName; - - NzSequence sequence; - sequence.framePerSecond = 10; // Par défaut pour les animations MD2 - - char name[16], last[16]; - stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + offsetof(md2_frame, name)); - stream.Read(last, 16*sizeof(char)); - - int pos = std::strlen(last)-1; - for (unsigned int j = 0; j < 2; ++j) - { - if (!std::isdigit(last[pos])) - break; - - pos--; - } - last[pos+1] = '\0'; - - unsigned int numFrames = 0; - for (unsigned int i = startFrame; i <= endFrame; ++i) - { - stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name)); - stream.Read(name, 16*sizeof(char)); - - pos = std::strlen(name)-1; - for (unsigned int j = 0; j < 2; ++j) - { - if (!std::isdigit(name[pos])) - break; - - pos--; - } - name[pos+1] = '\0'; - - if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom - { - // Alors on enregistre la séquence - sequence.firstFrame = i-numFrames; - sequence.lastFrame = i-1; - sequence.name = last; - animation->AddSequence(sequence); - - std::strcpy(last, name); - - numFrames = 0; - } - - numFrames++; - } - - // On ajoute la dernière frame (Qui n'a pas été traitée par la boucle) - sequence.firstFrame = endFrame-numFrames; - sequence.lastFrame = endFrame; - sequence.name = last; - animation->AddSequence(sequence); - - mesh->SetAnimation(animation); - animation->SetPersistent(false); - } - else - NazaraInternalError("Failed to create animaton"); - } - - /// Chargement des submesh - // Actuellement le loader ne charge qu'un submesh - // TODO: Utiliser les commandes OpenGL pour accélérer le rendu - NzMD2Mesh* subMesh = new NzMD2Mesh(mesh); - if (!subMesh->Create(header, stream, parameters)) - { - NazaraError("Failed to create MD2 mesh"); - return false; - } - - mesh->AddSubMesh(subMesh); - - return true; - } -} - -void NzLoaders_MD2_Register() -{ - NzMD2Mesh::Initialize(); - - NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); -} - -void NzLoaders_MD2_Unregister() -{ - NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); - - NzMD2Mesh::Uninitialize(); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters) + { + NazaraUnused(parameters); + + nzUInt32 magic[2]; + if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) + return false; + + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&magic[0], sizeof(nzUInt32)); + NzByteSwap(&magic[1], sizeof(nzUInt32)); + #endif + + return magic[0] == md2Ident && magic[1] == 8; + } + + bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) + { + md2_header header; + if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header)) + { + NazaraError("Failed to read header"); + return false; + } + + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&header.skinwidth, sizeof(nzUInt32)); + NzByteSwap(&header.skinheight, sizeof(nzUInt32)); + NzByteSwap(&header.framesize, sizeof(nzUInt32)); + NzByteSwap(&header.num_skins, sizeof(nzUInt32)); + NzByteSwap(&header.num_vertices, sizeof(nzUInt32)); + NzByteSwap(&header.num_st, sizeof(nzUInt32)); + NzByteSwap(&header.num_tris, sizeof(nzUInt32)); + NzByteSwap(&header.num_glcmds, sizeof(nzUInt32)); + NzByteSwap(&header.num_frames, sizeof(nzUInt32)); + NzByteSwap(&header.offset_skins, sizeof(nzUInt32)); + NzByteSwap(&header.offset_st, sizeof(nzUInt32)); + NzByteSwap(&header.offset_tris, sizeof(nzUInt32)); + NzByteSwap(&header.offset_frames, sizeof(nzUInt32)); + NzByteSwap(&header.offset_glcmds, sizeof(nzUInt32)); + NzByteSwap(&header.offset_end, sizeof(nzUInt32)); + #endif + + if (stream.GetSize() < header.offset_end) + { + NazaraError("Incomplete MD2 file"); + return false; + } + + /// Création du mesh + // Animé ou statique, c'est la question + bool animated; + unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); + unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); + + if (parameters.loadAnimations && startFrame != endFrame) + animated = true; + else + animated = false; + + if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait jamais échouer + { + NazaraInternalError("Failed to create mesh"); + return false; + } + + /// Chargement des skins + if (header.num_skins > 0) + { + stream.SetCursorPos(header.offset_skins); + { + char skin[68]; + for (unsigned int i = 0; i < header.num_skins; ++i) + { + stream.Read(skin, 68*sizeof(char)); + mesh->AddSkin(skin); + } + } + } + + /// Chargement des animmations + if (animated) + { + NzAnimation* animation = new NzAnimation; + if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1)) + { + // Décodage des séquences + NzString frameName; + + NzSequence sequence; + sequence.framePerSecond = 10; // Par défaut pour les animations MD2 + + char name[16], last[16]; + stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + offsetof(md2_frame, name)); + stream.Read(last, 16*sizeof(char)); + + int pos = std::strlen(last)-1; + for (unsigned int j = 0; j < 2; ++j) + { + if (!std::isdigit(last[pos])) + break; + + pos--; + } + last[pos+1] = '\0'; + + unsigned int numFrames = 0; + for (unsigned int i = startFrame; i <= endFrame; ++i) + { + stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name)); + stream.Read(name, 16*sizeof(char)); + + pos = std::strlen(name)-1; + for (unsigned int j = 0; j < 2; ++j) + { + if (!std::isdigit(name[pos])) + break; + + pos--; + } + name[pos+1] = '\0'; + + if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom + { + // Alors on enregistre la séquence + sequence.firstFrame = i-numFrames; + sequence.lastFrame = i-1; + sequence.name = last; + animation->AddSequence(sequence); + + std::strcpy(last, name); + + numFrames = 0; + } + + numFrames++; + } + + // On ajoute la dernière frame (Qui n'a pas été traitée par la boucle) + sequence.firstFrame = endFrame-numFrames; + sequence.lastFrame = endFrame; + sequence.name = last; + animation->AddSequence(sequence); + + mesh->SetAnimation(animation); + animation->SetPersistent(false); + } + else + NazaraInternalError("Failed to create animaton"); + } + + /// Chargement des submesh + // Actuellement le loader ne charge qu'un submesh + // TODO: Utiliser les commandes OpenGL pour accélérer le rendu + NzMD2Mesh* subMesh = new NzMD2Mesh(mesh); + if (!subMesh->Create(header, stream, parameters)) + { + NazaraError("Failed to create MD2 mesh"); + return false; + } + + mesh->AddSubMesh(subMesh); + + return true; + } +} + +void NzLoaders_MD2_Register() +{ + NzMD2Mesh::Initialize(); + + NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); +} + +void NzLoaders_MD2_Unregister() +{ + NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); + + NzMD2Mesh::Uninitialize(); +} diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp index 2d25e0db7..c4c311c3c 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp @@ -1,287 +1,292 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -NzMD2Mesh::NzMD2Mesh(const NzMesh* parent) : -NzKeyframeMesh(parent), -m_frames(nullptr), -m_indexBuffer(nullptr), -m_vertexBuffer(nullptr) -{ -} - -NzMD2Mesh::~NzMD2Mesh() -{ - Destroy(); -} - -bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters) -{ - Destroy(); - - unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); - unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); - - m_frameCount = endFrame - startFrame + 1; - m_vertexCount = header.num_tris*3; - - /// Chargement des vertices - std::vector texCoords(header.num_st); - std::vector triangles(header.num_tris); - - // Lecture des coordonnées de texture - stream.SetCursorPos(header.offset_st); - stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord)); - - #if defined(NAZARA_BIG_ENDIAN) - for (unsigned int i = 0; i < header.num_st; ++i) - { - NzByteSwap(&texCoords[i].u, sizeof(nzInt16)); - NzByteSwap(&texCoords[i].v, sizeof(nzInt16)); - } - #endif - - stream.SetCursorPos(header.offset_tris); - stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle)); - - #if defined(NAZARA_BIG_ENDIAN) - for (unsigned int i = 0; i < header.num_tris; ++i) - { - NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16)); - NzByteSwap(&texCoords[i].texCoords[0], sizeof(nzUInt16)); - - NzByteSwap(&triangles[i].vertices[1], sizeof(nzUInt16)); - NzByteSwap(&texCoords[i].texCoords[1], sizeof(nzUInt16)); - - NzByteSwap(&triangles[i].vertices[2], sizeof(nzUInt16)); - NzByteSwap(&texCoords[i].texCoords[2], sizeof(nzUInt16)); - } - #endif - - stream.SetCursorPos(header.offset_frames + header.framesize*startFrame); - - md2_frame frame; - frame.vertices.resize(header.num_vertices); - - // Pour que le modèle soit correctement aligné, on génère une matrice de rotation que nous appliquerons à chacune des vertices - NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(90.f, -90.f, 0.f)); - - unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); - - m_frames = new Frame[m_frameCount]; - for (unsigned int i = 0; i < m_frameCount; ++i) - { - stream.Read(&frame.scale, sizeof(NzVector3f)); - stream.Read(&frame.translate, sizeof(NzVector3f)); - stream.Read(&frame.name, 16*sizeof(char)); - stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex)); - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&frame.scale.x, sizeof(float)); - NzByteSwap(&frame.scale.y, sizeof(float)); - NzByteSwap(&frame.scale.z, sizeof(float)); - - NzByteSwap(&frame.translate.x, sizeof(float)); - NzByteSwap(&frame.translate.y, sizeof(float)); - NzByteSwap(&frame.translate.z, sizeof(float)); - #endif - - m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice de la normale plutôt que la normale (gain d'espace) - m_frames[i].vertices = new NzVector3f[m_vertexCount]; - - NzVector3f max, min; - for (unsigned int t = 0; t < header.num_tris; ++t) - { - for (unsigned int v = 0; v < 3; ++v) - { - const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]]; - - NzVector3f vertex = rotationMatrix * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z); - max.MakeCeil(vertex); - min.MakeFloor(vertex); - - m_frames[i].normal[t*3+v] = vert.n; - m_frames[i].vertices[t*3+v] = vertex; - } - } - - m_frames[i].aabb.SetExtends(min, max); - } - - m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant - m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic); - - nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); - if (!ptr) - { - NazaraError("Failed to map vertex buffer"); - Destroy(); - - return false; - } - - // On avance jusqu'aux premières coordonnées de texture - ptr += s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_TexCoord)->offset; - for (unsigned int t = 0; t < header.num_tris; ++t) - { - for (unsigned int v = 0; v < 3; ++v) - { - const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]]; - - NzVector2f* coords = reinterpret_cast(ptr); - coords->x = texC.u / static_cast(header.skinwidth); - coords->y = 1.f - texC.v / static_cast(header.skinheight); - - ptr += stride; - } - } - - if (!m_vertexBuffer->Unmap()) - { - NazaraError("Failed to unmap buffer"); - Destroy(); - - return false; - } - - m_vertexBuffer->AddResourceReference(); - m_vertexBuffer->SetPersistent(false); - - AnimateImpl(0, 0, 0.f); - - return true; -} - -void NzMD2Mesh::Destroy() -{ - if (m_frames) - { - for (unsigned int i = 0; i < m_frameCount; ++i) - { - delete[] m_frames[i].normal; - delete[] m_frames[i].vertices; - } - - delete[] m_frames; - m_frames = nullptr; - } - - if (m_indexBuffer) - { - m_indexBuffer->RemoveResourceReference(); - m_indexBuffer = nullptr; - } - - if (m_vertexBuffer) - { - m_vertexBuffer->RemoveResourceReference(); - m_vertexBuffer = nullptr; - } -} - -const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const -{ - return m_aabb; -} - -nzAnimationType NzMD2Mesh::GetAnimationType() const -{ - if (m_frameCount > 1) - return nzAnimationType_Keyframe; - else - return nzAnimationType_Static; -} - -unsigned int NzMD2Mesh::GetFrameCount() const -{ - return m_frameCount; -} - -const NzIndexBuffer* NzMD2Mesh::GetIndexBuffer() const -{ - return nullptr; - //return m_indexBuffer; -} - -nzPrimitiveType NzMD2Mesh::GetPrimitiveType() const -{ - return nzPrimitiveType_TriangleList; -} - -const NzVertexBuffer* NzMD2Mesh::GetVertexBuffer() const -{ - return m_vertexBuffer; -} - -const NzVertexDeclaration* NzMD2Mesh::GetVertexDeclaration() const -{ - return &s_declaration; -} - -void NzMD2Mesh::Initialize() -{ - NzVertexElement elements[3]; - elements[0].offset = 0; - elements[0].type = nzElementType_Float3; - elements[0].usage = nzElementUsage_Position; - - elements[1].offset = 3*sizeof(float); - elements[1].type = nzElementType_Float3; - elements[1].usage = nzElementUsage_Normal; - - elements[2].offset = 3*sizeof(float) + 3*sizeof(float); - elements[2].type = nzElementType_Float2; - elements[2].usage = nzElementUsage_TexCoord; - - s_declaration.Create(elements, 3); -} - -void NzMD2Mesh::Uninitialize() -{ - s_declaration.Destroy(); -} - -void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) -{ - nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); - if (!ptr) - { - NazaraError("Failed to map vertex buffer"); - return; - } - - unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); - unsigned int positionOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Position)->offset; - unsigned int normalOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Normal)->offset; - - Frame* fA = &m_frames[frameA]; - Frame* fB = &m_frames[frameB]; - for (unsigned int i = 0; i < m_vertexCount; ++i) - { - NzVector3f* position = reinterpret_cast(ptr + positionOffset); - NzVector3f* normal = reinterpret_cast(ptr + normalOffset); - - *position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]); - *normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]); - - ptr += stride; - } - - if (!m_vertexBuffer->Unmap()) - NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption"); - - // Interpolation de l'AABB - NzVector3f max1 = fA->aabb.GetMaximum(); - NzVector3f min1 = fA->aabb.GetMinimum(); - m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1)); -} - -NzVertexDeclaration NzMD2Mesh::s_declaration; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +NzMD2Mesh::NzMD2Mesh(const NzMesh* parent) : +NzKeyframeMesh(parent), +m_frames(nullptr), +m_indexBuffer(nullptr), +m_vertexBuffer(nullptr) +{ +} + +NzMD2Mesh::~NzMD2Mesh() +{ + Destroy(); +} + +bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters) +{ + Destroy(); + + unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); + unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); + + m_frameCount = endFrame - startFrame + 1; + m_vertexCount = header.num_tris * 3; + + /// Chargement des vertices + std::vector texCoords(header.num_st); + std::vector triangles(header.num_tris); + + // Lecture des coordonnées de texture + stream.SetCursorPos(header.offset_st); + stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord)); + + #if defined(NAZARA_BIG_ENDIAN) + for (unsigned int i = 0; i < header.num_st; ++i) + { + NzByteSwap(&texCoords[i].u, sizeof(nzInt16)); + NzByteSwap(&texCoords[i].v, sizeof(nzInt16)); + } + #endif + + stream.SetCursorPos(header.offset_tris); + stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle)); + + #if defined(NAZARA_BIG_ENDIAN) + for (unsigned int i = 0; i < header.num_tris; ++i) + { + NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16)); + NzByteSwap(&texCoords[i].texCoords[0], sizeof(nzUInt16)); + + NzByteSwap(&triangles[i].vertices[1], sizeof(nzUInt16)); + NzByteSwap(&texCoords[i].texCoords[1], sizeof(nzUInt16)); + + NzByteSwap(&triangles[i].vertices[2], sizeof(nzUInt16)); + NzByteSwap(&texCoords[i].texCoords[2], sizeof(nzUInt16)); + } + #endif + + stream.SetCursorPos(header.offset_frames + header.framesize*startFrame); + + md2_frame frame; + frame.vertices.resize(header.num_vertices); + + // Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices + NzQuaternionf rotationQuat = NzEulerAnglesf(-90.f, 90.f, 0.f); + //NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, -90.f, 0.f)); + + unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); + + m_frames = new Frame[m_frameCount]; + for (unsigned int i = 0; i < m_frameCount; ++i) + { + stream.Read(&frame.scale, sizeof(NzVector3f)); + stream.Read(&frame.translate, sizeof(NzVector3f)); + stream.Read(&frame.name, 16*sizeof(char)); + stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex)); + + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&frame.scale.x, sizeof(float)); + NzByteSwap(&frame.scale.y, sizeof(float)); + NzByteSwap(&frame.scale.z, sizeof(float)); + + NzByteSwap(&frame.translate.x, sizeof(float)); + NzByteSwap(&frame.translate.y, sizeof(float)); + NzByteSwap(&frame.translate.z, sizeof(float)); + #endif + + m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice MD2 de la normale plutôt que la normale (gain d'espace) + m_frames[i].vertices = new NzVector3f[m_vertexCount]; + + NzVector3f max, min; + for (unsigned int t = 0; t < header.num_tris; ++t) + { + for (unsigned int v = 0; v < 3; ++v) + { + const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]]; + + NzVector3f vertex = rotationQuat * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z); + + // On fait en sorte d'avoir deux vertices de délimitation, définissant un rectangle dans l'espace + max.Maximize(vertex); + min.Minimize(vertex); + + // Le MD2 ne définit pas ses vertices dans le bon ordre, il nous faut donc les ajouter dans l'ordre inverse + unsigned int index = m_vertexCount - (t*3 + v) - 1; + m_frames[i].normal[index] = vert.n; + m_frames[i].vertices[index] = vertex; + } + } + + m_frames[i].aabb.SetExtends(min, max); + } + + m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant + m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic); + + nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); + if (!ptr) + { + NazaraError("Failed to map vertex buffer"); + Destroy(); + + return false; + } + + // On avance jusqu'aux dernières coordonnées de texture et on les définit dans l'ordre inverse + ptr += s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_TexCoord)->offset + stride * (m_vertexCount-1); + for (unsigned int t = 0; t < header.num_tris; ++t) + { + for (unsigned int v = 0; v < 3; ++v) + { + const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]]; + + NzVector2f* coords = reinterpret_cast(ptr); + coords->x = texC.u / static_cast(header.skinwidth); + coords->y = 1.f - texC.v / static_cast(header.skinheight); + + ptr -= stride; + } + } + + if (!m_vertexBuffer->Unmap()) + { + NazaraError("Failed to unmap buffer"); + Destroy(); + + return false; + } + + m_vertexBuffer->AddResourceReference(); + m_vertexBuffer->SetPersistent(false); + + AnimateImpl(0, 0, 0.f); + + return true; +} + +void NzMD2Mesh::Destroy() +{ + if (m_frames) + { + for (unsigned int i = 0; i < m_frameCount; ++i) + { + delete[] m_frames[i].normal; + delete[] m_frames[i].vertices; + } + + delete[] m_frames; + m_frames = nullptr; + } + + if (m_indexBuffer) + { + m_indexBuffer->RemoveResourceReference(); + m_indexBuffer = nullptr; + } + + if (m_vertexBuffer) + { + m_vertexBuffer->RemoveResourceReference(); + m_vertexBuffer = nullptr; + } +} + +const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const +{ + return m_aabb; +} + +nzAnimationType NzMD2Mesh::GetAnimationType() const +{ + if (m_frameCount > 1) + return nzAnimationType_Keyframe; + else + return nzAnimationType_Static; +} + +unsigned int NzMD2Mesh::GetFrameCount() const +{ + return m_frameCount; +} + +const NzIndexBuffer* NzMD2Mesh::GetIndexBuffer() const +{ + return nullptr; + //return m_indexBuffer; +} + +nzPrimitiveType NzMD2Mesh::GetPrimitiveType() const +{ + return nzPrimitiveType_TriangleList; +} + +const NzVertexBuffer* NzMD2Mesh::GetVertexBuffer() const +{ + return m_vertexBuffer; +} + +const NzVertexDeclaration* NzMD2Mesh::GetVertexDeclaration() const +{ + return &s_declaration; +} + +void NzMD2Mesh::Initialize() +{ + NzVertexElement elements[3]; + elements[0].offset = 0; + elements[0].type = nzElementType_Float3; + elements[0].usage = nzElementUsage_Position; + + elements[1].offset = 3*sizeof(float); + elements[1].type = nzElementType_Float3; + elements[1].usage = nzElementUsage_Normal; + + elements[2].offset = 3*sizeof(float) + 3*sizeof(float); + elements[2].type = nzElementType_Float2; + elements[2].usage = nzElementUsage_TexCoord; + + s_declaration.Create(elements, 3); +} + +void NzMD2Mesh::Uninitialize() +{ + s_declaration.Destroy(); +} + +void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) +{ + nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); + if (!ptr) + { + NazaraError("Failed to map vertex buffer"); + return; + } + + unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); + unsigned int positionOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Position)->offset; + unsigned int normalOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Normal)->offset; + + Frame* fA = &m_frames[frameA]; + Frame* fB = &m_frames[frameB]; + for (unsigned int i = 0; i < m_vertexCount; ++i) + { + NzVector3f* position = reinterpret_cast(ptr + positionOffset); + NzVector3f* normal = reinterpret_cast(ptr + normalOffset); + + *position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]); + *normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]); + + ptr += stride; + } + + if (!m_vertexBuffer->Unmap()) + NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption"); + + // Interpolation de l'AABB + NzVector3f max1 = fA->aabb.GetMaximum(); + NzVector3f min1 = fA->aabb.GetMinimum(); + m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1)); +} + +NzVertexDeclaration NzMD2Mesh::s_declaration; diff --git a/src/Nazara/Utility/Loaders/PCX/Loader.cpp b/src/Nazara/Utility/Loaders/PCX/Loader.cpp index 74fc38725..b6b5f437a 100644 --- a/src/Nazara/Utility/Loaders/PCX/Loader.cpp +++ b/src/Nazara/Utility/Loaders/PCX/Loader.cpp @@ -1,352 +1,346 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -// Auteur du loader original : David Henry - -namespace -{ - struct pcx_header - { - nzUInt8 manufacturer; - nzUInt8 version; - nzUInt8 encoding; - nzUInt8 bitsPerPixel; - - nzUInt16 xmin, ymin; - nzUInt16 xmax, ymax; - nzUInt16 horzRes, vertRes; - - nzUInt8 palette[48]; - nzUInt8 reserved; - nzUInt8 numColorPlanes; - - nzUInt16 bytesPerScanLine; - nzUInt16 paletteType; - nzUInt16 horzSize, vertSize; - - nzUInt8 padding[54]; - }; - - bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - nzUInt8 manufacturer; - if (stream.Read(&manufacturer, 1) != 1) - return false; - - return manufacturer == 0x0a; - } - - bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - pcx_header header; - if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header)) - { - NazaraError("Failed to read header"); - return false; - } - - if (header.manufacturer != 0x0a) - { - NazaraError("Bad version number (" + NzString::Number(header.manufacturer) + ')'); - return false; - } - - #if defined(NAZARA_BIG_ENDIAN) - // Les fichiers PCX sont en little endian - NzByteSwap(&header.xmin, sizeof(nzUInt16)); - NzByteSwap(&header.ymin, sizeof(nzUInt16)); - NzByteSwap(&header.xmax, sizeof(nzUInt16)); - NzByteSwap(&header.ymax, sizeof(nzUInt16)); - NzByteSwap(&header.horzRes, sizeof(nzUInt16)); - NzByteSwap(&header.vertRes, sizeof(nzUInt16)); - - NzByteSwap(&header.bytesPerScanLine, sizeof(nzUInt16)); - NzByteSwap(&header.paletteType, sizeof(nzUInt16)); - NzByteSwap(&header.horzSize, sizeof(nzUInt16)); - NzByteSwap(&header.vertSize, sizeof(nzUInt16)); - #endif - - unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes; - unsigned int width = header.xmax - header.xmin+1; - unsigned int height = header.ymax - header.ymin+1; - - if (!image->Create(nzImageType_2D, nzPixelFormat_RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1)) - { - NazaraError("Failed to create image"); - return false; - } - - nzUInt8* pixels = image->GetPixels(); - - int rle_value = 0; - unsigned int rle_count = 0; - - switch (bitCount) - { - case 1: - { - for (unsigned int y = 0; y < height; ++y) - { - nzUInt8* ptr = &pixels[y * width * 3]; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - } - } - - rle_count--; - - for (int i = 7; i >= 0; --i) - { - int colorIndex = ((rle_value & (1 << i)) > 0); - - *ptr++ = header.palette[colorIndex * 3 + 0]; - *ptr++ = header.palette[colorIndex * 3 + 1]; - *ptr++ = header.palette[colorIndex * 3 + 2]; - } - } - } - break; - } - - case 4: - { - nzUInt8* colorIndex = new nzUInt8[width]; - nzUInt8* line = new nzUInt8[header.bytesPerScanLine]; - - for (unsigned int y = 0; y < height; ++y) - { - nzUInt8* ptr = &pixels[y * width * 3]; - - std::memset(colorIndex, 0, width); - - for (unsigned int c = 0; c < 4; ++c) - { - nzUInt8* pLine = line; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - delete[] colorIndex; - delete[] line; - - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - delete[] colorIndex; - delete[] line; - - return false; - } - } - } - - rle_count--; - *(pLine++) = rle_value; - } - - /* compute line's color indexes */ - for (unsigned int x = 0; x < width; ++x) - { - if (line[x / 8] & (128 >> (x % 8))) - colorIndex[x] += (1 << c); - } - } - - /* decode scan line. color index => rgb */ - for (unsigned int x = 0; x < width; ++x) - { - *ptr++ = header.palette[colorIndex[x] * 3 + 0]; - *ptr++ = header.palette[colorIndex[x] * 3 + 1]; - *ptr++ = header.palette[colorIndex[x] * 3 + 2]; - } - } - - /* release memory */ - delete[] colorIndex; - delete[] line; - break; - } - - case 8: - { - nzUInt8 palette[768]; - - /* the palette is contained in the last 769 bytes of the file */ - unsigned int curPos = stream.GetCursorPos(); - stream.SetCursorPos(stream.GetSize()-769); - nzUInt8 magic; - if (!stream.Read(&magic, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - /* first byte must be equal to 0x0c (12) */ - if (magic != 0x0c) - { - NazaraError("Colormap's first byte must be 0x0c (0x" + NzString::Number(magic, 16) + ')'); - return false; - } - - /* read palette */ - if (stream.Read(palette, 768) != 768) - { - NazaraError("Failed to read palette"); - return false; - } - - stream.SetCursorPos(curPos); - - /* read pixel data */ - for (unsigned int y = 0; y < height; ++y) - { - nzUInt8* ptr = &pixels[y * width * 3]; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - } - } - - rle_count--; - - *ptr++ = palette[rle_value * 3 + 0]; - *ptr++ = palette[rle_value * 3 + 1]; - *ptr++ = palette[rle_value * 3 + 2]; - } - } - break; - } - - case 24: - { - for (unsigned int y = 0; y < height; ++y) - { - /* for each color plane */ - for (int c = 0; c < 3; ++c) - { - nzUInt8* ptr = &pixels[y * width * 4]; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - } - } - - rle_count--; - ptr[c] = static_cast(rle_value); - ptr += 3; - } - } - } - break; - } - - default: - NazaraError("Failed to load " + NzString::Number(bitCount) + " bitcount pcx files"); - return false; - } - - if (parameters.loadFormat != nzPixelFormat_Undefined) - image->Convert(parameters.loadFormat); - - return true; - } -} - -void NzLoaders_PCX_Register() -{ - NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); -} - -void NzLoaders_PCX_Unregister() -{ - NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +// Auteur du loader original : David Henry + +namespace +{ + struct pcx_header + { + nzUInt8 manufacturer; + nzUInt8 version; + nzUInt8 encoding; + nzUInt8 bitsPerPixel; + + nzUInt16 xmin, ymin; + nzUInt16 xmax, ymax; + nzUInt16 horzRes, vertRes; + + nzUInt8 palette[48]; + nzUInt8 reserved; + nzUInt8 numColorPlanes; + + nzUInt16 bytesPerScanLine; + nzUInt16 paletteType; + nzUInt16 horzSize, vertSize; + + nzUInt8 padding[54]; + }; + + bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters) + { + NazaraUnused(parameters); + + nzUInt8 manufacturer; + if (stream.Read(&manufacturer, 1) != 1) + return false; + + return manufacturer == 0x0a; + } + + bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + { + NazaraUnused(parameters); + + pcx_header header; + if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header)) + { + NazaraError("Failed to read header"); + return false; + } + + #if defined(NAZARA_BIG_ENDIAN) + // Les fichiers PCX sont en little endian + NzByteSwap(&header.xmin, sizeof(nzUInt16)); + NzByteSwap(&header.ymin, sizeof(nzUInt16)); + NzByteSwap(&header.xmax, sizeof(nzUInt16)); + NzByteSwap(&header.ymax, sizeof(nzUInt16)); + NzByteSwap(&header.horzRes, sizeof(nzUInt16)); + NzByteSwap(&header.vertRes, sizeof(nzUInt16)); + + NzByteSwap(&header.bytesPerScanLine, sizeof(nzUInt16)); + NzByteSwap(&header.paletteType, sizeof(nzUInt16)); + NzByteSwap(&header.horzSize, sizeof(nzUInt16)); + NzByteSwap(&header.vertSize, sizeof(nzUInt16)); + #endif + + unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes; + unsigned int width = header.xmax - header.xmin+1; + unsigned int height = header.ymax - header.ymin+1; + + if (!image->Create(nzImageType_2D, nzPixelFormat_RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1)) + { + NazaraError("Failed to create image"); + return false; + } + + nzUInt8* pixels = image->GetPixels(); + + int rle_value = 0; + unsigned int rle_count = 0; + + switch (bitCount) + { + case 1: + { + for (unsigned int y = 0; y < height; ++y) + { + nzUInt8* ptr = &pixels[y * width * 3]; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + } + } + + rle_count--; + + for (int i = 7; i >= 0; --i) + { + int colorIndex = ((rle_value & (1 << i)) > 0); + + *ptr++ = header.palette[colorIndex * 3 + 0]; + *ptr++ = header.palette[colorIndex * 3 + 1]; + *ptr++ = header.palette[colorIndex * 3 + 2]; + } + } + } + break; + } + + case 4: + { + nzUInt8* colorIndex = new nzUInt8[width]; + nzUInt8* line = new nzUInt8[header.bytesPerScanLine]; + + for (unsigned int y = 0; y < height; ++y) + { + nzUInt8* ptr = &pixels[y * width * 3]; + + std::memset(colorIndex, 0, width); + + for (unsigned int c = 0; c < 4; ++c) + { + nzUInt8* pLine = line; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + delete[] colorIndex; + delete[] line; + + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + delete[] colorIndex; + delete[] line; + + return false; + } + } + } + + rle_count--; + *(pLine++) = rle_value; + } + + /* compute line's color indexes */ + for (unsigned int x = 0; x < width; ++x) + { + if (line[x / 8] & (128 >> (x % 8))) + colorIndex[x] += (1 << c); + } + } + + /* decode scan line. color index => rgb */ + for (unsigned int x = 0; x < width; ++x) + { + *ptr++ = header.palette[colorIndex[x] * 3 + 0]; + *ptr++ = header.palette[colorIndex[x] * 3 + 1]; + *ptr++ = header.palette[colorIndex[x] * 3 + 2]; + } + } + + /* release memory */ + delete[] colorIndex; + delete[] line; + break; + } + + case 8: + { + nzUInt8 palette[768]; + + /* the palette is contained in the last 769 bytes of the file */ + unsigned int curPos = stream.GetCursorPos(); + stream.SetCursorPos(stream.GetSize()-769); + nzUInt8 magic; + if (!stream.Read(&magic, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + /* first byte must be equal to 0x0c (12) */ + if (magic != 0x0c) + { + NazaraError("Colormap's first byte must be 0x0c (0x" + NzString::Number(magic, 16) + ')'); + return false; + } + + /* read palette */ + if (stream.Read(palette, 768) != 768) + { + NazaraError("Failed to read palette"); + return false; + } + + stream.SetCursorPos(curPos); + + /* read pixel data */ + for (unsigned int y = 0; y < height; ++y) + { + nzUInt8* ptr = &pixels[y * width * 3]; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + } + } + + rle_count--; + + *ptr++ = palette[rle_value * 3 + 0]; + *ptr++ = palette[rle_value * 3 + 1]; + *ptr++ = palette[rle_value * 3 + 2]; + } + } + break; + } + + case 24: + { + for (unsigned int y = 0; y < height; ++y) + { + /* for each color plane */ + for (int c = 0; c < 3; ++c) + { + nzUInt8* ptr = &pixels[y * width * 4]; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + } + } + + rle_count--; + ptr[c] = static_cast(rle_value); + ptr += 3; + } + } + } + break; + } + + default: + NazaraError("Failed to load " + NzString::Number(bitCount) + " bitcount pcx files"); + return false; + } + + if (parameters.loadFormat != nzPixelFormat_Undefined) + image->Convert(parameters.loadFormat); + + return true; + } +} + +void NzLoaders_PCX_Register() +{ + NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); +} + +void NzLoaders_PCX_Unregister() +{ + NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); +} diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 797c0bcf9..7a8845dc7 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -1,623 +1,681 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -bool NzMeshParams::IsValid() const -{ - if (!animation.IsValid()) - { - NazaraError("Invalid animation parameters"); - return false; - } - - if (!NzBuffer::IsSupported(storage)) - { - NazaraError("Storage not supported"); - return false; - } - - return true; -} - -struct NzMeshImpl -{ - std::map subMeshMap; - std::deque skins; - std::vector subMeshes; - nzAnimationType animationType; - NzAxisAlignedBox aabb; - const NzAnimation* animation = nullptr; -}; - -NzMesh::~NzMesh() -{ - Destroy(); -} - -unsigned int NzMesh::AddSkin(const NzString& skin, bool setDefault) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - - if (skin.IsEmpty()) - { - NazaraError("Skin is empty"); - return 0; - } - #endif - - if (setDefault) - m_impl->skins.push_front(skin); - else - m_impl->skins.push_back(skin); - - return m_impl->skins.size()-1; -} - -nzUInt8 NzMesh::AddSubMesh(NzSubMesh* subMesh) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - - if (!subMesh) - { - NazaraError("Invalid submesh"); - return 0; - } - #endif - - subMesh->AddResourceReference(); - - m_impl->aabb.SetNull(); // On invalide l'AABB - m_impl->subMeshes.push_back(subMesh); - - return m_impl->subMeshes.size()-1; -} - -nzUInt8 NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - - if (identifier.IsEmpty()) - { - NazaraError("Identifier is empty"); - return 0; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it != m_impl->subMeshMap.end()) - { - NazaraError("SubMesh identifier \"" + identifier + "\" is already used"); - return it->second; - } - - if (!subMesh) - { - NazaraError("Invalid submesh"); - return 0; - } - #endif - - nzUInt8 index = m_impl->subMeshes.size(); - - subMesh->AddResourceReference(); - - m_impl->aabb.SetNull(); // On invalide l'AABB - m_impl->subMeshes.push_back(subMesh); - m_impl->subMeshMap[identifier] = index; - - return index; -} - -void NzMesh::Animate(unsigned int frameA, unsigned int frameB, float interpolation) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - if (!m_impl->animation) - { - NazaraError("Mesh has no animation"); - return; - } - - unsigned int frameCount = m_impl->animation->GetFrameCount(); - if (frameA >= frameCount) - { - NazaraError("Frame A is out of range (" + NzString::Number(frameA) + " >= " + NzString::Number(frameCount) + ')'); - return; - } - - if (frameB >= frameCount) - { - NazaraError("Frame B is out of range (" + NzString::Number(frameB) + " >= " + NzString::Number(frameCount) + ')'); - return; - } - - if (interpolation < 0.f || interpolation > 1.f) - { - NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); - return; - } - #endif - - for (NzSubMesh* subMesh : m_impl->subMeshes) - subMesh->AnimateImpl(frameA, frameB, interpolation); - - m_impl->aabb.SetNull(); // On invalide l'AABB -} - -bool NzMesh::Create(nzAnimationType type) -{ - Destroy(); - - m_impl = new NzMeshImpl; - m_impl->animationType = type; - - return true; -} - -void NzMesh::Destroy() -{ - if (m_impl) - { - if (m_impl->animation) - m_impl->animation->RemoveResourceReference(); - - for (NzSubMesh* subMesh : m_impl->subMeshes) - subMesh->RemoveResourceReference(); - - delete m_impl; - m_impl = nullptr; - } -} - -const NzAxisAlignedBox& NzMesh::GetAABB() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return NzAxisAlignedBox::Null; - } - #endif - - if (m_impl->aabb.IsNull()) - { - for (NzSubMesh* subMesh : m_impl->subMeshes) - m_impl->aabb.ExtendTo(subMesh->GetAABB()); - } - - return m_impl->aabb; -} - -const NzAnimation* NzMesh::GetAnimation() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - #endif - - return m_impl->animation; -} - -nzAnimationType NzMesh::GetAnimationType() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nzAnimationType_Static; - } - #endif - - return m_impl->animationType; -} - -unsigned int NzMesh::GetFrameCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - - if (!m_impl->animation) - { - NazaraError("Mesh has no animation"); - return 0; - } - #endif - - return m_impl->animation->GetFrameCount(); -} - -NzString NzMesh::GetSkin(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return NzString(); - } - - if (index >= m_impl->skins.size()) - { - NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); - return NzString(); - } - #endif - - return m_impl->skins[index]; -} - -unsigned int NzMesh::GetSkinCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - #endif - - return m_impl->skins.size(); -} - -NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return nullptr; - } - - return m_impl->subMeshes[it->second]; - #else - return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; - #endif -} - -NzSubMesh* NzMesh::GetSubMesh(nzUInt8 index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - if (index >= m_impl->subMeshes.size()) - { - NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); - return nullptr; - } - #endif - - return m_impl->subMeshes[index]; -} - -const NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return nullptr; - } - - return m_impl->subMeshes[it->second]; - #else - return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; - #endif -} - -const NzSubMesh* NzMesh::GetSubMesh(nzUInt8 index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - if (index >= m_impl->subMeshes.size()) - { - NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); - return nullptr; - } - #endif - - return m_impl->subMeshes[index]; -} - -nzUInt8 NzMesh::GetSubMeshCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - #endif - - return m_impl->subMeshes.size(); -} - -unsigned int NzMesh::GetVertexCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - #endif - - unsigned int vertexCount = 0; - for (NzSubMesh* subMesh : m_impl->subMeshes) - vertexCount += subMesh->GetVertexCount(); - - return vertexCount; -} - -void NzMesh::InvalidateAABB() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - #endif - - m_impl->aabb.SetNull(); -} - -bool NzMesh::HasAnimation() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->animation != nullptr; -} - -bool NzMesh::HasSkin(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->skins.size() > index; -} - -bool NzMesh::HasSubMesh(const NzString& identifier) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end(); -} - -bool NzMesh::HasSubMesh(nzUInt8 index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return index < m_impl->subMeshes.size(); -} - -bool NzMesh::IsAnimable() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->animationType != nzAnimationType_Static; -} - -bool NzMesh::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzMesh::LoadFromFile(const NzString& filePath, const NzMeshParams& params) -{ - return NzMeshLoader::LoadFromFile(this, filePath, params); -} - -bool NzMesh::LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params) -{ - return NzMeshLoader::LoadFromMemory(this, data, size, params); -} - -bool NzMesh::LoadFromStream(NzInputStream& stream, const NzMeshParams& params) -{ - return NzMeshLoader::LoadFromStream(this, stream, params); -} - -void NzMesh::RemoveSkin(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - if (m_impl->skins.size() <= index) - { - NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); - return; - } - #endif - - auto it = m_impl->skins.begin(); - std::advance(it, index); - - m_impl->skins.erase(it); -} - -void NzMesh::RemoveSubMesh(const NzString& identifier) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return; - } - - unsigned int index = it->second; - #else - unsigned int index = m_impl->subMeshMap[identifier]; - #endif - - auto it2 = m_impl->subMeshes.begin(); - std::advance(it2, index); - - m_impl->subMeshes.erase(it2); - - m_impl->aabb.SetNull(); // On invalide l'AABB -} - -void NzMesh::RemoveSubMesh(nzUInt8 index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - if (index >= m_impl->subMeshes.size()) - { - NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); - return; - } - #endif - - auto it = m_impl->subMeshes.begin(); - std::advance(it, index); - - m_impl->subMeshes.erase(it); - - m_impl->aabb.SetNull(); // On invalide l'AABB -} - -bool NzMesh::SetAnimation(const NzAnimation* animation) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - - if (m_impl->animationType == nzAnimationType_Static) - { - NazaraError("Static meshes cannot have animation"); - return false; - } - #endif - - if (animation == m_impl->animation) - return true; - - if (m_impl->animation) - m_impl->animation->RemoveResourceReference(); - - if (animation) - { - #if NAZARA_UTILITY_SAFE - if (animation->GetType() != m_impl->animationType) - { - NazaraError("Animation's type must match mesh animation type"); - return false; - } - #endif - - m_impl->animation = animation; - m_impl->animation->AddResourceReference(); - } - else - m_impl->animation = nullptr; - - return true; -} - -NzMeshLoader::LoaderList NzMesh::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool NzMeshParams::IsValid() const +{ + if (!animation.IsValid()) + { + NazaraError("Invalid animation parameters"); + return false; + } + + if (!NzBuffer::IsSupported(storage)) + { + NazaraError("Storage not supported"); + return false; + } + + return true; +} + +struct NzMeshImpl +{ + std::deque skins; + std::map subMeshMap; + std::vector subMeshes; + nzAnimationType animationType; + NzAxisAlignedBox aabb; + const NzAnimation* animation = nullptr; +}; + +NzMesh::~NzMesh() +{ + Destroy(); +} + +bool NzMesh::AddSkin(const NzString& skin, bool setDefault) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (skin.IsEmpty()) + { + NazaraError("Skin is empty"); + return false; + } + #endif + + if (setDefault) + m_impl->skins.push_front(skin); + else + m_impl->skins.push_back(skin); + + return true; +} + +bool NzMesh::AddSubMesh(NzSubMesh* subMesh) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (!subMesh) + { + NazaraError("Invalid submesh"); + return false; + } + #endif + + subMesh->AddResourceListener(this, m_impl->subMeshes.size()); + + m_impl->aabb.SetNull(); // On invalide l'AABB + m_impl->subMeshes.push_back(subMesh); + + return true; +} + +bool NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (identifier.IsEmpty()) + { + NazaraError("Identifier is empty"); + return false; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it != m_impl->subMeshMap.end()) + { + NazaraError("SubMesh identifier \"" + identifier + "\" is already used"); + return false; + } + + if (!subMesh) + { + NazaraError("Invalid submesh"); + return false; + } + #endif + + int index = m_impl->subMeshes.size(); + + subMesh->AddResourceListener(this, index); + + m_impl->aabb.SetNull(); // On invalide l'AABB + m_impl->subMeshes.push_back(subMesh); + m_impl->subMeshMap[identifier] = index; + + return true; +} + +void NzMesh::Animate(unsigned int frameA, unsigned int frameB, float interpolation) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + if (!m_impl->animation) + { + NazaraError("Mesh has no animation"); + return; + } + + unsigned int frameCount = m_impl->animation->GetFrameCount(); + if (frameA >= frameCount) + { + NazaraError("Frame A is out of range (" + NzString::Number(frameA) + " >= " + NzString::Number(frameCount) + ')'); + return; + } + + if (frameB >= frameCount) + { + NazaraError("Frame B is out of range (" + NzString::Number(frameB) + " >= " + NzString::Number(frameCount) + ')'); + return; + } + + if (interpolation < 0.f || interpolation > 1.f) + { + NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); + return; + } + #endif + + for (NzSubMesh* subMesh : m_impl->subMeshes) + subMesh->AnimateImpl(frameA, frameB, interpolation); + + m_impl->aabb.SetNull(); // On invalide l'AABB +} + +bool NzMesh::Create(nzAnimationType type) +{ + Destroy(); + + m_impl = new NzMeshImpl; + m_impl->animationType = type; + + NotifyCreated(); + + return true; +} + +void NzMesh::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + if (m_impl->animation) + m_impl->animation->RemoveResourceListener(this); + + for (NzSubMesh* subMesh : m_impl->subMeshes) + subMesh->RemoveResourceListener(this); + + delete m_impl; + m_impl = nullptr; + } +} + +const NzAxisAlignedBox& NzMesh::GetAABB() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return NzAxisAlignedBox::Null; + } + #endif + + if (m_impl->aabb.IsNull()) + { + for (NzSubMesh* subMesh : m_impl->subMeshes) + m_impl->aabb.ExtendTo(subMesh->GetAABB()); + } + + return m_impl->aabb; +} + +const NzAnimation* NzMesh::GetAnimation() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + #endif + + return m_impl->animation; +} + +nzAnimationType NzMesh::GetAnimationType() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nzAnimationType_Static; + } + #endif + + return m_impl->animationType; +} + +unsigned int NzMesh::GetFrameCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + + if (!m_impl->animation) + { + NazaraError("Mesh has no animation"); + return 0; + } + #endif + + return m_impl->animation->GetFrameCount(); +} + +NzString NzMesh::GetSkin(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return NzString(); + } + + if (index >= m_impl->skins.size()) + { + NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); + return NzString(); + } + #endif + + return m_impl->skins[index]; +} + +unsigned int NzMesh::GetSkinCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + #endif + + return m_impl->skins.size(); +} + +NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return nullptr; + } + + return m_impl->subMeshes[it->second]; + #else + return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; + #endif +} + +NzSubMesh* NzMesh::GetSubMesh(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + if (index >= m_impl->subMeshes.size()) + { + NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); + return nullptr; + } + #endif + + return m_impl->subMeshes[index]; +} + +const NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return nullptr; + } + + return m_impl->subMeshes[it->second]; + #else + return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; + #endif +} + +const NzSubMesh* NzMesh::GetSubMesh(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + if (index >= m_impl->subMeshes.size()) + { + NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); + return nullptr; + } + #endif + + return m_impl->subMeshes[index]; +} + +unsigned int NzMesh::GetSubMeshCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + #endif + + return m_impl->subMeshes.size(); +} + +int NzMesh::GetSubMeshIndex(const NzString& identifier) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return -1; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return -1; + } + + return it->second; + #else + return m_impl->subMeshMap[identifier]; + #endif +} + +unsigned int NzMesh::GetVertexCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + #endif + + unsigned int vertexCount = 0; + for (NzSubMesh* subMesh : m_impl->subMeshes) + vertexCount += subMesh->GetVertexCount(); + + return vertexCount; +} + +void NzMesh::InvalidateAABB() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + #endif + + m_impl->aabb.SetNull(); +} + +bool NzMesh::HasAnimation() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->animation != nullptr; +} + +bool NzMesh::HasSkin(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->skins.size() > index; +} + +bool NzMesh::HasSubMesh(const NzString& identifier) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end(); +} + +bool NzMesh::HasSubMesh(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return index < m_impl->subMeshes.size(); +} + +bool NzMesh::IsAnimable() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->animationType != nzAnimationType_Static; +} + +bool NzMesh::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzMesh::LoadFromFile(const NzString& filePath, const NzMeshParams& params) +{ + return NzMeshLoader::LoadFromFile(this, filePath, params); +} + +bool NzMesh::LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params) +{ + return NzMeshLoader::LoadFromMemory(this, data, size, params); +} + +bool NzMesh::LoadFromStream(NzInputStream& stream, const NzMeshParams& params) +{ + return NzMeshLoader::LoadFromStream(this, stream, params); +} + +void NzMesh::RemoveSkin(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + if (m_impl->skins.size() <= index) + { + NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); + return; + } + #endif + + // On accède à l'itérateur correspondant à l'entrée #index + auto it = m_impl->skins.begin(); + std::advance(it, index); + + m_impl->skins.erase(it); +} + +void NzMesh::RemoveSubMesh(const NzString& identifier) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return; + } + + unsigned int index = it->second; + #else + unsigned int index = m_impl->subMeshMap[identifier]; + #endif + + // On déplace l'itérateur du début d'une distance de x + auto it2 = m_impl->subMeshes.begin(); + std::advance(it, index); + + // On libère la ressource + (*it2)->RemoveResourceListener(this); + m_impl->subMeshes.erase(it2); + + m_impl->aabb.SetNull(); // On invalide l'AABB +} + +void NzMesh::RemoveSubMesh(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + if (index >= m_impl->subMeshes.size()) + { + NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); + return; + } + #endif + + // On déplace l'itérateur du début de x + auto it = m_impl->subMeshes.begin(); + std::advance(it, index); + + // On libère la ressource + (*it)->RemoveResourceListener(this); + m_impl->subMeshes.erase(it); + + m_impl->aabb.SetNull(); // On invalide l'AABB +} + +bool NzMesh::SetAnimation(const NzAnimation* animation) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (m_impl->animationType == nzAnimationType_Static) + { + NazaraError("Static meshes cannot have animation"); + return false; + } + #endif + + if (animation == m_impl->animation) + return true; + + if (m_impl->animation) + m_impl->animation->RemoveResourceListener(this); + + if (animation) + { + #if NAZARA_UTILITY_SAFE + if (animation->GetType() != m_impl->animationType) + { + NazaraError("Animation's type must match mesh animation type"); + return false; + } + #endif + + animation->AddResourceListener(this); + } + + m_impl->animation = animation; + + return true; +} + +void NzMesh::OnResourceCreated(const NzResource* resource, int index) +{ + NazaraUnused(index); + + if (resource == m_impl->animation) + { + #if NAZARA_UTILITY_SAFE + if (m_impl->animation->GetType() != m_impl->animationType) + { + NazaraError("Animation's type must match mesh animation type"); + + m_impl->animation->RemoveResourceListener(this); + m_impl->animation = nullptr; + } + #endif + } +} + +void NzMesh::OnResourceReleased(const NzResource* resource, int index) +{ + if (resource == m_impl->animation) + SetAnimation(nullptr); + else + RemoveSubMesh(index); +} + +NzMeshLoader::LoaderList NzMesh::s_loaders; diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index a85273327..bf1fe2b6b 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -1,186 +1,199 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -NzStaticMesh::NzStaticMesh(const NzMesh* parent) : -NzSubMesh(parent) -{ -} - -NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) : -NzSubMesh(parent) -{ - #ifdef NAZARA_DEBUG - if (!Create(vertexDeclaration, vertexBuffer, indexBuffer)) - { - NazaraError("Failed to create mesh"); - throw std::runtime_error("Constructor failed"); - } - #else - Create(vertexDeclaration, vertexBuffer, indexBuffer); - #endif -} - -NzStaticMesh::~NzStaticMesh() -{ - Destroy(); -} - -bool NzStaticMesh::Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) -{ - Destroy(); - - #if NAZARA_UTILITY_SAFE - if (!vertexDeclaration) - { - NazaraError("Vertex declaration is null"); - return false; - } - - if (!vertexBuffer) - { - NazaraError("Vertex buffer is null"); - return false; - } - #endif - - if (indexBuffer) - { - m_indexBuffer = indexBuffer; - m_indexBuffer->AddResourceReference(); - } - - m_vertexBuffer = vertexBuffer; - m_vertexBuffer->AddResourceReference(); - - m_vertexDeclaration = vertexDeclaration; - m_vertexDeclaration->AddResourceReference(); - - return true; -} - -void NzStaticMesh::Destroy() -{ - m_aabb.SetNull(); - - if (m_indexBuffer) - { - m_indexBuffer->RemoveResourceReference(); - m_indexBuffer = nullptr; - } - - if (m_vertexBuffer) - { - m_vertexBuffer->RemoveResourceReference(); - m_vertexBuffer = nullptr; - } - - if (m_vertexDeclaration) - { - m_vertexDeclaration->RemoveResourceReference(); - m_vertexDeclaration = nullptr; - } -} - -bool NzStaticMesh::GenerateAABB() -{ - if (!m_aabb.IsNull()) - return true; - - const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position); - if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3 - { - // On lock le buffer pour itérer sur toutes les positions et composer notre AABB - nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_ReadOnly)); - if (!buffer) - { - NazaraWarning("Failed to lock vertex buffer"); - return false; - } - - buffer += position->offset; - unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData); - unsigned int vertexCount = m_vertexBuffer->GetVertexCount(); - for (unsigned int i = 0; i < vertexCount; ++i) - { - m_aabb.ExtendTo(*reinterpret_cast(buffer)); - - buffer += stride; - } - - if (!m_vertexBuffer->Unmap()) - NazaraWarning("Failed to unmap vertex buffer"); - } - - return true; -} - -const NzAxisAlignedBox& NzStaticMesh::GetAABB() const -{ - return m_aabb; -} - -nzAnimationType NzStaticMesh::GetAnimationType() const -{ - return nzAnimationType_Static; -} - -unsigned int NzStaticMesh::GetFrameCount() const -{ - return 1; -} - -const NzIndexBuffer* NzStaticMesh::GetIndexBuffer() const -{ - return m_indexBuffer; -} - -nzPrimitiveType NzStaticMesh::GetPrimitiveType() const -{ - return m_primitiveType; -} - -const NzVertexBuffer* NzStaticMesh::GetVertexBuffer() const -{ - return m_vertexBuffer; -} - -const NzVertexDeclaration* NzStaticMesh::GetVertexDeclaration() const -{ - return m_vertexDeclaration; -} - -bool NzStaticMesh::IsAnimated() const -{ - return false; -} - -bool NzStaticMesh::IsValid() const -{ - return m_vertexBuffer != nullptr && m_vertexDeclaration != nullptr; -} - -void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb) -{ - m_aabb = aabb; -} - -void NzStaticMesh::SetPrimitiveType(nzPrimitiveType primitiveType) -{ - m_primitiveType = primitiveType; -} - -void NzStaticMesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) -{ - NazaraUnused(frameA); - NazaraUnused(frameB); - NazaraUnused(interpolation); - - // Le safe mode est censé nous protéger de cet appel - NazaraError("Static mesh have no animation, please enable safe mode"); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +NzStaticMesh::NzStaticMesh(const NzMesh* parent) : +NzSubMesh(parent) +{ +} + +NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) : +NzSubMesh(parent) +{ + #ifdef NAZARA_DEBUG + if (!Create(vertexDeclaration, vertexBuffer, indexBuffer)) + { + NazaraError("Failed to create mesh"); + throw std::runtime_error("Constructor failed"); + } + #else + Create(vertexDeclaration, vertexBuffer, indexBuffer); + #endif +} + +NzStaticMesh::~NzStaticMesh() +{ + Destroy(); +} + +bool NzStaticMesh::Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) +{ + Destroy(); + + #if NAZARA_UTILITY_SAFE + if (!vertexDeclaration) + { + NazaraError("Invalid vertex declaration"); + return false; + } + + if (!vertexBuffer) + { + NazaraError("Invalid vertex buffer"); + return false; + } + #endif + + if (indexBuffer) + indexBuffer->AddResourceListener(this); + + m_indexBuffer = indexBuffer; + + m_vertexBuffer = vertexBuffer; + m_vertexBuffer->AddResourceListener(this); + + m_vertexDeclaration = vertexDeclaration; + m_vertexDeclaration->AddResourceListener(this); + + return true; +} + +void NzStaticMesh::Destroy() +{ + m_aabb.SetNull(); + + if (m_indexBuffer) + { + m_indexBuffer->RemoveResourceListener(this); + m_indexBuffer = nullptr; + } + + if (m_vertexBuffer) + { + m_vertexBuffer->RemoveResourceListener(this); + m_vertexBuffer = nullptr; + } + + if (m_vertexDeclaration) + { + m_vertexDeclaration->RemoveResourceListener(this); + m_vertexDeclaration = nullptr; + } +} + +bool NzStaticMesh::GenerateAABB() +{ + if (!m_aabb.IsNull()) + return true; + + const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position); + if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3 + { + // On lock le buffer pour itérer sur toutes les positions et composer notre AABB + nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_ReadOnly)); + if (!buffer) + { + NazaraWarning("Failed to lock vertex buffer"); + return false; + } + + buffer += position->offset; + unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData); + unsigned int vertexCount = m_vertexBuffer->GetVertexCount(); + for (unsigned int i = 0; i < vertexCount; ++i) + { + m_aabb.ExtendTo(*reinterpret_cast(buffer)); + + buffer += stride; + } + + if (!m_vertexBuffer->Unmap()) + NazaraWarning("Failed to unmap vertex buffer"); + } + + return true; +} + +const NzAxisAlignedBox& NzStaticMesh::GetAABB() const +{ + return m_aabb; +} + +nzAnimationType NzStaticMesh::GetAnimationType() const +{ + return nzAnimationType_Static; +} + +unsigned int NzStaticMesh::GetFrameCount() const +{ + return 1; +} + +const NzIndexBuffer* NzStaticMesh::GetIndexBuffer() const +{ + return m_indexBuffer; +} + +nzPrimitiveType NzStaticMesh::GetPrimitiveType() const +{ + return m_primitiveType; +} + +const NzVertexBuffer* NzStaticMesh::GetVertexBuffer() const +{ + return m_vertexBuffer; +} + +const NzVertexDeclaration* NzStaticMesh::GetVertexDeclaration() const +{ + return m_vertexDeclaration; +} + +bool NzStaticMesh::IsAnimated() const +{ + return false; +} + +bool NzStaticMesh::IsValid() const +{ + return m_vertexBuffer != nullptr && m_vertexDeclaration != nullptr; +} + +void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb) +{ + m_aabb = aabb; +} + +void NzStaticMesh::SetPrimitiveType(nzPrimitiveType primitiveType) +{ + m_primitiveType = primitiveType; +} + +void NzStaticMesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) +{ + NazaraUnused(frameA); + NazaraUnused(frameB); + NazaraUnused(interpolation); + + // Le safe mode est censé nous protéger de cet appel + NazaraError("Static mesh have no animation, please enable safe mode"); +} + +void NzStaticMesh::OnResourceReleased(const NzResource* resource, int index) +{ + NazaraUnused(index); + + if (resource == m_indexBuffer) + m_indexBuffer = nullptr; + else if (resource == m_vertexBuffer) + m_vertexBuffer = nullptr; + else if (resource == m_vertexDeclaration) + m_vertexDeclaration = nullptr; + else + NazaraInternalError("Not listening to " + NzString::Pointer(resource)); +} diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index f6be21c60..6c66a8f67 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -1,346 +1,372 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_VERTEXDECLARATION -#include -#else -#include -#endif - -#include - -namespace -{ - const unsigned int size[] = - { - sizeof(nzUInt32), // nzElementType_Color - 1*sizeof(double), // nzElementType_Double1 - 2*sizeof(double), // nzElementType_Double2 - 3*sizeof(double), // nzElementType_Double3 - 4*sizeof(double), // nzElementType_Double4 - 1*sizeof(float), // nzElementType_Float1 - 2*sizeof(float), // nzElementType_Float2 - 3*sizeof(float), // nzElementType_Float3 - 4*sizeof(float) // nzElementType_Float4 - }; - - bool VertexElementCompare(const NzVertexElement& elementA, const NzVertexElement& elementB) - { - // Nous classons d'abord par stream - if (elementA.stream == elementB.stream) - { - // Ensuite par usage - if (elementA.usage == elementB.usage) - // Et finalement par usageIndex - return elementA.usageIndex < elementB.usageIndex; - else - return elementA.usage < elementB.usage; - } - else - return elementA.stream < elementB.stream; - } -} - -struct NzVertexDeclarationImpl -{ - std::vector elements; - int elementPos[nzElementStream_Max+1][nzElementUsage_Max+1]; - int streamPos[nzElementStream_Max+1]; - unsigned int stride[nzElementStream_Max+1] = {0}; - - unsigned short refCount = 1; - NazaraMutex(mutex) -}; - -NzVertexDeclaration::NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount) -{ - #ifdef NAZARA_DEBUG - if (!Create(elements, elementCount)) - { - NazaraError("Failed to create declaration"); - throw std::runtime_error("Constructor failed"); - } - #else - Create(elements, elementCount); - #endif -} - -NzVertexDeclaration::NzVertexDeclaration(const NzVertexDeclaration& declaration) : -NzResource(), -m_sharedImpl(declaration.m_sharedImpl) -{ - if (m_sharedImpl) - { - NazaraMutexLock(m_sharedImpl->mutex); - m_sharedImpl->refCount++; - NazaraMutexUnlock(m_sharedImpl->mutex); - } -} - -NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept : -m_sharedImpl(declaration.m_sharedImpl) -{ - declaration.m_sharedImpl = nullptr; -} - -NzVertexDeclaration::~NzVertexDeclaration() -{ - Destroy(); -} - -bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int elementCount) -{ - Destroy(); - - #if NAZARA_UTILITY_SAFE - if (!elements || elementCount == 0) - { - NazaraError("No element"); - return false; - } - #endif - - NzVertexDeclarationImpl* impl = new NzVertexDeclarationImpl; - std::memset(&impl->elementPos, -1, (nzElementStream_Max+1)*(nzElementUsage_Max+1)*sizeof(int)); - std::memset(&impl->streamPos, -1, (nzElementStream_Max+1)*sizeof(int)); - - // On copie et trie les éléments - impl->elements.resize(elementCount); - std::memcpy(&impl->elements[0], elements, elementCount*sizeof(NzVertexElement)); - std::sort(impl->elements.begin(), impl->elements.end(), VertexElementCompare); - - for (unsigned int i = 0; i < elementCount; ++i) - { - NzVertexElement& current = impl->elements[i]; - #if NAZARA_UTILITY_SAFE - // Notre tableau étant trié, s'il y a collision, les deux éléments identiques se suivent... - if (i > 0) - { - NzVertexElement& previous = impl->elements[i-1]; // On accède à l'élément précédent - if (previous.usage == current.usage && previous.usageIndex == current.usageIndex && previous.stream == current.stream) - { - // Les deux éléments sont identiques là où ils ne devraient pas, nous avons une collision... - NazaraError("Element usage 0x" + NzString::Number(current.usage, 16) + " collision with usage index " + NzString::Number(current.usageIndex) + " on stream 0x" + NzString::Number(current.stream, 16)); - delete impl; - - return false; - } - } - #endif - - if (current.usageIndex == 0) - impl->elementPos[current.stream][current.usage] = i; - - if (impl->streamPos[current.stream] == -1) - impl->streamPos[current.stream] = i; // Premier élément du stream (via le triage) - - impl->stride[current.stream] += size[current.type]; - } - - #if NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 - for (unsigned int& stride : impl->stride) - stride = ((static_cast(stride)-1)/32+1)*32; - #endif - - m_sharedImpl = impl; - - return true; -} - -void NzVertexDeclaration::Destroy() -{ - if (!m_sharedImpl) - return; - - NazaraMutexLock(m_sharedImpl->mutex); - bool freeSharedImpl = (--m_sharedImpl->refCount == 0); - NazaraMutexUnlock(m_sharedImpl->mutex); - - if (freeSharedImpl) - delete m_sharedImpl; - - m_sharedImpl = nullptr; -} - -const NzVertexElement* NzVertexDeclaration::GetElement(unsigned int i) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return nullptr; - } - - if (i >= m_sharedImpl->elements.size()) - { - NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_sharedImpl->elements.size()) + ')'); - return nullptr; - } - #endif - - return &m_sharedImpl->elements[i]; -} - -const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, unsigned int i) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return nullptr; - } - - int streamPos = m_sharedImpl->streamPos[stream]; - if (streamPos == -1) - { - NazaraError("Declaration has no stream 0x" + NzString::Number(stream, 16)); - return nullptr; - } - - unsigned int upperLimit = GetElementCount(stream); - if (i >= upperLimit) - { - NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(upperLimit) + ')'); - return nullptr; - } - #endif - - return &m_sharedImpl->elements[m_sharedImpl->streamPos[stream]+i]; -} - -const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return nullptr; - } - #endif - - int elementPos = m_sharedImpl->elementPos[stream][usage]; - if (elementPos == -1) - return nullptr; - - elementPos += usageIndex; - if (static_cast(elementPos) >= m_sharedImpl->elements.size()) - return nullptr; - - NzVertexElement& element = m_sharedImpl->elements[elementPos]; - if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) - return nullptr; - - return &element; -} - -unsigned int NzVertexDeclaration::GetElementCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return 0; - } - #endif - - return m_sharedImpl->elements.size(); -} - -unsigned int NzVertexDeclaration::GetElementCount(nzElementStream stream) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return 0; - } - #endif - - int streamPos = m_sharedImpl->streamPos[stream]; - if (streamPos == -1) - return 0; - - unsigned int upperLimit = 0; - if (stream == nzElementStream_Max) - upperLimit = m_sharedImpl->elements.size(); - else - { - for (unsigned int upperStream = stream+1; upperStream <= nzElementStream_Max; ++upperStream) - { - if (m_sharedImpl->streamPos[upperStream] != -1) - { - upperLimit = m_sharedImpl->streamPos[upperStream]; - break; - } - else if (upperStream == nzElementStream_Max) // Dernier stream, toujours pas de limite - upperLimit = m_sharedImpl->elements.size(); - } - } - - return upperLimit-streamPos; -} - -unsigned int NzVertexDeclaration::GetStride(nzElementStream stream) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return 0; - } - #endif - - return m_sharedImpl->stride[stream]; -} - -bool NzVertexDeclaration::HasStream(nzElementStream stream) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return false; - } - #endif - - return m_sharedImpl->streamPos[stream] != -1; -} - -bool NzVertexDeclaration::IsValid() const -{ - return m_sharedImpl != nullptr; -} - -NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration) -{ - Destroy(); - - m_sharedImpl = declaration.m_sharedImpl; - if (m_sharedImpl) - { - NazaraMutexLock(m_sharedImpl->mutex); - m_sharedImpl->refCount++; - NazaraMutexUnlock(m_sharedImpl->mutex); - } - - return *this; -} - -NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) noexcept -{ - Destroy(); - - m_sharedImpl = declaration.m_sharedImpl; - declaration.m_sharedImpl = nullptr; - - return *this; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_VERTEXDECLARATION +#include +#else +#include +#endif + +#include + +namespace +{ + const unsigned int elementCount[] = + { + 4, // nzElementType_Color + 1, // nzElementType_Double1 + 2, // nzElementType_Double2 + 3, // nzElementType_Double3 + 4, // nzElementType_Double4 + 1, // nzElementType_Float1 + 2, // nzElementType_Float2 + 3, // nzElementType_Float3 + 4 // nzElementType_Float4 + }; + + const unsigned int elementSize[] = + { + 4*sizeof(nzUInt8), // nzElementType_Color + 1*sizeof(double), // nzElementType_Double1 + 2*sizeof(double), // nzElementType_Double2 + 3*sizeof(double), // nzElementType_Double3 + 4*sizeof(double), // nzElementType_Double4 + 1*sizeof(float), // nzElementType_Float1 + 2*sizeof(float), // nzElementType_Float2 + 3*sizeof(float), // nzElementType_Float3 + 4*sizeof(float) // nzElementType_Float4 + }; + + bool VertexElementCompare(const NzVertexElement& elementA, const NzVertexElement& elementB) + { + // Nous classons d'abord par stream + if (elementA.stream == elementB.stream) + { + // Ensuite par usage + if (elementA.usage == elementB.usage) + // Et finalement par usageIndex + return elementA.usageIndex < elementB.usageIndex; + else + return elementA.usage < elementB.usage; + } + else + return elementA.stream < elementB.stream; + } +} + +struct NzVertexDeclarationImpl +{ + std::vector elements; + int elementPos[nzElementStream_Max+1][nzElementUsage_Max+1]; + int streamPos[nzElementStream_Max+1]; + unsigned int stride[nzElementStream_Max+1] = {0}; + + unsigned short refCount = 1; + NazaraMutex(mutex) +}; + +NzVertexDeclaration::NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount) +{ + #ifdef NAZARA_DEBUG + if (!Create(elements, elementCount)) + { + NazaraError("Failed to create declaration"); + throw std::runtime_error("Constructor failed"); + } + #else + Create(elements, elementCount); + #endif +} + +NzVertexDeclaration::NzVertexDeclaration(const NzVertexDeclaration& declaration) : +NzResource(), +m_sharedImpl(declaration.m_sharedImpl) +{ + if (m_sharedImpl) + { + NazaraMutexLock(m_sharedImpl->mutex); + m_sharedImpl->refCount++; + NazaraMutexUnlock(m_sharedImpl->mutex); + } +} + +NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept : +m_sharedImpl(declaration.m_sharedImpl) +{ + declaration.m_sharedImpl = nullptr; +} + +NzVertexDeclaration::~NzVertexDeclaration() +{ + Destroy(); +} + +bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int elementCount) +{ + Destroy(); + + #if NAZARA_UTILITY_SAFE + if (!elements || elementCount == 0) + { + NazaraError("No element"); + return false; + } + #endif + + NzVertexDeclarationImpl* impl = new NzVertexDeclarationImpl; + std::memset(&impl->elementPos, -1, (nzElementStream_Max+1)*(nzElementUsage_Max+1)*sizeof(int)); + std::memset(&impl->streamPos, -1, (nzElementStream_Max+1)*sizeof(int)); + + // On copie et trie les éléments + impl->elements.resize(elementCount); + std::memcpy(&impl->elements[0], elements, elementCount*sizeof(NzVertexElement)); + std::sort(impl->elements.begin(), impl->elements.end(), VertexElementCompare); + + for (unsigned int i = 0; i < elementCount; ++i) + { + NzVertexElement& current = impl->elements[i]; + #if NAZARA_UTILITY_SAFE + // Notre tableau étant trié, s'il y a collision, les deux éléments identiques se suivent... + if (i > 0) + { + NzVertexElement& previous = impl->elements[i-1]; // On accède à l'élément précédent + if (previous.usage == current.usage && previous.usageIndex == current.usageIndex && previous.stream == current.stream) + { + // Les deux éléments sont identiques là où ils ne devraient pas, nous avons une collision... + NazaraError("Element usage 0x" + NzString::Number(current.usage, 16) + " collision with usage index " + NzString::Number(current.usageIndex) + " on stream 0x" + NzString::Number(current.stream, 16)); + delete impl; + + return false; + } + } + #endif + + if (current.usageIndex == 0) + impl->elementPos[current.stream][current.usage] = i; + + if (impl->streamPos[current.stream] == -1) + impl->streamPos[current.stream] = i; // Premier élément du stream (via le triage) + + impl->stride[current.stream] += elementSize[current.type]; + } + + #if NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 + for (unsigned int& stride : impl->stride) + stride = ((static_cast(stride)-1)/32+1)*32; + #endif + + m_sharedImpl = impl; + + NotifyCreated(); + return true; +} + +void NzVertexDeclaration::Destroy() +{ + if (!m_sharedImpl) + return; + + NotifyDestroy(); + + NazaraMutexLock(m_sharedImpl->mutex); + bool freeSharedImpl = (--m_sharedImpl->refCount == 0); + NazaraMutexUnlock(m_sharedImpl->mutex); + + if (freeSharedImpl) + delete m_sharedImpl; + + m_sharedImpl = nullptr; +} + +const NzVertexElement* NzVertexDeclaration::GetElement(unsigned int i) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return nullptr; + } + + if (i >= m_sharedImpl->elements.size()) + { + NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_sharedImpl->elements.size()) + ')'); + return nullptr; + } + #endif + + return &m_sharedImpl->elements[i]; +} + +const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, unsigned int i) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return nullptr; + } + + int streamPos = m_sharedImpl->streamPos[stream]; + if (streamPos == -1) + { + NazaraError("Declaration has no stream 0x" + NzString::Number(stream, 16)); + return nullptr; + } + + unsigned int upperLimit = GetElementCount(stream); + if (i >= upperLimit) + { + NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(upperLimit) + ')'); + return nullptr; + } + #endif + + return &m_sharedImpl->elements[m_sharedImpl->streamPos[stream]+i]; +} + +const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return nullptr; + } + #endif + + int elementPos = m_sharedImpl->elementPos[stream][usage]; + if (elementPos == -1) + return nullptr; + + elementPos += usageIndex; + if (static_cast(elementPos) >= m_sharedImpl->elements.size()) + return nullptr; + + NzVertexElement& element = m_sharedImpl->elements[elementPos]; + if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) + return nullptr; + + return &element; +} + +unsigned int NzVertexDeclaration::GetElementCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return 0; + } + #endif + + return m_sharedImpl->elements.size(); +} + +unsigned int NzVertexDeclaration::GetElementCount(nzElementStream stream) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return 0; + } + #endif + + int streamPos = m_sharedImpl->streamPos[stream]; + if (streamPos == -1) + return 0; + + unsigned int upperLimit = 0; + if (stream == nzElementStream_Max) + upperLimit = m_sharedImpl->elements.size(); + else + { + for (unsigned int upperStream = stream+1; upperStream <= nzElementStream_Max; ++upperStream) + { + if (m_sharedImpl->streamPos[upperStream] != -1) + { + upperLimit = m_sharedImpl->streamPos[upperStream]; + break; + } + else if (upperStream == nzElementStream_Max) // Dernier stream, toujours pas de limite + upperLimit = m_sharedImpl->elements.size(); + } + } + + return upperLimit-streamPos; +} + +unsigned int NzVertexDeclaration::GetStride(nzElementStream stream) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return 0; + } + #endif + + return m_sharedImpl->stride[stream]; +} + +bool NzVertexDeclaration::HasStream(nzElementStream stream) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return false; + } + #endif + + return m_sharedImpl->streamPos[stream] != -1; +} + +bool NzVertexDeclaration::IsValid() const +{ + return m_sharedImpl != nullptr; +} + +NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration) +{ + Destroy(); + + m_sharedImpl = declaration.m_sharedImpl; + if (m_sharedImpl) + { + NazaraMutexLock(m_sharedImpl->mutex); + m_sharedImpl->refCount++; + NazaraMutexUnlock(m_sharedImpl->mutex); + } + + return *this; +} + +NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) noexcept +{ + Destroy(); + + m_sharedImpl = declaration.m_sharedImpl; + declaration.m_sharedImpl = nullptr; + + return *this; +} + +unsigned int NzVertexDeclaration::GetElementCount(nzElementType type) +{ + return elementCount[type]; +} + +unsigned int NzVertexDeclaration::GetElementSize(nzElementType type) +{ + return elementSize[type]; +} diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index a9d3e1ed2..acfecb9e5 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -1,529 +1,534 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) - #include - #include - #include -#elif defined(NAZARA_PLATFORM_LINUX) - #include - #include - #include -#else - #error Lack of implementation: Window -#endif - -#include - -namespace -{ - NzWindow* fullscreenWindow = nullptr; -} - -NzWindow::NzWindow() : -#if NAZARA_UTILITY_THREADED_WINDOW -m_impl(nullptr), -m_eventListener(true), -m_waitForEvent(false) -#else -m_impl(nullptr) -#endif -{ -} - -NzWindow::NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style) : -#if NAZARA_UTILITY_THREADED_WINDOW -m_impl(nullptr), -m_eventListener(true), -m_waitForEvent(false) -#else -m_impl(nullptr) -#endif -{ - Create(mode, title, style); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzWindow::NzWindow(NzWindowHandle handle) : -#if NAZARA_UTILITY_THREADED_WINDOW -m_impl(nullptr), -m_eventListener(true), -m_waitForEvent(false) -#else -m_impl(nullptr) -#endif -{ - Create(handle); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzWindow::~NzWindow() -{ - Destroy(); -} - -bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) -{ - // Si la fenêtre est déjà ouverte, nous conservons sa position - bool opened = IsOpen(); - NzVector2i position; - if (opened) - position = m_impl->GetPosition(); - - Destroy(); - - // Inspiré du code de la SFML par Laurent Gomila - if (style & nzWindowStyle_Fullscreen) - { - if (fullscreenWindow) - { - NazaraError("Window (" + NzString::Pointer(fullscreenWindow) + ") already in fullscreen mode"); - style &= ~nzWindowStyle_Fullscreen; - } - else - { - if (!mode.IsFullscreenValid()) - { - NazaraWarning("Mode is not fullscreen valid"); - mode = NzVideoMode::GetFullscreenModes()[0]; - } - - fullscreenWindow = this; - } - } - else if (style & nzWindowStyle_Closable || style & nzWindowStyle_Resizable) - style |= nzWindowStyle_Titlebar; - - m_impl = new NzWindowImpl(this); - if (!m_impl->Create(mode, title, style)) - { - NazaraError("Failed to create window implementation"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - m_ownsWindow = true; - - if (!OnWindowCreated()) - { - NazaraError("Failed to initialize window extension"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - // Paramètres par défaut - m_impl->EnableKeyRepeat(true); - m_impl->EnableSmoothScrolling(false); - m_impl->SetCursor(nzWindowCursor_Default); - m_impl->SetMaximumSize(-1, -1); - m_impl->SetMinimumSize(-1, -1); - m_impl->SetVisible(true); - - if (opened) - m_impl->SetPosition(position.x, position.y); - - return true; -} - -bool NzWindow::Create(NzWindowHandle handle) -{ - Destroy(); - - m_impl = new NzWindowImpl(this); - if (!m_impl->Create(handle)) - { - NazaraError("Unable to create window implementation"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - m_ownsWindow = false; - - if (!OnWindowCreated()) - { - NazaraError("Failed to initialize window's derivate"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - return true; -} - -void NzWindow::Destroy() -{ - if (m_impl) - { - OnWindowDestroying(); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - - if (fullscreenWindow == this) - fullscreenWindow = nullptr; - } -} - -void NzWindow::EnableKeyRepeat(bool enable) -{ - if (m_impl) - m_impl->EnableKeyRepeat(enable); -} - -void NzWindow::EnableSmoothScrolling(bool enable) -{ - if (m_impl) - m_impl->EnableSmoothScrolling(enable); -} - -NzWindowHandle NzWindow::GetHandle() const -{ - if (m_impl) - return m_impl->GetHandle(); - else - return reinterpret_cast(0); -} - -unsigned int NzWindow::GetHeight() const -{ - if (m_impl) - return m_impl->GetHeight(); - else - return 0; -} - -NzVector2i NzWindow::GetPosition() const -{ - if (m_impl) - return m_impl->GetPosition(); - else - return NzVector2i(0); -} - -NzVector2ui NzWindow::GetSize() const -{ - if (m_impl) - return m_impl->GetSize(); - else - return NzVector2ui(0U); -} - -NzString NzWindow::GetTitle() const -{ - if (m_impl) - return m_impl->GetTitle(); - else - return NzString(); -} - -unsigned int NzWindow::GetWidth() const -{ - if (m_impl) - return m_impl->GetWidth(); - else - return 0; -} - -bool NzWindow::HasFocus() const -{ - if (m_impl) - return m_impl->HasFocus(); - else - return false; -} - -bool NzWindow::IsOpen() const -{ - return m_impl != nullptr; -} - -bool NzWindow::IsMinimized() const -{ - if (m_impl) - return m_impl->IsMinimized(); - else - return false; -} - -bool NzWindow::IsVisible() const -{ - if (m_impl) - return m_impl->IsVisible(); - else - return false; -} - -bool NzWindow::PollEvent(NzEvent* event) -{ - if (!m_impl) - return false; - - #if NAZARA_UTILITY_THREADED_WINDOW - NzLockGuard lock(m_eventMutex); - #else - m_impl->ProcessEvents(false); - #endif - - if (!m_events.empty()) - { - if (event) - *event = m_events.front(); - - m_events.pop(); - - return true; - } - - return false; -} - -void NzWindow::SetCursor(nzWindowCursor cursor) -{ - if (m_impl) - m_impl->SetCursor(cursor); -} - -void NzWindow::SetCursor(const NzCursor& cursor) -{ - #if NAZARA_UTILITY_SAFE - if (!cursor.IsValid()) - { - NazaraError("Cursor is not valid"); - return; - } - #endif - - if (m_impl) - m_impl->SetCursor(cursor); -} - -void NzWindow::SetEventListener(bool listener) -{ - if (!m_impl) - return; - - #if NAZARA_UTILITY_THREADED_WINDOW - m_impl->SetEventListener(listener); - if (!listener) - { - // On vide la pile des évènements - NzLockGuard lock(m_eventMutex); - while (!m_events.empty()) - m_events.pop(); - } - #else - if (m_ownsWindow) - { - // Inutile de transmettre l'ordre dans ce cas-là - if (!listener) - NazaraError("A non-threaded window needs to listen to events"); - } - else - m_impl->SetEventListener(listener); - #endif -} - -void NzWindow::SetFocus() -{ - if (m_impl) - m_impl->SetFocus(); -} - -void NzWindow::SetIcon(const NzIcon& icon) -{ - #if NAZARA_UTILITY_SAFE - if (!icon.IsValid()) - { - NazaraError("Icon is not valid"); - return; - } - #endif - - if (m_impl) - m_impl->SetIcon(icon); -} - -void NzWindow::SetMaximumSize(const NzVector2i& maxSize) -{ - if (m_impl) - m_impl->SetMaximumSize(maxSize.x, maxSize.y); -} - -void NzWindow::SetMaximumSize(int width, int height) -{ - if (m_impl) - m_impl->SetMaximumSize(width, height); -} - -void NzWindow::SetMinimumSize(const NzVector2i& minSize) -{ - if (m_impl) - m_impl->SetMinimumSize(minSize.x, minSize.y); -} - -void NzWindow::SetMinimumSize(int width, int height) -{ - if (m_impl) - m_impl->SetMinimumSize(width, height); -} - -void NzWindow::SetPosition(const NzVector2i& position) -{ - if (m_impl) - m_impl->SetPosition(position.x, position.y); -} - -void NzWindow::SetPosition(int x, int y) -{ - if (m_impl) - m_impl->SetPosition(x, y); -} - -void NzWindow::SetSize(const NzVector2i& size) -{ - if (m_impl) - m_impl->SetSize(size.x, size.y); -} - -void NzWindow::SetSize(unsigned int width, unsigned int height) -{ - if (m_impl) - m_impl->SetSize(width, height); -} - -void NzWindow::SetStayOnTop(bool stayOnTop) -{ - if (m_impl) - m_impl->SetStayOnTop(stayOnTop); -} - -void NzWindow::SetTitle(const NzString& title) -{ - if (m_impl) - m_impl->SetTitle(title); -} - -void NzWindow::SetVisible(bool visible) -{ - if (m_impl) - m_impl->SetVisible(visible); -} - -bool NzWindow::WaitEvent(NzEvent* event) -{ - if (!m_impl) - return false; - - #if NAZARA_UTILITY_THREADED_WINDOW - NzLockGuard lock(m_eventMutex); - - if (m_events.empty()) - { - m_waitForEvent = true; - m_eventConditionMutex.Lock(); - m_eventMutex.Unlock(); - m_eventCondition.Wait(&m_eventConditionMutex); - m_eventMutex.Lock(); - m_eventConditionMutex.Unlock(); - m_waitForEvent = false; - } - - if (!m_events.empty()) - { - if (event) - *event = m_events.front(); - - m_events.pop(); - - return true; - } - - return false; - #else - while (m_events.empty()) - m_impl->ProcessEvents(true); - - if (event) - *event = m_events.front(); - - m_events.pop(); - - return true; - #endif -} - -void NzWindow::OnWindowDestroying() -{ -} - -bool NzWindow::OnWindowCreated() -{ - return true; -} - -void NzWindow::IgnoreNextMouseEvent(int mouseX, int mouseY) const -{ - if (m_impl) - m_impl->IgnoreNextMouseEvent(mouseX, mouseY); -} - -void NzWindow::PushEvent(const NzEvent& event) -{ - #if NAZARA_UTILITY_THREADED_WINDOW - m_eventMutex.Lock(); - #endif - - m_events.push(event); - - #if NAZARA_UTILITY_THREADED_WINDOW - m_eventMutex.Unlock(); - - if (m_waitForEvent) - { - m_eventConditionMutex.Lock(); - m_eventCondition.Signal(); - m_eventConditionMutex.Unlock(); - } - #endif -} - -bool NzWindow::Initialize() -{ - return NzWindowImpl::Initialize(); -} - -void NzWindow::Uninitialize() -{ - NzWindowImpl::Uninitialize(); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) + #include + #include + #include +#elif defined(NAZARA_PLATFORM_LINUX) + #include + #include + #include +#else + #error Lack of implementation: Window +#endif + +#include + +namespace +{ + NzWindow* fullscreenWindow = nullptr; +} + +NzWindow::NzWindow() : +#if NAZARA_UTILITY_THREADED_WINDOW +m_impl(nullptr), +m_eventListener(true), +m_waitForEvent(false) +#else +m_impl(nullptr) +#endif +{ +} + +NzWindow::NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style) : +#if NAZARA_UTILITY_THREADED_WINDOW +m_impl(nullptr), +m_eventListener(true), +m_waitForEvent(false) +#else +m_impl(nullptr) +#endif +{ + Create(mode, title, style); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzWindow::NzWindow(NzWindowHandle handle) : +#if NAZARA_UTILITY_THREADED_WINDOW +m_impl(nullptr), +m_eventListener(true), +m_waitForEvent(false) +#else +m_impl(nullptr) +#endif +{ + Create(handle); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzWindow::~NzWindow() +{ + Destroy(); +} + +bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) +{ + // Si la fenêtre est déjà ouverte, nous conservons sa position + bool opened = IsOpen(); + NzVector2i position; + if (opened) + position = m_impl->GetPosition(); + + Destroy(); + + // Inspiré du code de la SFML par Laurent Gomila + if (style & nzWindowStyle_Fullscreen) + { + if (fullscreenWindow) + { + NazaraError("Window (" + NzString::Pointer(fullscreenWindow) + ") already in fullscreen mode"); + style &= ~nzWindowStyle_Fullscreen; + } + else + { + if (!mode.IsFullscreenValid()) + { + NazaraWarning("Video mode is not fullscreen valid"); + mode = NzVideoMode::GetFullscreenModes()[0]; + } + + fullscreenWindow = this; + } + } + else if (style & nzWindowStyle_Closable || style & nzWindowStyle_Resizable) + style |= nzWindowStyle_Titlebar; + + m_impl = new NzWindowImpl(this); + if (!m_impl->Create(mode, title, style)) + { + NazaraError("Failed to create window implementation"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + m_ownsWindow = true; + + if (!OnWindowCreated()) + { + NazaraError("Failed to initialize window extension"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + // Paramètres par défaut + m_impl->EnableKeyRepeat(true); + m_impl->EnableSmoothScrolling(false); + m_impl->SetCursor(nzWindowCursor_Default); + m_impl->SetMaximumSize(-1, -1); + m_impl->SetMinimumSize(-1, -1); + m_impl->SetVisible(true); + + if (opened) + m_impl->SetPosition(position.x, position.y); + + return true; +} + +bool NzWindow::Create(NzWindowHandle handle) +{ + Destroy(); + + m_impl = new NzWindowImpl(this); + if (!m_impl->Create(handle)) + { + NazaraError("Unable to create window implementation"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + m_ownsWindow = false; + + if (!OnWindowCreated()) + { + NazaraError("Failed to initialize window's derivate"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + return true; +} + +void NzWindow::Destroy() +{ + if (m_impl) + { + OnWindowDestroy(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + + if (fullscreenWindow == this) + fullscreenWindow = nullptr; + } +} + +void NzWindow::EnableKeyRepeat(bool enable) +{ + if (m_impl) + m_impl->EnableKeyRepeat(enable); +} + +void NzWindow::EnableSmoothScrolling(bool enable) +{ + if (m_impl) + m_impl->EnableSmoothScrolling(enable); +} + +NzWindowHandle NzWindow::GetHandle() const +{ + if (m_impl) + return m_impl->GetHandle(); + else + return static_cast(0); +} + +unsigned int NzWindow::GetHeight() const +{ + if (m_impl) + return m_impl->GetHeight(); + else + return 0; +} + +NzVector2i NzWindow::GetPosition() const +{ + if (m_impl) + return m_impl->GetPosition(); + else + return NzVector2i(0); +} + +NzVector2ui NzWindow::GetSize() const +{ + if (m_impl) + return m_impl->GetSize(); + else + return NzVector2ui(0U); +} + +NzString NzWindow::GetTitle() const +{ + if (m_impl) + return m_impl->GetTitle(); + else + return NzString(); +} + +unsigned int NzWindow::GetWidth() const +{ + if (m_impl) + return m_impl->GetWidth(); + else + return 0; +} + +bool NzWindow::HasFocus() const +{ + if (m_impl) + return m_impl->HasFocus(); + else + return false; +} + +bool NzWindow::IsOpen() const +{ + return m_impl != nullptr; +} + +bool NzWindow::IsMinimized() const +{ + if (m_impl) + return m_impl->IsMinimized(); + else + return false; +} + +bool NzWindow::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzWindow::IsVisible() const +{ + if (m_impl) + return m_impl->IsVisible(); + else + return false; +} + +bool NzWindow::PollEvent(NzEvent* event) +{ + if (!m_impl) + return false; + + #if NAZARA_UTILITY_THREADED_WINDOW + NzLockGuard lock(m_eventMutex); + #else + m_impl->ProcessEvents(false); + #endif + + if (!m_events.empty()) + { + if (event) + *event = m_events.front(); + + m_events.pop(); + + return true; + } + + return false; +} + +void NzWindow::SetCursor(nzWindowCursor cursor) +{ + if (m_impl) + m_impl->SetCursor(cursor); +} + +void NzWindow::SetCursor(const NzCursor& cursor) +{ + #if NAZARA_UTILITY_SAFE + if (!cursor.IsValid()) + { + NazaraError("Cursor is not valid"); + return; + } + #endif + + if (m_impl) + m_impl->SetCursor(cursor); +} + +void NzWindow::SetEventListener(bool listener) +{ + if (!m_impl) + return; + + #if NAZARA_UTILITY_THREADED_WINDOW + m_impl->SetEventListener(listener); + if (!listener) + { + // On vide la pile des évènements + NzLockGuard lock(m_eventMutex); + while (!m_events.empty()) + m_events.pop(); + } + #else + if (m_ownsWindow) + { + // Inutile de transmettre l'ordre dans ce cas-là + if (!listener) + NazaraError("A non-threaded window needs to listen to events"); + } + else + m_impl->SetEventListener(listener); + #endif +} + +void NzWindow::SetFocus() +{ + if (m_impl) + m_impl->SetFocus(); +} + +void NzWindow::SetIcon(const NzIcon& icon) +{ + #if NAZARA_UTILITY_SAFE + if (!icon.IsValid()) + { + NazaraError("Icon is not valid"); + return; + } + #endif + + if (m_impl) + m_impl->SetIcon(icon); +} + +void NzWindow::SetMaximumSize(const NzVector2i& maxSize) +{ + if (m_impl) + m_impl->SetMaximumSize(maxSize.x, maxSize.y); +} + +void NzWindow::SetMaximumSize(int width, int height) +{ + if (m_impl) + m_impl->SetMaximumSize(width, height); +} + +void NzWindow::SetMinimumSize(const NzVector2i& minSize) +{ + if (m_impl) + m_impl->SetMinimumSize(minSize.x, minSize.y); +} + +void NzWindow::SetMinimumSize(int width, int height) +{ + if (m_impl) + m_impl->SetMinimumSize(width, height); +} + +void NzWindow::SetPosition(const NzVector2i& position) +{ + if (m_impl) + m_impl->SetPosition(position.x, position.y); +} + +void NzWindow::SetPosition(int x, int y) +{ + if (m_impl) + m_impl->SetPosition(x, y); +} + +void NzWindow::SetSize(const NzVector2i& size) +{ + if (m_impl) + m_impl->SetSize(size.x, size.y); +} + +void NzWindow::SetSize(unsigned int width, unsigned int height) +{ + if (m_impl) + m_impl->SetSize(width, height); +} + +void NzWindow::SetStayOnTop(bool stayOnTop) +{ + if (m_impl) + m_impl->SetStayOnTop(stayOnTop); +} + +void NzWindow::SetTitle(const NzString& title) +{ + if (m_impl) + m_impl->SetTitle(title); +} + +void NzWindow::SetVisible(bool visible) +{ + if (m_impl) + m_impl->SetVisible(visible); +} + +bool NzWindow::WaitEvent(NzEvent* event) +{ + if (!m_impl) + return false; + + #if NAZARA_UTILITY_THREADED_WINDOW + NzLockGuard lock(m_eventMutex); + + if (m_events.empty()) + { + m_waitForEvent = true; + m_eventConditionMutex.Lock(); + m_eventMutex.Unlock(); + m_eventCondition.Wait(&m_eventConditionMutex); + m_eventMutex.Lock(); + m_eventConditionMutex.Unlock(); + m_waitForEvent = false; + } + + if (!m_events.empty()) + { + if (event) + *event = m_events.front(); + + m_events.pop(); + + return true; + } + + return false; + #else + while (m_events.empty()) + m_impl->ProcessEvents(true); + + if (event) + *event = m_events.front(); + + m_events.pop(); + + return true; + #endif +} + +bool NzWindow::OnWindowCreated() +{ + return true; +} + +void NzWindow::OnWindowDestroy() +{ +} + +void NzWindow::IgnoreNextMouseEvent(int mouseX, int mouseY) const +{ + if (m_impl) + m_impl->IgnoreNextMouseEvent(mouseX, mouseY); +} + +void NzWindow::PushEvent(const NzEvent& event) +{ + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventMutex.Lock(); + #endif + + m_events.push(event); + + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventMutex.Unlock(); + + if (m_waitForEvent) + { + m_eventConditionMutex.Lock(); + m_eventCondition.Signal(); + m_eventConditionMutex.Unlock(); + } + #endif +} + +bool NzWindow::Initialize() +{ + return NzWindowImpl::Initialize(); +} + +void NzWindow::Uninitialize() +{ + NzWindowImpl::Uninitialize(); +} From 4cfbd68796217b02181fac0c0a07f9d13ea2928c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 20 Sep 2012 22:32:53 +0200 Subject: [PATCH 13/31] Fixed WindowStyle_Titlebar enum Former-commit-id: 6c239b54ce2f734e0221cf87bd059ee1c73b5fe2 --- include/Nazara/Utility/Enums.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 8cf5bd786..4fbe7dc8e 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -242,7 +242,7 @@ enum nzWindowStyleFlags nzWindowStyle_Closable = 0x2, nzWindowStyle_Resizable = 0x4, - nzWindowStyle_Titlebar = 0x4, + nzWindowStyle_Titlebar = 0x8, nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar }; From f9443e37d4d29a1393e8ed71e74481892f4e5754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 21 Sep 2012 12:06:28 +0200 Subject: [PATCH 14/31] Fixed DopplerEffect comments Former-commit-id: 26b6f08b6bbc54b0e96d708feda4229e182cb918 --- examples/DopplerEffect/main.cpp | 136 ++++++++++++++++---------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp index b02b416c3..14a39a849 100644 --- a/examples/DopplerEffect/main.cpp +++ b/examples/DopplerEffect/main.cpp @@ -1,68 +1,68 @@ -#include -#include -#include // Thread::Sleep -#include -#include - -int main() -{ - // NzKeyboard ne nécessite pas l'initialisation d'Utility - NzInitializer audio; - if (!audio) - { - std::cout << "Failed to initialize audio module" << std::endl; - std::getchar(); - return 1; - } - - NzSound sound; - if (!sound.LoadFromFile("resources/siren.wav")) - { - std::cout << "Failed to load sound" << std::endl; - std::getchar(); - return 1; - } - - std::cout << "Demonstration de l'effet doppler avec Nazara" << std::endl; - std::cout << "Appuyez sur entree pour demarrer" << std::endl; - std::cout << "Appuyez sur echap pour arreter" << std::endl; - - std::getchar(); - - // On fait en sorte de répéter le son - sound.EnableLooping(true); - - // La source du son se situe en (50, 0, 5) - sound.SetPosition(50, 0, 5); - - // Et possède une vitesse de -10 par seconde sur l'axe X - sound.SetVelocity(-10, 0, 0); - - // On joue le son - sound.Play(); - - // La boucle du programme (Pour déplacer le son) - NzClock clock; - while (sound.GetStatus() == nzSoundStatus_Playing) - { - // Comme le son se joue dans un thread séparé, on peut mettre en pause celui-ci régulièrement - int sleepTime = 1000/60 - clock.GetMilliseconds(); // 60 FPS - - if (sleepTime > 0) - NzThread::Sleep(sleepTime); - - // On bouge la source du son en fonction du au temps depuis chaque mise à jour - NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); - sound.SetPosition(pos); - - std::cout << "Sound position: " << pos << std::endl; - - // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap - if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) - sound.Stop(); // On arrête le son (Stoppant également la boucle) - - clock.Restart(); - } - - return 0; -} +#include +#include +#include // Thread::Sleep +#include +#include + +int main() +{ + // NzKeyboard ne nécessite pas l'initialisation d'Utility + NzInitializer audio; + if (!audio) + { + std::cout << "Failed to initialize audio module" << std::endl; + std::getchar(); + return 1; + } + + NzSound sound; + if (!sound.LoadFromFile("resources/siren.wav")) + { + std::cout << "Failed to load sound" << std::endl; + std::getchar(); + return 1; + } + + std::cout << "Demonstration de l'effet doppler avec Nazara" << std::endl; + std::cout << "Appuyez sur entree pour demarrer" << std::endl; + std::cout << "Appuyez sur echap pour arreter" << std::endl; + + std::getchar(); + + // On fait en sorte de répéter le son + sound.EnableLooping(true); + + // La source du son se situe en (50, 0, 5) + sound.SetPosition(50, 0, 5); + + // Et possède une vitesse de -10 par seconde sur l'axe X + sound.SetVelocity(-10, 0, 0); + + // On joue le son + sound.Play(); + + // La boucle du programme (Pour déplacer le son) + NzClock clock; + while (sound.GetStatus() == nzSoundStatus_Playing) + { + // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement + int sleepTime = 1000/60 - clock.GetMilliseconds(); // 60 FPS + + if (sleepTime > 0) + NzThread::Sleep(sleepTime); + + // On bouge la source du son en fonction du temps depuis chaque mise à jour + NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); + sound.SetPosition(pos); + + std::cout << "Sound position: " << pos << std::endl; + + // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap + if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) + sound.Stop(); // On arrête le son (Stoppant également la boucle) + + clock.Restart(); + } + + return 0; +} From 2ea37a187755f6e4d6eb350b55c7a242ae058502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 21 Sep 2012 12:07:13 +0200 Subject: [PATCH 15/31] Added InputStream::EndOfStream() Former-commit-id: d8618fbb677a73cb6890d913af66adb22e6c2a39 --- include/Nazara/Core/File.hpp | 247 ++--- include/Nazara/Core/InputStream.hpp | 52 +- src/Nazara/Core/File.cpp | 1597 ++++++++++++++------------- 3 files changed, 952 insertions(+), 944 deletions(-) diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 3bb64342e..c912fd84b 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -1,123 +1,124 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_FILE_HPP -#define NAZARA_FILE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE -#include -#else -#include -#endif - -class NzFileImpl; - -class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable -{ - public: - enum CursorPosition - { - AtBegin, // Début du fichier - AtCurrent, // Position du pointeur - AtEnd // Fin du fichier - }; - - enum OpenMode - { - Current = 0x00, // Utilise le mode d'ouverture actuel - - Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin - Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert - ReadOnly = 0x04, // Ouvre uniquement en lecture - ReadWrite = 0x08, // Ouvre en lecture/écriture - Text = 0x10, // Ouvre en mode texte - Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe - WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas - }; - - NzFile(); - NzFile(const NzString& filePath); - NzFile(const NzString& filePath, unsigned long openMode); - NzFile(NzFile&& file) noexcept; - ~NzFile(); - - bool Copy(const NzString& newFilePath); - void Close(); - - bool Delete(); - - bool EndOfFile() const; - - bool Exists() const; - - void Flush(); - - time_t GetCreationTime() const; - nzUInt64 GetCursorPos() const; - NzString GetDirectoryPath() const; - NzString GetFilePath() const; - NzString GetFileName() const; - time_t GetLastAccessTime() const; - time_t GetLastWriteTime() const; - NzString GetLine(unsigned int lineSize = 0); - nzUInt64 GetSize() const; - - bool IsOpen() const; - - bool Open(unsigned long openMode = Current); - - std::size_t Read(void* buffer, std::size_t size); - std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); - bool Rename(const NzString& newFilePath); - - bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0); - bool SetCursorPos(nzUInt64 offset); - void SetEndianness(nzEndianness endianness); - bool SetFile(const NzString& filePath); - bool SetOpenMode(unsigned int openMode); - - bool Write(const NzString& string); - std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); - - NzFile& operator=(const NzString& filePath); - NzFile& operator=(NzFile&& file) noexcept; - - static NzString AbsolutePath(const NzString& filePath); - static bool Copy(const NzString& sourcePath, const NzString& targetPath); - static bool Delete(const NzString& filePath); - static bool Exists(const NzString& filePath); - static time_t GetCreationTime(const NzString& filePath); - static time_t GetLastAccessTime(const NzString& filePath); - static time_t GetLastWriteTime(const NzString& filePath); - static NzHashDigest GetHash(const NzString& filePath, nzHash hash); - static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash); - static nzUInt64 GetSize(const NzString& filePath); - static bool IsAbsolute(const NzString& path); - static NzString NormalizePath(const NzString& filePath); - static NzString NormalizeSeparators(const NzString& filePath); - static bool Rename(const NzString& sourcePath, const NzString& targetPath); - - private: - bool FillHash(NzHashImpl* hash) const; - - NazaraMutexAttrib(m_mutex, mutable) - - nzEndianness m_endianness; - NzString m_filePath; - NzFileImpl* m_impl; - unsigned int m_openMode; -}; - -#endif // NAZARA_FILE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_FILE_HPP +#define NAZARA_FILE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE +#include +#else +#include +#endif + +class NzFileImpl; + +class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable +{ + public: + enum CursorPosition + { + AtBegin, // Début du fichier + AtCurrent, // Position du pointeur + AtEnd // Fin du fichier + }; + + enum OpenMode + { + Current = 0x00, // Utilise le mode d'ouverture actuel + + Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin + Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert + ReadOnly = 0x04, // Ouvre uniquement en lecture + ReadWrite = 0x08, // Ouvre en lecture/écriture + Text = 0x10, // Ouvre en mode texte + Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe + WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas + }; + + NzFile(); + NzFile(const NzString& filePath); + NzFile(const NzString& filePath, unsigned long openMode); + NzFile(NzFile&& file) noexcept; + ~NzFile(); + + bool Copy(const NzString& newFilePath); + void Close(); + + bool Delete(); + + bool EndOfFile() const; + bool EndOfStream() const; + + bool Exists() const; + + void Flush(); + + time_t GetCreationTime() const; + nzUInt64 GetCursorPos() const; + NzString GetDirectoryPath() const; + NzString GetFilePath() const; + NzString GetFileName() const; + time_t GetLastAccessTime() const; + time_t GetLastWriteTime() const; + NzString GetLine(unsigned int lineSize = 0); + nzUInt64 GetSize() const; + + bool IsOpen() const; + + bool Open(unsigned long openMode = Current); + + std::size_t Read(void* buffer, std::size_t size); + std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); + bool Rename(const NzString& newFilePath); + + bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0); + bool SetCursorPos(nzUInt64 offset); + void SetEndianness(nzEndianness endianness); + bool SetFile(const NzString& filePath); + bool SetOpenMode(unsigned int openMode); + + bool Write(const NzString& string); + std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); + + NzFile& operator=(const NzString& filePath); + NzFile& operator=(NzFile&& file) noexcept; + + static NzString AbsolutePath(const NzString& filePath); + static bool Copy(const NzString& sourcePath, const NzString& targetPath); + static bool Delete(const NzString& filePath); + static bool Exists(const NzString& filePath); + static time_t GetCreationTime(const NzString& filePath); + static time_t GetLastAccessTime(const NzString& filePath); + static time_t GetLastWriteTime(const NzString& filePath); + static NzHashDigest GetHash(const NzString& filePath, nzHash hash); + static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash); + static nzUInt64 GetSize(const NzString& filePath); + static bool IsAbsolute(const NzString& path); + static NzString NormalizePath(const NzString& filePath); + static NzString NormalizeSeparators(const NzString& filePath); + static bool Rename(const NzString& sourcePath, const NzString& targetPath); + + private: + bool FillHash(NzHashImpl* hash) const; + + NazaraMutexAttrib(m_mutex, mutable) + + nzEndianness m_endianness; + NzString m_filePath; + NzFileImpl* m_impl; + unsigned int m_openMode; +}; + +#endif // NAZARA_FILE_HPP diff --git a/include/Nazara/Core/InputStream.hpp b/include/Nazara/Core/InputStream.hpp index 28b951b85..eca1a42b0 100644 --- a/include/Nazara/Core/InputStream.hpp +++ b/include/Nazara/Core/InputStream.hpp @@ -1,25 +1,27 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_INPUTSTREAM_HPP -#define NAZARA_INPUTSTREAM_HPP - -#include - -class NzInputStream -{ - public: - virtual ~NzInputStream(); - - virtual nzUInt64 GetCursorPos() const = 0; - virtual nzUInt64 GetSize() const = 0; - - virtual std::size_t Read(void* buffer, std::size_t size) = 0; - - virtual bool SetCursorPos(nzUInt64 offset) = 0; -}; - -#endif // NAZARA_INPUTSTREAM_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_INPUTSTREAM_HPP +#define NAZARA_INPUTSTREAM_HPP + +#include + +class NzInputStream +{ + public: + virtual ~NzInputStream(); + + virtual bool EndOfStream() const = 0; + + virtual nzUInt64 GetCursorPos() const = 0; + virtual nzUInt64 GetSize() const = 0; + + virtual std::size_t Read(void* buffer, std::size_t size) = 0; + + virtual bool SetCursorPos(nzUInt64 offset) = 0; +}; + +#endif // NAZARA_INPUTSTREAM_HPP diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 55cba809e..d01aefc7c 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -1,796 +1,801 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) - #include -#elif defined(NAZARA_PLATFORM_POSIX) - #include -#else - #error OS not handled -#endif - -#include - -NzFile::NzFile() : -m_endianness(nzEndianness_Unknown), -m_impl(nullptr), -m_openMode(0) -{ -} - -NzFile::NzFile(const NzString& filePath) : -m_endianness(nzEndianness_Unknown), -m_impl(nullptr), -m_openMode(0) -{ - SetFile(filePath); -} - -NzFile::NzFile(const NzString& filePath, unsigned long openMode) : -m_endianness(nzEndianness_Unknown), -m_impl(nullptr), -m_openMode(0) -{ - SetFile(filePath); - Open(openMode); -} - -NzFile::NzFile(NzFile&& file) noexcept : -m_endianness(file.m_endianness), -m_filePath(std::move(file.m_filePath)), -m_impl(file.m_impl), -m_openMode(file.m_openMode) -{ - file.m_impl = nullptr; -} - -NzFile::~NzFile() -{ - Close(); -} - -bool NzFile::Copy(const NzString& newFilePath) -{ - return Copy(m_filePath, newFilePath); -} - -void NzFile::Close() -{ - NazaraLock(m_mutex) - - if (m_impl) - { - m_impl->Close(); - delete m_impl; - m_impl = nullptr; - } -} - -bool NzFile::Delete() -{ - NazaraLock(m_mutex) - - Close(); - - return Delete(m_filePath); -} - -bool NzFile::EndOfFile() const -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->EndOfFile(); -} - -bool NzFile::Exists() const -{ - NazaraLock(m_mutex) - - if (IsOpen()) - return true; // Le fichier est ouvert, donc il existe - else - return Exists(m_filePath); -} - -void NzFile::Flush() -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return; - } - - if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) - { - NazaraError("Cannot flush file without write access"); - return; - } - #endif - - m_impl->Flush(); -} - -time_t NzFile::GetCreationTime() const -{ - NazaraLock(m_mutex) - - return GetCreationTime(m_filePath); -} - -nzUInt64 NzFile::GetCursorPos() const -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->GetCursorPos(); -} - -NzString NzFile::GetDirectoryPath() const -{ - NazaraLock(m_mutex) - - return m_filePath.SubstrTo(NAZARA_DIRECTORY_SEPARATOR, -1, true); -} - -NzString NzFile::GetFilePath() const -{ - NazaraLock(m_mutex) - - return m_filePath; -} - -NzString NzFile::GetFileName() const -{ - NazaraLock(m_mutex) - - return m_filePath.SubstrFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); -} - -time_t NzFile::GetLastAccessTime() const -{ - NazaraLock(m_mutex) - - return GetLastAccessTime(m_filePath); -} - -time_t NzFile::GetLastWriteTime() const -{ - NazaraLock(m_mutex) - - return GetLastWriteTime(m_filePath); -} - -NzString NzFile::GetLine(unsigned int lineSize) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return NzString(); - } - - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) - { - NazaraError("File not opened with read access"); - return NzString(); - } - #endif - - NzString line; - if (lineSize == 0) // Taille maximale indéterminée - { - while (!m_impl->EndOfFile()) - { - char c; - if (m_impl->Read(&c, sizeof(char)) == sizeof(char)) - { - if (c == '\n') - { - if (m_openMode & Text && line.EndsWith('\r')) - line.Resize(-1); - - break; - } - - line += c; - } - else - break; - } - } - else - { - line.Reserve(lineSize); - for (unsigned int i = 0; i < lineSize; ++i) - { - char c; - if (m_impl->Read(&c, sizeof(char)) == sizeof(char)) - { - if (c == '\n') - { - if (m_openMode & Text && line.EndsWith('\r')) - line.Resize(-1); - - break; - } - - line += c; - } - else - break; - } - } - - return line; -} - -nzUInt64 NzFile::GetSize() const -{ - NazaraLock(m_mutex) - - return GetSize(m_filePath); -} - -bool NzFile::IsOpen() const -{ - NazaraLock(m_mutex) - - return m_impl != nullptr; -} - -std::size_t NzFile::Read(void* buffer, std::size_t size) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return 0; - } - - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) - { - NazaraError("File not opened with read access"); - return 0; - } - #endif - - if (size == 0) - return 0; - - if (buffer) - return m_impl->Read(buffer, size); - else - { - // Si nous ne devons rien lire, nous avançons simplement - nzUInt64 currentPos = m_impl->GetCursorPos(); - - m_impl->SetCursorPos(NzFile::AtCurrent, size); - - return m_impl->GetCursorPos()-currentPos; - } -} - -std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) -{ - std::size_t byteRead = Read(buffer, typeSize*count); - if (byteRead == 0) - return 0; - - if (buffer && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) - { - unsigned int typeCount = byteRead/typeSize; - for (unsigned int i = 0; i < typeCount; ++i) - NzByteSwap(reinterpret_cast(buffer) + i*typeSize, typeSize); - } - - return byteRead; -} - -bool NzFile::Rename(const NzString& newFilePath) -{ - NazaraLock(m_mutex) - - bool opened = IsOpen(); - Close(); - - bool success = Rename(m_filePath, newFilePath); - if (success) - m_filePath = NormalizePath(newFilePath); - - if (opened) - Open(); - - return success; -} - -bool NzFile::Open(unsigned long openMode) -{ - NazaraLock(m_mutex) - - Close(); - - if (m_filePath.IsEmpty()) - return false; - - if (openMode != 0) - m_openMode = openMode; - - if (m_openMode == 0) - return false; - - m_impl = new NzFileImpl(this); - if (!m_impl->Open(m_filePath, m_openMode)) - { - delete m_impl; - m_impl = nullptr; - - return false; - } - - return true; -} - -bool NzFile::SetCursorPos(CursorPosition pos, nzInt64 offset) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->SetCursorPos(pos, offset); -} - -bool NzFile::SetCursorPos(nzUInt64 offset) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->SetCursorPos(AtBegin, offset); -} - -void NzFile::SetEndianness(nzEndianness endianness) -{ - NazaraLock(m_mutex) - - m_endianness = endianness; -} - -bool NzFile::SetFile(const NzString& filePath) -{ - NazaraLock(m_mutex) - - if (IsOpen()) - { - if (filePath.IsEmpty()) - return false; - - NzFileImpl* impl = new NzFileImpl(this); - if (!impl->Open(filePath, m_openMode)) - { - delete impl; - return false; - } - - m_impl->Close(); - delete m_impl; - - m_impl = impl; - } - - m_filePath = AbsolutePath(filePath); - return true; -} - -bool NzFile::SetOpenMode(unsigned int openMode) -{ - NazaraLock(m_mutex) - - if (openMode == 0 || openMode == m_openMode) - return true; - - if (IsOpen()) - { - NzFileImpl* impl = new NzFileImpl(this); - if (!impl->Open(m_filePath, openMode)) - { - delete impl; - - return false; - } - - m_impl->Close(); - delete m_impl; - - m_impl = impl; - } - - m_openMode = openMode; - - return true; -} - -bool NzFile::Write(const NzString& string) -{ - NazaraLock(m_mutex) - - NzString temp(string); - - if (m_openMode & Text) - { - #if defined(NAZARA_PLATFORM_WINDOWS) - temp.Replace("\n", "\r\n"); - #elif defined(NAZARA_PLATFORM_LINUX) - // Rien à faire - #elif defined(NAZARA_PLATFORM_MACOS) - temp.Replace('\n', '\r'); - #else - #error OS not handled - #endif - } - - unsigned int size = temp.GetSize(); - std::size_t bytesWritten = Write(temp.GetBuffer(), sizeof(char), size); - - return bytesWritten == size*sizeof(char); -} - -std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int count) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return 0; - } - - if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) - { - NazaraError("File not opened with write access"); - return 0; - } - #endif - - if (!buffer || count == 0 || typeSize == 0) - return 0; - - std::size_t bytesWritten; - if (m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) - { - char* buf = new char[count*typeSize]; - std::memcpy(buf, buffer, count*typeSize); - - for (unsigned int i = 0; i < count; ++i) - NzByteSwap(&buf[i*typeSize], typeSize); - - bytesWritten = m_impl->Write(buf, count*typeSize); - - delete[] buf; - } - else - bytesWritten = m_impl->Write(buffer, count*typeSize); - - return bytesWritten; -} - -NzFile& NzFile::operator=(const NzString& filePath) -{ - SetFile(filePath); - - return *this; -} - -NzFile& NzFile::operator=(NzFile&& file) noexcept -{ - NazaraLock(m_mutex) - - std::swap(m_endianness, file.m_endianness); - std::swap(m_filePath, file.m_filePath); - std::swap(m_impl, file.m_impl); - std::swap(m_openMode, file.m_openMode); - - return *this; -} - -NzString NzFile::AbsolutePath(const NzString& filePath) -{ - // Je n'utilise pas les fonctions de l'OS car elles ne fonctionnent que pour un chemin existant - NzString path = NormalizePath(filePath); - if (path.IsEmpty()) - return NzString(); - - NzString base; - unsigned int start; - #ifdef NAZARA_PLATFORM_WINDOWS - if (path.Match("?:*")) - start = 1; - else if (path.Match("\\\\*")) - { - base = "\\\\"; - start = 2; - } - else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine - { - NzString drive = NzDirectory::GetCurrent().SubstrTo('\\'); - NzString end = path.Substr(1, -1); - if (end.IsEmpty()) - path = drive; - else - path = drive + '\\' + end; - - start = 1; - } - else - { - NazaraError("Path unrecognized"); - return path; - } - #elif defined(NAZARA_PLATEFORM_LINUX) - base = '/'; - start = 0; - #else - #error OS case not implemented - #endif - - static NzString upDir = NAZARA_DIRECTORY_SEPARATOR + NzString('.'); - - if (path.Find(upDir) == NzString::npos) - return path; - - std::vector sep; - if (path.Split(sep, NAZARA_DIRECTORY_SEPARATOR) <= 1) - return path; - - // Nous avons un chemin absolu, mais il nous faut un peu le nettoyer - unsigned int pathLen = base.GetSize(); - for (unsigned int i = 0; i < sep.size(); ++i) - { - if (sep[i] == '.') - sep.erase(sep.begin() + i--); - else if (sep[i] == "..") - { - if (i > start) // Si nous ne sommes pas dans la partie protégée - sep.erase(sep.begin() + i--); - - sep.erase(sep.begin() + i--); - } - else - pathLen += sep[i].GetSize(); - } - - pathLen += sep.size()-1; - - ///FIXME: Le destructeur de NzStringStream provoque un bug lors de la libération de son vector - - //NzStringStream stream(base); - NzString stream; - stream.Reserve(pathLen); - stream.Append(base); - for (unsigned int i = 0; i < sep.size(); ++i) - { - stream.Append(sep[i]); - if (i != sep.size()-1) - stream.Append(NAZARA_DIRECTORY_SEPARATOR); - /*if (i != sep.size()-1) - stream << sep[i] << NAZARA_DIRECTORY_SEPARATOR; - else - stream << sep[i];*/ - } - - return stream; -} - -bool NzFile::Copy(const NzString& sourcePath, const NzString& targetPath) -{ - if (sourcePath.IsEmpty() || targetPath.IsEmpty()) - return false; - - return NzFileImpl::Copy(NormalizePath(sourcePath), NormalizePath(targetPath)); -} - -bool NzFile::Delete(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return false; - - return NzFileImpl::Delete(NormalizePath(filePath)); -} - -bool NzFile::Exists(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return false; - - return NzFileImpl::Exists(NormalizePath(filePath)); -} - -time_t NzFile::GetCreationTime(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetCreationTime(NormalizePath(filePath)); -} - -time_t NzFile::GetLastAccessTime(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetLastAccessTime(NormalizePath(filePath)); -} - -time_t NzFile::GetLastWriteTime(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetLastWriteTime(NormalizePath(filePath)); -} - -NzHashDigest NzFile::GetHash(const NzString& filePath, nzHash hash) -{ - NzFile file(filePath); - - NzHash h(hash); - return h.Hash(file); -} - -NzHashDigest NzFile::GetHash(const NzString& filePath, NzHashImpl* hash) -{ - NzFile file(filePath); - - NzHash h(hash); - return h.Hash(file); -} - -nzUInt64 NzFile::GetSize(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetSize(NormalizePath(filePath)); -} - -bool NzFile::IsAbsolute(const NzString& path) -{ - NzString wpath(path); - wpath.Trim(); - - if (wpath.IsEmpty()) - return false; - - #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS - wpath = NormalizeSeparators(wpath); - #endif - - #ifdef NAZARA_PLATFORM_WINDOWS - if (path.Match("?:*")) - return true; - else if (path.Match("\\\\*")) - return true; - else if (wpath.StartsWith('\\')) // Spécial : '\' fait référence au disque racine - return true; - else - return false; - #elif defined(NAZARA_PLATEFORM_LINUX) - return wpath.StartsWith('/'); - #else - #error OS case not implemented - #endif -} - -NzString NzFile::NormalizePath(const NzString& filePath) -{ - NzString path(filePath); - path.Trim(); - - #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS - path = NormalizeSeparators(path); - #endif - - if (!IsAbsolute(path)) - path = NzDirectory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR + path; - - while (path.EndsWith(NAZARA_DIRECTORY_SEPARATOR)) - path.Resize(-1); - - return path; -} - -NzString NzFile::NormalizeSeparators(const NzString& filePath) -{ - NzString path(filePath); - - #if defined(NAZARA_PLATFORM_WINDOWS) - path.Replace('/', '\\'); - #elif defined(NAZARA_PLATFORM_LINUX) - path.Replace('\\', '/'); - #else - #error OS case not implemented - #endif - - return path; -} - -bool NzFile::Rename(const NzString& sourcePath, const NzString& targetPath) -{ - if (sourcePath.IsEmpty() || targetPath.IsEmpty()) - return false; - - return NzFileImpl::Rename(NormalizePath(sourcePath), NormalizePath(targetPath)); -} - -bool NzFile::FillHash(NzHashImpl* hash) const -{ - NzFile file(m_filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Unable to open file"); - return false; - } - - nzUInt64 remainingSize = file.GetSize(); - - char buffer[NAZARA_CORE_FILE_BUFFERSIZE]; - unsigned int size; - while (remainingSize > 0) - { - size = (remainingSize >= NAZARA_CORE_FILE_BUFFERSIZE) ? NAZARA_CORE_FILE_BUFFERSIZE : static_cast(remainingSize); - if (file.Read(&buffer[0], sizeof(char), size) != sizeof(char)*size) - { - NazaraError("Unable to read file"); - return false; - } - - remainingSize -= size; - hash->Append(reinterpret_cast(&buffer[0]), size); - } - - return true; -} // Fermeture automatique du fichier +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) + #include +#elif defined(NAZARA_PLATFORM_POSIX) + #include +#else + #error OS not handled +#endif + +#include + +NzFile::NzFile() : +m_endianness(nzEndianness_Unknown), +m_impl(nullptr), +m_openMode(0) +{ +} + +NzFile::NzFile(const NzString& filePath) : +m_endianness(nzEndianness_Unknown), +m_impl(nullptr), +m_openMode(0) +{ + SetFile(filePath); +} + +NzFile::NzFile(const NzString& filePath, unsigned long openMode) : +m_endianness(nzEndianness_Unknown), +m_impl(nullptr), +m_openMode(0) +{ + SetFile(filePath); + Open(openMode); +} + +NzFile::NzFile(NzFile&& file) noexcept : +m_endianness(file.m_endianness), +m_filePath(std::move(file.m_filePath)), +m_impl(file.m_impl), +m_openMode(file.m_openMode) +{ + file.m_impl = nullptr; +} + +NzFile::~NzFile() +{ + Close(); +} + +bool NzFile::Copy(const NzString& newFilePath) +{ + return Copy(m_filePath, newFilePath); +} + +void NzFile::Close() +{ + NazaraLock(m_mutex) + + if (m_impl) + { + m_impl->Close(); + delete m_impl; + m_impl = nullptr; + } +} + +bool NzFile::Delete() +{ + NazaraLock(m_mutex) + + Close(); + + return Delete(m_filePath); +} + +bool NzFile::EndOfFile() const +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->EndOfFile(); +} + +bool NzFile::EndOfStream() const; +{ + return EndOfFile(); +} + +bool NzFile::Exists() const +{ + NazaraLock(m_mutex) + + if (IsOpen()) + return true; // Le fichier est ouvert, donc il existe + else + return Exists(m_filePath); +} + +void NzFile::Flush() +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return; + } + + if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) + { + NazaraError("Cannot flush file without write access"); + return; + } + #endif + + m_impl->Flush(); +} + +time_t NzFile::GetCreationTime() const +{ + NazaraLock(m_mutex) + + return GetCreationTime(m_filePath); +} + +nzUInt64 NzFile::GetCursorPos() const +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->GetCursorPos(); +} + +NzString NzFile::GetDirectoryPath() const +{ + NazaraLock(m_mutex) + + return m_filePath.SubstrTo(NAZARA_DIRECTORY_SEPARATOR, -1, true); +} + +NzString NzFile::GetFilePath() const +{ + NazaraLock(m_mutex) + + return m_filePath; +} + +NzString NzFile::GetFileName() const +{ + NazaraLock(m_mutex) + + return m_filePath.SubstrFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); +} + +time_t NzFile::GetLastAccessTime() const +{ + NazaraLock(m_mutex) + + return GetLastAccessTime(m_filePath); +} + +time_t NzFile::GetLastWriteTime() const +{ + NazaraLock(m_mutex) + + return GetLastWriteTime(m_filePath); +} + +NzString NzFile::GetLine(unsigned int lineSize) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return NzString(); + } + + if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) + { + NazaraError("File not opened with read access"); + return NzString(); + } + #endif + + NzString line; + if (lineSize == 0) // Taille maximale indéterminée + { + while (!m_impl->EndOfFile()) + { + char c; + if (m_impl->Read(&c, sizeof(char)) == sizeof(char)) + { + if (c == '\n') + { + if (m_openMode & Text && line.EndsWith('\r')) + line.Resize(-1); + + break; + } + + line += c; + } + else + break; + } + } + else + { + line.Reserve(lineSize); + for (unsigned int i = 0; i < lineSize; ++i) + { + char c; + if (m_impl->Read(&c, sizeof(char)) == sizeof(char)) + { + if (c == '\n') + { + if (m_openMode & Text && line.EndsWith('\r')) + line.Resize(-1); + + break; + } + + line += c; + } + else + break; + } + } + + return line; +} + +nzUInt64 NzFile::GetSize() const +{ + NazaraLock(m_mutex) + + return GetSize(m_filePath); +} + +bool NzFile::IsOpen() const +{ + NazaraLock(m_mutex) + + return m_impl != nullptr; +} + +std::size_t NzFile::Read(void* buffer, std::size_t size) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return 0; + } + + if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) + { + NazaraError("File not opened with read access"); + return 0; + } + #endif + + if (size == 0) + return 0; + + if (buffer) + return m_impl->Read(buffer, size); + else + { + // Si nous ne devons rien lire, nous avançons simplement + nzUInt64 currentPos = m_impl->GetCursorPos(); + + m_impl->SetCursorPos(NzFile::AtCurrent, size); + + return m_impl->GetCursorPos()-currentPos; + } +} + +std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) +{ + std::size_t byteRead = Read(buffer, typeSize*count); + if (byteRead == 0) + return 0; + + if (buffer && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) + { + unsigned int typeCount = byteRead/typeSize; + for (unsigned int i = 0; i < typeCount; ++i) + NzByteSwap(reinterpret_cast(buffer) + i*typeSize, typeSize); + } + + return byteRead; +} + +bool NzFile::Rename(const NzString& newFilePath) +{ + NazaraLock(m_mutex) + + bool opened = IsOpen(); + Close(); + + bool success = Rename(m_filePath, newFilePath); + if (success) + m_filePath = NormalizePath(newFilePath); + + if (opened) + Open(); + + return success; +} + +bool NzFile::Open(unsigned long openMode) +{ + NazaraLock(m_mutex) + + Close(); + + if (m_filePath.IsEmpty()) + return false; + + if (openMode != 0) + m_openMode = openMode; + + if (m_openMode == 0) + return false; + + m_impl = new NzFileImpl(this); + if (!m_impl->Open(m_filePath, m_openMode)) + { + delete m_impl; + m_impl = nullptr; + + return false; + } + + return true; +} + +bool NzFile::SetCursorPos(CursorPosition pos, nzInt64 offset) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->SetCursorPos(pos, offset); +} + +bool NzFile::SetCursorPos(nzUInt64 offset) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->SetCursorPos(AtBegin, offset); +} + +void NzFile::SetEndianness(nzEndianness endianness) +{ + NazaraLock(m_mutex) + + m_endianness = endianness; +} + +bool NzFile::SetFile(const NzString& filePath) +{ + NazaraLock(m_mutex) + + if (IsOpen()) + { + if (filePath.IsEmpty()) + return false; + + NzFileImpl* impl = new NzFileImpl(this); + if (!impl->Open(filePath, m_openMode)) + { + delete impl; + return false; + } + + m_impl->Close(); + delete m_impl; + + m_impl = impl; + } + + m_filePath = AbsolutePath(filePath); + return true; +} + +bool NzFile::SetOpenMode(unsigned int openMode) +{ + NazaraLock(m_mutex) + + if (openMode == 0 || openMode == m_openMode) + return true; + + if (IsOpen()) + { + NzFileImpl* impl = new NzFileImpl(this); + if (!impl->Open(m_filePath, openMode)) + { + delete impl; + + return false; + } + + m_impl->Close(); + delete m_impl; + + m_impl = impl; + } + + m_openMode = openMode; + + return true; +} + +bool NzFile::Write(const NzString& string) +{ + NazaraLock(m_mutex) + + NzString temp(string); + + if (m_openMode & Text) + { + #if defined(NAZARA_PLATFORM_WINDOWS) + temp.Replace("\n", "\r\n"); + #elif defined(NAZARA_PLATFORM_LINUX) + // Rien à faire + #elif defined(NAZARA_PLATFORM_MACOS) + temp.Replace('\n', '\r'); + #else + #error OS not handled + #endif + } + + unsigned int size = temp.GetSize(); + std::size_t bytesWritten = Write(temp.GetBuffer(), sizeof(char), size); + + return bytesWritten == size*sizeof(char); +} + +std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int count) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return 0; + } + + if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) + { + NazaraError("File not opened with write access"); + return 0; + } + #endif + + if (!buffer || count == 0 || typeSize == 0) + return 0; + + std::size_t bytesWritten; + if (m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) + { + char* buf = new char[count*typeSize]; + std::memcpy(buf, buffer, count*typeSize); + + for (unsigned int i = 0; i < count; ++i) + NzByteSwap(&buf[i*typeSize], typeSize); + + bytesWritten = m_impl->Write(buf, count*typeSize); + + delete[] buf; + } + else + bytesWritten = m_impl->Write(buffer, count*typeSize); + + return bytesWritten; +} + +NzFile& NzFile::operator=(const NzString& filePath) +{ + SetFile(filePath); + + return *this; +} + +NzFile& NzFile::operator=(NzFile&& file) noexcept +{ + NazaraLock(m_mutex) + + std::swap(m_endianness, file.m_endianness); + std::swap(m_filePath, file.m_filePath); + std::swap(m_impl, file.m_impl); + std::swap(m_openMode, file.m_openMode); + + return *this; +} + +NzString NzFile::AbsolutePath(const NzString& filePath) +{ + // Je n'utilise pas les fonctions de l'OS car elles ne fonctionnent que pour un chemin existant + NzString path = NormalizePath(filePath); + if (path.IsEmpty()) + return NzString(); + + NzString base; + unsigned int start; + #ifdef NAZARA_PLATFORM_WINDOWS + if (path.Match("?:*")) + start = 1; + else if (path.Match("\\\\*")) + { + base = "\\\\"; + start = 2; + } + else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + { + NzString drive = NzDirectory::GetCurrent().SubstrTo('\\'); + NzString end = path.Substr(1, -1); + if (end.IsEmpty()) + path = drive; + else + path = drive + '\\' + end; + + start = 1; + } + else + { + NazaraError("Path unrecognized"); + return path; + } + #elif defined(NAZARA_PLATEFORM_LINUX) + base = '/'; + start = 0; + #else + #error OS case not implemented + #endif + + static NzString upDir = NAZARA_DIRECTORY_SEPARATOR + NzString('.'); + + if (path.Find(upDir) == NzString::npos) + return path; + + std::vector sep; + if (path.Split(sep, NAZARA_DIRECTORY_SEPARATOR) <= 1) + return path; + + // Nous avons un chemin absolu, mais il nous faut un peu le nettoyer + unsigned int pathLen = base.GetSize(); + for (unsigned int i = 0; i < sep.size(); ++i) + { + if (sep[i] == '.') + sep.erase(sep.begin() + i--); + else if (sep[i] == "..") + { + if (i > start) // Si nous ne sommes pas dans la partie protégée + sep.erase(sep.begin() + i--); + + sep.erase(sep.begin() + i--); + } + else + pathLen += sep[i].GetSize(); + } + + pathLen += sep.size()-1; + + ///FIXME: Le destructeur de NzStringStream provoque un bug lors de la libération de son vector + + //NzStringStream stream(base); + NzString stream; + stream.Reserve(pathLen); + stream.Append(base); + for (unsigned int i = 0; i < sep.size(); ++i) + { + stream.Append(sep[i]); + if (i != sep.size()-1) + stream.Append(NAZARA_DIRECTORY_SEPARATOR); + /*if (i != sep.size()-1) + stream << sep[i] << NAZARA_DIRECTORY_SEPARATOR; + else + stream << sep[i];*/ + } + + return stream; +} + +bool NzFile::Copy(const NzString& sourcePath, const NzString& targetPath) +{ + if (sourcePath.IsEmpty() || targetPath.IsEmpty()) + return false; + + return NzFileImpl::Copy(NormalizePath(sourcePath), NormalizePath(targetPath)); +} + +bool NzFile::Delete(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return false; + + return NzFileImpl::Delete(NormalizePath(filePath)); +} + +bool NzFile::Exists(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return false; + + return NzFileImpl::Exists(NormalizePath(filePath)); +} + +time_t NzFile::GetCreationTime(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetCreationTime(NormalizePath(filePath)); +} + +time_t NzFile::GetLastAccessTime(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetLastAccessTime(NormalizePath(filePath)); +} + +time_t NzFile::GetLastWriteTime(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetLastWriteTime(NormalizePath(filePath)); +} + +NzHashDigest NzFile::GetHash(const NzString& filePath, nzHash hash) +{ + NzFile file(filePath); + + NzHash h(hash); + return h.Hash(file); +} + +NzHashDigest NzFile::GetHash(const NzString& filePath, NzHashImpl* hash) +{ + NzFile file(filePath); + + NzHash h(hash); + return h.Hash(file); +} + +nzUInt64 NzFile::GetSize(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetSize(NormalizePath(filePath)); +} + +bool NzFile::IsAbsolute(const NzString& path) +{ + NzString wpath(path); + wpath.Trim(); + + if (wpath.IsEmpty()) + return false; + + #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS + wpath = NormalizeSeparators(wpath); + #endif + + #ifdef NAZARA_PLATFORM_WINDOWS + if (path.Match("?:*")) + return true; + else if (path.Match("\\\\*")) + return true; + else if (wpath.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + return true; + else + return false; + #elif defined(NAZARA_PLATEFORM_LINUX) + return wpath.StartsWith('/'); + #else + #error OS case not implemented + #endif +} + +NzString NzFile::NormalizePath(const NzString& filePath) +{ + NzString path(filePath); + path.Trim(); + + #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS + path = NormalizeSeparators(path); + #endif + + if (!IsAbsolute(path)) + path = NzDirectory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR + path; + + while (path.EndsWith(NAZARA_DIRECTORY_SEPARATOR)) + path.Resize(-1); + + return path; +} + +NzString NzFile::NormalizeSeparators(const NzString& filePath) +{ + NzString path(filePath); + + #if defined(NAZARA_PLATFORM_WINDOWS) + path.Replace('/', '\\'); + #elif defined(NAZARA_PLATFORM_LINUX) + path.Replace('\\', '/'); + #else + #error OS case not implemented + #endif + + return path; +} + +bool NzFile::Rename(const NzString& sourcePath, const NzString& targetPath) +{ + if (sourcePath.IsEmpty() || targetPath.IsEmpty()) + return false; + + return NzFileImpl::Rename(NormalizePath(sourcePath), NormalizePath(targetPath)); +} + +bool NzFile::FillHash(NzHashImpl* hash) const +{ + NzFile file(m_filePath); + if (!file.Open(NzFile::ReadOnly)) + { + NazaraError("Unable to open file"); + return false; + } + + nzUInt64 remainingSize = file.GetSize(); + + char buffer[NAZARA_CORE_FILE_BUFFERSIZE]; + unsigned int size; + while (remainingSize > 0) + { + size = (remainingSize >= NAZARA_CORE_FILE_BUFFERSIZE) ? NAZARA_CORE_FILE_BUFFERSIZE : static_cast(remainingSize); + if (file.Read(&buffer[0], sizeof(char), size) != sizeof(char)*size) + { + NazaraError("Unable to read file"); + return false; + } + + remainingSize -= size; + hash->Append(reinterpret_cast(&buffer[0]), size); + } + + return true; +} // Fermeture automatique du fichier From cc6f2a6fc9d5a55fde96f15e634038ca166a3abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 21 Sep 2012 12:39:40 +0200 Subject: [PATCH 16/31] Added InputStream::GetLine(size); Former-commit-id: 4c5afc038877bfa9865285d044663df3f7932d58 --- include/Nazara/Core/File.hpp | 2 +- include/Nazara/Core/InputStream.hpp | 3 ++ src/Nazara/Core/File.cpp | 49 ++----------------------- src/Nazara/Core/InputStream.cpp | 57 +++++++++++++++++++++++++---- 4 files changed, 57 insertions(+), 54 deletions(-) diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index c912fd84b..a8a4ed19e 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -72,7 +72,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable NzString GetFileName() const; time_t GetLastAccessTime() const; time_t GetLastWriteTime() const; - NzString GetLine(unsigned int lineSize = 0); + NzString GetLine(unsigned int lineSize = 0) override; nzUInt64 GetSize() const; bool IsOpen() const; diff --git a/include/Nazara/Core/InputStream.hpp b/include/Nazara/Core/InputStream.hpp index eca1a42b0..f8e734cb2 100644 --- a/include/Nazara/Core/InputStream.hpp +++ b/include/Nazara/Core/InputStream.hpp @@ -9,6 +9,8 @@ #include +class NzString; + class NzInputStream { public: @@ -17,6 +19,7 @@ class NzInputStream virtual bool EndOfStream() const = 0; virtual nzUInt64 GetCursorPos() const = 0; + virtual NzString GetLine(unsigned int lineSize = 0); virtual nzUInt64 GetSize() const = 0; virtual std::size_t Read(void* buffer, std::size_t size) = 0; diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index d01aefc7c..7f9d117f1 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -100,7 +100,7 @@ bool NzFile::EndOfFile() const return m_impl->EndOfFile(); } -bool NzFile::EndOfStream() const; +bool NzFile::EndOfStream() const { return EndOfFile(); } @@ -211,50 +211,9 @@ NzString NzFile::GetLine(unsigned int lineSize) } #endif - NzString line; - if (lineSize == 0) // Taille maximale indéterminée - { - while (!m_impl->EndOfFile()) - { - char c; - if (m_impl->Read(&c, sizeof(char)) == sizeof(char)) - { - if (c == '\n') - { - if (m_openMode & Text && line.EndsWith('\r')) - line.Resize(-1); - - break; - } - - line += c; - } - else - break; - } - } - else - { - line.Reserve(lineSize); - for (unsigned int i = 0; i < lineSize; ++i) - { - char c; - if (m_impl->Read(&c, sizeof(char)) == sizeof(char)) - { - if (c == '\n') - { - if (m_openMode & Text && line.EndsWith('\r')) - line.Resize(-1); - - break; - } - - line += c; - } - else - break; - } - } + NzString line = NzInputStream::GetLine(lineSize); + if (m_openMode & Text && !m_impl->EndOfFile() && line.EndsWith('\r')) + line.Resize(-1); return line; } diff --git a/src/Nazara/Core/InputStream.cpp b/src/Nazara/Core/InputStream.cpp index 2759f4d83..f2ef22a25 100644 --- a/src/Nazara/Core/InputStream.cpp +++ b/src/Nazara/Core/InputStream.cpp @@ -1,8 +1,49 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -NzInputStream::~NzInputStream() = default; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +NzInputStream::~NzInputStream() = default; + +NzString NzInputStream::GetLine(unsigned int lineSize) +{ + NzString line; + if (lineSize == 0) // Taille maximale indéterminée + { + while (!EndOfStream()) + { + char c; + if (Read(&c, sizeof(char)) == sizeof(char)) + { + if (c == '\n') + break; + + line += c; + } + else + break; + } + } + else + { + line.Reserve(lineSize); + for (unsigned int i = 0; i < lineSize; ++i) + { + char c; + if (Read(&c, sizeof(char)) == sizeof(char)) + { + if (c == '\n') + break; + + line += c; + } + else + break; + } + } + + return line; +} From 84509ecc16d08d735cc45086c7f06edefb25562a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 21 Sep 2012 12:41:48 +0200 Subject: [PATCH 17/31] Fixed useless headers includes Former-commit-id: 17429fb0c822b6044c7a990b85e05ca37dcd0b90 --- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index 8af677a6b..b458d3ff4 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -5,9 +5,7 @@ #include #include #include -#include #include -#include #include #include #include From 4b3772e2d83853833cb0c4df0a238fc103265cbf Mon Sep 17 00:00:00 2001 From: DigitalPulseSoftware Date: Fri, 21 Sep 2012 14:20:38 +0200 Subject: [PATCH 18/31] Fixed typo Former-commit-id: 440a4d3939cfee80ba4224dc8ed90084adaf0380 --- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index b458d3ff4..32042a9bc 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -96,7 +96,7 @@ namespace } } - /// Chargement des animmations + /// Chargement des animations if (animated) { NzAnimation* animation = new NzAnimation; From a73cd1374ac3397cac295e177604c6d70e18ab4a Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Sep 2012 14:24:48 +0200 Subject: [PATCH 19/31] Normalized line ending Former-commit-id: bd061c48bdc8f0d26159dac3b41017defef5ae1e --- .gitattributes | 2 + build/scripts/module/renderer.lua | 82 +- examples/AnimatedMesh/main.cpp | 1324 +-- examples/DopplerEffect/main.cpp | 136 +- include/Nazara/Core.hpp | 124 +- include/Nazara/Core/Config.hpp | 170 +- include/Nazara/Core/Enums.hpp | 60 +- include/Nazara/Core/File.hpp | 248 +- include/Nazara/Core/InputStream.hpp | 60 +- include/Nazara/Core/Resource.hpp | 144 +- include/Nazara/Core/ResourceListener.hpp | 50 +- include/Nazara/Core/ResourceLoader.inl | 284 +- include/Nazara/Core/String.hpp | 641 +- include/Nazara/Math/Config.hpp | 98 +- include/Nazara/Math/Matrix4.hpp | 290 +- include/Nazara/Math/Matrix4.inl | 1884 +-- include/Nazara/Math/Quaternion.hpp | 186 +- include/Nazara/Math/Quaternion.inl | 856 +- include/Nazara/Math/Vector2.hpp | 210 +- include/Nazara/Math/Vector2.inl | 976 +- include/Nazara/Math/Vector3.hpp | 242 +- include/Nazara/Math/Vector3.inl | 1198 +- include/Nazara/Math/Vector4.hpp | 196 +- include/Nazara/Math/Vector4.inl | 1006 +- include/Nazara/Renderer.hpp | 82 +- include/Nazara/Renderer/Config.hpp | 82 +- include/Nazara/Renderer/Context.hpp | 98 +- include/Nazara/Renderer/Enums.hpp | 348 +- include/Nazara/Renderer/OpenGL.hpp | 466 +- include/Nazara/Renderer/RenderTarget.hpp | 82 +- include/Nazara/Renderer/RenderTexture.hpp | 120 +- include/Nazara/Renderer/RenderWindow.hpp | 136 +- include/Nazara/Renderer/Texture.hpp | 184 +- include/Nazara/Utility/Animation.hpp | 156 +- include/Nazara/Utility/Enums.hpp | 500 +- include/Nazara/Utility/KeyframeMesh.hpp | 1 - include/Nazara/Utility/Mesh.hpp | 196 +- include/Nazara/Utility/PixelFormat.hpp | 108 +- include/Nazara/Utility/PixelFormat.inl | 974 +- include/Nazara/Utility/StaticMesh.hpp | 102 +- include/Nazara/Utility/VertexDeclaration.hpp | 112 +- include/Nazara/Utility/Window.hpp | 224 +- src/Nazara/Audio/SoundBuffer.cpp | 458 +- src/Nazara/Core/ByteArray.cpp | 530 +- src/Nazara/Core/Debug/MemoryLeakTracker.cpp | 542 +- src/Nazara/Core/File.cpp | 1520 +-- src/Nazara/Core/InputStream.cpp | 98 +- src/Nazara/Core/Resource.cpp | 276 +- src/Nazara/Core/ResourceListener.cpp | 52 +- src/Nazara/Core/String.cpp | 10326 ++++++++--------- src/Nazara/Renderer/Context.cpp | 718 +- src/Nazara/Renderer/GLSLShader.cpp | 1424 +-- src/Nazara/Renderer/GLSLShader.hpp | 162 +- src/Nazara/Renderer/HardwareBuffer.cpp | 436 +- src/Nazara/Renderer/OcclusionQuery.cpp | 196 +- src/Nazara/Renderer/OpenGL.cpp | 2028 ++-- src/Nazara/Renderer/RenderTexture.cpp | 1456 +-- src/Nazara/Renderer/RenderWindow.cpp | 552 +- src/Nazara/Renderer/Renderer.cpp | 1804 +-- src/Nazara/Renderer/Shader.cpp | 1254 +- src/Nazara/Renderer/Texture.cpp | 3112 ++--- src/Nazara/Renderer/Win32/ContextImpl.cpp | 468 +- src/Nazara/Utility/Animation.cpp | 684 +- src/Nazara/Utility/Buffer.cpp | 678 +- src/Nazara/Utility/Image.cpp | 2374 ++-- src/Nazara/Utility/Loaders/MD2/Loader.cpp | 396 +- src/Nazara/Utility/Loaders/MD2/Mesh.cpp | 584 +- src/Nazara/Utility/Loaders/PCX/Loader.cpp | 692 +- src/Nazara/Utility/Mesh.cpp | 1362 +-- src/Nazara/Utility/StaticMesh.cpp | 398 +- src/Nazara/Utility/VertexDeclaration.cpp | 744 +- src/Nazara/Utility/Window.cpp | 1068 +- 72 files changed, 25415 insertions(+), 25415 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dfe077042 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/build/scripts/module/renderer.lua b/build/scripts/module/renderer.lua index f154cbbd7..09a1b260e 100644 --- a/build/scripts/module/renderer.lua +++ b/build/scripts/module/renderer.lua @@ -1,42 +1,42 @@ -if (not _OPTIONS["one-library"]) then - project "NazaraRenderer" -end - -defines "NAZARA_RENDERER_OPENGL" - -files -{ - "../include/Nazara/Renderer/**.hpp", - "../include/Nazara/Renderer/**.inl", - "../src/Nazara/Renderer/**.hpp", - "../src/Nazara/Renderer/**.cpp" -} - -if (os.is("windows")) then - excludes { "../src/Nazara/Renderer/Posix/*.hpp", "../src/Nazara/Renderer/Posix/*.cpp" } - links "gdi32" - links "opengl32" - links "winmm" -else - excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } -end - -if (_OPTIONS["one-library"]) then - excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" -else - configuration "DebugStatic" - links "NazaraCore-s-d" - links "NazaraUtility-s-d" - - configuration "ReleaseStatic" - links "NazaraCore-s" - links "NazaraUtility-s" - - configuration "DebugDLL" - links "NazaraCore-d" - links "NazaraUtility-d" - - configuration "ReleaseDLL" - links "NazaraCore" - links "NazaraUtility" +if (not _OPTIONS["one-library"]) then + project "NazaraRenderer" +end + +defines "NAZARA_RENDERER_OPENGL" + +files +{ + "../include/Nazara/Renderer/**.hpp", + "../include/Nazara/Renderer/**.inl", + "../src/Nazara/Renderer/**.hpp", + "../src/Nazara/Renderer/**.cpp" +} + +if (os.is("windows")) then + excludes { "../src/Nazara/Renderer/Posix/*.hpp", "../src/Nazara/Renderer/Posix/*.cpp" } + links "gdi32" + links "opengl32" + links "winmm" +else + excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } +end + +if (_OPTIONS["one-library"]) then + excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" +else + configuration "DebugStatic" + links "NazaraCore-s-d" + links "NazaraUtility-s-d" + + configuration "ReleaseStatic" + links "NazaraCore-s" + links "NazaraUtility-s" + + configuration "DebugDLL" + links "NazaraCore-d" + links "NazaraUtility-d" + + configuration "ReleaseDLL" + links "NazaraCore" + links "NazaraUtility" end \ No newline at end of file diff --git a/examples/AnimatedMesh/main.cpp b/examples/AnimatedMesh/main.cpp index fbe4af5c2..f90cbd866 100644 --- a/examples/AnimatedMesh/main.cpp +++ b/examples/AnimatedMesh/main.cpp @@ -1,662 +1,662 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Une structure pour contenir nos informations (Cette structure est très simpliste) -struct Model -{ - NzMatrix4f matrix; // Les transformations subies par le modèle - NzMesh mesh; // Le mesh - NzTexture texture; // Sa texture -}; - -struct AnimatedModel : public Model -{ - // Quelques variables pour l'animation - const NzSequence* currentSequence = nullptr; // La séquence en cours - float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) - unsigned int currentFrame = 0; // La première frame - unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là -}; - -void AnimateModel(AnimatedModel& moedel, float elapsed); -bool CreateCheckerTexture(NzTexture* texture); -bool CreateFloorMesh(NzMesh* mesh); -void DrawModel(const Model& model); -void SetSequence(AnimatedModel& model, const NzString& name); - -int main() -{ - // Tout d'abord on affiche les instructions - std::cout << "Controls: ZQSD" << std::endl; - std::cout << "Escape to quit" << std::endl; - std::cout << "Left click to capture/free the mouse" << std::endl; - std::cout << "Right click to control Dr. Freak" << std::endl; - - // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) - NzContextParameters::defaultCompatibilityProfile = true; - - // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utilitaire) - // Cette étape est obligatoire pour beaucoup de fonctionnalités (Notamment le chargement de ressources et le rendu) - NzInitializer renderer; - if (!renderer) - { - // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log - std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; - std::getchar(); // On laise le temps de voir l'erreur - return EXIT_FAILURE; - } - - // 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 - // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] - // Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters - NzMeshParams parameters; - - // Le loader doit-il automatiquement charger les animations ? - // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. - // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné - // qu'elles sont fourniees avec le mesh. - // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut - // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés - parameters.loadAnimations = true; // Vaut true par défaut - - // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de - // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. - parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut - - AnimatedModel drfreak; - if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. - { - // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. - std::cout << "Failed to load mesh" << std::endl; - std::getchar(); // On laise le temps de voir l'erreur - return EXIT_FAILURE; - } - - if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? - { - // Cette démo n'a aucun intérêt sans animations - std::cout << "Mesh has no animation" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - SetSequence(drfreak, "stand"); - - // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture - if (drfreak.mesh.HasSkin()) - { - // Contrairement aux autres ressources, la texture n'est pas critique - if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin())) - drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire - else - std::cout << "Failed to load texture" << std::endl; - } - - if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée - { - std::cout << "Creating checker texture for mesh" << std::endl; - - if (!CreateCheckerTexture(&drfreak.texture)) - { - std::cout << "Failed to create mesh texture" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - } - - // Nous créons maintenant notre sol - Model floor; - if (!CreateFloorMesh(&floor.mesh)) - { - std::cout << "Failed to create floor" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - if (!CreateCheckerTexture(&floor.texture)) - { - std::cout << "Failed to create floor texture" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Le sol ne subit aucune transformation - floor.matrix.MakeIdentity(); - - // Pour effectuer un rendu, il faut que la carte graphique sache comment le faire. - // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors de son pipeline. - // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! - // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. - // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL - // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. - NzShader shader; - if (!shader.Create(nzShaderLanguage_GLSL)) - { - std::cout << "Failed to load shader" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders - // Pour notre exemple nous prendrons un shader très simple - // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader - - // Le fragment shader traite la couleur de nos pixels - if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag")) - { - std::cout << "Failed to load fragment shader from file" << std::endl; - // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec - std::cout << "Log: " << shader.GetLog() << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Le vertex shader (Transformation des vertices de l'espace 3D vers l'espace écran) - if (!shader.LoadFromFile(nzShaderType_Vertex, "shaders/basic.vert")) - { - std::cout << "Failed to load vertex shader from file" << std::endl; - std::cout << "Log: " << shader.GetLog() << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Une fois les codes sources de notre shader chargé, nous pouvons le compiler, afin de le rendre utilisable - if (!shader.Compile()) - { - std::cout << "Failed to compile shader" << std::endl; - std::cout << "Log: " << shader.GetLog() << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça - // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow - // Tout d'abord, sa taille, disons celle du bureau divisé par deux - - // Un VideoMode est une structure contenant une longueur (width), une largeur (height) et le nombre de bits par pixels (bitsPerPixel) - NzVideoMode mode = NzVideoMode::GetDesktopMode(); // Nous récupérons le mode actuellement utilisé par le bureau - - // Nous divisons sa longueur et sa largeur par deux - mode.width /= 2; - mode.height /= 2; - - // Maintenant le titre, rien de plus simple... - NzString windowTitle = "Nazara Demo - AnimatedMesh"; - - // Nous pouvons créer notre fenêtre ! (Via le constructeur directement ou par la méthode Create) - NzRenderWindow window; - - // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède une bordure elle sera légèrement plus grande). - // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle. - // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. - // Attention que cela permet à la fenêtre de changer sa taille et qu'il faudra donc traiter l'évènement. - // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) - if (!window.Create(mode, windowTitle, nzWindowStyle_Default)) - { - std::cout << "Failed to create window" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - // Notre belle fenêtre est créée, nous pouvons la configurer - - // On cache le curseur - window.SetCursor(nzWindowCursor_None); - - // Nous limitons les FPS à 100 - window.SetFramerateLimit(100); - - // La matrice de projection définit la transformation du vertice 3D à un point 2D - NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(window.GetWidth())/window.GetHeight(), 1.f, 1000.f)); - - // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements - NzClock secondClock, updateClock; // Des horloges pour gérer le temps - unsigned int fps = 0; // Compteur de FPS - - // Quelques variables pour notre improvisation de physique - float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Les coordonnées locales du "bas" du modèle - NzVector3f modelPos(0.f, -groundPos, -50.f); - NzVector3f modelVel(0.f, 0.f, 0.f); - NzQuaternionf modelOrient(NzQuaternionf::Identity()); - NzEulerAnglesf modelRot(0.f, 0.f, 0.f); - float modelSpeed = 150.f; - - // Nous initialisons la matrice - drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); - - // Notre caméra - NzVector3f camPos(0.f, 25.f, -20.f); - NzQuaternionf camOrient(NzQuaternionf::Identity()); - NzEulerAnglesf camRot(0.f, 0.f, 0.f); // Les angles d'eulers sont bien plus facile à utiliser - NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos); - float camSpeed = 100.f; - float sensitivity = 0.8f; - - // Quelques variables - bool camMode = true; - bool thirdPerson = false; - bool windowOpen = true; - - // On peut commencer la boucle du programme - while (windowOpen) - { - // Ici nous gérons les évènements - NzEvent event; - while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? - { - // Nous avons un évènement ! - - switch (event.type) // De quel type est cet évènement ? - { - case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution - windowOpen = false; // Nous terminons alors la boucle - break; - - case nzEventType_MouseMoved: // La souris a bougé - { - // Si nous ne sommes pas en mode free-fly, on ne traite pas l'évènement - if (!camMode || thirdPerson) - break; - - // On modifie l'angle de la caméra grâce au déplacement relatif de la souris - camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity); - - // Pour éviter les loopings mais surtout les problèmes de calculation de la matrice de vue, on restreint les angles - camRot.pitch = NzClamp(camRot.pitch - event.mouseMove.deltaY*sensitivity, -89.f, 89.f); - - // La matrice vue représente les transformations effectuées par la caméra - // On recalcule la matrice de la caméra et on l'envoie au renderer - camOrient = camRot; // Conversion des angles d'euler en quaternion - NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward())); - - // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre - NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window); - break; - } - - case nzEventType_MouseButtonPressed: // L'utilisateur (ou son chat) vient de cliquer sur la souris - if (event.mouseButton.button == NzMouse::Left) // Est-ce le clic gauche ? - { - // L'utilisateur vient d'appuyer sur le bouton left de la souris - // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence - if (camMode) - { - camMode = false; - window.SetCursor(nzWindowCursor_Default); - } - else - { - camMode = true; - window.SetCursor(nzWindowCursor_None); - } - } - else if (event.mouseButton.button == NzMouse::Right) // Est-ce le clic droit ? - { - if (thirdPerson) - { - // On arrête le mouvement - SetSequence(drfreak, "stand"); - - // Afin de synchroniser le quaternion avec les angles d'euler - camRot = camOrient.ToEulerAngles(); - thirdPerson = false; - } - else - thirdPerson = true; - } - break; - - case nzEventType_Resized: // L'utilisateur a changé la taille de la fenêtre, le coquin ! - NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage - - // Il nous faut aussi mettre à jour notre matrice de projection - NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(event.size.width)/event.size.height, 1.f, 1000.f)); - break; - - case nzEventType_KeyPressed: // Une touche du clavier vient d'être enfoncée - if (thirdPerson && - (event.key.code == NzKeyboard::Z || // Est-ce la touche Z ? - event.key.code == NzKeyboard::S || // Ou bien la touche S ? - event.key.code == NzKeyboard::Q || // Ou encore la touche Q ? - event.key.code == NzKeyboard::D)) // Et pourquoi pas la touche D ? - { - // Si une touche concernant le déplacement est appuyée - SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement - } - else if (event.key.code == NzKeyboard::Escape) - windowOpen = false; - - break; - - case nzEventType_KeyReleased: // Une touche du clavier vient d'être relachée - if (thirdPerson && - !NzKeyboard::IsKeyPressed(NzKeyboard::Z) && // Est-ce que la touche Z est enfoncée en ce moment ? - !NzKeyboard::IsKeyPressed(NzKeyboard::S) && // Ou bien la touche S ? - !NzKeyboard::IsKeyPressed(NzKeyboard::Q) && // Etc.. - !NzKeyboard::IsKeyPressed(NzKeyboard::D)) // Etc.. - { - // Si plus aucune touche de déplacement n'est enfoncée - SetSequence(drfreak, "stand"); - } - - break; - - default: // Les autres évènements, on s'en fiche - break; - } - } - - // Mise à jour de la partie logique - if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde - { - float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour - - // Déplacement de la caméra - static const NzVector3f forward(NzVector3f::Forward()); - static const NzVector3f left(NzVector3f::Left()); - static const NzVector3f up(NzVector3f::Up()); - - // Notre rotation sous forme de quaternion nous permet de tourner un vecteur - // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" - - if (thirdPerson) - { - // Nous déplaçons le personnage en fonction des touches pressées - - if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) - modelPos += modelOrient * forward * modelSpeed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) - modelPos -= modelOrient * forward * modelSpeed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) - modelRot.yaw += camSpeed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) - modelRot.yaw -= camSpeed * elapsedTime; - - modelOrient = modelRot; - } - else - { - // Sinon, c'est la caméra qui se déplace (en fonction des mêmes touches) - - // Un boost en maintenant le shift gauche - float speed = (NzKeyboard::IsKeyPressed(NzKeyboard::Key::LShift)) ? camSpeed*5 : camSpeed; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) - camPos += camOrient * forward * speed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) - camPos -= camOrient * forward * speed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) - camPos += camOrient * left * speed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) - camPos -= camOrient * left * speed * elapsedTime; - - // En revanche, ici la hauteur est toujours la même, peu importe notre orientation - if (NzKeyboard::IsKeyPressed(NzKeyboard::Space)) - camPos += up * speed * elapsedTime; - - if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl)) - camPos -= up * speed * elapsedTime; - } - - // Oui les quaternions et les matrices sont calculés même si la caméra ne bouge pas - // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés - if (thirdPerson) - { - static NzQuaternionf rotDown(NzEulerAnglesf(-15.f, 0.f, 0.f)); // Une rotation pour regarder vers le bas - camOrient = modelOrient * rotDown; - - camPos = modelPos + camOrient * NzVector3f(0.f, 25.f, 60.f); - } - - NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward())); - - // Mise à jour de la matrice du personnage - drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); - - // Animation - AnimateModel(drfreak, elapsedTime); - updateClock.Restart(); - } - - // On active le shader et paramètrons le rendu - NzRenderer::SetShader(&shader); - - // Notre scène 3D requiert un test de profondeur - NzRenderer::Enable(nzRendererParameter_DepthTest, true); - - // Nous voulons avoir un fond bien gris - NzRenderer::SetClearColor(128, 128, 128); - - // Et nous effaçons les buffers de couleur et de profondeur - NzRenderer::Clear(nzRendererClear_Color | nzRendererClear_Depth); - - // Affichage des meshs - DrawModel(floor); - - // Notre Dr. Freak possède des normales, nous pouvons alors éliminer les faces qu'on ne voit pas - NzRenderer::Enable(nzRendererParameter_FaceCulling, true); - - DrawModel(drfreak); - - NzRenderer::Enable(nzRendererParameter_FaceCulling, false); - - // Nous mettons à jour l'écran - window.Display(); - - fps++; - - // Toutes les secondes - if (secondClock.GetMilliseconds() >= 1000) - { - window.SetTitle(windowTitle + " (FPS: " + NzString::Number(fps) + ')'); - fps = 0; - secondClock.Restart(); - } - } - - return EXIT_SUCCESS; -} - -void AnimateModel(AnimatedModel& model, float elapsed) -{ - model.interpolation += model.currentSequence->framePerSecond * elapsed; - while (model.interpolation > 1.f) - { - model.interpolation -= 1.f; - - model.currentFrame = model.nextFrame; - if (++model.nextFrame > model.currentSequence->lastFrame) - model.nextFrame = model.currentSequence->firstFrame; - } - - model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation); -} - -bool CreateCheckerTexture(NzTexture* texture) -{ - NzImage image; - // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) - if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16)) - { - // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) - std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl; - return false; - } - - // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel - // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. - unsigned int blockCountX = image.GetWidth()/16; - unsigned int blockCountY = image.GetHeight()/16; - for (unsigned int x = 0; x < blockCountX; ++x) - { - for (unsigned int y = 0; y < blockCountY; ++y) - { - // Une belle texture de damier - NzColor color = (x%2 == y%2) ? NzColor::White : NzColor::Black; - // Fill remplit une zone de la texture avec une couleur - image.Fill(color, NzRectui(x*16, y*16, 16, 16)); - } - } - - if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image - { - // Nous n'avons vraiment pas beaucoup de chance.. - std::cout << "Failed to load image" << std::endl; - return false; - } - - texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture - texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée - - return true; -} - -bool CreateFloorMesh(NzMesh* mesh) -{ - // Cette fonction créé un mesh statique simpliste pour servir de sol - - // Nous créons un mesh statique - if (!mesh->Create(nzAnimationType_Static)) - { - // L'échec est techniquement impossible mais le moteur étant en constante évolution ... - std::cout << "Failed to create mesh" << std::endl; - return false; - } - - // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer - // Elles sont composées de VertexElement, chacun décrivant un élément du buffer - NzVertexDeclaration* declaration = new NzVertexDeclaration; - - // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) - // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) - // -Usage: Comment cette donnée doit-elle être envoyée au shader - // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) - // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) - // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. - NzVertexElement elements[2]; - elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices - elements[0].offset = 0; // Celles-ci sont placées au début - elements[0].type = nzElementType_Float3; // Sont composées de trois flottants - - elements[1].usage = nzElementUsage_TexCoord; - elements[1].offset = 3*sizeof(float); - elements[1].type = nzElementType_Float2; - - if (!declaration->Create(elements, 2)) - { - // Nos éléments sont invalides ! - std::cout << "Failed to create vertex declaration" << std::endl; - return false; - } - - // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage - // Et nous indiquons que nous n'y toucherons plus - NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static); - - // Doit respecter la declaration - float vertices[] = - { - // Vertex 1 - -1000.f, 0.f, -1000.f, // Position - 0.f, 0.f, // UV - - // Vertex 2 - -1000.f, 0.f, 1000.f, // Position - 0.f, 10.f, // UV - - // Vertex 3 - 1000.f, 0.f, -1000.f, // Position - 10.f, 0.f, // UV - - // Vertex 4 - 1000.f, 0.f, 1000.f, // Position - 10.f, 10.f // UV - }; - - // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) - if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices - { - std::cout << "Failed to fill buffer" << std::endl; - return false; - } - - NzStaticMesh* subMesh = new NzStaticMesh(mesh); - if (!subMesh->Create(declaration, buffer)) - { - std::cout << "Failed to create subMesh" << std::endl; - return false; - } - - subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip); - - // On ajoute le submesh au mesh - mesh->AddSubMesh(subMesh); - - // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. - // Les ressources seront donc automatiquement libérées lorsqu'elles ne seront plus référencées par une classe - buffer->SetPersistent(false); - declaration->SetPersistent(false); - subMesh->SetPersistent(false); // Pour le submesh, c'est déjà le comportement par défaut - - return true; -} - -void DrawModel(const Model& model) -{ - // La matrice world est celle qui représente les transformations du modèle - NzRenderer::SetMatrix(nzMatrixType_World, model.matrix); - - NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu - shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture); - - // Un mesh est divisé en plusieurs submeshes - unsigned int subMeshCount = model.mesh.GetSubMeshCount(); - for (unsigned int i = 0; i < subMeshCount; ++i) - { - // On récupère le submesh - const NzSubMesh* subMesh = model.mesh.GetSubMesh(i); - - // On paramètre le Renderer avec ses données - NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer()); - NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer()); - NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration()); - - // On fait le rendu - NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount()); - } -} - -void SetSequence(AnimatedModel& model, const NzString& sequenceName) -{ - // On récupère l'animation du mesh - const NzAnimation* animation = model.mesh.GetAnimation(); - - // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) - const NzSequence* sequence = animation->GetSequence(sequenceName); - if (model.currentSequence != sequence) - { - model.currentSequence = sequence; - - // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame - model.nextFrame = model.currentSequence->firstFrame; - } -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Une structure pour contenir nos informations (Cette structure est très simpliste) +struct Model +{ + NzMatrix4f matrix; // Les transformations subies par le modèle + NzMesh mesh; // Le mesh + NzTexture texture; // Sa texture +}; + +struct AnimatedModel : public Model +{ + // Quelques variables pour l'animation + const NzSequence* currentSequence = nullptr; // La séquence en cours + float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante) + unsigned int currentFrame = 0; // La première frame + unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là +}; + +void AnimateModel(AnimatedModel& moedel, float elapsed); +bool CreateCheckerTexture(NzTexture* texture); +bool CreateFloorMesh(NzMesh* mesh); +void DrawModel(const Model& model); +void SetSequence(AnimatedModel& model, const NzString& name); + +int main() +{ + // Tout d'abord on affiche les instructions + std::cout << "Controls: ZQSD" << std::endl; + std::cout << "Escape to quit" << std::endl; + std::cout << "Left click to capture/free the mouse" << std::endl; + std::cout << "Right click to control Dr. Freak" << std::endl; + + // Cette ligne active le mode de compatibilité d'OpenGL lors de l'initialisation de Nazara (Nécessaire pour le shader) + NzContextParameters::defaultCompatibilityProfile = true; + + // Maintenant nous initialisons le Renderer (Qui initialisera le noyau ainsi que le module utilitaire) + // Cette étape est obligatoire pour beaucoup de fonctionnalités (Notamment le chargement de ressources et le rendu) + NzInitializer renderer; + if (!renderer) + { + // Ça n'a pas fonctionné, le pourquoi se trouve dans le fichier NazaraLog.log + std::cout << "Failed to initialize Nazara, see NazaraLog.log for further informations" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + // 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 + // Vous initialisez une ressource, et la chargez via sa méthode LoadFrom[File|Memory|Stream] + // Note: il est possible de donner des instructions au loader (qui va charger le fichier en ressource) via les ResourceParameters + NzMeshParams parameters; + + // Le loader doit-il automatiquement charger les animations ? + // Attention, ce paramètre possède une signification différente selon le type d'animation du mesh. + // -Pour les animations keyframe (image-clé), c'est la seule et unique façon de charger les animations, étant donné + // qu'elles sont fourniees avec le mesh. + // -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut + // Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés + parameters.loadAnimations = true; // Vaut true par défaut + + // Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de + // le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer. + parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut + + AnimatedModel drfreak; + if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement. + { + // Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas. + std::cout << "Failed to load mesh" << std::endl; + std::getchar(); // On laise le temps de voir l'erreur + return EXIT_FAILURE; + } + + if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ? + { + // Cette démo n'a aucun intérêt sans animations + std::cout << "Mesh has no animation" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + SetSequence(drfreak, "stand"); + + // Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture + if (drfreak.mesh.HasSkin()) + { + // Contrairement aux autres ressources, la texture n'est pas critique + if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin())) + drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire + else + std::cout << "Failed to load texture" << std::endl; + } + + if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée + { + std::cout << "Creating checker texture for mesh" << std::endl; + + if (!CreateCheckerTexture(&drfreak.texture)) + { + std::cout << "Failed to create mesh texture" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + } + + // Nous créons maintenant notre sol + Model floor; + if (!CreateFloorMesh(&floor.mesh)) + { + std::cout << "Failed to create floor" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + if (!CreateCheckerTexture(&floor.texture)) + { + std::cout << "Failed to create floor texture" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Le sol ne subit aucune transformation + floor.matrix.MakeIdentity(); + + // Pour effectuer un rendu, il faut que la carte graphique sache comment le faire. + // Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors de son pipeline. + // Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets ! + // Il existe plusieurs langages de shaders, GLSL pour OpenGL, HLSL pour Direct3D et Cg qui peut être utilisé pour les deux. + // Le Renderer de Nazara utilise OpenGL, par conséquent nous utiliserons le GLSL + // La méthode NzShader::IsLanguageSupported permet de savoir si un langage est supporté. + NzShader shader; + if (!shader.Create(nzShaderLanguage_GLSL)) + { + std::cout << "Failed to load shader" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Une fois le shader créé, nous devons lui spécifier les codes sources de nos shaders + // Pour notre exemple nous prendrons un shader très simple + // Un shader doit obligatoirement posséder au moins deux codes, un pour le fragment shader et un pour le vertex shader + + // Le fragment shader traite la couleur de nos pixels + if (!shader.LoadFromFile(nzShaderType_Fragment, "shaders/basic.frag")) + { + std::cout << "Failed to load fragment shader from file" << std::endl; + // À la différence des autres ressources, le shader possède un log qui peut indiquer les erreurs en cas d'échec + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Le vertex shader (Transformation des vertices de l'espace 3D vers l'espace écran) + if (!shader.LoadFromFile(nzShaderType_Vertex, "shaders/basic.vert")) + { + std::cout << "Failed to load vertex shader from file" << std::endl; + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Une fois les codes sources de notre shader chargé, nous pouvons le compiler, afin de le rendre utilisable + if (!shader.Compile()) + { + std::cout << "Failed to compile shader" << std::endl; + std::cout << "Log: " << shader.GetLog() << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Nos ressources sont chargées, et c'est bien beau, mais il nous faudrait une fenêtre pour afficher tout ça + // Window représente une fenêtre singulière, pour y effectuer un rendu il nous faut une RenderWindow + // Tout d'abord, sa taille, disons celle du bureau divisé par deux + + // Un VideoMode est une structure contenant une longueur (width), une largeur (height) et le nombre de bits par pixels (bitsPerPixel) + NzVideoMode mode = NzVideoMode::GetDesktopMode(); // Nous récupérons le mode actuellement utilisé par le bureau + + // Nous divisons sa longueur et sa largeur par deux + mode.width /= 2; + mode.height /= 2; + + // Maintenant le titre, rien de plus simple... + NzString windowTitle = "Nazara Demo - AnimatedMesh"; + + // Nous pouvons créer notre fenêtre ! (Via le constructeur directement ou par la méthode Create) + NzRenderWindow window; + + // Le premier argument définit la taille de rendu de la fenêtre (Si elle possède une bordure elle sera légèrement plus grande). + // Le deuxième argument est le titre de la fenêtre lors de sa création, vous pouvez le modifier à tout moment via window.SetTitle. + // Le troisième argument représente la décoration de la fenêtre, sa bordure, ses boutons. + // Attention que cela permet à la fenêtre de changer sa taille et qu'il faudra donc traiter l'évènement. + // Par défaut le troisième argument vaut nzWindowStyle_Default (Bordure + Bouton de fermeture + Redimensionnement) + if (!window.Create(mode, windowTitle, nzWindowStyle_Default)) + { + std::cout << "Failed to create window" << std::endl; + std::getchar(); + return EXIT_FAILURE; + } + + // Notre belle fenêtre est créée, nous pouvons la configurer + + // On cache le curseur + window.SetCursor(nzWindowCursor_None); + + // Nous limitons les FPS à 100 + window.SetFramerateLimit(100); + + // La matrice de projection définit la transformation du vertice 3D à un point 2D + NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(window.GetWidth())/window.GetHeight(), 1.f, 1000.f)); + + // Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements + NzClock secondClock, updateClock; // Des horloges pour gérer le temps + unsigned int fps = 0; // Compteur de FPS + + // Quelques variables pour notre improvisation de physique + float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Les coordonnées locales du "bas" du modèle + NzVector3f modelPos(0.f, -groundPos, -50.f); + NzVector3f modelVel(0.f, 0.f, 0.f); + NzQuaternionf modelOrient(NzQuaternionf::Identity()); + NzEulerAnglesf modelRot(0.f, 0.f, 0.f); + float modelSpeed = 150.f; + + // Nous initialisons la matrice + drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); + + // Notre caméra + NzVector3f camPos(0.f, 25.f, -20.f); + NzQuaternionf camOrient(NzQuaternionf::Identity()); + NzEulerAnglesf camRot(0.f, 0.f, 0.f); // Les angles d'eulers sont bien plus facile à utiliser + NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos); + float camSpeed = 100.f; + float sensitivity = 0.8f; + + // Quelques variables + bool camMode = true; + bool thirdPerson = false; + bool windowOpen = true; + + // On peut commencer la boucle du programme + while (windowOpen) + { + // Ici nous gérons les évènements + NzEvent event; + while (window.PollEvent(&event)) // Avons-nous un évènement dans la file ? + { + // Nous avons un évènement ! + + switch (event.type) // De quel type est cet évènement ? + { + case nzEventType_Quit: // L'utilisateur/L'OS nous a demandé de terminer notre exécution + windowOpen = false; // Nous terminons alors la boucle + break; + + case nzEventType_MouseMoved: // La souris a bougé + { + // Si nous ne sommes pas en mode free-fly, on ne traite pas l'évènement + if (!camMode || thirdPerson) + break; + + // On modifie l'angle de la caméra grâce au déplacement relatif de la souris + camRot.yaw = NzNormalizeAngle(camRot.yaw - event.mouseMove.deltaX*sensitivity); + + // Pour éviter les loopings mais surtout les problèmes de calculation de la matrice de vue, on restreint les angles + camRot.pitch = NzClamp(camRot.pitch - event.mouseMove.deltaY*sensitivity, -89.f, 89.f); + + // La matrice vue représente les transformations effectuées par la caméra + // On recalcule la matrice de la caméra et on l'envoie au renderer + camOrient = camRot; // Conversion des angles d'euler en quaternion + NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward())); + + // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre + NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window); + break; + } + + case nzEventType_MouseButtonPressed: // L'utilisateur (ou son chat) vient de cliquer sur la souris + if (event.mouseButton.button == NzMouse::Left) // Est-ce le clic gauche ? + { + // L'utilisateur vient d'appuyer sur le bouton left de la souris + // Nous allons inverser le mode caméra et montrer/cacher le curseur en conséquence + if (camMode) + { + camMode = false; + window.SetCursor(nzWindowCursor_Default); + } + else + { + camMode = true; + window.SetCursor(nzWindowCursor_None); + } + } + else if (event.mouseButton.button == NzMouse::Right) // Est-ce le clic droit ? + { + if (thirdPerson) + { + // On arrête le mouvement + SetSequence(drfreak, "stand"); + + // Afin de synchroniser le quaternion avec les angles d'euler + camRot = camOrient.ToEulerAngles(); + thirdPerson = false; + } + else + thirdPerson = true; + } + break; + + case nzEventType_Resized: // L'utilisateur a changé la taille de la fenêtre, le coquin ! + NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage + + // Il nous faut aussi mettre à jour notre matrice de projection + NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast(event.size.width)/event.size.height, 1.f, 1000.f)); + break; + + case nzEventType_KeyPressed: // Une touche du clavier vient d'être enfoncée + if (thirdPerson && + (event.key.code == NzKeyboard::Z || // Est-ce la touche Z ? + event.key.code == NzKeyboard::S || // Ou bien la touche S ? + event.key.code == NzKeyboard::Q || // Ou encore la touche Q ? + event.key.code == NzKeyboard::D)) // Et pourquoi pas la touche D ? + { + // Si une touche concernant le déplacement est appuyée + SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement + } + else if (event.key.code == NzKeyboard::Escape) + windowOpen = false; + + break; + + case nzEventType_KeyReleased: // Une touche du clavier vient d'être relachée + if (thirdPerson && + !NzKeyboard::IsKeyPressed(NzKeyboard::Z) && // Est-ce que la touche Z est enfoncée en ce moment ? + !NzKeyboard::IsKeyPressed(NzKeyboard::S) && // Ou bien la touche S ? + !NzKeyboard::IsKeyPressed(NzKeyboard::Q) && // Etc.. + !NzKeyboard::IsKeyPressed(NzKeyboard::D)) // Etc.. + { + // Si plus aucune touche de déplacement n'est enfoncée + SetSequence(drfreak, "stand"); + } + + break; + + default: // Les autres évènements, on s'en fiche + break; + } + } + + // Mise à jour de la partie logique + if (updateClock.GetMilliseconds() >= 1000/60) // 60 fois par seconde + { + float elapsedTime = updateClock.GetSeconds(); // Le temps depuis la dernière mise à jour + + // Déplacement de la caméra + static const NzVector3f forward(NzVector3f::Forward()); + static const NzVector3f left(NzVector3f::Left()); + static const NzVector3f up(NzVector3f::Up()); + + // Notre rotation sous forme de quaternion nous permet de tourner un vecteur + // Par exemple ici, quaternion * forward nous permet de récupérer le vecteur de la direction "avant" + + if (thirdPerson) + { + // Nous déplaçons le personnage en fonction des touches pressées + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) + modelPos += modelOrient * forward * modelSpeed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) + modelPos -= modelOrient * forward * modelSpeed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) + modelRot.yaw += camSpeed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) + modelRot.yaw -= camSpeed * elapsedTime; + + modelOrient = modelRot; + } + else + { + // Sinon, c'est la caméra qui se déplace (en fonction des mêmes touches) + + // Un boost en maintenant le shift gauche + float speed = (NzKeyboard::IsKeyPressed(NzKeyboard::Key::LShift)) ? camSpeed*5 : camSpeed; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Z)) + camPos += camOrient * forward * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::S)) + camPos -= camOrient * forward * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::Q)) + camPos += camOrient * left * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::D)) + camPos -= camOrient * left * speed * elapsedTime; + + // En revanche, ici la hauteur est toujours la même, peu importe notre orientation + if (NzKeyboard::IsKeyPressed(NzKeyboard::Space)) + camPos += up * speed * elapsedTime; + + if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl)) + camPos -= up * speed * elapsedTime; + } + + // Oui les quaternions et les matrices sont calculés même si la caméra ne bouge pas + // C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés + if (thirdPerson) + { + static NzQuaternionf rotDown(NzEulerAnglesf(-15.f, 0.f, 0.f)); // Une rotation pour regarder vers le bas + camOrient = modelOrient * rotDown; + + camPos = modelPos + camOrient * NzVector3f(0.f, 25.f, 60.f); + } + + NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward())); + + // Mise à jour de la matrice du personnage + drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); + + // Animation + AnimateModel(drfreak, elapsedTime); + updateClock.Restart(); + } + + // On active le shader et paramètrons le rendu + NzRenderer::SetShader(&shader); + + // Notre scène 3D requiert un test de profondeur + NzRenderer::Enable(nzRendererParameter_DepthTest, true); + + // Nous voulons avoir un fond bien gris + NzRenderer::SetClearColor(128, 128, 128); + + // Et nous effaçons les buffers de couleur et de profondeur + NzRenderer::Clear(nzRendererClear_Color | nzRendererClear_Depth); + + // Affichage des meshs + DrawModel(floor); + + // Notre Dr. Freak possède des normales, nous pouvons alors éliminer les faces qu'on ne voit pas + NzRenderer::Enable(nzRendererParameter_FaceCulling, true); + + DrawModel(drfreak); + + NzRenderer::Enable(nzRendererParameter_FaceCulling, false); + + // Nous mettons à jour l'écran + window.Display(); + + fps++; + + // Toutes les secondes + if (secondClock.GetMilliseconds() >= 1000) + { + window.SetTitle(windowTitle + " (FPS: " + NzString::Number(fps) + ')'); + fps = 0; + secondClock.Restart(); + } + } + + return EXIT_SUCCESS; +} + +void AnimateModel(AnimatedModel& model, float elapsed) +{ + model.interpolation += model.currentSequence->framePerSecond * elapsed; + while (model.interpolation > 1.f) + { + model.interpolation -= 1.f; + + model.currentFrame = model.nextFrame; + if (++model.nextFrame > model.currentSequence->lastFrame) + model.nextFrame = model.currentSequence->firstFrame; + } + + model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation); +} + +bool CreateCheckerTexture(NzTexture* texture) +{ + NzImage image; + // Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté) + if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16)) + { + // Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect) + std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl; + return false; + } + + // Pour modifier les pixels, nous pouvons accéder directement à ces derniers avec GetPixels(), ou bien à un pixel + // via [Get|Set]PixelColor, mais pour cette occasion nous utiliserons une méthode bien pratique, Fill. + unsigned int blockCountX = image.GetWidth()/16; + unsigned int blockCountY = image.GetHeight()/16; + for (unsigned int x = 0; x < blockCountX; ++x) + { + for (unsigned int y = 0; y < blockCountY; ++y) + { + // Une belle texture de damier + NzColor color = (x%2 == y%2) ? NzColor::White : NzColor::Black; + // Fill remplit une zone de la texture avec une couleur + image.Fill(color, NzRectui(x*16, y*16, 16, 16)); + } + } + + if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image + { + // Nous n'avons vraiment pas beaucoup de chance.. + std::cout << "Failed to load image" << std::endl; + return false; + } + + texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture + texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée + + return true; +} + +bool CreateFloorMesh(NzMesh* mesh) +{ + // Cette fonction créé un mesh statique simpliste pour servir de sol + + // Nous créons un mesh statique + if (!mesh->Create(nzAnimationType_Static)) + { + // L'échec est techniquement impossible mais le moteur étant en constante évolution ... + std::cout << "Failed to create mesh" << std::endl; + return false; + } + + // Les vertex declaration ont pour seul but de décrire l'agencement d'un vertex buffer + // Elles sont composées de VertexElement, chacun décrivant un élément du buffer + NzVertexDeclaration* declaration = new NzVertexDeclaration; + + // Il y a cinq paramètres différents (stream, usage, type, offset, usageIndex) + // -Stream: À quoi serviront les données ? À définir des sommets (nzElementStream_VertexData) ou à l'instancing (nzElementStream_InstancedData) + // -Usage: Comment cette donnée doit-elle être envoyée au shader + // -Type: Comment sont stockées ces données ? (Un triplet de float ? Deux double ? ..) + // -Offset: La position de la donnée dans le buffer (les données sont entrelacées) + // -UsageIndex: Pour les coordonnées de texture, définit l'indice de texture utilisé. + NzVertexElement elements[2]; + elements[0].usage = nzElementUsage_Position; // Notre premier élément sera la position des vertices + elements[0].offset = 0; // Celles-ci sont placées au début + elements[0].type = nzElementType_Float3; // Sont composées de trois flottants + + elements[1].usage = nzElementUsage_TexCoord; + elements[1].offset = 3*sizeof(float); + elements[1].type = nzElementType_Float2; + + if (!declaration->Create(elements, 2)) + { + // Nos éléments sont invalides ! + std::cout << "Failed to create vertex declaration" << std::endl; + return false; + } + + // Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage + // Et nous indiquons que nous n'y toucherons plus + NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static); + + // Doit respecter la declaration + float vertices[] = + { + // Vertex 1 + -1000.f, 0.f, -1000.f, // Position + 0.f, 0.f, // UV + + // Vertex 2 + -1000.f, 0.f, 1000.f, // Position + 0.f, 10.f, // UV + + // Vertex 3 + 1000.f, 0.f, -1000.f, // Position + 10.f, 0.f, // UV + + // Vertex 4 + 1000.f, 0.f, 1000.f, // Position + 10.f, 10.f // UV + }; + + // Afin de modifier un buffer, il nous faut soit le verrouiller (accès bas-niveau), soit le remplir (accès de plus haut niveau) + if (!buffer->Fill(vertices, 0, 4)) // Nous remplissons à partir de l'index 0, et nous envoyons 4 vertices + { + std::cout << "Failed to fill buffer" << std::endl; + return false; + } + + NzStaticMesh* subMesh = new NzStaticMesh(mesh); + if (!subMesh->Create(declaration, buffer)) + { + std::cout << "Failed to create subMesh" << std::endl; + return false; + } + + subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip); + + // On ajoute le submesh au mesh + mesh->AddSubMesh(subMesh); + + // Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères. + // Les ressources seront donc automatiquement libérées lorsqu'elles ne seront plus référencées par une classe + buffer->SetPersistent(false); + declaration->SetPersistent(false); + subMesh->SetPersistent(false); // Pour le submesh, c'est déjà le comportement par défaut + + return true; +} + +void DrawModel(const Model& model) +{ + // La matrice world est celle qui représente les transformations du modèle + NzRenderer::SetMatrix(nzMatrixType_World, model.matrix); + + NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu + shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture); + + // Un mesh est divisé en plusieurs submeshes + unsigned int subMeshCount = model.mesh.GetSubMeshCount(); + for (unsigned int i = 0; i < subMeshCount; ++i) + { + // On récupère le submesh + const NzSubMesh* subMesh = model.mesh.GetSubMesh(i); + + // On paramètre le Renderer avec ses données + NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer()); + NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer()); + NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration()); + + // On fait le rendu + NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount()); + } +} + +void SetSequence(AnimatedModel& model, const NzString& sequenceName) +{ + // On récupère l'animation du mesh + const NzAnimation* animation = model.mesh.GetAnimation(); + + // Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence()) + const NzSequence* sequence = animation->GetSequence(sequenceName); + if (model.currentSequence != sequence) + { + model.currentSequence = sequence; + + // Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame + model.nextFrame = model.currentSequence->firstFrame; + } +} diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp index 14a39a849..ef4bcf936 100644 --- a/examples/DopplerEffect/main.cpp +++ b/examples/DopplerEffect/main.cpp @@ -1,68 +1,68 @@ -#include -#include -#include // Thread::Sleep -#include -#include - -int main() -{ - // NzKeyboard ne nécessite pas l'initialisation d'Utility - NzInitializer audio; - if (!audio) - { - std::cout << "Failed to initialize audio module" << std::endl; - std::getchar(); - return 1; - } - - NzSound sound; - if (!sound.LoadFromFile("resources/siren.wav")) - { - std::cout << "Failed to load sound" << std::endl; - std::getchar(); - return 1; - } - - std::cout << "Demonstration de l'effet doppler avec Nazara" << std::endl; - std::cout << "Appuyez sur entree pour demarrer" << std::endl; - std::cout << "Appuyez sur echap pour arreter" << std::endl; - - std::getchar(); - - // On fait en sorte de répéter le son - sound.EnableLooping(true); - - // La source du son se situe en (50, 0, 5) - sound.SetPosition(50, 0, 5); - - // Et possède une vitesse de -10 par seconde sur l'axe X - sound.SetVelocity(-10, 0, 0); - - // On joue le son - sound.Play(); - - // La boucle du programme (Pour déplacer le son) - NzClock clock; - while (sound.GetStatus() == nzSoundStatus_Playing) - { - // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement - int sleepTime = 1000/60 - clock.GetMilliseconds(); // 60 FPS - - if (sleepTime > 0) - NzThread::Sleep(sleepTime); - - // On bouge la source du son en fonction du temps depuis chaque mise à jour - NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); - sound.SetPosition(pos); - - std::cout << "Sound position: " << pos << std::endl; - - // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap - if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) - sound.Stop(); // On arrête le son (Stoppant également la boucle) - - clock.Restart(); - } - - return 0; -} +#include +#include +#include // Thread::Sleep +#include +#include + +int main() +{ + // NzKeyboard ne nécessite pas l'initialisation d'Utility + NzInitializer audio; + if (!audio) + { + std::cout << "Failed to initialize audio module" << std::endl; + std::getchar(); + return 1; + } + + NzSound sound; + if (!sound.LoadFromFile("resources/siren.wav")) + { + std::cout << "Failed to load sound" << std::endl; + std::getchar(); + return 1; + } + + std::cout << "Demonstration de l'effet doppler avec Nazara" << std::endl; + std::cout << "Appuyez sur entree pour demarrer" << std::endl; + std::cout << "Appuyez sur echap pour arreter" << std::endl; + + std::getchar(); + + // On fait en sorte de répéter le son + sound.EnableLooping(true); + + // La source du son se situe en (50, 0, 5) + sound.SetPosition(50, 0, 5); + + // Et possède une vitesse de -10 par seconde sur l'axe X + sound.SetVelocity(-10, 0, 0); + + // On joue le son + sound.Play(); + + // La boucle du programme (Pour déplacer le son) + NzClock clock; + while (sound.GetStatus() == nzSoundStatus_Playing) + { + // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement + int sleepTime = 1000/60 - clock.GetMilliseconds(); // 60 FPS + + if (sleepTime > 0) + NzThread::Sleep(sleepTime); + + // On bouge la source du son en fonction du temps depuis chaque mise à jour + NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); + sound.SetPosition(pos); + + std::cout << "Sound position: " << pos << std::endl; + + // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap + if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) + sound.Stop(); // On arrête le son (Stoppant également la boucle) + + clock.Restart(); + } + + return 0; +} diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index a084f1cd2..2b699c747 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -1,62 +1,62 @@ -// This file was automatically generated by Nazara - -/* - Nazara Engine - Core module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// This file was automatically generated by Nazara + +/* + Nazara Engine - Core module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Core/Config.hpp b/include/Nazara/Core/Config.hpp index 021568c7f..be4f2c6cd 100644 --- a/include/Nazara/Core/Config.hpp +++ b/include/Nazara/Core/Config.hpp @@ -1,85 +1,85 @@ -/* - Nazara Engine - Core module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_CORE_HPP -#define NAZARA_CONFIG_CORE_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Appelle exit dès qu'une assertion est invalide -#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1 - -// Teste les assertions -#define NAZARA_CORE_ENABLE_ASSERTS 0 - -// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash) -#define NAZARA_CORE_FILE_BUFFERSIZE 4096 - -// Le moteur doit-il incorporer les Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8) -#define NAZARA_CORE_INCLUDE_UNICODEDATA 0 - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_CORE_MEMORYLEAKTRACKER 0 - -// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution) -#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1 - -// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule) -#define NAZARA_CORE_REAL_PRECISION 6 - -// Duplique la sortie du log sur le flux de sortie standard (cout) -#define NAZARA_CORE_DUPLICATE_TO_COUT 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_CORE_SAFE 1 - -// Protège les classes des accès concurrentiels -#define NAZARA_CORE_THREADSAFE 1 - -// Les classes à protéger des accès concurrentiels -#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW) -#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock -#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory -#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib -#define NAZARA_THREADSAFETY_FILE 1 // NzFile -#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest -#define NAZARA_THREADSAFETY_LOG 1 // NzLog -#define NAZARA_THREADSAFETY_RESOURCE 1 // NzResource -#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW) -#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream - -// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver) -#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096 - -// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS) -#define NAZARA_CORE_WINDOWS_VISTA 0 - -/* -// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes) -#define NAZARA_CORE_TIMER_WAKEUPTIME 10 -*/ - -#endif // NAZARA_CONFIG_CORE_HPP +/* + Nazara Engine - Core module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_CORE_HPP +#define NAZARA_CONFIG_CORE_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Appelle exit dès qu'une assertion est invalide +#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1 + +// Teste les assertions +#define NAZARA_CORE_ENABLE_ASSERTS 0 + +// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash) +#define NAZARA_CORE_FILE_BUFFERSIZE 4096 + +// Le moteur doit-il incorporer les Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8) +#define NAZARA_CORE_INCLUDE_UNICODEDATA 0 + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_CORE_MEMORYLEAKTRACKER 0 + +// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution) +#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1 + +// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule) +#define NAZARA_CORE_REAL_PRECISION 6 + +// Duplique la sortie du log sur le flux de sortie standard (cout) +#define NAZARA_CORE_DUPLICATE_TO_COUT 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_CORE_SAFE 1 + +// Protège les classes des accès concurrentiels +#define NAZARA_CORE_THREADSAFE 1 + +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW) +#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock +#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory +#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib +#define NAZARA_THREADSAFETY_FILE 1 // NzFile +#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest +#define NAZARA_THREADSAFETY_LOG 1 // NzLog +#define NAZARA_THREADSAFETY_RESOURCE 1 // NzResource +#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW) +#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream + +// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver) +#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096 + +// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS) +#define NAZARA_CORE_WINDOWS_VISTA 0 + +/* +// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes) +#define NAZARA_CORE_TIMER_WAKEUPTIME 10 +*/ + +#endif // NAZARA_CONFIG_CORE_HPP diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 21ac61c6e..9dcd77593 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -1,30 +1,30 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_CORE_HPP -#define NAZARA_ENUMS_CORE_HPP - -enum nzEndianness -{ - nzEndianness_Unknown = -1, - - nzEndianness_BigEndian, - nzEndianness_LittleEndian, - - nzEndianness_Max = nzEndianness_LittleEndian -}; - -enum nzErrorType -{ - nzErrorType_AssertFailed, - nzErrorType_Internal, - nzErrorType_Normal, - nzErrorType_Warning, - - nzErrorType_Max = nzErrorType_Warning -}; - -#endif // NAZARA_ENUMS_CORE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_CORE_HPP +#define NAZARA_ENUMS_CORE_HPP + +enum nzEndianness +{ + nzEndianness_Unknown = -1, + + nzEndianness_BigEndian, + nzEndianness_LittleEndian, + + nzEndianness_Max = nzEndianness_LittleEndian +}; + +enum nzErrorType +{ + nzErrorType_AssertFailed, + nzErrorType_Internal, + nzErrorType_Normal, + nzErrorType_Warning, + + nzErrorType_Max = nzErrorType_Warning +}; + +#endif // NAZARA_ENUMS_CORE_HPP diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index a8a4ed19e..1f36f99f6 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -1,124 +1,124 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_FILE_HPP -#define NAZARA_FILE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE -#include -#else -#include -#endif - -class NzFileImpl; - -class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable -{ - public: - enum CursorPosition - { - AtBegin, // Début du fichier - AtCurrent, // Position du pointeur - AtEnd // Fin du fichier - }; - - enum OpenMode - { - Current = 0x00, // Utilise le mode d'ouverture actuel - - Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin - Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert - ReadOnly = 0x04, // Ouvre uniquement en lecture - ReadWrite = 0x08, // Ouvre en lecture/écriture - Text = 0x10, // Ouvre en mode texte - Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe - WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas - }; - - NzFile(); - NzFile(const NzString& filePath); - NzFile(const NzString& filePath, unsigned long openMode); - NzFile(NzFile&& file) noexcept; - ~NzFile(); - - bool Copy(const NzString& newFilePath); - void Close(); - - bool Delete(); - - bool EndOfFile() const; - bool EndOfStream() const; - - bool Exists() const; - - void Flush(); - - time_t GetCreationTime() const; - nzUInt64 GetCursorPos() const; - NzString GetDirectoryPath() const; - NzString GetFilePath() const; - NzString GetFileName() const; - time_t GetLastAccessTime() const; - time_t GetLastWriteTime() const; - NzString GetLine(unsigned int lineSize = 0) override; - nzUInt64 GetSize() const; - - bool IsOpen() const; - - bool Open(unsigned long openMode = Current); - - std::size_t Read(void* buffer, std::size_t size); - std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); - bool Rename(const NzString& newFilePath); - - bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0); - bool SetCursorPos(nzUInt64 offset); - void SetEndianness(nzEndianness endianness); - bool SetFile(const NzString& filePath); - bool SetOpenMode(unsigned int openMode); - - bool Write(const NzString& string); - std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); - - NzFile& operator=(const NzString& filePath); - NzFile& operator=(NzFile&& file) noexcept; - - static NzString AbsolutePath(const NzString& filePath); - static bool Copy(const NzString& sourcePath, const NzString& targetPath); - static bool Delete(const NzString& filePath); - static bool Exists(const NzString& filePath); - static time_t GetCreationTime(const NzString& filePath); - static time_t GetLastAccessTime(const NzString& filePath); - static time_t GetLastWriteTime(const NzString& filePath); - static NzHashDigest GetHash(const NzString& filePath, nzHash hash); - static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash); - static nzUInt64 GetSize(const NzString& filePath); - static bool IsAbsolute(const NzString& path); - static NzString NormalizePath(const NzString& filePath); - static NzString NormalizeSeparators(const NzString& filePath); - static bool Rename(const NzString& sourcePath, const NzString& targetPath); - - private: - bool FillHash(NzHashImpl* hash) const; - - NazaraMutexAttrib(m_mutex, mutable) - - nzEndianness m_endianness; - NzString m_filePath; - NzFileImpl* m_impl; - unsigned int m_openMode; -}; - -#endif // NAZARA_FILE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_FILE_HPP +#define NAZARA_FILE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE +#include +#else +#include +#endif + +class NzFileImpl; + +class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable +{ + public: + enum CursorPosition + { + AtBegin, // Début du fichier + AtCurrent, // Position du pointeur + AtEnd // Fin du fichier + }; + + enum OpenMode + { + Current = 0x00, // Utilise le mode d'ouverture actuel + + Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin + Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert + ReadOnly = 0x04, // Ouvre uniquement en lecture + ReadWrite = 0x08, // Ouvre en lecture/écriture + Text = 0x10, // Ouvre en mode texte + Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe + WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas + }; + + NzFile(); + NzFile(const NzString& filePath); + NzFile(const NzString& filePath, unsigned long openMode); + NzFile(NzFile&& file) noexcept; + ~NzFile(); + + bool Copy(const NzString& newFilePath); + void Close(); + + bool Delete(); + + bool EndOfFile() const; + bool EndOfStream() const; + + bool Exists() const; + + void Flush(); + + time_t GetCreationTime() const; + nzUInt64 GetCursorPos() const; + NzString GetDirectoryPath() const; + NzString GetFilePath() const; + NzString GetFileName() const; + time_t GetLastAccessTime() const; + time_t GetLastWriteTime() const; + NzString GetLine(unsigned int lineSize = 0) override; + nzUInt64 GetSize() const; + + bool IsOpen() const; + + bool Open(unsigned long openMode = Current); + + std::size_t Read(void* buffer, std::size_t size); + std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); + bool Rename(const NzString& newFilePath); + + bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0); + bool SetCursorPos(nzUInt64 offset); + void SetEndianness(nzEndianness endianness); + bool SetFile(const NzString& filePath); + bool SetOpenMode(unsigned int openMode); + + bool Write(const NzString& string); + std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count); + + NzFile& operator=(const NzString& filePath); + NzFile& operator=(NzFile&& file) noexcept; + + static NzString AbsolutePath(const NzString& filePath); + static bool Copy(const NzString& sourcePath, const NzString& targetPath); + static bool Delete(const NzString& filePath); + static bool Exists(const NzString& filePath); + static time_t GetCreationTime(const NzString& filePath); + static time_t GetLastAccessTime(const NzString& filePath); + static time_t GetLastWriteTime(const NzString& filePath); + static NzHashDigest GetHash(const NzString& filePath, nzHash hash); + static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash); + static nzUInt64 GetSize(const NzString& filePath); + static bool IsAbsolute(const NzString& path); + static NzString NormalizePath(const NzString& filePath); + static NzString NormalizeSeparators(const NzString& filePath); + static bool Rename(const NzString& sourcePath, const NzString& targetPath); + + private: + bool FillHash(NzHashImpl* hash) const; + + NazaraMutexAttrib(m_mutex, mutable) + + nzEndianness m_endianness; + NzString m_filePath; + NzFileImpl* m_impl; + unsigned int m_openMode; +}; + +#endif // NAZARA_FILE_HPP diff --git a/include/Nazara/Core/InputStream.hpp b/include/Nazara/Core/InputStream.hpp index f8e734cb2..cc2507314 100644 --- a/include/Nazara/Core/InputStream.hpp +++ b/include/Nazara/Core/InputStream.hpp @@ -1,30 +1,30 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_INPUTSTREAM_HPP -#define NAZARA_INPUTSTREAM_HPP - -#include - -class NzString; - -class NzInputStream -{ - public: - virtual ~NzInputStream(); - - virtual bool EndOfStream() const = 0; - - virtual nzUInt64 GetCursorPos() const = 0; - virtual NzString GetLine(unsigned int lineSize = 0); - virtual nzUInt64 GetSize() const = 0; - - virtual std::size_t Read(void* buffer, std::size_t size) = 0; - - virtual bool SetCursorPos(nzUInt64 offset) = 0; -}; - -#endif // NAZARA_INPUTSTREAM_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_INPUTSTREAM_HPP +#define NAZARA_INPUTSTREAM_HPP + +#include + +class NzString; + +class NzInputStream +{ + public: + virtual ~NzInputStream(); + + virtual bool EndOfStream() const = 0; + + virtual nzUInt64 GetCursorPos() const = 0; + virtual NzString GetLine(unsigned int lineSize = 0); + virtual nzUInt64 GetSize() const = 0; + + virtual std::size_t Read(void* buffer, std::size_t size) = 0; + + virtual bool SetCursorPos(nzUInt64 offset) = 0; +}; + +#endif // NAZARA_INPUTSTREAM_HPP diff --git a/include/Nazara/Core/Resource.hpp b/include/Nazara/Core/Resource.hpp index 57ca3d2f5..0da8c78c3 100644 --- a/include/Nazara/Core/Resource.hpp +++ b/include/Nazara/Core/Resource.hpp @@ -1,72 +1,72 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RESOURCE_HPP -#define NAZARA_RESOURCE_HPP - -#include -#include - -#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_RESOURCE -#include -#else -#include -#endif - -class NzResourceListener; - -struct NzResourceEntry -{ - NzResourceEntry(NzResourceListener* resourceListener, int i = 0) : - listener(resourceListener), - index(i) - { - } - - bool operator<(const NzResourceEntry& rhs) const - { - return listener < rhs.listener; - } - - NzResourceListener* listener; - int index; -}; - -class NAZARA_API NzResource -{ - public: - NzResource(bool persistent = true); - NzResource(const NzResource& resource); - virtual ~NzResource(); - - void AddResourceListener(NzResourceListener* listener, int index = 0) const; - void AddResourceReference() const; - - bool IsPersistent() const; - - void RemoveResourceListener(NzResourceListener* listener) const; - void RemoveResourceReference() const; - - void SetPersistent(bool persistent = true); - - protected: - void NotifyCreated(); - void NotifyDestroy(); - - private: - void EnsureResourceListenerUpdate() const; - - NazaraMutexAttrib(m_mutex, mutable) - - // Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms - mutable std::set m_resourceListeners; - mutable std::set m_resourceListenersCache; - mutable bool m_resourceListenerUpdated; - bool m_resourcePersistent; - mutable unsigned int m_resourceReferenceCount; -}; - -#endif // NAZARA_RESOURCE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RESOURCE_HPP +#define NAZARA_RESOURCE_HPP + +#include +#include + +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_RESOURCE +#include +#else +#include +#endif + +class NzResourceListener; + +struct NzResourceEntry +{ + NzResourceEntry(NzResourceListener* resourceListener, int i = 0) : + listener(resourceListener), + index(i) + { + } + + bool operator<(const NzResourceEntry& rhs) const + { + return listener < rhs.listener; + } + + NzResourceListener* listener; + int index; +}; + +class NAZARA_API NzResource +{ + public: + NzResource(bool persistent = true); + NzResource(const NzResource& resource); + virtual ~NzResource(); + + void AddResourceListener(NzResourceListener* listener, int index = 0) const; + void AddResourceReference() const; + + bool IsPersistent() const; + + void RemoveResourceListener(NzResourceListener* listener) const; + void RemoveResourceReference() const; + + void SetPersistent(bool persistent = true); + + protected: + void NotifyCreated(); + void NotifyDestroy(); + + private: + void EnsureResourceListenerUpdate() const; + + NazaraMutexAttrib(m_mutex, mutable) + + // Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms + mutable std::set m_resourceListeners; + mutable std::set m_resourceListenersCache; + mutable bool m_resourceListenerUpdated; + bool m_resourcePersistent; + mutable unsigned int m_resourceReferenceCount; +}; + +#endif // NAZARA_RESOURCE_HPP diff --git a/include/Nazara/Core/ResourceListener.hpp b/include/Nazara/Core/ResourceListener.hpp index cff90fe58..646ca1e53 100644 --- a/include/Nazara/Core/ResourceListener.hpp +++ b/include/Nazara/Core/ResourceListener.hpp @@ -1,25 +1,25 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RESOURCELISTENER_HPP -#define NAZARA_RESOURCELISTENER_HPP - -#include - -class NzResource; - -class NAZARA_API NzResourceListener -{ - public: - NzResourceListener() = default; - virtual ~NzResourceListener(); - - virtual void OnResourceCreated(const NzResource* resource, int index); - virtual void OnResourceDestroy(const NzResource* resource, int index); - virtual void OnResourceReleased(const NzResource* resource, int index); -}; - -#endif // NAZARA_RESOURCELISTENER_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RESOURCELISTENER_HPP +#define NAZARA_RESOURCELISTENER_HPP + +#include + +class NzResource; + +class NAZARA_API NzResourceListener +{ + public: + NzResourceListener() = default; + virtual ~NzResourceListener(); + + virtual void OnResourceCreated(const NzResource* resource, int index); + virtual void OnResourceDestroy(const NzResource* resource, int index); + virtual void OnResourceReleased(const NzResource* resource, int index); +}; + +#endif // NAZARA_RESOURCELISTENER_HPP diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl index 392c04c0e..244a18a92 100644 --- a/include/Nazara/Core/ResourceLoader.inl +++ b/include/Nazara/Core/ResourceLoader.inl @@ -1,142 +1,142 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -template -bool NzResourceLoader::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters) -{ - #if NAZARA_CORE_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid parameters"); - return false; - } - #endif - - NzString path = NzFile::NormalizePath(filePath); - NzString ext = path.SubstrFrom('.', -1, true); - if (ext.IsEmpty()) - { - NazaraError("Failed to get file extension"); - return false; - } - - NzFile file(path, NzFile::ReadOnly); - if (!file.IsOpen()) - { - NazaraError("Failed to open file"); - return false; - } - - for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) - { - for (const NzString& loaderExt : std::get<0>(*loader)) - { - int cmp = NzString::Compare(loaderExt, ext); - if (cmp == 0) - { - if (!std::get<1>(*loader)(file, parameters)) - continue; - - file.SetCursorPos(0); - - // Chargement de la ressource - if (std::get<2>(*loader)(resource, file, parameters)) - return true; - - NazaraWarning("Loader failed"); - - file.SetCursorPos(0); - } - else if (cmp < 0) // S'il est encore possible que l'extension se situe après - continue; - - break; - } - } - - NazaraError("Failed to load file: no loader"); - - return false; -} - -template -bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) -{ - NzMemoryStream stream(data, size); - - return LoadFromStream(resource, stream, parameters); -} - -template -bool NzResourceLoader::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters) -{ - #if NAZARA_CORE_SAFE - if (!parameters.IsValid()) - { - NazaraError("Invalid parameters"); - return false; - } - - if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize()) - { - NazaraError("No data to load"); - return false; - } - #endif - - nzUInt64 streamPos = stream.GetCursorPos(); - for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) - { - // Le loader supporte-t-il les données ? - if (!std::get<1>(*loader)(stream, parameters)) - continue; - - // On repositionne le stream au début - stream.SetCursorPos(streamPos); - - // Chargement de la ressource - if (std::get<2>(*loader)(resource, stream, parameters)) - return true; - - NazaraWarning("Loader failed"); - stream.SetCursorPos(streamPos); // On repositionne au début - } - - NazaraError("Failed to load file: no loader"); - return false; -} - -template -void NzResourceLoader::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) -{ - ///FIXME: Trouver une alternative à ce code monstrueux - std::vector exts; - fileExtensions.SplitAny(exts, " /\\.,;|-_"); - - std::set extensions; - std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); - - Type::s_loaders.insert(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); -} - -template -void NzResourceLoader::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) -{ - std::vector exts; - fileExtensions.SplitAny(exts, " /\\.,;|-_"); - - std::set extensions; - std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); - - Type::s_loaders.erase(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); -} - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +template +bool NzResourceLoader::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters) +{ + #if NAZARA_CORE_SAFE + if (!parameters.IsValid()) + { + NazaraError("Invalid parameters"); + return false; + } + #endif + + NzString path = NzFile::NormalizePath(filePath); + NzString ext = path.SubstrFrom('.', -1, true); + if (ext.IsEmpty()) + { + NazaraError("Failed to get file extension"); + return false; + } + + NzFile file(path, NzFile::ReadOnly); + if (!file.IsOpen()) + { + NazaraError("Failed to open file"); + return false; + } + + for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) + { + for (const NzString& loaderExt : std::get<0>(*loader)) + { + int cmp = NzString::Compare(loaderExt, ext); + if (cmp == 0) + { + if (!std::get<1>(*loader)(file, parameters)) + continue; + + file.SetCursorPos(0); + + // Chargement de la ressource + if (std::get<2>(*loader)(resource, file, parameters)) + return true; + + NazaraWarning("Loader failed"); + + file.SetCursorPos(0); + } + else if (cmp < 0) // S'il est encore possible que l'extension se situe après + continue; + + break; + } + } + + NazaraError("Failed to load file: no loader"); + + return false; +} + +template +bool NzResourceLoader::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters) +{ + NzMemoryStream stream(data, size); + + return LoadFromStream(resource, stream, parameters); +} + +template +bool NzResourceLoader::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters) +{ + #if NAZARA_CORE_SAFE + if (!parameters.IsValid()) + { + NazaraError("Invalid parameters"); + return false; + } + + if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize()) + { + NazaraError("No data to load"); + return false; + } + #endif + + nzUInt64 streamPos = stream.GetCursorPos(); + for (auto loader = Type::s_loaders.begin(); loader != Type::s_loaders.end(); ++loader) + { + // Le loader supporte-t-il les données ? + if (!std::get<1>(*loader)(stream, parameters)) + continue; + + // On repositionne le stream au début + stream.SetCursorPos(streamPos); + + // Chargement de la ressource + if (std::get<2>(*loader)(resource, stream, parameters)) + return true; + + NazaraWarning("Loader failed"); + stream.SetCursorPos(streamPos); // On repositionne au début + } + + NazaraError("Failed to load file: no loader"); + return false; +} + +template +void NzResourceLoader::RegisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + ///FIXME: Trouver une alternative à ce code monstrueux + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set extensions; + std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); + + Type::s_loaders.insert(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); +} + +template +void NzResourceLoader::UnregisterLoader(const NzString& fileExtensions, CheckFunction checkFunc, LoadFunction loadFunc) +{ + std::vector exts; + fileExtensions.SplitAny(exts, " /\\.,;|-_"); + + std::set extensions; + std::copy(exts.begin(), exts.end(), std::inserter(extensions, extensions.begin())); + + Type::s_loaders.erase(std::make_tuple(std::move(extensions), checkFunc, loadFunc)); +} + +#include diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp index 52f715e9f..bed1cdd3c 100644 --- a/include/Nazara/Core/String.hpp +++ b/include/Nazara/Core/String.hpp @@ -1,321 +1,320 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_STRING_HPP -#define NAZARA_STRING_HPP - -#include -#include -#include -#include -#include - -#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING -#include -#else -#include -#endif - -class NzAbstractHash; -class NzHashDigest; - -class NAZARA_API NzString : public NzHashable -{ - public: - enum Flags - { - None = 0x00, // Mode par défaut - CaseInsensitive = 0x01, // Insensible à la casse - HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 - TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne - TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne - }; - - struct SharedString; - - NzString(); - NzString(char character); - NzString(const char* string); - NzString(const std::string& string); - NzString(const NzString& string); - NzString(NzString&& string) noexcept; - NzString(SharedString* sharedString); - ~NzString(); - - NzString& Append(char character); - NzString& Append(const char* string); - NzString& Append(const NzString& string); - - void Clear(bool keepBuffer = false); - - bool Contains(char character, int start = 0, nzUInt32 flags = None) const; - bool Contains(const char* string, int start = 0, nzUInt32 flags = None) const; - bool Contains(const NzString& string, int start = 0, nzUInt32 flags = None) const; - - unsigned int Count(char character, int start = 0, nzUInt32 flags = None) const; - unsigned int Count(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int Count(const NzString& string, int start = 0, nzUInt32 flags = None) const; - unsigned int CountAny(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int CountAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; - - bool EndsWith(char character, nzUInt32 flags = None) const; - bool EndsWith(const char* string, nzUInt32 flags = None) const; - bool EndsWith(const NzString& string, nzUInt32 flags = None) const; - - unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const; - unsigned int Find(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int Find(const NzString& string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindAny(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindLast(char character, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLast(const char *string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLast(const NzString& string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastAny(const char* string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastAny(const NzString& string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastWord(const char* string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindLastWord(const NzString& string, int start = -1, nzUInt32 flags = None) const; - unsigned int FindWord(const char* string, int start = 0, nzUInt32 flags = None) const; - unsigned int FindWord(const NzString& string, int start = 0, nzUInt32 flags = None) const; - - char* GetBuffer(); - unsigned int GetCapacity() const; - const char* GetConstBuffer() const; - unsigned int GetLength() const; - unsigned int GetSize() const; - char* GetUtf8Buffer(unsigned int* size = nullptr) const; - char16_t* GetUtf16Buffer(unsigned int* size = nullptr) const; - char32_t* GetUtf32Buffer(unsigned int* size = nullptr) const; - wchar_t* GetWideBuffer(unsigned int* size = nullptr) const; - - NzString GetWord(unsigned int index, nzUInt32 flags = None) const; - unsigned int GetWordPosition(unsigned int index, nzUInt32 flags = None) const; - - NzString& Insert(int pos, char character); - NzString& Insert(int pos, const char* string); - NzString& Insert(int pos, const NzString& string); - - bool IsEmpty() const; - bool IsNull() const; - bool IsNumber(nzUInt8 radix = 10, nzUInt32 flags = CaseInsensitive) const; - - bool Match(const char* pattern) const; - bool Match(const NzString& pattern) const; - - NzString& Prepend(char character); - NzString& Prepend(const char* string); - NzString& Prepend(const NzString& string); - - unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None); - unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None); - unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None); - unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None); - //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); - //unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None); - - void Reserve(unsigned int bufferSize); - - NzString& Resize(int size, char character = ' '); - NzString Resized(int size, char character = ' ') const; - - NzString& Reverse(); - NzString Reversed() const; - - NzString Simplified(nzUInt32 flags = None) const; - NzString& Simplify(nzUInt32 flags = None); - - unsigned int Split(std::vector& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const; - unsigned int Split(std::vector& result, const char* separation, int start = 0, nzUInt32 flags = None) const; - unsigned int Split(std::vector& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const; - unsigned int SplitAny(std::vector& result, const char* separations, int start = 0, nzUInt32 flags = None) const; - unsigned int SplitAny(std::vector& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const; - - bool StartsWith(char character, nzUInt32 flags = None) const; - bool StartsWith(const char* string, nzUInt32 flags = None) const; - bool StartsWith(const NzString& string, nzUInt32 flags = None) const; - - NzString Substr(int startPos, int endPos = -1) const; - NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; - NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; - - void Swap(NzString& str); - - bool ToBool(bool* value, nzUInt32 flags = None) const; - bool ToDouble(double* value) const; - bool ToInteger(long long* value, nzUInt8 radix = 10) const; - NzString ToLower(nzUInt32 flags = None) const; - NzString ToUpper(nzUInt32 flags = None) const; - - NzString& Trim(nzUInt32 flags = None); - NzString& Trim(char character, nzUInt32 flags = None); - NzString Trimmed(nzUInt32 flags = None) const; - NzString Trimmed(char character, nzUInt32 flags = None) const; - - // Méthodes STD - char* begin(); - const char* begin() const; - char* end(); - const char* end() const; - void push_front(char c); - void push_back(char c); - /*char* rbegin(); - const char* rbegin() const; - char* rend(); - const char* rend() const;*/ - - typedef const char& const_reference; - typedef char* iterator; - //typedef char* reverse_iterator; - typedef char value_type; - // Méthodes STD - - operator std::string() const; - - char& operator[](unsigned int pos); - char operator[](unsigned int pos) const; - - NzString& operator=(char character); - NzString& operator=(const char* string); - NzString& operator=(const std::string& string); - NzString& operator=(const NzString& string); - NzString& operator=(NzString&& string) noexcept; - - NzString operator+(char character) const; - NzString operator+(const char* string) const; - NzString operator+(const std::string& string) const; - NzString operator+(const NzString& string) const; - - NzString& operator+=(char character); - NzString& operator+=(const char* string); - NzString& operator+=(const std::string& string); - NzString& operator+=(const NzString& string); - - bool operator==(char character) const; - bool operator==(const char* string) const; - bool operator==(const std::string& string) const; - - bool operator!=(char character) const; - bool operator!=(const char* string) const; - bool operator!=(const std::string& string) const; - - bool operator<(char character) const; - bool operator<(const char* string) const; - bool operator<(const std::string& string) const; - - bool operator<=(char character) const; - bool operator<=(const char* string) const; - bool operator<=(const std::string& string) const; - - bool operator>(char character) const; - bool operator>(const char* string) const; - bool operator>(const std::string& string) const; - - bool operator>=(char character) const; - bool operator>=(const char* string) const; - bool operator>=(const std::string& string) const; - - static NzString Boolean(bool boolean); - static int Compare(const NzString& first, const NzString& second); - static NzString Number(float number); - static NzString Number(double number); - static NzString Number(long double number); - static NzString Number(signed char number, nzUInt8 radix = 10); - static NzString Number(unsigned char number, nzUInt8 radix = 10); - static NzString Number(short number, nzUInt8 radix = 10); - static NzString Number(unsigned short number, nzUInt8 radix = 10); - static NzString Number(int number, nzUInt8 radix = 10); - static NzString Number(unsigned int number, nzUInt8 radix = 10); - static NzString Number(long number, nzUInt8 radix = 10); - static NzString Number(unsigned long number, nzUInt8 radix = 10); - static NzString Number(long long number, nzUInt8 radix = 10); - static NzString Number(unsigned long long number, nzUInt8 radix = 10); - static NzString Pointer(const void* ptr); - static NzString Unicode(char32_t character); - static NzString Unicode(const char* u8String); - static NzString Unicode(const char16_t* u16String); - static NzString Unicode(const char32_t* u32String); - static NzString Unicode(const wchar_t* wString); - - NAZARA_API friend std::istream& operator>>(std::istream& in, NzString& string); - NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzString& string); - - NAZARA_API friend NzString operator+(char character, const NzString& string); - NAZARA_API friend NzString operator+(const char* string, const NzString& nstring); - NAZARA_API friend NzString operator+(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator==(const NzString& first, const NzString& second); - NAZARA_API friend bool operator!=(const NzString& first, const NzString& second); - NAZARA_API friend bool operator<(const NzString& first, const NzString& second); - NAZARA_API friend bool operator<=(const NzString& first, const NzString& second); - NAZARA_API friend bool operator>(const NzString& first, const NzString& second); - NAZARA_API friend bool operator>=(const NzString& first, const NzString& second); - - NAZARA_API friend bool operator==(char character, const NzString& nstring); - NAZARA_API friend bool operator==(const char* string, const NzString& nstring); - NAZARA_API friend bool operator==(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator!=(char character, const NzString& nstring); - NAZARA_API friend bool operator!=(const char* string, const NzString& nstring); - NAZARA_API friend bool operator!=(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator<(char character, const NzString& nstring); - NAZARA_API friend bool operator<(const char* string, const NzString& nstring); - NAZARA_API friend bool operator<(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator<=(char character, const NzString& nstring); - NAZARA_API friend bool operator<=(const char* string, const NzString& nstring); - NAZARA_API friend bool operator<=(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator>(char character, const NzString& nstring); - NAZARA_API friend bool operator>(const char* string, const NzString& nstring); - NAZARA_API friend bool operator>(const std::string& string, const NzString& nstring); - - NAZARA_API friend bool operator>=(char character, const NzString& nstring); - NAZARA_API friend bool operator>=(const char* string, const NzString& nstring); - NAZARA_API friend bool operator>=(const std::string& string, const NzString& nstring); - - struct NAZARA_API SharedString - { - SharedString() = default; - - SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) : - capacity(bufferSize), - size(stringSize), - string(str), - refCount(referenceCount) - { - } - - unsigned int capacity; - unsigned int size; - char* string; - - unsigned short refCount = 1; - NazaraMutex(mutex) - }; - - static SharedString emptyString; - static const unsigned int npos; - - private: - void EnsureOwnership(); - bool FillHash(NzHashImpl* hash) const; - void ReleaseString(); - - SharedString* m_sharedString; -}; - -namespace std -{ - NAZARA_API istream& getline(istream& is, NzString& str); - NAZARA_API istream& getline(istream& is, NzString& str, char delim); - NAZARA_API void swap(NzString& lhs, NzString& rhs); -} - -#endif // NAZARA_STRING_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_STRING_HPP +#define NAZARA_STRING_HPP + +#include +#include +#include +#include +#include + +#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING +#include +#else +#include +#endif + +class NzAbstractHash; +class NzHashDigest; + +class NAZARA_API NzString : public NzHashable +{ + public: + enum Flags + { + None = 0x00, // Mode par défaut + CaseInsensitive = 0x01, // Insensible à la casse + HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 + TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne + TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne + }; + + struct SharedString; + + NzString(); + NzString(char character); + NzString(const char* string); + NzString(const std::string& string); + NzString(const NzString& string); + NzString(NzString&& string) noexcept; + NzString(SharedString* sharedString); + ~NzString(); + + NzString& Append(char character); + NzString& Append(const char* string); + NzString& Append(const NzString& string); + + void Clear(bool keepBuffer = false); + + bool Contains(char character, int start = 0, nzUInt32 flags = None) const; + bool Contains(const char* string, int start = 0, nzUInt32 flags = None) const; + bool Contains(const NzString& string, int start = 0, nzUInt32 flags = None) const; + + unsigned int Count(char character, int start = 0, nzUInt32 flags = None) const; + unsigned int Count(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int Count(const NzString& string, int start = 0, nzUInt32 flags = None) const; + unsigned int CountAny(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int CountAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; + + bool EndsWith(char character, nzUInt32 flags = None) const; + bool EndsWith(const char* string, nzUInt32 flags = None) const; + bool EndsWith(const NzString& string, nzUInt32 flags = None) const; + + unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const; + unsigned int Find(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int Find(const NzString& string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindAny(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindAny(const NzString& string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindLast(char character, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLast(const char *string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLast(const NzString& string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastAny(const char* string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastAny(const NzString& string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastWord(const char* string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindLastWord(const NzString& string, int start = -1, nzUInt32 flags = None) const; + unsigned int FindWord(const char* string, int start = 0, nzUInt32 flags = None) const; + unsigned int FindWord(const NzString& string, int start = 0, nzUInt32 flags = None) const; + + char* GetBuffer(); + unsigned int GetCapacity() const; + const char* GetConstBuffer() const; + unsigned int GetLength() const; + unsigned int GetSize() const; + char* GetUtf8Buffer(unsigned int* size = nullptr) const; + char16_t* GetUtf16Buffer(unsigned int* size = nullptr) const; + char32_t* GetUtf32Buffer(unsigned int* size = nullptr) const; + wchar_t* GetWideBuffer(unsigned int* size = nullptr) const; + NzString GetWord(unsigned int index, nzUInt32 flags = None) const; + unsigned int GetWordPosition(unsigned int index, nzUInt32 flags = None) const; + + NzString& Insert(int pos, char character); + NzString& Insert(int pos, const char* string); + NzString& Insert(int pos, const NzString& string); + + bool IsEmpty() const; + bool IsNull() const; + bool IsNumber(nzUInt8 radix = 10, nzUInt32 flags = CaseInsensitive) const; + + bool Match(const char* pattern) const; + bool Match(const NzString& pattern) const; + + NzString& Prepend(char character); + NzString& Prepend(const char* string); + NzString& Prepend(const NzString& string); + + unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None); + unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None); + unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None); + unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None); + //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None); + //unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None); + + void Reserve(unsigned int bufferSize); + + NzString& Resize(int size, char character = ' '); + NzString Resized(int size, char character = ' ') const; + + NzString& Reverse(); + NzString Reversed() const; + + NzString Simplified(nzUInt32 flags = None) const; + NzString& Simplify(nzUInt32 flags = None); + + unsigned int Split(std::vector& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const; + unsigned int Split(std::vector& result, const char* separation, int start = 0, nzUInt32 flags = None) const; + unsigned int Split(std::vector& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const; + unsigned int SplitAny(std::vector& result, const char* separations, int start = 0, nzUInt32 flags = None) const; + unsigned int SplitAny(std::vector& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const; + + bool StartsWith(char character, nzUInt32 flags = None) const; + bool StartsWith(const char* string, nzUInt32 flags = None) const; + bool StartsWith(const NzString& string, nzUInt32 flags = None) const; + + NzString Substr(int startPos, int endPos = -1) const; + NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; + NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const; + + void Swap(NzString& str); + + bool ToBool(bool* value, nzUInt32 flags = None) const; + bool ToDouble(double* value) const; + bool ToInteger(long long* value, nzUInt8 radix = 10) const; + NzString ToLower(nzUInt32 flags = None) const; + NzString ToUpper(nzUInt32 flags = None) const; + + NzString& Trim(nzUInt32 flags = None); + NzString& Trim(char character, nzUInt32 flags = None); + NzString Trimmed(nzUInt32 flags = None) const; + NzString Trimmed(char character, nzUInt32 flags = None) const; + + // Méthodes STD + char* begin(); + const char* begin() const; + char* end(); + const char* end() const; + void push_front(char c); + void push_back(char c); + /*char* rbegin(); + const char* rbegin() const; + char* rend(); + const char* rend() const;*/ + + typedef const char& const_reference; + typedef char* iterator; + //typedef char* reverse_iterator; + typedef char value_type; + // Méthodes STD + + operator std::string() const; + + char& operator[](unsigned int pos); + char operator[](unsigned int pos) const; + + NzString& operator=(char character); + NzString& operator=(const char* string); + NzString& operator=(const std::string& string); + NzString& operator=(const NzString& string); + NzString& operator=(NzString&& string) noexcept; + + NzString operator+(char character) const; + NzString operator+(const char* string) const; + NzString operator+(const std::string& string) const; + NzString operator+(const NzString& string) const; + + NzString& operator+=(char character); + NzString& operator+=(const char* string); + NzString& operator+=(const std::string& string); + NzString& operator+=(const NzString& string); + + bool operator==(char character) const; + bool operator==(const char* string) const; + bool operator==(const std::string& string) const; + + bool operator!=(char character) const; + bool operator!=(const char* string) const; + bool operator!=(const std::string& string) const; + + bool operator<(char character) const; + bool operator<(const char* string) const; + bool operator<(const std::string& string) const; + + bool operator<=(char character) const; + bool operator<=(const char* string) const; + bool operator<=(const std::string& string) const; + + bool operator>(char character) const; + bool operator>(const char* string) const; + bool operator>(const std::string& string) const; + + bool operator>=(char character) const; + bool operator>=(const char* string) const; + bool operator>=(const std::string& string) const; + + static NzString Boolean(bool boolean); + static int Compare(const NzString& first, const NzString& second); + static NzString Number(float number); + static NzString Number(double number); + static NzString Number(long double number); + static NzString Number(signed char number, nzUInt8 radix = 10); + static NzString Number(unsigned char number, nzUInt8 radix = 10); + static NzString Number(short number, nzUInt8 radix = 10); + static NzString Number(unsigned short number, nzUInt8 radix = 10); + static NzString Number(int number, nzUInt8 radix = 10); + static NzString Number(unsigned int number, nzUInt8 radix = 10); + static NzString Number(long number, nzUInt8 radix = 10); + static NzString Number(unsigned long number, nzUInt8 radix = 10); + static NzString Number(long long number, nzUInt8 radix = 10); + static NzString Number(unsigned long long number, nzUInt8 radix = 10); + static NzString Pointer(const void* ptr); + static NzString Unicode(char32_t character); + static NzString Unicode(const char* u8String); + static NzString Unicode(const char16_t* u16String); + static NzString Unicode(const char32_t* u32String); + static NzString Unicode(const wchar_t* wString); + + NAZARA_API friend std::istream& operator>>(std::istream& in, NzString& string); + NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzString& string); + + NAZARA_API friend NzString operator+(char character, const NzString& string); + NAZARA_API friend NzString operator+(const char* string, const NzString& nstring); + NAZARA_API friend NzString operator+(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator==(const NzString& first, const NzString& second); + NAZARA_API friend bool operator!=(const NzString& first, const NzString& second); + NAZARA_API friend bool operator<(const NzString& first, const NzString& second); + NAZARA_API friend bool operator<=(const NzString& first, const NzString& second); + NAZARA_API friend bool operator>(const NzString& first, const NzString& second); + NAZARA_API friend bool operator>=(const NzString& first, const NzString& second); + + NAZARA_API friend bool operator==(char character, const NzString& nstring); + NAZARA_API friend bool operator==(const char* string, const NzString& nstring); + NAZARA_API friend bool operator==(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator!=(char character, const NzString& nstring); + NAZARA_API friend bool operator!=(const char* string, const NzString& nstring); + NAZARA_API friend bool operator!=(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator<(char character, const NzString& nstring); + NAZARA_API friend bool operator<(const char* string, const NzString& nstring); + NAZARA_API friend bool operator<(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator<=(char character, const NzString& nstring); + NAZARA_API friend bool operator<=(const char* string, const NzString& nstring); + NAZARA_API friend bool operator<=(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator>(char character, const NzString& nstring); + NAZARA_API friend bool operator>(const char* string, const NzString& nstring); + NAZARA_API friend bool operator>(const std::string& string, const NzString& nstring); + + NAZARA_API friend bool operator>=(char character, const NzString& nstring); + NAZARA_API friend bool operator>=(const char* string, const NzString& nstring); + NAZARA_API friend bool operator>=(const std::string& string, const NzString& nstring); + + struct NAZARA_API SharedString + { + SharedString() = default; + + SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) : + capacity(bufferSize), + size(stringSize), + string(str), + refCount(referenceCount) + { + } + + unsigned int capacity; + unsigned int size; + char* string; + + unsigned short refCount = 1; + NazaraMutex(mutex) + }; + + static SharedString emptyString; + static const unsigned int npos; + + private: + void EnsureOwnership(); + bool FillHash(NzHashImpl* hash) const; + void ReleaseString(); + + SharedString* m_sharedString; +}; + +namespace std +{ + NAZARA_API istream& getline(istream& is, NzString& str); + NAZARA_API istream& getline(istream& is, NzString& str, char delim); + NAZARA_API void swap(NzString& lhs, NzString& rhs); +} + +#endif // NAZARA_STRING_HPP diff --git a/include/Nazara/Math/Config.hpp b/include/Nazara/Math/Config.hpp index 71ee93ee4..2683c0c9b 100644 --- a/include/Nazara/Math/Config.hpp +++ b/include/Nazara/Math/Config.hpp @@ -1,49 +1,49 @@ -/* - Nazara Engine - Mathematics module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - Rémi "overdrivr" Bèges (remi.beges@laposte.net) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_MATH_HPP -#define NAZARA_CONFIG_MATH_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Définit le radian comme l'unité utilisée pour les angles -#define NAZARA_MATH_ANGLE_RADIAN 0 - -// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) -#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_MATH_SAFE 1 - -// Protège les classes des accès concurrentiels -#define NAZARA_MATH_THREADSAFE 1 - -// Les classes à protéger des accès concurrentiels -#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) -#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) - -#endif // NAZARA_CONFIG_MATH_HPP +/* + Nazara Engine - Mathematics module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Rémi "overdrivr" Bèges (remi.beges@laposte.net) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_MATH_HPP +#define NAZARA_CONFIG_MATH_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Définit le radian comme l'unité utilisée pour les angles +#define NAZARA_MATH_ANGLE_RADIAN 0 + +// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine) +#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_MATH_SAFE 1 + +// Protège les classes des accès concurrentiels +#define NAZARA_MATH_THREADSAFE 1 + +// Les classes à protéger des accès concurrentiels +#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW) +#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW) + +#endif // NAZARA_CONFIG_MATH_HPP diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 82919f28a..a8b2cd5cc 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -1,145 +1,145 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MATRIX4_HPP -#define NAZARA_MATRIX4_HPP - -#include -#include - -#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4 -#include -#else -#include -#endif - -template class NzEulerAngles; -template class NzQuaternion; -template class NzVector2; -template class NzVector3; -template class NzVector4; - -template class NzMatrix4 -{ - public: - NzMatrix4(); - NzMatrix4(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44); - NzMatrix4(const T matrix[16]); - //NzMatrix4(const NzMatrix3& matrix); - template explicit NzMatrix4(const NzMatrix4& matrix); - NzMatrix4(const NzMatrix4& matrix); - NzMatrix4(NzMatrix4&& matrix) noexcept; - ~NzMatrix4(); - - NzMatrix4 Concatenate(const NzMatrix4& matrix) const; - NzMatrix4 ConcatenateAffine(const NzMatrix4& matrix) const; - - T GetDeterminant() const; - NzMatrix4 GetInverse() const; - NzQuaternion GetRotation() const; - //NzMatrix3 GetRotationMatrix() const; - NzVector3 GetScale() const; - NzVector3 GetTranslation() const; - NzMatrix4 GetTransposed() const; - - bool HasNegativeScale() const; - bool HasScale() const; - - bool IsAffine() const; - bool IsDefined() const; - - void MakeIdentity(); - void MakeLookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); - void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); - void MakePerspective(T angle, T ratio, T zNear, T zFar); - void MakeRotation(const NzQuaternion& rotation); - void MakeScale(const NzVector3& scale); - void MakeTranslation(const NzVector3& translation); - void MakeZero(); - - void Set(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44); - void Set(const T matrix[16]); - //NzMatrix4(const NzMatrix3& matrix); - void Set(const NzMatrix4& matrix); - void Set(NzMatrix4&& matrix); - template void Set(const NzMatrix4& matrix); - void SetRotation(const NzQuaternion& rotation); - void SetScale(const NzVector3& scale); - void SetTranslation(const NzVector3& translation); - - NzString ToString() const; - - NzVector2 Transform(const NzVector2& vector, T z = 0.0, T w = 1.0) const; - NzVector3 Transform(const NzVector3& vector, T w = 1.0) const; - NzVector4 Transform(const NzVector4& vector) const; - - NzMatrix4& Transpose(); - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator()(unsigned int x, unsigned int y); - const T& operator()(unsigned int x, unsigned int y) const; - - NzMatrix4& operator=(const NzMatrix4& matrix); - NzMatrix4& operator=(NzMatrix4&& matrix) noexcept; - - NzMatrix4 operator*(const NzMatrix4& matrix) const; - NzVector2 operator*(const NzVector2& vector) const; - NzVector3 operator*(const NzVector3& vector) const; - NzVector4 operator*(const NzVector4& vector) const; - NzMatrix4 operator*(T scalar) const; - - NzMatrix4& operator*=(const NzMatrix4& matrix); - NzMatrix4& operator*=(T scalar); - - static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); - static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); - static NzMatrix4 Identity(); - static NzMatrix4 LookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); - static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); - static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar); - static NzMatrix4 Rotate(const NzQuaternion& rotation); - static NzMatrix4 Scale(const NzVector3& scale); - static NzMatrix4 Translate(const NzVector3& translation); - static NzMatrix4 Zero(); - - struct SharedMatrix - { - T m11, m12, m13, m14, - m21, m22, m23, m24, - m31, m32, m33, m34, - m41, m42, m43, m44; - - unsigned short refCount = 1; - NazaraMutex(mutex) - }; - - private: - void EnsureOwnership(); - void ReleaseMatrix(); - - SharedMatrix* m_sharedMatrix = nullptr; -}; - -template std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix); - -template NzMatrix4 operator*(T scale, const NzMatrix4& matrix); - -typedef NzMatrix4 NzMatrix4d; -typedef NzMatrix4 NzMatrix4f; - -#include - -#endif // NAZARA_MATRIX4_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_MATRIX4_HPP +#define NAZARA_MATRIX4_HPP + +#include +#include + +#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4 +#include +#else +#include +#endif + +template class NzEulerAngles; +template class NzQuaternion; +template class NzVector2; +template class NzVector3; +template class NzVector4; + +template class NzMatrix4 +{ + public: + NzMatrix4(); + NzMatrix4(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44); + NzMatrix4(const T matrix[16]); + //NzMatrix4(const NzMatrix3& matrix); + template explicit NzMatrix4(const NzMatrix4& matrix); + NzMatrix4(const NzMatrix4& matrix); + NzMatrix4(NzMatrix4&& matrix) noexcept; + ~NzMatrix4(); + + NzMatrix4 Concatenate(const NzMatrix4& matrix) const; + NzMatrix4 ConcatenateAffine(const NzMatrix4& matrix) const; + + T GetDeterminant() const; + NzMatrix4 GetInverse() const; + NzQuaternion GetRotation() const; + //NzMatrix3 GetRotationMatrix() const; + NzVector3 GetScale() const; + NzVector3 GetTranslation() const; + NzMatrix4 GetTransposed() const; + + bool HasNegativeScale() const; + bool HasScale() const; + + bool IsAffine() const; + bool IsDefined() const; + + void MakeIdentity(); + void MakeLookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); + void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); + void MakePerspective(T angle, T ratio, T zNear, T zFar); + void MakeRotation(const NzQuaternion& rotation); + void MakeScale(const NzVector3& scale); + void MakeTranslation(const NzVector3& translation); + void MakeZero(); + + void Set(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44); + void Set(const T matrix[16]); + //NzMatrix4(const NzMatrix3& matrix); + void Set(const NzMatrix4& matrix); + void Set(NzMatrix4&& matrix); + template void Set(const NzMatrix4& matrix); + void SetRotation(const NzQuaternion& rotation); + void SetScale(const NzVector3& scale); + void SetTranslation(const NzVector3& translation); + + NzString ToString() const; + + NzVector2 Transform(const NzVector2& vector, T z = 0.0, T w = 1.0) const; + NzVector3 Transform(const NzVector3& vector, T w = 1.0) const; + NzVector4 Transform(const NzVector4& vector) const; + + NzMatrix4& Transpose(); + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator()(unsigned int x, unsigned int y); + const T& operator()(unsigned int x, unsigned int y) const; + + NzMatrix4& operator=(const NzMatrix4& matrix); + NzMatrix4& operator=(NzMatrix4&& matrix) noexcept; + + NzMatrix4 operator*(const NzMatrix4& matrix) const; + NzVector2 operator*(const NzVector2& vector) const; + NzVector3 operator*(const NzVector3& vector) const; + NzVector4 operator*(const NzVector4& vector) const; + NzMatrix4 operator*(T scalar) const; + + NzMatrix4& operator*=(const NzMatrix4& matrix); + NzMatrix4& operator*=(T scalar); + + static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); + static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); + static NzMatrix4 Identity(); + static NzMatrix4 LookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); + static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0); + static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar); + static NzMatrix4 Rotate(const NzQuaternion& rotation); + static NzMatrix4 Scale(const NzVector3& scale); + static NzMatrix4 Translate(const NzVector3& translation); + static NzMatrix4 Zero(); + + struct SharedMatrix + { + T m11, m12, m13, m14, + m21, m22, m23, m24, + m31, m32, m33, m34, + m41, m42, m43, m44; + + unsigned short refCount = 1; + NazaraMutex(mutex) + }; + + private: + void EnsureOwnership(); + void ReleaseMatrix(); + + SharedMatrix* m_sharedMatrix = nullptr; +}; + +template std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix); + +template NzMatrix4 operator*(T scale, const NzMatrix4& matrix); + +typedef NzMatrix4 NzMatrix4d; +typedef NzMatrix4 NzMatrix4f; + +#include + +#endif // NAZARA_MATRIX4_HPP diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 0e4d6b230..5dbad7f42 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -1,942 +1,942 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) - -#define F(a) static_cast(a) - -template -NzMatrix4::NzMatrix4() -{ -} - -template -NzMatrix4::NzMatrix4(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44) -{ - Set(r11, r12, r13, r14, - r21, r22, r23, r24, - r31, r32, r33, r34, - r41, r42, r43, r44); -} - -template -NzMatrix4::NzMatrix4(const T matrix[16]) -{ - Set(matrix); -} - -template -template -NzMatrix4::NzMatrix4(const NzMatrix4& matrix) -{ - Set(matrix); -} - -template -NzMatrix4::NzMatrix4(const NzMatrix4& matrix) -{ - Set(matrix); -} - -template -NzMatrix4::NzMatrix4(NzMatrix4&& matrix) noexcept -{ - Set(matrix); -} - -template -NzMatrix4::~NzMatrix4() -{ - ReleaseMatrix(); -} - -template -NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& matrix) const -{ - return Concatenate(*this, matrix); -} - -template -NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& matrix) const -{ - return ConcatenateAffine(*this, matrix); -} - -template -T NzMatrix4::GetDeterminant() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return F(0.0); - } - #endif - - T A = m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24); - T B = m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14); - T C = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); - T D = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); - - return m_sharedMatrix->m11*A - m_sharedMatrix->m21*B + m_sharedMatrix->m31*C - m_sharedMatrix->m41*D; -} - -template -NzMatrix4 NzMatrix4::GetInverse() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzMatrix4(); - } - #endif - - T det = GetDeterminant(); - if (!NzNumberEquals(det, F(0.0))) - { - return NzMatrix4((m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24)) / det, - -(m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14)) / det, - (m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, - -(m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, - - -(m_sharedMatrix->m21*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m33) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31)) / det, - - (m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det, - - -(m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, - -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, - (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det); - } - else - { - NazaraError("Matrix has no inverse"); - - return Identity(); - } -} - -template -NzVector3 NzMatrix4::GetScale() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzVector3(); - } - #endif - - return NzVector3(std::sqrt(m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31), - std::sqrt(m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32), - std::sqrt(m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33)); -} - -template -NzVector3 NzMatrix4::GetTranslation() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzVector3(); - } - #endif - - return NzVector3(m_sharedMatrix->m41, m_sharedMatrix->m42, m_sharedMatrix->m43); -} - -template -NzMatrix4 NzMatrix4::GetTransposed() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return NzMatrix4(); - } - #endif - - return NzMatrix4(m_sharedMatrix->m11, m_sharedMatrix->m21, m_sharedMatrix->m31, m_sharedMatrix->m41, - m_sharedMatrix->m12, m_sharedMatrix->m22, m_sharedMatrix->m32, m_sharedMatrix->m42, - m_sharedMatrix->m13, m_sharedMatrix->m23, m_sharedMatrix->m33, m_sharedMatrix->m43, - m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34, m_sharedMatrix->m44); -} - -template -bool NzMatrix4::HasNegativeScale() const -{ - return GetDeterminant() < F(0.0); -} - -template -bool NzMatrix4::HasScale() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return false; - } - #endif - - T t = m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31; - if (!NzNumberEquals(t, F(1.0))) - return true; - - t = m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32; - if (!NzNumberEquals(t, F(1.0))) - return true; - - t = m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33; - if (!NzNumberEquals(t, F(1.0))) - return true; - - return false; -} - -template -bool NzMatrix4::IsAffine() const -{ - #if NAZARA_MATH_SAFE - if (!IsDefined()) - { - NazaraError("Matrix not defined"); - return false; - } - #endif - - return NzNumberEquals(m_sharedMatrix->m14, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m24, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m34, F(0.0)) && - NzNumberEquals(m_sharedMatrix->m44, F(1.0)); -} - -template -bool NzMatrix4::IsDefined() const -{ - return m_sharedMatrix != nullptr; -} - -template -void NzMatrix4::MakeIdentity() -{ - Set(F(1.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(1.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzMatrix4::MakeOrtho(T left, T top, T width, T height, T zNear, T zFar) -{ - // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204941(v=vs.85).aspx - Set(F(2.0)/(width-left), F(0.0), F(0.0), -(width+left)/(width-left), - F(0.0), F(2.0)/(top-height), F(0.0), -(top+height)/(top-height), - F(0.0), F(0.0), F(-2.0)/(zFar-zNear), -(zFar+zNear)/(zFar-zNear), - F(0.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzMatrix4::MakeLookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up) -{ - NzVector3 f = NzVector3::Normalize(target - eye); - NzVector3 u(up.GetNormal()); - NzVector3 s = NzVector3::Normalize(f.CrossProduct(u)); - u = s.CrossProduct(f); - - Set(s.x, u.x, -f.x, T(0.0), - s.y, u.y, -f.y, T(0.0), - s.z, u.z, -f.z, T(0.0), - -s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0)); -} - -template -void NzMatrix4::MakePerspective(T angle, T ratio, T zNear, T zFar) -{ - // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204944(v=vs.85).aspx - #if NAZARA_MATH_ANGLE_RADIAN - angle /= F(2.0); - #else - angle = NzDegreeToRadian(angle/F(2.0)); - #endif - - T yScale = F(1.0) / std::tan(angle); - - Set(yScale / ratio, F(0.0), F(0.0), F(0.0), - F(0.0), yScale, F(0.0), F(0.0), - F(0.0), F(0.0), zFar / (zNear-zFar), F(-1.0), - F(0.0), F(0.0), (zNear*zFar) / (zNear-zFar), F(0.0)); -} - -template -void NzMatrix4::MakeRotation(const NzQuaternion& rotation) -{ - // http://www.flipcode.com/documents/matrfaq.html#Q54 -/* - | 2 2 | - | 1 - 2Y - 2Z 2XY + 2ZW 2XZ - 2YW | - | | - | 2 2 | - M = | 2XY - 2ZW 1 - 2X - 2Z 2YZ + 2XW | - | | - | 2 2 | - | 2XZ + 2YW 2YZ - 2XW 1 - 2X - 2Y | - | | -*/ - ///FIXME: À corriger (Rotation quaternino != rotation matricielle) - Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, - F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, - F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, - F(0.0), - - F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, - F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, - F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, - F(0.0), - - F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, - F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, - F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, - F(0.0), - - F(0.0), - F(0.0), - F(0.0), - F(1.0)); -} - -template -void NzMatrix4::MakeScale(const NzVector3& scale) -{ - Set(scale.x, F(0.0), F(0.0), F(0.0), - F(0.0), scale.y, F(0.0), F(0.0), - F(0.0), F(0.0), scale.z, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzMatrix4::MakeTranslation(const NzVector3& translation) -{ - Set(F(1.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(1.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0), F(0.0), - translation.x, translation.y, translation.z, F(1.0)); -} - -template -void NzMatrix4::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0)); -} - -template -void NzMatrix4::Set(T r11, T r12, T r13, T r14, - T r21, T r22, T r23, T r24, - T r31, T r32, T r33, T r34, - T r41, T r42, T r43, T r44) -{ - EnsureOwnership(); - - m_sharedMatrix->m11 = r11; - m_sharedMatrix->m12 = r12; - m_sharedMatrix->m13 = r13; - m_sharedMatrix->m14 = r14; - m_sharedMatrix->m21 = r21; - m_sharedMatrix->m22 = r22; - m_sharedMatrix->m23 = r23; - m_sharedMatrix->m24 = r24; - m_sharedMatrix->m31 = r31; - m_sharedMatrix->m32 = r32; - m_sharedMatrix->m33 = r33; - m_sharedMatrix->m34 = r34; - m_sharedMatrix->m41 = r41; - m_sharedMatrix->m42 = r42; - m_sharedMatrix->m43 = r43; - m_sharedMatrix->m44 = r44; -} - -template -void NzMatrix4::Set(const T matrix[16]) -{ - EnsureOwnership(); - - // Ici nous sommes certains de la continuité des éléments en mémoire - std::memcpy(&m_sharedMatrix->m11, matrix, 16*sizeof(T)); -} - -template -void NzMatrix4::Set(const NzMatrix4& matrix) -{ - ReleaseMatrix(); - - m_sharedMatrix = matrix.m_sharedMatrix; - if (m_sharedMatrix) - { - NazaraMutexLock(m_sharedMatrix->mutex); - m_sharedMatrix->refCount++; - NazaraMutexUnlock(m_sharedMatrix->mutex); - } -} - -template -void NzMatrix4::Set(NzMatrix4&& matrix) -{ - std::swap(m_sharedMatrix, matrix.m_sharedMatrix); -} - -template -template -void NzMatrix4::Set(const NzMatrix4& matrix) -{ - Set(F(matrix.m_sharedMatrix->m11), F(matrix.m_sharedMatrix->m12), F(matrix.m_sharedMatrix->m13), F(matrix.m_sharedMatrix->m14), - F(matrix.m_sharedMatrix->m21), F(matrix.m_sharedMatrix->m22), F(matrix.m_sharedMatrix->m23), F(matrix.m_sharedMatrix->m24), - F(matrix.m_sharedMatrix->m31), F(matrix.m_sharedMatrix->m32), F(matrix.m_sharedMatrix->m33), F(matrix.m_sharedMatrix->m34), - F(matrix.m_sharedMatrix->m41), F(matrix.m_sharedMatrix->m42), F(matrix.m_sharedMatrix->m43), F(matrix.m_sharedMatrix->m44)); -} - -template -void NzMatrix4::SetRotation(const NzQuaternion& rotation) -{ - // http://www.flipcode.com/documents/matrfaq.html#Q54 - EnsureOwnership(); - - m_sharedMatrix->m11 = F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z; - m_sharedMatrix->m22 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z; - m_sharedMatrix->m33 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y; - - m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; - m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; - m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; - m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; - m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; - m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; -} - -template -void NzMatrix4::SetScale(const NzVector3& scale) -{ - EnsureOwnership(); - - m_sharedMatrix->m11 = scale.x; - m_sharedMatrix->m22 = scale.y; - m_sharedMatrix->m33 = scale.z; -} - -template -void NzMatrix4::SetTranslation(const NzVector3& translation) -{ - EnsureOwnership(); - - m_sharedMatrix->m41 = translation.x; - m_sharedMatrix->m42 = translation.y; - m_sharedMatrix->m43 = translation.z; - m_sharedMatrix->m44 = F(1.0); -} - -template -NzString NzMatrix4::ToString() const -{ - if (!m_sharedMatrix) - return "Matrix4(undefined)"; - - NzStringStream ss; - return ss << "Matrix4(" << m_sharedMatrix->m11 << ", " << m_sharedMatrix->m12 << ", " << m_sharedMatrix->m13 << ", " << m_sharedMatrix->m14 << ",\n" - << " " << m_sharedMatrix->m21 << ", " << m_sharedMatrix->m22 << ", " << m_sharedMatrix->m23 << ", " << m_sharedMatrix->m24 << ",\n" - << " " << m_sharedMatrix->m31 << ", " << m_sharedMatrix->m32 << ", " << m_sharedMatrix->m33 << ", " << m_sharedMatrix->m34 << ",\n" - << " " << m_sharedMatrix->m41 << ", " << m_sharedMatrix->m42 << ", " << m_sharedMatrix->m43 << ", " << m_sharedMatrix->m44 << ')'; -} - -template -NzVector2 NzMatrix4::Transform(const NzVector2& vector, T z, T w) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return vector; - } - #endif - - return NzVector2(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*z + m_sharedMatrix->m14*w, - m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*z + m_sharedMatrix->m24*w); -} - -template -NzVector3 NzMatrix4::Transform(const NzVector3& vector, T w) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return vector; - } - #endif - - return NzVector3(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*w, - m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*w, - m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*w); -} - -template -NzVector4 NzMatrix4::Transform(const NzVector4& vector) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return vector; - } - #endif - - return NzVector4(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*vector.w, - m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*vector.w, - m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*vector.w, - m_sharedMatrix->m41*vector.x + m_sharedMatrix->m42*vector.y + m_sharedMatrix->m43*vector.z + m_sharedMatrix->m44*vector.w); -} - -template -NzMatrix4& NzMatrix4::Transpose() -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - std::swap(m_sharedMatrix->m12, m_sharedMatrix->m21); - std::swap(m_sharedMatrix->m13, m_sharedMatrix->m31); - std::swap(m_sharedMatrix->m14, m_sharedMatrix->m41); - std::swap(m_sharedMatrix->m23, m_sharedMatrix->m32); - std::swap(m_sharedMatrix->m24, m_sharedMatrix->m42); - std::swap(m_sharedMatrix->m34, m_sharedMatrix->m43); - - return *this; -} - -template -NzMatrix4::operator NzString() const -{ - return ToString(); -} - -template -NzMatrix4::operator T*() -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return nullptr; - } - #endif - - EnsureOwnership(); - - return &m_sharedMatrix->m11; -} - -template -NzMatrix4::operator const T*() const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return nullptr; - } - #endif - - return &m_sharedMatrix->m11; -} - -template -T& NzMatrix4::operator()(unsigned int x, unsigned int y) -{ - #if NAZARA_MATH_SAFE - if (x > 3 || y > 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - EnsureOwnership(); - - return (&m_sharedMatrix->m11)[y*4+x]; -} - -template -const T& NzMatrix4::operator()(unsigned int x, unsigned int y) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - throw std::runtime_error("Tried to access element of Matrix not defined"); - } - - if (x > 3 || y > 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - return (&m_sharedMatrix->m11)[y*4+x]; -} - -template -NzMatrix4& NzMatrix4::operator=(const NzMatrix4& matrix) -{ - Set(matrix); - - return *this; -} - -template -NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) noexcept -{ - Set(matrix); - - return *this; -} - -template -NzMatrix4 NzMatrix4::operator*(const NzMatrix4& matrix) const -{ - return Concatenate(matrix); -} - -template -NzVector2 NzMatrix4::operator*(const NzVector2& vector) const -{ - return Transform(vector); -} - -template -NzVector3 NzMatrix4::operator*(const NzVector3& vector) const -{ - return Transform(vector); -} - -template -NzVector4 NzMatrix4::operator*(const NzVector4& vector) const -{ - return Transform(vector); -} - -template -NzMatrix4 NzMatrix4::operator*(T scalar) const -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - return NzMatrix4(m_sharedMatrix->m11 * scalar, m_sharedMatrix->m12 * scalar, m_sharedMatrix->m13 * scalar, m_sharedMatrix->m14 * scalar, - m_sharedMatrix->m21 * scalar, m_sharedMatrix->m22 * scalar, m_sharedMatrix->m23 * scalar, m_sharedMatrix->m24 * scalar, - m_sharedMatrix->m31 * scalar, m_sharedMatrix->m32 * scalar, m_sharedMatrix->m33 * scalar, m_sharedMatrix->m34 * scalar, - m_sharedMatrix->m41 * scalar, m_sharedMatrix->m42 * scalar, m_sharedMatrix->m43 * scalar, m_sharedMatrix->m44 * scalar); -} - -template -NzMatrix4& NzMatrix4::operator*=(const NzMatrix4& matrix) -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - Set(Concatenate(*this, matrix)); - - return *this; -} - -template -NzMatrix4& NzMatrix4::operator*=(T scalar) -{ - #if NAZARA_MATH_SAFE - if (!m_sharedMatrix) - { - NazaraError("Matrix not defined"); - return *this; - } - #endif - - m_sharedMatrix->m11 *= scalar; - m_sharedMatrix->m12 *= scalar; - m_sharedMatrix->m13 *= scalar; - m_sharedMatrix->m14 *= scalar; - m_sharedMatrix->m21 *= scalar; - m_sharedMatrix->m22 *= scalar; - m_sharedMatrix->m23 *= scalar; - m_sharedMatrix->m24 *= scalar; - m_sharedMatrix->m31 *= scalar; - m_sharedMatrix->m32 *= scalar; - m_sharedMatrix->m33 *= scalar; - m_sharedMatrix->m34 *= scalar; - m_sharedMatrix->m41 *= scalar; - m_sharedMatrix->m42 *= scalar; - m_sharedMatrix->m43 *= scalar; - m_sharedMatrix->m44 *= scalar; - - return *this; -} - -template -NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) -{ - #if NAZARA_MATH_SAFE - if (!m1.IsDefined()) - { - NazaraError("First matrix not defined"); - return NzMatrix4(); - } - - if (!m2.IsDefined()) - { - NazaraError("Second matrix not defined"); - return NzMatrix4(); - } - #endif - - #if NAZARA_MATH_MATRIX4_CHECK_AFFINE - if (m1.IsAffine() && m2.IsAffine()) - return ConcatenateAffine(m1, m2); - #endif - - return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m44, - - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m44, - - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m44, - - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m43, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m44); -} - -template -NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2) -{ - #if NAZARA_MATH_SAFE - if (!m1.IsDefined()) - { - NazaraError("First matrix not defined"); - return NzMatrix4(); - } - - if (!m2.IsDefined()) - { - NazaraError("Second matrix not defined"); - return NzMatrix4(); - } - #endif - - #ifdef NAZARA_DEBUG - if (!m1.IsAffine()) - { - NazaraError("First matrix not affine"); - return NzMatrix4(); - } - - if (!m2.IsAffine()) - { - NazaraError("Second matrix not affine"); - return NzMatrix4(); - } - #endif - - return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, - F(0.0), - - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, - F(0.0), - - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, - m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, - F(0.0), - - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m2.m_sharedMatrix->m41, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m2.m_sharedMatrix->m42, - m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m2.m_sharedMatrix->m43, - F(1.0)); -} - -template -NzMatrix4 NzMatrix4::Identity() -{ - NzMatrix4 matrix; - matrix.MakeIdentity(); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::LookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up) -{ - NzMatrix4 matrix; - matrix.MakeLookAt(eye, target, up); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Ortho(T left, T top, T width, T height, T zNear, T zFar) -{ - NzMatrix4 matrix; - matrix.MakeOrtho(left, top, width, height, zNear, zFar); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Perspective(T angle, T ratio, T zNear, T zFar) -{ - NzMatrix4 matrix; - matrix.MakePerspective(angle, ratio, zNear, zFar); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Rotate(const NzQuaternion& rotation) -{ - NzMatrix4 matrix; - matrix.MakeRotation(rotation); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Scale(const NzVector3& scale) -{ - NzMatrix4 matrix; - matrix.MakeScale(scale); - - return matrix; -} - -template -NzMatrix4 NzMatrix4::Translate(const NzVector3& translation) -{ - NzMatrix4 mat; - mat.MakeTranslation(translation); - - return mat; -} - -template -NzMatrix4 NzMatrix4::Zero() -{ - NzMatrix4 matrix; - matrix.MakeZero(); - - return matrix; -} - -template -std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix) -{ - return out << matrix.ToString(); -} - -template -NzMatrix4 operator*(T scale, const NzMatrix4& matrix) -{ - return matrix * scale; -} - -template -void NzMatrix4::EnsureOwnership() -{ - if (m_sharedMatrix) - { - NazaraLock(m_sharedMatrix->mutex); - if (m_sharedMatrix->refCount > 1) - { - m_sharedMatrix->refCount--; - - SharedMatrix* sharedMatrix = new SharedMatrix; - std::memcpy(&sharedMatrix->m11, &m_sharedMatrix->m11, 16*sizeof(T)); - } - } - else - m_sharedMatrix = new SharedMatrix; -} - -template -void NzMatrix4::ReleaseMatrix() -{ - if (!m_sharedMatrix) - return; - - NazaraMutexLock(m_sharedMatrix->mutex); - bool freeSharedMatrix = (--m_sharedMatrix->refCount == 0); - NazaraMutexUnlock(m_sharedMatrix->mutex); - - if (freeSharedMatrix) - delete m_sharedMatrix; - - m_sharedMatrix = nullptr; -} - -#undef F - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +///FIXME: Le MLT détecte de faux-leaks ici (Problème lié aux inline ?) + +#define F(a) static_cast(a) + +template +NzMatrix4::NzMatrix4() +{ +} + +template +NzMatrix4::NzMatrix4(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44) +{ + Set(r11, r12, r13, r14, + r21, r22, r23, r24, + r31, r32, r33, r34, + r41, r42, r43, r44); +} + +template +NzMatrix4::NzMatrix4(const T matrix[16]) +{ + Set(matrix); +} + +template +template +NzMatrix4::NzMatrix4(const NzMatrix4& matrix) +{ + Set(matrix); +} + +template +NzMatrix4::NzMatrix4(const NzMatrix4& matrix) +{ + Set(matrix); +} + +template +NzMatrix4::NzMatrix4(NzMatrix4&& matrix) noexcept +{ + Set(matrix); +} + +template +NzMatrix4::~NzMatrix4() +{ + ReleaseMatrix(); +} + +template +NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& matrix) const +{ + return Concatenate(*this, matrix); +} + +template +NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& matrix) const +{ + return ConcatenateAffine(*this, matrix); +} + +template +T NzMatrix4::GetDeterminant() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return F(0.0); + } + #endif + + T A = m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24); + T B = m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14); + T C = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); + T D = m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14); + + return m_sharedMatrix->m11*A - m_sharedMatrix->m21*B + m_sharedMatrix->m31*C - m_sharedMatrix->m41*D; +} + +template +NzMatrix4 NzMatrix4::GetInverse() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzMatrix4(); + } + #endif + + T det = GetDeterminant(); + if (!NzNumberEquals(det, F(0.0))) + { + return NzMatrix4((m_sharedMatrix->m22*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m32*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) + m_sharedMatrix->m42*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24)) / det, + -(m_sharedMatrix->m12*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m34) - m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14)) / det, + (m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m44 - m_sharedMatrix->m43*m_sharedMatrix->m14) + m_sharedMatrix->m42*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, + -(m_sharedMatrix->m12*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m24) - m_sharedMatrix->m22*(m_sharedMatrix->m13*m_sharedMatrix->m34 - m_sharedMatrix->m33*m_sharedMatrix->m14) + m_sharedMatrix->m32*(m_sharedMatrix->m13*m_sharedMatrix->m24 - m_sharedMatrix->m23*m_sharedMatrix->m14)) / det, + + -(m_sharedMatrix->m21*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m33*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m43) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m23*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m33) - m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31)) / det, + + (m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m24*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m44 - m_sharedMatrix->m34*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m44 - m_sharedMatrix->m24*m_sharedMatrix->m41) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m34 - m_sharedMatrix->m24*m_sharedMatrix->m31) + m_sharedMatrix->m14*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det, + + -(m_sharedMatrix->m21*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m22*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m23*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m32*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m31*m_sharedMatrix->m43 - m_sharedMatrix->m33*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m31*m_sharedMatrix->m42 - m_sharedMatrix->m32*m_sharedMatrix->m41)) / det, + -(m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m42) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m43 - m_sharedMatrix->m23*m_sharedMatrix->m41) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m42 - m_sharedMatrix->m22*m_sharedMatrix->m41)) / det, + (m_sharedMatrix->m11*(m_sharedMatrix->m22*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m32) - m_sharedMatrix->m12*(m_sharedMatrix->m21*m_sharedMatrix->m33 - m_sharedMatrix->m23*m_sharedMatrix->m31) + m_sharedMatrix->m13*(m_sharedMatrix->m21*m_sharedMatrix->m32 - m_sharedMatrix->m22*m_sharedMatrix->m31)) / det); + } + else + { + NazaraError("Matrix has no inverse"); + + return Identity(); + } +} + +template +NzVector3 NzMatrix4::GetScale() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzVector3(); + } + #endif + + return NzVector3(std::sqrt(m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31), + std::sqrt(m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32), + std::sqrt(m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33)); +} + +template +NzVector3 NzMatrix4::GetTranslation() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzVector3(); + } + #endif + + return NzVector3(m_sharedMatrix->m41, m_sharedMatrix->m42, m_sharedMatrix->m43); +} + +template +NzMatrix4 NzMatrix4::GetTransposed() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return NzMatrix4(); + } + #endif + + return NzMatrix4(m_sharedMatrix->m11, m_sharedMatrix->m21, m_sharedMatrix->m31, m_sharedMatrix->m41, + m_sharedMatrix->m12, m_sharedMatrix->m22, m_sharedMatrix->m32, m_sharedMatrix->m42, + m_sharedMatrix->m13, m_sharedMatrix->m23, m_sharedMatrix->m33, m_sharedMatrix->m43, + m_sharedMatrix->m14, m_sharedMatrix->m24, m_sharedMatrix->m34, m_sharedMatrix->m44); +} + +template +bool NzMatrix4::HasNegativeScale() const +{ + return GetDeterminant() < F(0.0); +} + +template +bool NzMatrix4::HasScale() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return false; + } + #endif + + T t = m_sharedMatrix->m11*m_sharedMatrix->m11 + m_sharedMatrix->m21*m_sharedMatrix->m21 + m_sharedMatrix->m31*m_sharedMatrix->m31; + if (!NzNumberEquals(t, F(1.0))) + return true; + + t = m_sharedMatrix->m12*m_sharedMatrix->m12 + m_sharedMatrix->m22*m_sharedMatrix->m22 + m_sharedMatrix->m32*m_sharedMatrix->m32; + if (!NzNumberEquals(t, F(1.0))) + return true; + + t = m_sharedMatrix->m13*m_sharedMatrix->m13 + m_sharedMatrix->m23*m_sharedMatrix->m23 + m_sharedMatrix->m33*m_sharedMatrix->m33; + if (!NzNumberEquals(t, F(1.0))) + return true; + + return false; +} + +template +bool NzMatrix4::IsAffine() const +{ + #if NAZARA_MATH_SAFE + if (!IsDefined()) + { + NazaraError("Matrix not defined"); + return false; + } + #endif + + return NzNumberEquals(m_sharedMatrix->m14, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m24, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m34, F(0.0)) && + NzNumberEquals(m_sharedMatrix->m44, F(1.0)); +} + +template +bool NzMatrix4::IsDefined() const +{ + return m_sharedMatrix != nullptr; +} + +template +void NzMatrix4::MakeIdentity() +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(1.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(1.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeOrtho(T left, T top, T width, T height, T zNear, T zFar) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204941(v=vs.85).aspx + Set(F(2.0)/(width-left), F(0.0), F(0.0), -(width+left)/(width-left), + F(0.0), F(2.0)/(top-height), F(0.0), -(top+height)/(top-height), + F(0.0), F(0.0), F(-2.0)/(zFar-zNear), -(zFar+zNear)/(zFar-zNear), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeLookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up) +{ + NzVector3 f = NzVector3::Normalize(target - eye); + NzVector3 u(up.GetNormal()); + NzVector3 s = NzVector3::Normalize(f.CrossProduct(u)); + u = s.CrossProduct(f); + + Set(s.x, u.x, -f.x, T(0.0), + s.y, u.y, -f.y, T(0.0), + s.z, u.z, -f.z, T(0.0), + -s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0)); +} + +template +void NzMatrix4::MakePerspective(T angle, T ratio, T zNear, T zFar) +{ + // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204944(v=vs.85).aspx + #if NAZARA_MATH_ANGLE_RADIAN + angle /= F(2.0); + #else + angle = NzDegreeToRadian(angle/F(2.0)); + #endif + + T yScale = F(1.0) / std::tan(angle); + + Set(yScale / ratio, F(0.0), F(0.0), F(0.0), + F(0.0), yScale, F(0.0), F(0.0), + F(0.0), F(0.0), zFar / (zNear-zFar), F(-1.0), + F(0.0), F(0.0), (zNear*zFar) / (zNear-zFar), F(0.0)); +} + +template +void NzMatrix4::MakeRotation(const NzQuaternion& rotation) +{ + // http://www.flipcode.com/documents/matrfaq.html#Q54 +/* + | 2 2 | + | 1 - 2Y - 2Z 2XY + 2ZW 2XZ - 2YW | + | | + | 2 2 | + M = | 2XY - 2ZW 1 - 2X - 2Z 2YZ + 2XW | + | | + | 2 2 | + | 2XZ + 2YW 2YZ - 2XW 1 - 2X - 2Y | + | | +*/ + ///FIXME: À corriger (Rotation quaternino != rotation matricielle) + Set(F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z, + F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w, + F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w, + F(0.0), + + F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w, + F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z, + F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w, + F(0.0), + + F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w, + F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w, + F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y, + F(0.0), + + F(0.0), + F(0.0), + F(0.0), + F(1.0)); +} + +template +void NzMatrix4::MakeScale(const NzVector3& scale) +{ + Set(scale.x, F(0.0), F(0.0), F(0.0), + F(0.0), scale.y, F(0.0), F(0.0), + F(0.0), F(0.0), scale.z, F(0.0), + F(0.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzMatrix4::MakeTranslation(const NzVector3& translation) +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(1.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(1.0), F(0.0), + translation.x, translation.y, translation.z, F(1.0)); +} + +template +void NzMatrix4::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0), + F(0.0), F(0.0), F(0.0), F(0.0)); +} + +template +void NzMatrix4::Set(T r11, T r12, T r13, T r14, + T r21, T r22, T r23, T r24, + T r31, T r32, T r33, T r34, + T r41, T r42, T r43, T r44) +{ + EnsureOwnership(); + + m_sharedMatrix->m11 = r11; + m_sharedMatrix->m12 = r12; + m_sharedMatrix->m13 = r13; + m_sharedMatrix->m14 = r14; + m_sharedMatrix->m21 = r21; + m_sharedMatrix->m22 = r22; + m_sharedMatrix->m23 = r23; + m_sharedMatrix->m24 = r24; + m_sharedMatrix->m31 = r31; + m_sharedMatrix->m32 = r32; + m_sharedMatrix->m33 = r33; + m_sharedMatrix->m34 = r34; + m_sharedMatrix->m41 = r41; + m_sharedMatrix->m42 = r42; + m_sharedMatrix->m43 = r43; + m_sharedMatrix->m44 = r44; +} + +template +void NzMatrix4::Set(const T matrix[16]) +{ + EnsureOwnership(); + + // Ici nous sommes certains de la continuité des éléments en mémoire + std::memcpy(&m_sharedMatrix->m11, matrix, 16*sizeof(T)); +} + +template +void NzMatrix4::Set(const NzMatrix4& matrix) +{ + ReleaseMatrix(); + + m_sharedMatrix = matrix.m_sharedMatrix; + if (m_sharedMatrix) + { + NazaraMutexLock(m_sharedMatrix->mutex); + m_sharedMatrix->refCount++; + NazaraMutexUnlock(m_sharedMatrix->mutex); + } +} + +template +void NzMatrix4::Set(NzMatrix4&& matrix) +{ + std::swap(m_sharedMatrix, matrix.m_sharedMatrix); +} + +template +template +void NzMatrix4::Set(const NzMatrix4& matrix) +{ + Set(F(matrix.m_sharedMatrix->m11), F(matrix.m_sharedMatrix->m12), F(matrix.m_sharedMatrix->m13), F(matrix.m_sharedMatrix->m14), + F(matrix.m_sharedMatrix->m21), F(matrix.m_sharedMatrix->m22), F(matrix.m_sharedMatrix->m23), F(matrix.m_sharedMatrix->m24), + F(matrix.m_sharedMatrix->m31), F(matrix.m_sharedMatrix->m32), F(matrix.m_sharedMatrix->m33), F(matrix.m_sharedMatrix->m34), + F(matrix.m_sharedMatrix->m41), F(matrix.m_sharedMatrix->m42), F(matrix.m_sharedMatrix->m43), F(matrix.m_sharedMatrix->m44)); +} + +template +void NzMatrix4::SetRotation(const NzQuaternion& rotation) +{ + // http://www.flipcode.com/documents/matrfaq.html#Q54 + EnsureOwnership(); + + m_sharedMatrix->m11 = F(1.0) - F(2.0)*rotation.y*rotation.y - F(2.0)*rotation.z*rotation.z; + m_sharedMatrix->m22 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.z*rotation.z; + m_sharedMatrix->m33 = F(1.0) - F(2.0)*rotation.x*rotation.x - F(2.0)*rotation.y*rotation.y; + + m_sharedMatrix->m12 = F(2.0)*rotation.x*rotation.y - F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m13 = F(2.0)*rotation.x*rotation.z + F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m21 = F(2.0)*rotation.x*rotation.y + F(2.0)*rotation.z*rotation.w; + m_sharedMatrix->m23 = F(2.0)*rotation.y*rotation.z - F(2.0)*rotation.x*rotation.w; + m_sharedMatrix->m31 = F(2.0)*rotation.x*rotation.z - F(2.0)*rotation.y*rotation.w; + m_sharedMatrix->m32 = F(2.0)*rotation.y*rotation.z + F(2.0)*rotation.x*rotation.w; +} + +template +void NzMatrix4::SetScale(const NzVector3& scale) +{ + EnsureOwnership(); + + m_sharedMatrix->m11 = scale.x; + m_sharedMatrix->m22 = scale.y; + m_sharedMatrix->m33 = scale.z; +} + +template +void NzMatrix4::SetTranslation(const NzVector3& translation) +{ + EnsureOwnership(); + + m_sharedMatrix->m41 = translation.x; + m_sharedMatrix->m42 = translation.y; + m_sharedMatrix->m43 = translation.z; + m_sharedMatrix->m44 = F(1.0); +} + +template +NzString NzMatrix4::ToString() const +{ + if (!m_sharedMatrix) + return "Matrix4(undefined)"; + + NzStringStream ss; + return ss << "Matrix4(" << m_sharedMatrix->m11 << ", " << m_sharedMatrix->m12 << ", " << m_sharedMatrix->m13 << ", " << m_sharedMatrix->m14 << ",\n" + << " " << m_sharedMatrix->m21 << ", " << m_sharedMatrix->m22 << ", " << m_sharedMatrix->m23 << ", " << m_sharedMatrix->m24 << ",\n" + << " " << m_sharedMatrix->m31 << ", " << m_sharedMatrix->m32 << ", " << m_sharedMatrix->m33 << ", " << m_sharedMatrix->m34 << ",\n" + << " " << m_sharedMatrix->m41 << ", " << m_sharedMatrix->m42 << ", " << m_sharedMatrix->m43 << ", " << m_sharedMatrix->m44 << ')'; +} + +template +NzVector2 NzMatrix4::Transform(const NzVector2& vector, T z, T w) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return vector; + } + #endif + + return NzVector2(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*z + m_sharedMatrix->m14*w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*z + m_sharedMatrix->m24*w); +} + +template +NzVector3 NzMatrix4::Transform(const NzVector3& vector, T w) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return vector; + } + #endif + + return NzVector3(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*w, + m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*w); +} + +template +NzVector4 NzMatrix4::Transform(const NzVector4& vector) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return vector; + } + #endif + + return NzVector4(m_sharedMatrix->m11*vector.x + m_sharedMatrix->m12*vector.y + m_sharedMatrix->m13*vector.z + m_sharedMatrix->m14*vector.w, + m_sharedMatrix->m21*vector.x + m_sharedMatrix->m22*vector.y + m_sharedMatrix->m23*vector.z + m_sharedMatrix->m24*vector.w, + m_sharedMatrix->m31*vector.x + m_sharedMatrix->m32*vector.y + m_sharedMatrix->m33*vector.z + m_sharedMatrix->m34*vector.w, + m_sharedMatrix->m41*vector.x + m_sharedMatrix->m42*vector.y + m_sharedMatrix->m43*vector.z + m_sharedMatrix->m44*vector.w); +} + +template +NzMatrix4& NzMatrix4::Transpose() +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + std::swap(m_sharedMatrix->m12, m_sharedMatrix->m21); + std::swap(m_sharedMatrix->m13, m_sharedMatrix->m31); + std::swap(m_sharedMatrix->m14, m_sharedMatrix->m41); + std::swap(m_sharedMatrix->m23, m_sharedMatrix->m32); + std::swap(m_sharedMatrix->m24, m_sharedMatrix->m42); + std::swap(m_sharedMatrix->m34, m_sharedMatrix->m43); + + return *this; +} + +template +NzMatrix4::operator NzString() const +{ + return ToString(); +} + +template +NzMatrix4::operator T*() +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return nullptr; + } + #endif + + EnsureOwnership(); + + return &m_sharedMatrix->m11; +} + +template +NzMatrix4::operator const T*() const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return nullptr; + } + #endif + + return &m_sharedMatrix->m11; +} + +template +T& NzMatrix4::operator()(unsigned int x, unsigned int y) +{ + #if NAZARA_MATH_SAFE + if (x > 3 || y > 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + EnsureOwnership(); + + return (&m_sharedMatrix->m11)[y*4+x]; +} + +template +const T& NzMatrix4::operator()(unsigned int x, unsigned int y) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + throw std::runtime_error("Tried to access element of Matrix not defined"); + } + + if (x > 3 || y > 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + return (&m_sharedMatrix->m11)[y*4+x]; +} + +template +NzMatrix4& NzMatrix4::operator=(const NzMatrix4& matrix) +{ + Set(matrix); + + return *this; +} + +template +NzMatrix4& NzMatrix4::operator=(NzMatrix4&& matrix) noexcept +{ + Set(matrix); + + return *this; +} + +template +NzMatrix4 NzMatrix4::operator*(const NzMatrix4& matrix) const +{ + return Concatenate(matrix); +} + +template +NzVector2 NzMatrix4::operator*(const NzVector2& vector) const +{ + return Transform(vector); +} + +template +NzVector3 NzMatrix4::operator*(const NzVector3& vector) const +{ + return Transform(vector); +} + +template +NzVector4 NzMatrix4::operator*(const NzVector4& vector) const +{ + return Transform(vector); +} + +template +NzMatrix4 NzMatrix4::operator*(T scalar) const +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + return NzMatrix4(m_sharedMatrix->m11 * scalar, m_sharedMatrix->m12 * scalar, m_sharedMatrix->m13 * scalar, m_sharedMatrix->m14 * scalar, + m_sharedMatrix->m21 * scalar, m_sharedMatrix->m22 * scalar, m_sharedMatrix->m23 * scalar, m_sharedMatrix->m24 * scalar, + m_sharedMatrix->m31 * scalar, m_sharedMatrix->m32 * scalar, m_sharedMatrix->m33 * scalar, m_sharedMatrix->m34 * scalar, + m_sharedMatrix->m41 * scalar, m_sharedMatrix->m42 * scalar, m_sharedMatrix->m43 * scalar, m_sharedMatrix->m44 * scalar); +} + +template +NzMatrix4& NzMatrix4::operator*=(const NzMatrix4& matrix) +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + Set(Concatenate(*this, matrix)); + + return *this; +} + +template +NzMatrix4& NzMatrix4::operator*=(T scalar) +{ + #if NAZARA_MATH_SAFE + if (!m_sharedMatrix) + { + NazaraError("Matrix not defined"); + return *this; + } + #endif + + m_sharedMatrix->m11 *= scalar; + m_sharedMatrix->m12 *= scalar; + m_sharedMatrix->m13 *= scalar; + m_sharedMatrix->m14 *= scalar; + m_sharedMatrix->m21 *= scalar; + m_sharedMatrix->m22 *= scalar; + m_sharedMatrix->m23 *= scalar; + m_sharedMatrix->m24 *= scalar; + m_sharedMatrix->m31 *= scalar; + m_sharedMatrix->m32 *= scalar; + m_sharedMatrix->m33 *= scalar; + m_sharedMatrix->m34 *= scalar; + m_sharedMatrix->m41 *= scalar; + m_sharedMatrix->m42 *= scalar; + m_sharedMatrix->m43 *= scalar; + m_sharedMatrix->m44 *= scalar; + + return *this; +} + +template +NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) +{ + #if NAZARA_MATH_SAFE + if (!m1.IsDefined()) + { + NazaraError("First matrix not defined"); + return NzMatrix4(); + } + + if (!m2.IsDefined()) + { + NazaraError("Second matrix not defined"); + return NzMatrix4(); + } + #endif + + #if NAZARA_MATH_MATRIX4_CHECK_AFFINE + if (m1.IsAffine() && m2.IsAffine()) + return ConcatenateAffine(m1, m2); + #endif + + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m14*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m24*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m34*m2.m_sharedMatrix->m44, + + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m43, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m14 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m24 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m34 + m1.m_sharedMatrix->m44*m2.m_sharedMatrix->m44); +} + +template +NzMatrix4 NzMatrix4::ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2) +{ + #if NAZARA_MATH_SAFE + if (!m1.IsDefined()) + { + NazaraError("First matrix not defined"); + return NzMatrix4(); + } + + if (!m2.IsDefined()) + { + NazaraError("Second matrix not defined"); + return NzMatrix4(); + } + #endif + + #ifdef NAZARA_DEBUG + if (!m1.IsAffine()) + { + NazaraError("First matrix not affine"); + return NzMatrix4(); + } + + if (!m2.IsAffine()) + { + NazaraError("Second matrix not affine"); + return NzMatrix4(); + } + #endif + + return NzMatrix4(m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m11*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m12*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m13*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m21*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m22*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m23*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m31, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m32, + m1.m_sharedMatrix->m31*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m32*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m33*m2.m_sharedMatrix->m33, + F(0.0), + + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m11 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m21 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m31 + m2.m_sharedMatrix->m41, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m12 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m22 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m32 + m2.m_sharedMatrix->m42, + m1.m_sharedMatrix->m41*m2.m_sharedMatrix->m13 + m1.m_sharedMatrix->m42*m2.m_sharedMatrix->m23 + m1.m_sharedMatrix->m43*m2.m_sharedMatrix->m33 + m2.m_sharedMatrix->m43, + F(1.0)); +} + +template +NzMatrix4 NzMatrix4::Identity() +{ + NzMatrix4 matrix; + matrix.MakeIdentity(); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::LookAt(const NzVector3& eye, const NzVector3& target, const NzVector3& up) +{ + NzMatrix4 matrix; + matrix.MakeLookAt(eye, target, up); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Ortho(T left, T top, T width, T height, T zNear, T zFar) +{ + NzMatrix4 matrix; + matrix.MakeOrtho(left, top, width, height, zNear, zFar); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Perspective(T angle, T ratio, T zNear, T zFar) +{ + NzMatrix4 matrix; + matrix.MakePerspective(angle, ratio, zNear, zFar); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Rotate(const NzQuaternion& rotation) +{ + NzMatrix4 matrix; + matrix.MakeRotation(rotation); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Scale(const NzVector3& scale) +{ + NzMatrix4 matrix; + matrix.MakeScale(scale); + + return matrix; +} + +template +NzMatrix4 NzMatrix4::Translate(const NzVector3& translation) +{ + NzMatrix4 mat; + mat.MakeTranslation(translation); + + return mat; +} + +template +NzMatrix4 NzMatrix4::Zero() +{ + NzMatrix4 matrix; + matrix.MakeZero(); + + return matrix; +} + +template +std::ostream& operator<<(std::ostream& out, const NzMatrix4& matrix) +{ + return out << matrix.ToString(); +} + +template +NzMatrix4 operator*(T scale, const NzMatrix4& matrix) +{ + return matrix * scale; +} + +template +void NzMatrix4::EnsureOwnership() +{ + if (m_sharedMatrix) + { + NazaraLock(m_sharedMatrix->mutex); + if (m_sharedMatrix->refCount > 1) + { + m_sharedMatrix->refCount--; + + SharedMatrix* sharedMatrix = new SharedMatrix; + std::memcpy(&sharedMatrix->m11, &m_sharedMatrix->m11, 16*sizeof(T)); + } + } + else + m_sharedMatrix = new SharedMatrix; +} + +template +void NzMatrix4::ReleaseMatrix() +{ + if (!m_sharedMatrix) + return; + + NazaraMutexLock(m_sharedMatrix->mutex); + bool freeSharedMatrix = (--m_sharedMatrix->refCount == 0); + NazaraMutexUnlock(m_sharedMatrix->mutex); + + if (freeSharedMatrix) + delete m_sharedMatrix; + + m_sharedMatrix = nullptr; +} + +#undef F + +#include diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index f4b2ab97a..bed9d5277 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -1,93 +1,93 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_QUATERNION_HPP -#define NAZARA_QUATERNION_HPP - -#include - -template class NzEulerAngles; -template class NzVector3; - -template class NzQuaternion -{ - public: - NzQuaternion(); - NzQuaternion(T W, T X, T Y, T Z); - NzQuaternion(T quat[4]); - NzQuaternion(T angle, const NzVector3& axis); - NzQuaternion(const NzEulerAngles& angles); - //NzQuaternion(const NzMatrix3& mat); - template explicit NzQuaternion(const NzQuaternion& quat); - NzQuaternion(const NzQuaternion& quat) = default; - ~NzQuaternion() = default; - - T DotProduct(const NzQuaternion& vec) const; - - NzQuaternion GetConjugate() const; - NzQuaternion GetInverse() const; - NzQuaternion GetNormal() const; - - void Inverse(); - - void MakeIdentity(); - void MakeZero(); - - T Magnitude() const; - - T Normalize(); - - void Set(T W, T X, T Y, T Z); - void Set(T quat[4]); - void Set(T angle, const NzVector3& normalizedAxis); - void Set(const NzEulerAngles& angles); - //void Set(const NzMatrix3& mat); - void Set(const NzQuaternion& quat); - template void Set(const NzQuaternion& quat); - - T SquaredMagnitude() const; - - NzEulerAngles ToEulerAngles() const; - //NzMatrix3 ToRotationMatrix() const; - NzString ToString() const; - - operator NzString() const; - - NzQuaternion& operator=(const NzQuaternion& quat); - - NzQuaternion operator+(const NzQuaternion& quat) const; - NzQuaternion operator*(const NzQuaternion& quat) const; - NzVector3 operator*(const NzVector3& vec) const; - NzQuaternion operator*(T scale) const; - NzQuaternion operator/(const NzQuaternion& quat) const; - - NzQuaternion& operator+=(const NzQuaternion& quat); - NzQuaternion& operator*=(const NzQuaternion& quat); - NzQuaternion& operator*=(T scale); - NzQuaternion& operator/=(const NzQuaternion& quat); - - bool operator==(const NzQuaternion& quat) const; - bool operator!=(const NzQuaternion& quat) const; - bool operator<(const NzQuaternion& quat) const; - bool operator<=(const NzQuaternion& quat) const; - bool operator>(const NzQuaternion& quat) const; - bool operator>=(const NzQuaternion& quat) const; - - static NzQuaternion Identity(); - static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp); - static NzQuaternion Zero(); - - T w, x, y, z; -}; - -template std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat); - -typedef NzQuaternion NzQuaterniond; -typedef NzQuaternion NzQuaternionf; - -#include - -#endif // NAZARA_QUATERNION_HPP +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_QUATERNION_HPP +#define NAZARA_QUATERNION_HPP + +#include + +template class NzEulerAngles; +template class NzVector3; + +template class NzQuaternion +{ + public: + NzQuaternion(); + NzQuaternion(T W, T X, T Y, T Z); + NzQuaternion(T quat[4]); + NzQuaternion(T angle, const NzVector3& axis); + NzQuaternion(const NzEulerAngles& angles); + //NzQuaternion(const NzMatrix3& mat); + template explicit NzQuaternion(const NzQuaternion& quat); + NzQuaternion(const NzQuaternion& quat) = default; + ~NzQuaternion() = default; + + T DotProduct(const NzQuaternion& vec) const; + + NzQuaternion GetConjugate() const; + NzQuaternion GetInverse() const; + NzQuaternion GetNormal() const; + + void Inverse(); + + void MakeIdentity(); + void MakeZero(); + + T Magnitude() const; + + T Normalize(); + + void Set(T W, T X, T Y, T Z); + void Set(T quat[4]); + void Set(T angle, const NzVector3& normalizedAxis); + void Set(const NzEulerAngles& angles); + //void Set(const NzMatrix3& mat); + void Set(const NzQuaternion& quat); + template void Set(const NzQuaternion& quat); + + T SquaredMagnitude() const; + + NzEulerAngles ToEulerAngles() const; + //NzMatrix3 ToRotationMatrix() const; + NzString ToString() const; + + operator NzString() const; + + NzQuaternion& operator=(const NzQuaternion& quat); + + NzQuaternion operator+(const NzQuaternion& quat) const; + NzQuaternion operator*(const NzQuaternion& quat) const; + NzVector3 operator*(const NzVector3& vec) const; + NzQuaternion operator*(T scale) const; + NzQuaternion operator/(const NzQuaternion& quat) const; + + NzQuaternion& operator+=(const NzQuaternion& quat); + NzQuaternion& operator*=(const NzQuaternion& quat); + NzQuaternion& operator*=(T scale); + NzQuaternion& operator/=(const NzQuaternion& quat); + + bool operator==(const NzQuaternion& quat) const; + bool operator!=(const NzQuaternion& quat) const; + bool operator<(const NzQuaternion& quat) const; + bool operator<=(const NzQuaternion& quat) const; + bool operator>(const NzQuaternion& quat) const; + bool operator>=(const NzQuaternion& quat) const; + + static NzQuaternion Identity(); + static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp); + static NzQuaternion Zero(); + + T w, x, y, z; +}; + +template std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat); + +typedef NzQuaternion NzQuaterniond; +typedef NzQuaternion NzQuaternionf; + +#include + +#endif // NAZARA_QUATERNION_HPP diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index 92bf1329d..d86f66ea9 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -1,428 +1,428 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzQuaternion::NzQuaternion() -{ -} - -template -NzQuaternion::NzQuaternion(T W, T X, T Y, T Z) -{ - Set(W, X, Y, Z); -} - -template -NzQuaternion::NzQuaternion(T quat[4]) -{ - Set(quat); -} - -template -NzQuaternion::NzQuaternion(T angle, const NzVector3& axis) -{ - Set(angle, axis); -} - -template -NzQuaternion::NzQuaternion(const NzEulerAngles& angles) -{ - Set(angles); -} -/* -template -NzQuaternion::NzQuaternion(const NzMatrix3& mat) -{ - Set(mat); -} -*/ -template -template -NzQuaternion::NzQuaternion(const NzQuaternion& quat) -{ - Set(quat); -} - -template -T NzQuaternion::DotProduct(const NzQuaternion& quat) const -{ - return w*quat.w + x*quat.x + y*quat.y + z*quat.z; -} - -template -NzQuaternion NzQuaternion::GetConjugate() const -{ - return NzQuaternion(w, -x, -y, -z); -} - -template -NzQuaternion NzQuaternion::GetInverse() const -{ - NzQuaternion quat(*this); - quat.Inverse(); - - return quat; -} - -template -NzQuaternion NzQuaternion::GetNormal() const -{ - NzQuaternion quat(*this); - quat.Normalize(); - - return quat; -} - -template -void NzQuaternion::Inverse() -{ - T norm = SquaredMagnitude(); - if (norm > F(0.0)) - { - T invNorm = F(1.0) / norm; - - w *= invNorm; - x *= -invNorm; - y *= -invNorm; - z *= -invNorm; - } -} - -template -void NzQuaternion::MakeIdentity() -{ - Set(F(1.0), F(0.0), F(0.0), F(0.0)); -} - -template -void NzQuaternion::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0), F(0.0)); -} - -template -T NzQuaternion::Magnitude() const -{ - return std::sqrt(SquaredMagnitude()); -} - -template -T NzQuaternion::Normalize() -{ - T squaredMagnitude = SquaredMagnitude(); - - // Inutile de vérifier si la magnitude au carrée est négative (Elle ne peut pas l'être) - if (!NzNumberEquals(squaredMagnitude, F(1.0))) - { - T norm = std::sqrt(squaredMagnitude); - T invNorm = F(1.0) / norm; - - w *= invNorm; - x *= invNorm; - y *= invNorm; - z *= invNorm; - - return norm; - } - else - return F(1.0); // Le quaternion est déjà normalisé -} - -template -void NzQuaternion::Set(T W, T X, T Y, T Z) -{ - w = W; - x = X; - y = Y; - z = Z; -} - -template -void NzQuaternion::Set(T quat[4]) -{ - w = quat[0]; - x = quat[1]; - y = quat[2]; - z = quat[3]; -} - -template -void NzQuaternion::Set(T angle, const NzVector3& axis) -{ - angle /= F(2.0); - - #if !NAZARA_MATH_ANGLE_RADIAN - angle = NzDegreeToRadian(angle); - #endif - - NzVector3 normalizedAxis = axis.GetNormal(); - - T sinAngle = std::sin(angle); - - w = std::cos(angle); - x = normalizedAxis.x * sinAngle; - y = normalizedAxis.y * sinAngle; - z = normalizedAxis.z * sinAngle; - - Normalize(); -} - -template -void NzQuaternion::Set(const NzEulerAngles& angles) -{ - Set(angles.ToQuaternion()); -} - -template -template -void NzQuaternion::Set(const NzQuaternion& quat) -{ - w = static_cast(quat.w); - x = static_cast(quat.x); - y = static_cast(quat.y); - z = static_cast(quat.z); -} - -template -void NzQuaternion::Set(const NzQuaternion& quat) -{ - w = quat.w; - x = quat.x; - y = quat.y; - z = quat.z; -} - -template -T NzQuaternion::SquaredMagnitude() const -{ - return w*w + x*x + y*y + z*z; -} - -template -NzEulerAngles NzQuaternion::ToEulerAngles() const -{ - T test = x*y + z*w; - if (test > F(0.499)) - // singularity at north pole - return NzEulerAngles(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0)); - - if (test < F(-0.499)) - return NzEulerAngles(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0)); - - return NzEulerAngles(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*x* - F(2.0)*z*z)), - NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*y*y - F(2.0)*z*z)), - NzRadians(std::asin(F(2.0)*test))); -} - -template -NzString NzQuaternion::ToString() const -{ - NzStringStream ss; - - return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')'; -} - -template -NzQuaternion::operator NzString() const -{ - return ToString(); -} - -template -NzQuaternion& NzQuaternion::operator=(const NzQuaternion& quat) -{ - Set(quat); - - return *this; -} - -template -NzQuaternion NzQuaternion::operator+(const NzQuaternion& quat) const -{ - return NzQuaternion(w + quat.w, - x + quat.x, - y + quat.y, - z + quat.z); -} - -template -NzQuaternion NzQuaternion::operator*(const NzQuaternion& quat) const -{ - return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z, - w*quat.x + x*quat.w + y*quat.z - z*quat.y, - w*quat.y + y*quat.w + z*quat.x - x*quat.z, - w*quat.z + z*quat.w + x*quat.y - y*quat.x); -} - -template -NzVector3 NzQuaternion::operator*(const NzVector3& vec) const -{ - NzVector3f quatVec(x, y, z); - NzVector3f uv = quatVec.CrossProduct(vec); - NzVector3f uuv = quatVec.CrossProduct(uv); - uv *= F(2.0) * w; - uuv *= F(2.0); - - return vec + uv + uuv; -} - -template -NzQuaternion NzQuaternion::operator*(T scale) const -{ - return NzQuaternion(w * scale, - x * scale, - y * scale, - z * scale); -} - -template -NzQuaternion NzQuaternion::operator/(const NzQuaternion& quat) const -{ - return GetConjugate(quat) * (*this); -} - -template -NzQuaternion& NzQuaternion::operator+=(const NzQuaternion& quat) -{ - return operator=(operator+(quat)); -} - -template -NzQuaternion& NzQuaternion::operator*=(const NzQuaternion& quat) -{ - return operator=(operator*(quat)); -} - -template -NzQuaternion& NzQuaternion::operator*=(T scale) -{ - return operator=(operator*(scale)); -} - -template -NzQuaternion& NzQuaternion::operator/=(const NzQuaternion& quat) -{ - return operator=(operator/(quat)); -} - -template -bool NzQuaternion::operator==(const NzQuaternion& quat) const -{ - return NzNumberEquals(w, quat.w) && - NzNumberEquals(x, quat.x) && - NzNumberEquals(y, quat.y) && - NzNumberEquals(z, quat.z); -} - -template -bool NzQuaternion::operator!=(const NzQuaternion& quat) const -{ - return !operator==(quat); -} - -template -bool NzQuaternion::operator<(const NzQuaternion& quat) const -{ - return w < quat.w && x < quat.x && y < quat.y && z < quat.z; -} - -template -bool NzQuaternion::operator<=(const NzQuaternion& quat) const -{ - return operator<(quat) || operator==(quat); -} - -template -bool NzQuaternion::operator>(const NzQuaternion& quat) const -{ - return !operator<=(quat); -} - -template -bool NzQuaternion::operator>=(const NzQuaternion& quat) const -{ - return !operator<(quat); -} - -template -NzQuaternion NzQuaternion::Identity() -{ - NzQuaternion quaternion; - quaternion.MakeIdentity(); - - return quaternion; -} - -template -NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp) -{ - if (interp <= F(0.0)) - return quatA; - - if (interp >= F(1.0)) - return quatB; - - NzQuaternion q; - - T cosOmega = quatA.DotProduct(quatB); - if (cosOmega < F(0.0)) - { - // On inverse tout - q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z); - cosOmega = -cosOmega; - } - else - q.Set(quatB); - - T k0, k1; - if (cosOmega > F(0.9999)) - { - // Interpolation linéaire pour éviter une division par zéro - k0 = F(1.0) - interp; - k1 = interp; - } - else - { - T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); - T omega = std::atan2(sinOmega, cosOmega); - - // Pour éviter deux divisions - sinOmega = F(1.0)/sinOmega; - - k0 = std::sin((F(1.0) - interp) * omega) * sinOmega; - k1 = std::sin(interp*omega) * sinOmega; - } - - NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z); - return result += q*k1; -} - -template -NzQuaternion NzQuaternion::Zero() -{ - NzQuaternion quaternion; - quaternion.MakeZero(); - - return quaternion; -} - -template -std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat) -{ - return out << quat.ToString(); -} - -#undef F - -#include +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzQuaternion::NzQuaternion() +{ +} + +template +NzQuaternion::NzQuaternion(T W, T X, T Y, T Z) +{ + Set(W, X, Y, Z); +} + +template +NzQuaternion::NzQuaternion(T quat[4]) +{ + Set(quat); +} + +template +NzQuaternion::NzQuaternion(T angle, const NzVector3& axis) +{ + Set(angle, axis); +} + +template +NzQuaternion::NzQuaternion(const NzEulerAngles& angles) +{ + Set(angles); +} +/* +template +NzQuaternion::NzQuaternion(const NzMatrix3& mat) +{ + Set(mat); +} +*/ +template +template +NzQuaternion::NzQuaternion(const NzQuaternion& quat) +{ + Set(quat); +} + +template +T NzQuaternion::DotProduct(const NzQuaternion& quat) const +{ + return w*quat.w + x*quat.x + y*quat.y + z*quat.z; +} + +template +NzQuaternion NzQuaternion::GetConjugate() const +{ + return NzQuaternion(w, -x, -y, -z); +} + +template +NzQuaternion NzQuaternion::GetInverse() const +{ + NzQuaternion quat(*this); + quat.Inverse(); + + return quat; +} + +template +NzQuaternion NzQuaternion::GetNormal() const +{ + NzQuaternion quat(*this); + quat.Normalize(); + + return quat; +} + +template +void NzQuaternion::Inverse() +{ + T norm = SquaredMagnitude(); + if (norm > F(0.0)) + { + T invNorm = F(1.0) / norm; + + w *= invNorm; + x *= -invNorm; + y *= -invNorm; + z *= -invNorm; + } +} + +template +void NzQuaternion::MakeIdentity() +{ + Set(F(1.0), F(0.0), F(0.0), F(0.0)); +} + +template +void NzQuaternion::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0)); +} + +template +T NzQuaternion::Magnitude() const +{ + return std::sqrt(SquaredMagnitude()); +} + +template +T NzQuaternion::Normalize() +{ + T squaredMagnitude = SquaredMagnitude(); + + // Inutile de vérifier si la magnitude au carrée est négative (Elle ne peut pas l'être) + if (!NzNumberEquals(squaredMagnitude, F(1.0))) + { + T norm = std::sqrt(squaredMagnitude); + T invNorm = F(1.0) / norm; + + w *= invNorm; + x *= invNorm; + y *= invNorm; + z *= invNorm; + + return norm; + } + else + return F(1.0); // Le quaternion est déjà normalisé +} + +template +void NzQuaternion::Set(T W, T X, T Y, T Z) +{ + w = W; + x = X; + y = Y; + z = Z; +} + +template +void NzQuaternion::Set(T quat[4]) +{ + w = quat[0]; + x = quat[1]; + y = quat[2]; + z = quat[3]; +} + +template +void NzQuaternion::Set(T angle, const NzVector3& axis) +{ + angle /= F(2.0); + + #if !NAZARA_MATH_ANGLE_RADIAN + angle = NzDegreeToRadian(angle); + #endif + + NzVector3 normalizedAxis = axis.GetNormal(); + + T sinAngle = std::sin(angle); + + w = std::cos(angle); + x = normalizedAxis.x * sinAngle; + y = normalizedAxis.y * sinAngle; + z = normalizedAxis.z * sinAngle; + + Normalize(); +} + +template +void NzQuaternion::Set(const NzEulerAngles& angles) +{ + Set(angles.ToQuaternion()); +} + +template +template +void NzQuaternion::Set(const NzQuaternion& quat) +{ + w = static_cast(quat.w); + x = static_cast(quat.x); + y = static_cast(quat.y); + z = static_cast(quat.z); +} + +template +void NzQuaternion::Set(const NzQuaternion& quat) +{ + w = quat.w; + x = quat.x; + y = quat.y; + z = quat.z; +} + +template +T NzQuaternion::SquaredMagnitude() const +{ + return w*w + x*x + y*y + z*z; +} + +template +NzEulerAngles NzQuaternion::ToEulerAngles() const +{ + T test = x*y + z*w; + if (test > F(0.499)) + // singularity at north pole + return NzEulerAngles(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0)); + + if (test < F(-0.499)) + return NzEulerAngles(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0)); + + return NzEulerAngles(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*x* - F(2.0)*z*z)), + NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*y*y - F(2.0)*z*z)), + NzRadians(std::asin(F(2.0)*test))); +} + +template +NzString NzQuaternion::ToString() const +{ + NzStringStream ss; + + return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')'; +} + +template +NzQuaternion::operator NzString() const +{ + return ToString(); +} + +template +NzQuaternion& NzQuaternion::operator=(const NzQuaternion& quat) +{ + Set(quat); + + return *this; +} + +template +NzQuaternion NzQuaternion::operator+(const NzQuaternion& quat) const +{ + return NzQuaternion(w + quat.w, + x + quat.x, + y + quat.y, + z + quat.z); +} + +template +NzQuaternion NzQuaternion::operator*(const NzQuaternion& quat) const +{ + return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z, + w*quat.x + x*quat.w + y*quat.z - z*quat.y, + w*quat.y + y*quat.w + z*quat.x - x*quat.z, + w*quat.z + z*quat.w + x*quat.y - y*quat.x); +} + +template +NzVector3 NzQuaternion::operator*(const NzVector3& vec) const +{ + NzVector3f quatVec(x, y, z); + NzVector3f uv = quatVec.CrossProduct(vec); + NzVector3f uuv = quatVec.CrossProduct(uv); + uv *= F(2.0) * w; + uuv *= F(2.0); + + return vec + uv + uuv; +} + +template +NzQuaternion NzQuaternion::operator*(T scale) const +{ + return NzQuaternion(w * scale, + x * scale, + y * scale, + z * scale); +} + +template +NzQuaternion NzQuaternion::operator/(const NzQuaternion& quat) const +{ + return GetConjugate(quat) * (*this); +} + +template +NzQuaternion& NzQuaternion::operator+=(const NzQuaternion& quat) +{ + return operator=(operator+(quat)); +} + +template +NzQuaternion& NzQuaternion::operator*=(const NzQuaternion& quat) +{ + return operator=(operator*(quat)); +} + +template +NzQuaternion& NzQuaternion::operator*=(T scale) +{ + return operator=(operator*(scale)); +} + +template +NzQuaternion& NzQuaternion::operator/=(const NzQuaternion& quat) +{ + return operator=(operator/(quat)); +} + +template +bool NzQuaternion::operator==(const NzQuaternion& quat) const +{ + return NzNumberEquals(w, quat.w) && + NzNumberEquals(x, quat.x) && + NzNumberEquals(y, quat.y) && + NzNumberEquals(z, quat.z); +} + +template +bool NzQuaternion::operator!=(const NzQuaternion& quat) const +{ + return !operator==(quat); +} + +template +bool NzQuaternion::operator<(const NzQuaternion& quat) const +{ + return w < quat.w && x < quat.x && y < quat.y && z < quat.z; +} + +template +bool NzQuaternion::operator<=(const NzQuaternion& quat) const +{ + return operator<(quat) || operator==(quat); +} + +template +bool NzQuaternion::operator>(const NzQuaternion& quat) const +{ + return !operator<=(quat); +} + +template +bool NzQuaternion::operator>=(const NzQuaternion& quat) const +{ + return !operator<(quat); +} + +template +NzQuaternion NzQuaternion::Identity() +{ + NzQuaternion quaternion; + quaternion.MakeIdentity(); + + return quaternion; +} + +template +NzQuaternion NzQuaternion::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp) +{ + if (interp <= F(0.0)) + return quatA; + + if (interp >= F(1.0)) + return quatB; + + NzQuaternion q; + + T cosOmega = quatA.DotProduct(quatB); + if (cosOmega < F(0.0)) + { + // On inverse tout + q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z); + cosOmega = -cosOmega; + } + else + q.Set(quatB); + + T k0, k1; + if (cosOmega > F(0.9999)) + { + // Interpolation linéaire pour éviter une division par zéro + k0 = F(1.0) - interp; + k1 = interp; + } + else + { + T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); + T omega = std::atan2(sinOmega, cosOmega); + + // Pour éviter deux divisions + sinOmega = F(1.0)/sinOmega; + + k0 = std::sin((F(1.0) - interp) * omega) * sinOmega; + k1 = std::sin(interp*omega) * sinOmega; + } + + NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z); + return result += q*k1; +} + +template +NzQuaternion NzQuaternion::Zero() +{ + NzQuaternion quaternion; + quaternion.MakeZero(); + + return quaternion; +} + +template +std::ostream& operator<<(std::ostream& out, const NzQuaternion& quat) +{ + return out << quat.ToString(); +} + +#undef F + +#include diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 9d24dbc69..1cbf1a65a 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -1,105 +1,105 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_VECTOR2_HPP -#define NAZARA_VECTOR2_HPP - -#include - -template class NzVector2 -{ - public: - NzVector2(); - NzVector2(T X, T Y); - explicit NzVector2(T scale); - NzVector2(T vec[2]); - template explicit NzVector2(const NzVector2& vec); - NzVector2(const NzVector2& vec) = default; - ~NzVector2() = default; - - T AbsDotProduct(const NzVector2& vec) const; - - T Distance(const NzVector2& vec) const; - float Distancef(const NzVector2& vec) const; - - T DotProduct(const NzVector2& vec) const; - - NzVector2 GetNormal() const; - - T Length() const; - float Lengthf() const; - - void MakeUnitX(); - void MakeUnitY(); - void MakeZero(); - - void Maximize(const NzVector2& vec); - void Minimize(const NzVector2& vec); - - void Normalize(); - - void Set(T X, T Y); - void Set(T scale); - void Set(T vec[2]); - template void Set(const NzVector2& vec); - - T SquaredDistance(const NzVector2& vec) const; - T SquaredLength() const; - - NzString ToString() const; - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - const NzVector2& operator+() const; - NzVector2 operator-() const; - - NzVector2 operator+(const NzVector2& vec) const; - NzVector2 operator-(const NzVector2& vec) const; - NzVector2 operator*(const NzVector2& vec) const; - NzVector2 operator*(T scale) const; - NzVector2 operator/(const NzVector2& vec) const; - NzVector2 operator/(T scale) const; - - NzVector2& operator+=(const NzVector2& vec); - NzVector2& operator-=(const NzVector2& vec); - NzVector2& operator*=(const NzVector2& vec); - NzVector2& operator*=(T scale); - NzVector2& operator/=(const NzVector2& vec); - NzVector2& operator/=(T scale); - - bool operator==(const NzVector2& vec) const; - bool operator!=(const NzVector2& vec) const; - bool operator<(const NzVector2& vec) const; - bool operator<=(const NzVector2& vec) const; - bool operator>(const NzVector2& vec) const; - bool operator>=(const NzVector2& vec) const; - - static NzVector2 UnitX(); - static NzVector2 UnitY(); - static NzVector2 Zero(); - - T x, y; -}; - -template std::ostream& operator<<(std::ostream& out, const NzVector2& vec); - -template NzVector2 operator*(T scale, const NzVector2& vec); -template NzVector2 operator/(T scale, const NzVector2& vec); - -typedef NzVector2 NzVector2d; -typedef NzVector2 NzVector2f; -typedef NzVector2 NzVector2i; -typedef NzVector2 NzVector2ui; - -#include - -#endif // NAZARA_VECTOR2_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VECTOR2_HPP +#define NAZARA_VECTOR2_HPP + +#include + +template class NzVector2 +{ + public: + NzVector2(); + NzVector2(T X, T Y); + explicit NzVector2(T scale); + NzVector2(T vec[2]); + template explicit NzVector2(const NzVector2& vec); + NzVector2(const NzVector2& vec) = default; + ~NzVector2() = default; + + T AbsDotProduct(const NzVector2& vec) const; + + T Distance(const NzVector2& vec) const; + float Distancef(const NzVector2& vec) const; + + T DotProduct(const NzVector2& vec) const; + + NzVector2 GetNormal() const; + + T Length() const; + float Lengthf() const; + + void MakeUnitX(); + void MakeUnitY(); + void MakeZero(); + + void Maximize(const NzVector2& vec); + void Minimize(const NzVector2& vec); + + void Normalize(); + + void Set(T X, T Y); + void Set(T scale); + void Set(T vec[2]); + template void Set(const NzVector2& vec); + + T SquaredDistance(const NzVector2& vec) const; + T SquaredLength() const; + + NzString ToString() const; + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + const NzVector2& operator+() const; + NzVector2 operator-() const; + + NzVector2 operator+(const NzVector2& vec) const; + NzVector2 operator-(const NzVector2& vec) const; + NzVector2 operator*(const NzVector2& vec) const; + NzVector2 operator*(T scale) const; + NzVector2 operator/(const NzVector2& vec) const; + NzVector2 operator/(T scale) const; + + NzVector2& operator+=(const NzVector2& vec); + NzVector2& operator-=(const NzVector2& vec); + NzVector2& operator*=(const NzVector2& vec); + NzVector2& operator*=(T scale); + NzVector2& operator/=(const NzVector2& vec); + NzVector2& operator/=(T scale); + + bool operator==(const NzVector2& vec) const; + bool operator!=(const NzVector2& vec) const; + bool operator<(const NzVector2& vec) const; + bool operator<=(const NzVector2& vec) const; + bool operator>(const NzVector2& vec) const; + bool operator>=(const NzVector2& vec) const; + + static NzVector2 UnitX(); + static NzVector2 UnitY(); + static NzVector2 Zero(); + + T x, y; +}; + +template std::ostream& operator<<(std::ostream& out, const NzVector2& vec); + +template NzVector2 operator*(T scale, const NzVector2& vec); +template NzVector2 operator/(T scale, const NzVector2& vec); + +typedef NzVector2 NzVector2d; +typedef NzVector2 NzVector2f; +typedef NzVector2 NzVector2i; +typedef NzVector2 NzVector2ui; + +#include + +#endif // NAZARA_VECTOR2_HPP diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 1c4639a52..4ea664b61 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -1,488 +1,488 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzVector2::NzVector2() -{ -} - -template -NzVector2::NzVector2(T X, T Y) -{ - Set(X, Y); -} - -template -NzVector2::NzVector2(T scale) -{ - Set(scale); -} - -template -NzVector2::NzVector2(T vec[2]) -{ - Set(vec); -} - -template -template -NzVector2::NzVector2(const NzVector2& vec) -{ - Set(vec); -} - -template -T NzVector2::AbsDotProduct(const NzVector2& vec) const -{ - return std::fabs(x * vec.x) + std::fabs(y * vec.y); -} - -template<> -inline int NzVector2::AbsDotProduct(const NzVector2& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y); -} - -template<> -inline unsigned int NzVector2::AbsDotProduct(const NzVector2& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y); -} - -template -T NzVector2::Distance(const NzVector2& vec) const -{ - return std::sqrt(SquaredDistance(vec)); -} - -template -float NzVector2::Distancef(const NzVector2& vec) const -{ - return std::sqrt(static_cast(SquaredDistance(vec))); -} - -template -T NzVector2::DotProduct(const NzVector2& vec) const -{ - return x*vec.x + y*vec.y; -} - -template -NzVector2 NzVector2::GetNormal() const -{ - NzVector2 vec(*this); - vec.Normalize(); - - return vec; -} - -template -T NzVector2::Length() const -{ - return std::sqrt(SquaredLength()); -} - -template -float NzVector2::Lengthf() const -{ - return std::sqrt(static_cast(SquaredLength())); -} - -template -void NzVector2::MakeUnitX() -{ - Set(F(1.0), F(0.0)); -} - -template -void NzVector2::MakeUnitY() -{ - Set(F(0.0), F(1.0)); -} - -template -void NzVector2::MakeZero() -{ - Set(F(0.0), F(0.0)); -} - -template -void NzVector2::Maximize(const NzVector2& vec) -{ - if (vec.x > x) - x = vec.x; - - if (vec.y > y) - y = vec.y; -} - -template -void NzVector2::Minimize(const NzVector2& vec) -{ - if (vec.x < x) - x = vec.x; - - if (vec.y < y) - y = vec.y; -} - -template -void NzVector2::Normalize() -{ - T squaredLength = SquaredLength(); - - if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) - { - T length = std::sqrt(squaredLength); - - x /= length; - y /= length; - } -} - -template -void NzVector2::Set(T X, T Y) -{ - x = X; - y = Y; -} - -template -void NzVector2::Set(T scale) -{ - x = scale; - y = scale; -} - -template -void NzVector2::Set(T vec[2]) -{ - std::memcpy(&x, vec, 2*sizeof(T)); -} - -template -template -void NzVector2::Set(const NzVector2& vec) -{ - x = F(vec.x); - y = F(vec.y); -} - -template -T NzVector2::SquaredDistance(const NzVector2& vec) const -{ - return operator-(vec).SquaredLength(); -} - -template -T NzVector2::SquaredLength() const -{ - return x*x + y*y; -} - -template -NzString NzVector2::ToString() const -{ - NzStringStream ss; - - return ss << "Vector2(" << x << ", " << y << ')'; -} - -template -NzVector2::operator NzString() const -{ - return ToString(); -} - -template -NzVector2::operator T*() -{ - return &x; -} - -template -NzVector2::operator const T*() const -{ - return &x; -} - -template -T& NzVector2::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 2) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector2::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 2) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -const NzVector2& NzVector2::operator+() const -{ - return *this; -} - -template -NzVector2 NzVector2::operator-() const -{ - return NzVector2(-x, -y); -} - -template -NzVector2 NzVector2::operator+(const NzVector2& vec) const -{ - return NzVector2(x + vec.x, y + vec.y); -} - -template -NzVector2 NzVector2::operator-(const NzVector2& vec) const -{ - return NzVector2(x - vec.x, y - vec.y); -} - -template -NzVector2 NzVector2::operator*(const NzVector2& vec) const -{ - return NzVector2(x * vec.x, y * vec.y); -} - -template -NzVector2 NzVector2::operator*(T scale) const -{ - return NzVector2(x * scale, y * scale); -} - -template -NzVector2 NzVector2::operator/(const NzVector2& vec) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector2(x / vec.x, y / vec.y); -} - -template -NzVector2 NzVector2::operator/(T scale) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector2(x / scale, y / scale); -} - -template -NzVector2& NzVector2::operator+=(const NzVector2& vec) -{ - x += vec.x; - y += vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator-=(const NzVector2& vec) -{ - x -= vec.x; - y -= vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator*=(const NzVector2& vec) -{ - x *= vec.x; - y *= vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator*=(T scale) -{ - x *= scale; - y *= scale; - - return *this; -} - -template -NzVector2& NzVector2::operator/=(const NzVector2& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= vec.x; - y /= vec.y; - - return *this; -} - -template -NzVector2& NzVector2::operator/=(T scale) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= scale; - y /= scale; - - return *this; -} - -template -bool NzVector2::operator==(const NzVector2& vec) const -{ - return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y); -} - -template -bool NzVector2::operator!=(const NzVector2& vec) const -{ - return !operator==(vec); -} - -template -bool NzVector2::operator<(const NzVector2& vec) const -{ - return x < vec.x && y < vec.y; -} - -template -bool NzVector2::operator<=(const NzVector2& vec) const -{ - return operator<(vec) || operator==(vec); -} - -template -bool NzVector2::operator>(const NzVector2& vec) const -{ - return !operator<=(vec); -} - -template -bool NzVector2::operator>=(const NzVector2& vec) const -{ - return !operator<(vec); -} - -template -NzVector2 NzVector2::UnitX() -{ - NzVector2 vector; - vector.MakeUnitX(); - - return vector; -} - -template -NzVector2 NzVector2::UnitY() -{ - NzVector2 vector; - vector.MakeUnitY(); - - return vector; -} - -template -NzVector2 NzVector2::Zero() -{ - NzVector2 vector; - vector.MakeZero(); - - return vector; -} - -template -std::ostream& operator<<(std::ostream& out, const NzVector2& vec) -{ - return out << vec.ToString(); -} - -template -NzVector2 operator*(T scale, const NzVector2& vec) -{ - return NzVector2(scale * vec.x, scale * vec.y); -} - -template -NzVector2 operator/(T scale, const NzVector2& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector2(scale/vec.x, scale/vec.y); -} - -#undef F - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzVector2::NzVector2() +{ +} + +template +NzVector2::NzVector2(T X, T Y) +{ + Set(X, Y); +} + +template +NzVector2::NzVector2(T scale) +{ + Set(scale); +} + +template +NzVector2::NzVector2(T vec[2]) +{ + Set(vec); +} + +template +template +NzVector2::NzVector2(const NzVector2& vec) +{ + Set(vec); +} + +template +T NzVector2::AbsDotProduct(const NzVector2& vec) const +{ + return std::fabs(x * vec.x) + std::fabs(y * vec.y); +} + +template<> +inline int NzVector2::AbsDotProduct(const NzVector2& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y); +} + +template<> +inline unsigned int NzVector2::AbsDotProduct(const NzVector2& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y); +} + +template +T NzVector2::Distance(const NzVector2& vec) const +{ + return std::sqrt(SquaredDistance(vec)); +} + +template +float NzVector2::Distancef(const NzVector2& vec) const +{ + return std::sqrt(static_cast(SquaredDistance(vec))); +} + +template +T NzVector2::DotProduct(const NzVector2& vec) const +{ + return x*vec.x + y*vec.y; +} + +template +NzVector2 NzVector2::GetNormal() const +{ + NzVector2 vec(*this); + vec.Normalize(); + + return vec; +} + +template +T NzVector2::Length() const +{ + return std::sqrt(SquaredLength()); +} + +template +float NzVector2::Lengthf() const +{ + return std::sqrt(static_cast(SquaredLength())); +} + +template +void NzVector2::MakeUnitX() +{ + Set(F(1.0), F(0.0)); +} + +template +void NzVector2::MakeUnitY() +{ + Set(F(0.0), F(1.0)); +} + +template +void NzVector2::MakeZero() +{ + Set(F(0.0), F(0.0)); +} + +template +void NzVector2::Maximize(const NzVector2& vec) +{ + if (vec.x > x) + x = vec.x; + + if (vec.y > y) + y = vec.y; +} + +template +void NzVector2::Minimize(const NzVector2& vec) +{ + if (vec.x < x) + x = vec.x; + + if (vec.y < y) + y = vec.y; +} + +template +void NzVector2::Normalize() +{ + T squaredLength = SquaredLength(); + + if (squaredLength-F(1.0) > std::numeric_limits::epsilon()) + { + T length = std::sqrt(squaredLength); + + x /= length; + y /= length; + } +} + +template +void NzVector2::Set(T X, T Y) +{ + x = X; + y = Y; +} + +template +void NzVector2::Set(T scale) +{ + x = scale; + y = scale; +} + +template +void NzVector2::Set(T vec[2]) +{ + std::memcpy(&x, vec, 2*sizeof(T)); +} + +template +template +void NzVector2::Set(const NzVector2& vec) +{ + x = F(vec.x); + y = F(vec.y); +} + +template +T NzVector2::SquaredDistance(const NzVector2& vec) const +{ + return operator-(vec).SquaredLength(); +} + +template +T NzVector2::SquaredLength() const +{ + return x*x + y*y; +} + +template +NzString NzVector2::ToString() const +{ + NzStringStream ss; + + return ss << "Vector2(" << x << ", " << y << ')'; +} + +template +NzVector2::operator NzString() const +{ + return ToString(); +} + +template +NzVector2::operator T*() +{ + return &x; +} + +template +NzVector2::operator const T*() const +{ + return &x; +} + +template +T& NzVector2::operator[](unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i >= 2) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +T NzVector2::operator[](unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i >= 2) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +const NzVector2& NzVector2::operator+() const +{ + return *this; +} + +template +NzVector2 NzVector2::operator-() const +{ + return NzVector2(-x, -y); +} + +template +NzVector2 NzVector2::operator+(const NzVector2& vec) const +{ + return NzVector2(x + vec.x, y + vec.y); +} + +template +NzVector2 NzVector2::operator-(const NzVector2& vec) const +{ + return NzVector2(x - vec.x, y - vec.y); +} + +template +NzVector2 NzVector2::operator*(const NzVector2& vec) const +{ + return NzVector2(x * vec.x, y * vec.y); +} + +template +NzVector2 NzVector2::operator*(T scale) const +{ + return NzVector2(x * scale, y * scale); +} + +template +NzVector2 NzVector2::operator/(const NzVector2& vec) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector2(x / vec.x, y / vec.y); +} + +template +NzVector2 NzVector2::operator/(T scale) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector2(x / scale, y / scale); +} + +template +NzVector2& NzVector2::operator+=(const NzVector2& vec) +{ + x += vec.x; + y += vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator-=(const NzVector2& vec) +{ + x -= vec.x; + y -= vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator*=(const NzVector2& vec) +{ + x *= vec.x; + y *= vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator*=(T scale) +{ + x *= scale; + y *= scale; + + return *this; +} + +template +NzVector2& NzVector2::operator/=(const NzVector2& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= vec.x; + y /= vec.y; + + return *this; +} + +template +NzVector2& NzVector2::operator/=(T scale) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= scale; + y /= scale; + + return *this; +} + +template +bool NzVector2::operator==(const NzVector2& vec) const +{ + return NzNumberEquals(x, vec.x) && + NzNumberEquals(y, vec.y); +} + +template +bool NzVector2::operator!=(const NzVector2& vec) const +{ + return !operator==(vec); +} + +template +bool NzVector2::operator<(const NzVector2& vec) const +{ + return x < vec.x && y < vec.y; +} + +template +bool NzVector2::operator<=(const NzVector2& vec) const +{ + return operator<(vec) || operator==(vec); +} + +template +bool NzVector2::operator>(const NzVector2& vec) const +{ + return !operator<=(vec); +} + +template +bool NzVector2::operator>=(const NzVector2& vec) const +{ + return !operator<(vec); +} + +template +NzVector2 NzVector2::UnitX() +{ + NzVector2 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector2 NzVector2::UnitY() +{ + NzVector2 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector2 NzVector2::Zero() +{ + NzVector2 vector; + vector.MakeZero(); + + return vector; +} + +template +std::ostream& operator<<(std::ostream& out, const NzVector2& vec) +{ + return out << vec.ToString(); +} + +template +NzVector2 operator*(T scale, const NzVector2& vec) +{ + return NzVector2(scale * vec.x, scale * vec.y); +} + +template +NzVector2 operator/(T scale, const NzVector2& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector2(scale/vec.x, scale/vec.y); +} + +#undef F + +#include diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 8734bed41..2750c6b7b 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -1,121 +1,121 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_VECTOR3_HPP -#define NAZARA_VECTOR3_HPP - -#include -#include - -template class NzVector3 -{ - public: - NzVector3(); - NzVector3(T X, T Y, T Z); - explicit NzVector3(T scale); - NzVector3(T vec[3]); - NzVector3(const NzVector2& vec, T Z = 0.0); - template explicit NzVector3(const NzVector3& vec); - NzVector3(const NzVector3& vec) = default; - ~NzVector3() = default; - - T AbsDotProduct(const NzVector3& vec) const; - - NzVector3 CrossProduct(const NzVector3& vec) const; - - T Distance(const NzVector3& vec) const; - float Distancef(const NzVector3& vec) const; - - T DotProduct(const NzVector3& vec) const; - - NzVector3 GetNormal() const; - - T Length() const; - float Lengthf() const; - - void MakeForward(); - void MakeLeft(); - void MakeUnitX(); - void MakeUnitY(); - void MakeUnitZ(); - void MakeUp(); - void MakeZero(); - - void Maximize(const NzVector3& vec); - void Minimize(const NzVector3& vec); - - void Normalize(); - - void Set(T X, T Y, T Z); - void Set(T scale); - void Set(T vec[3]); - void Set(const NzVector2& vec, T Z = 0.0); - template void Set(const NzVector3& vec); - - T SquaredDistance(const NzVector3& vec) const; - T SquaredLength() const; - - NzString ToString() const; - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - const NzVector3& operator+() const; - NzVector3 operator-() const; - - NzVector3 operator+(const NzVector3& vec) const; - NzVector3 operator-(const NzVector3& vec) const; - NzVector3 operator*(const NzVector3& vec) const; - NzVector3 operator*(T scale) const; - NzVector3 operator/(const NzVector3& vec) const; - NzVector3 operator/(T scale) const; - - NzVector3& operator+=(const NzVector3& vec); - NzVector3& operator-=(const NzVector3& vec); - NzVector3& operator*=(const NzVector3& vec); - NzVector3& operator*=(T scale); - NzVector3& operator/=(const NzVector3& vec); - NzVector3& operator/=(T scale); - - bool operator==(const NzVector3& vec) const; - bool operator!=(const NzVector3& vec) const; - bool operator<(const NzVector3& vec) const; - bool operator<=(const NzVector3& vec) const; - bool operator>(const NzVector3& vec) const; - bool operator>=(const NzVector3& vec) const; - - static NzVector3 CrossProduct(const NzVector3& vec1, const NzVector3& vec2); - static T DotProduct(const NzVector3& vec1, const NzVector3& vec2); - static NzVector3 Forward(); - static NzVector3 Left(); - static NzVector3 Normalize(const NzVector3& vec); - static NzVector3 UnitX(); - static NzVector3 UnitY(); - static NzVector3 UnitZ(); - static NzVector3 Up(); - static NzVector3 Zero(); - - T x, y, z; -}; - -template std::ostream& operator<<(std::ostream& out, const NzVector3& vec); - -template NzVector3 operator*(T scale, const NzVector3& vec); -template NzVector3 operator/(T scale, const NzVector3& vec); - -typedef NzVector3 NzVector3d; -typedef NzVector3 NzVector3f; -typedef NzVector3 NzVector3i; -typedef NzVector3 NzVector3ui; - -#include - -#endif // NAZARA_VECTOR3_HPP +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VECTOR3_HPP +#define NAZARA_VECTOR3_HPP + +#include +#include + +template class NzVector3 +{ + public: + NzVector3(); + NzVector3(T X, T Y, T Z); + explicit NzVector3(T scale); + NzVector3(T vec[3]); + NzVector3(const NzVector2& vec, T Z = 0.0); + template explicit NzVector3(const NzVector3& vec); + NzVector3(const NzVector3& vec) = default; + ~NzVector3() = default; + + T AbsDotProduct(const NzVector3& vec) const; + + NzVector3 CrossProduct(const NzVector3& vec) const; + + T Distance(const NzVector3& vec) const; + float Distancef(const NzVector3& vec) const; + + T DotProduct(const NzVector3& vec) const; + + NzVector3 GetNormal() const; + + T Length() const; + float Lengthf() const; + + void MakeForward(); + void MakeLeft(); + void MakeUnitX(); + void MakeUnitY(); + void MakeUnitZ(); + void MakeUp(); + void MakeZero(); + + void Maximize(const NzVector3& vec); + void Minimize(const NzVector3& vec); + + void Normalize(); + + void Set(T X, T Y, T Z); + void Set(T scale); + void Set(T vec[3]); + void Set(const NzVector2& vec, T Z = 0.0); + template void Set(const NzVector3& vec); + + T SquaredDistance(const NzVector3& vec) const; + T SquaredLength() const; + + NzString ToString() const; + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + const NzVector3& operator+() const; + NzVector3 operator-() const; + + NzVector3 operator+(const NzVector3& vec) const; + NzVector3 operator-(const NzVector3& vec) const; + NzVector3 operator*(const NzVector3& vec) const; + NzVector3 operator*(T scale) const; + NzVector3 operator/(const NzVector3& vec) const; + NzVector3 operator/(T scale) const; + + NzVector3& operator+=(const NzVector3& vec); + NzVector3& operator-=(const NzVector3& vec); + NzVector3& operator*=(const NzVector3& vec); + NzVector3& operator*=(T scale); + NzVector3& operator/=(const NzVector3& vec); + NzVector3& operator/=(T scale); + + bool operator==(const NzVector3& vec) const; + bool operator!=(const NzVector3& vec) const; + bool operator<(const NzVector3& vec) const; + bool operator<=(const NzVector3& vec) const; + bool operator>(const NzVector3& vec) const; + bool operator>=(const NzVector3& vec) const; + + static NzVector3 CrossProduct(const NzVector3& vec1, const NzVector3& vec2); + static T DotProduct(const NzVector3& vec1, const NzVector3& vec2); + static NzVector3 Forward(); + static NzVector3 Left(); + static NzVector3 Normalize(const NzVector3& vec); + static NzVector3 UnitX(); + static NzVector3 UnitY(); + static NzVector3 UnitZ(); + static NzVector3 Up(); + static NzVector3 Zero(); + + T x, y, z; +}; + +template std::ostream& operator<<(std::ostream& out, const NzVector3& vec); + +template NzVector3 operator*(T scale, const NzVector3& vec); +template NzVector3 operator/(T scale, const NzVector3& vec); + +typedef NzVector3 NzVector3d; +typedef NzVector3 NzVector3f; +typedef NzVector3 NzVector3i; +typedef NzVector3 NzVector3ui; + +#include + +#endif // NAZARA_VECTOR3_HPP diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 294aceaac..d0c72b984 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -1,599 +1,599 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzVector3::NzVector3() -{ -} - -template -NzVector3::NzVector3(T X, T Y, T Z) -{ - Set(X, Y, Z); -} - -template -NzVector3::NzVector3(T scale) -{ - Set(scale); -} - -template -NzVector3::NzVector3(T vec[3]) -{ - Set(vec); -} - -template -NzVector3::NzVector3(const NzVector2& vec, T Z) -{ - Set(vec, Z); -} - -template -template -NzVector3::NzVector3(const NzVector3& vec) -{ - Set(vec); -} - -template -T NzVector3::AbsDotProduct(const NzVector3& vec) const -{ - return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z); -} - -template<> -inline int NzVector3::AbsDotProduct(const NzVector3& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); -} - -template<> -inline unsigned int NzVector3::AbsDotProduct(const NzVector3& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); -} - -template -NzVector3 NzVector3::CrossProduct(const NzVector3& vec) const -{ - return NzVector3(y * vec.z - z * vec.y, z * vec.x - x * vec.z, x * vec.y - y * vec.x); -} - -template -T NzVector3::Distance(const NzVector3& vec) const -{ - return std::sqrt(SquaredDistance(vec)); -} - -template -float NzVector3::Distancef(const NzVector3& vec) const -{ - return std::sqrt(static_cast(SquaredDistance())); -} - -template -T NzVector3::DotProduct(const NzVector3& vec) const -{ - return x*vec.x + y*vec.y + z*vec.z; -} - -template -NzVector3 NzVector3::GetNormal() const -{ - NzVector3 vec(*this); - vec.Normalize(); - - return vec; -} - -template -T NzVector3::Length() const -{ - return std::sqrt(SquaredLength()); -} - -template -float NzVector3::Lengthf() const -{ - return std::sqrt(static_cast(SquaredLength())); -} - -template -void NzVector3::MakeForward() -{ - Set(F(0.0), F(0.0), F(-1.0)); -} - -template -void NzVector3::MakeLeft() -{ - Set(F(-1.0), F(0.0), F(0.0)); -} - -template -void NzVector3::MakeUnitX() -{ - Set(F(1.0), F(0.0), F(0.0)); -} - -template -void NzVector3::MakeUnitY() -{ - Set(F(0.0), F(1.0), F(0.0)); -} - -template -void NzVector3::MakeUnitZ() -{ - Set(F(0.0), F(0.0), F(1.0)); -} - -template -void NzVector3::MakeUp() -{ - Set(F(0.0), F(1.0), F(0.0)); -} - -template -void NzVector3::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0)); -} - -template -void NzVector3::Maximize(const NzVector3& vec) -{ - if (vec.x > x) - x = vec.x; - - if (vec.y > y) - y = vec.y; - - if (vec.z > z) - z = vec.z; -} - -template -void NzVector3::Minimize(const NzVector3& vec) -{ - if (vec.x < x) - x = vec.x; - - if (vec.y < y) - y = vec.y; - - if (vec.z < z) - z = vec.z; -} - -template -void NzVector3::Normalize() -{ - T squaredLength = SquaredLength(); - - if (!NzNumberEquals(squaredLength, F(1.0))) - { - T invLength = F(1.0) / std::sqrt(squaredLength); - - x *= invLength; - y *= invLength; - z *= invLength; - } -} - -template -void NzVector3::Set(T X, T Y, T Z) -{ - x = X; - y = Y; - z = Z; -} - -template -void NzVector3::Set(T scale) -{ - x = scale; - y = scale; - z = scale; -} - -template -void NzVector3::Set(T vec[3]) -{ - std::memcpy(&x, vec, 3*sizeof(T)); -} - -template -void NzVector3::Set(const NzVector2& vec, T Z) -{ - x = vec.x; - y = vec.y; - z = Z; -} - -template -template -void NzVector3::Set(const NzVector3& vec) -{ - x = F(vec.x); - y = F(vec.y); - z = F(vec.z); -} - -template -T NzVector3::SquaredDistance(const NzVector3& vec) const -{ - return operator-(vec).SquaredLength(); -} - -template -T NzVector3::SquaredLength() const -{ - return x*x + y*y + z*z; -} - -template -NzString NzVector3::ToString() const -{ - NzStringStream ss; - - return ss << "Vector3(" << x << ", " << y << ", " << z <<')'; -} - -template -NzVector3::operator NzString() const -{ - return ToString(); -} - -template -NzVector3::operator T*() -{ - return &x; -} - -template -NzVector3::operator const T*() const -{ - return &x; -} - -template -T& NzVector3::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector3::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 3) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; - - throw std::out_of_range(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -const NzVector3& NzVector3::operator+() const -{ - return *this; -} - -template -NzVector3 NzVector3::operator-() const -{ - return NzVector3(-x, -y, -z); -} - -template -NzVector3 NzVector3::operator+(const NzVector3& vec) const -{ - return NzVector3(x + vec.x, y + vec.y, z + vec.z); -} - -template -NzVector3 NzVector3::operator-(const NzVector3& vec) const -{ - return NzVector3(x - vec.x, y - vec.y, z - vec.z); -} - -template -NzVector3 NzVector3::operator*(const NzVector3& vec) const -{ - return NzVector3(x * vec.x, y * vec.y, z * vec.z); -} - -template -NzVector3 NzVector3::operator*(T scale) const -{ - return NzVector3(x * scale, y * scale, z * scale); -} - -template -NzVector3 NzVector3::operator/(const NzVector3& vec) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector3(x / vec.x, y / vec.y, z / vec.z); -} - -template -NzVector3 NzVector3::operator/(T scale) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector3(x / scale, y / scale, z / scale); -} - -template -NzVector3& NzVector3::operator+=(const NzVector3& vec) -{ - x += vec.x; - y += vec.y; - z += vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator-=(const NzVector3& vec) -{ - x -= vec.x; - y -= vec.y; - z -= vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator*=(const NzVector3& vec) -{ - x *= vec.x; - y *= vec.y; - z *= vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator*=(T scale) -{ - x *= scale; - y *= scale; - z *= scale; - - return *this; -} - -template -NzVector3& NzVector3::operator/=(const NzVector3& vec) -{ - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - - x /= vec.x; - y /= vec.y; - z /= vec.z; - - return *this; -} - -template -NzVector3& NzVector3::operator/=(T scale) -{ - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - - x /= scale; - y /= scale; - z /= scale; - - return *this; -} - -template -bool NzVector3::operator==(const NzVector3& vec) const -{ - return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y) && - NzNumberEquals(z, vec.z); -} - -template -bool NzVector3::operator!=(const NzVector3& vec) const -{ - return !operator==(vec); -} - -template -bool NzVector3::operator<(const NzVector3& vec) const -{ - return x < vec.x && y < vec.y && z < vec.z; -} - -template -bool NzVector3::operator<=(const NzVector3& vec) const -{ - return operator<(vec) || operator==(vec); -} - -template -bool NzVector3::operator>(const NzVector3& vec) const -{ - return !operator<=(vec); -} - -template -bool NzVector3::operator>=(const NzVector3& vec) const -{ - return !operator<(vec); -} - -template -NzVector3 NzVector3::CrossProduct(const NzVector3& vec1, const NzVector3& vec2) -{ - return vec1.CrossProduct(vec2); -} - -template -T NzVector3::DotProduct(const NzVector3& vec1, const NzVector3& vec2) -{ - return vec1.DotProduct(vec2); -} - -template -NzVector3 NzVector3::Forward() -{ - NzVector3 vector; - vector.MakeForward(); - - return vector; -} - -template -NzVector3 NzVector3::Left() -{ - NzVector3 vector; - vector.MakeLeft(); - - return vector; -} - -template -NzVector3 NzVector3::Normalize(const NzVector3& vec) -{ - return vec.GetNormal(); -} - -template -NzVector3 NzVector3::UnitX() -{ - NzVector3 vector; - vector.MakeUnitX(); - - return vector; -} - -template -NzVector3 NzVector3::UnitY() -{ - NzVector3 vector; - vector.MakeUnitY(); - - return vector; -} - -template -NzVector3 NzVector3::UnitZ() -{ - NzVector3 vector; - vector.MakeUnitZ(); - - return vector; -} - -template -NzVector3 NzVector3::Up() -{ - NzVector3 vector; - vector.MakeUp(); - - return vector; -} - -template -NzVector3 NzVector3::Zero() -{ - NzVector3 vector; - vector.MakeZero(); - - return vector; -} - -template -std::ostream& operator<<(std::ostream& out, const NzVector3& vec) -{ - return out << vec.ToString(); -} - -template -NzVector3 operator*(T scale, const NzVector3& vec) -{ - return NzVector3(scale * vec.x, scale * vec.y, scale * vec.z); -} - -template -NzVector3 operator/(T scale, const NzVector3& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector3(scale / vec.x, scale / vec.y, scale / vec.z); -} - -#undef F - -#include +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzVector3::NzVector3() +{ +} + +template +NzVector3::NzVector3(T X, T Y, T Z) +{ + Set(X, Y, Z); +} + +template +NzVector3::NzVector3(T scale) +{ + Set(scale); +} + +template +NzVector3::NzVector3(T vec[3]) +{ + Set(vec); +} + +template +NzVector3::NzVector3(const NzVector2& vec, T Z) +{ + Set(vec, Z); +} + +template +template +NzVector3::NzVector3(const NzVector3& vec) +{ + Set(vec); +} + +template +T NzVector3::AbsDotProduct(const NzVector3& vec) const +{ + return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z); +} + +template<> +inline int NzVector3::AbsDotProduct(const NzVector3& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); +} + +template<> +inline unsigned int NzVector3::AbsDotProduct(const NzVector3& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z); +} + +template +NzVector3 NzVector3::CrossProduct(const NzVector3& vec) const +{ + return NzVector3(y * vec.z - z * vec.y, z * vec.x - x * vec.z, x * vec.y - y * vec.x); +} + +template +T NzVector3::Distance(const NzVector3& vec) const +{ + return std::sqrt(SquaredDistance(vec)); +} + +template +float NzVector3::Distancef(const NzVector3& vec) const +{ + return std::sqrt(static_cast(SquaredDistance())); +} + +template +T NzVector3::DotProduct(const NzVector3& vec) const +{ + return x*vec.x + y*vec.y + z*vec.z; +} + +template +NzVector3 NzVector3::GetNormal() const +{ + NzVector3 vec(*this); + vec.Normalize(); + + return vec; +} + +template +T NzVector3::Length() const +{ + return std::sqrt(SquaredLength()); +} + +template +float NzVector3::Lengthf() const +{ + return std::sqrt(static_cast(SquaredLength())); +} + +template +void NzVector3::MakeForward() +{ + Set(F(0.0), F(0.0), F(-1.0)); +} + +template +void NzVector3::MakeLeft() +{ + Set(F(-1.0), F(0.0), F(0.0)); +} + +template +void NzVector3::MakeUnitX() +{ + Set(F(1.0), F(0.0), F(0.0)); +} + +template +void NzVector3::MakeUnitY() +{ + Set(F(0.0), F(1.0), F(0.0)); +} + +template +void NzVector3::MakeUnitZ() +{ + Set(F(0.0), F(0.0), F(1.0)); +} + +template +void NzVector3::MakeUp() +{ + Set(F(0.0), F(1.0), F(0.0)); +} + +template +void NzVector3::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0)); +} + +template +void NzVector3::Maximize(const NzVector3& vec) +{ + if (vec.x > x) + x = vec.x; + + if (vec.y > y) + y = vec.y; + + if (vec.z > z) + z = vec.z; +} + +template +void NzVector3::Minimize(const NzVector3& vec) +{ + if (vec.x < x) + x = vec.x; + + if (vec.y < y) + y = vec.y; + + if (vec.z < z) + z = vec.z; +} + +template +void NzVector3::Normalize() +{ + T squaredLength = SquaredLength(); + + if (!NzNumberEquals(squaredLength, F(1.0))) + { + T invLength = F(1.0) / std::sqrt(squaredLength); + + x *= invLength; + y *= invLength; + z *= invLength; + } +} + +template +void NzVector3::Set(T X, T Y, T Z) +{ + x = X; + y = Y; + z = Z; +} + +template +void NzVector3::Set(T scale) +{ + x = scale; + y = scale; + z = scale; +} + +template +void NzVector3::Set(T vec[3]) +{ + std::memcpy(&x, vec, 3*sizeof(T)); +} + +template +void NzVector3::Set(const NzVector2& vec, T Z) +{ + x = vec.x; + y = vec.y; + z = Z; +} + +template +template +void NzVector3::Set(const NzVector3& vec) +{ + x = F(vec.x); + y = F(vec.y); + z = F(vec.z); +} + +template +T NzVector3::SquaredDistance(const NzVector3& vec) const +{ + return operator-(vec).SquaredLength(); +} + +template +T NzVector3::SquaredLength() const +{ + return x*x + y*y + z*z; +} + +template +NzString NzVector3::ToString() const +{ + NzStringStream ss; + + return ss << "Vector3(" << x << ", " << y << ", " << z <<')'; +} + +template +NzVector3::operator NzString() const +{ + return ToString(); +} + +template +NzVector3::operator T*() +{ + return &x; +} + +template +NzVector3::operator const T*() const +{ + return &x; +} + +template +T& NzVector3::operator[](unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i >= 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +T NzVector3::operator[](unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i >= 3) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +const NzVector3& NzVector3::operator+() const +{ + return *this; +} + +template +NzVector3 NzVector3::operator-() const +{ + return NzVector3(-x, -y, -z); +} + +template +NzVector3 NzVector3::operator+(const NzVector3& vec) const +{ + return NzVector3(x + vec.x, y + vec.y, z + vec.z); +} + +template +NzVector3 NzVector3::operator-(const NzVector3& vec) const +{ + return NzVector3(x - vec.x, y - vec.y, z - vec.z); +} + +template +NzVector3 NzVector3::operator*(const NzVector3& vec) const +{ + return NzVector3(x * vec.x, y * vec.y, z * vec.z); +} + +template +NzVector3 NzVector3::operator*(T scale) const +{ + return NzVector3(x * scale, y * scale, z * scale); +} + +template +NzVector3 NzVector3::operator/(const NzVector3& vec) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector3(x / vec.x, y / vec.y, z / vec.z); +} + +template +NzVector3 NzVector3::operator/(T scale) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector3(x / scale, y / scale, z / scale); +} + +template +NzVector3& NzVector3::operator+=(const NzVector3& vec) +{ + x += vec.x; + y += vec.y; + z += vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator-=(const NzVector3& vec) +{ + x -= vec.x; + y -= vec.y; + z -= vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator*=(const NzVector3& vec) +{ + x *= vec.x; + y *= vec.y; + z *= vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator*=(T scale) +{ + x *= scale; + y *= scale; + z *= scale; + + return *this; +} + +template +NzVector3& NzVector3::operator/=(const NzVector3& vec) +{ + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + + x /= vec.x; + y /= vec.y; + z /= vec.z; + + return *this; +} + +template +NzVector3& NzVector3::operator/=(T scale) +{ + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + + x /= scale; + y /= scale; + z /= scale; + + return *this; +} + +template +bool NzVector3::operator==(const NzVector3& vec) const +{ + return NzNumberEquals(x, vec.x) && + NzNumberEquals(y, vec.y) && + NzNumberEquals(z, vec.z); +} + +template +bool NzVector3::operator!=(const NzVector3& vec) const +{ + return !operator==(vec); +} + +template +bool NzVector3::operator<(const NzVector3& vec) const +{ + return x < vec.x && y < vec.y && z < vec.z; +} + +template +bool NzVector3::operator<=(const NzVector3& vec) const +{ + return operator<(vec) || operator==(vec); +} + +template +bool NzVector3::operator>(const NzVector3& vec) const +{ + return !operator<=(vec); +} + +template +bool NzVector3::operator>=(const NzVector3& vec) const +{ + return !operator<(vec); +} + +template +NzVector3 NzVector3::CrossProduct(const NzVector3& vec1, const NzVector3& vec2) +{ + return vec1.CrossProduct(vec2); +} + +template +T NzVector3::DotProduct(const NzVector3& vec1, const NzVector3& vec2) +{ + return vec1.DotProduct(vec2); +} + +template +NzVector3 NzVector3::Forward() +{ + NzVector3 vector; + vector.MakeForward(); + + return vector; +} + +template +NzVector3 NzVector3::Left() +{ + NzVector3 vector; + vector.MakeLeft(); + + return vector; +} + +template +NzVector3 NzVector3::Normalize(const NzVector3& vec) +{ + return vec.GetNormal(); +} + +template +NzVector3 NzVector3::UnitX() +{ + NzVector3 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector3 NzVector3::UnitY() +{ + NzVector3 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector3 NzVector3::UnitZ() +{ + NzVector3 vector; + vector.MakeUnitZ(); + + return vector; +} + +template +NzVector3 NzVector3::Up() +{ + NzVector3 vector; + vector.MakeUp(); + + return vector; +} + +template +NzVector3 NzVector3::Zero() +{ + NzVector3 vector; + vector.MakeZero(); + + return vector; +} + +template +std::ostream& operator<<(std::ostream& out, const NzVector3& vec) +{ + return out << vec.ToString(); +} + +template +NzVector3 operator*(T scale, const NzVector3& vec) +{ + return NzVector3(scale * vec.x, scale * vec.y, scale * vec.z); +} + +template +NzVector3 operator/(T scale, const NzVector3& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector3(scale / vec.x, scale / vec.y, scale / vec.z); +} + +#undef F + +#include diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index b48502127..06b24b558 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -1,98 +1,98 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_VECTOR4_HPP -#define NAZARA_VECTOR4_HPP - -#include -#include - -template class NzVector4 -{ - public: - NzVector4(); - NzVector4(T X, T Y, T Z, T W = 1.0); - explicit NzVector4(T scale); - NzVector4(T vec[4]); - NzVector4(const NzVector3& vec, T W = 1.0); - template explicit NzVector4(const NzVector4& vec); - NzVector4(const NzVector4& vec) = default; - ~NzVector4() = default; - - T AbsDotProduct(const NzVector4& vec) const; - - T DotProduct(const NzVector4& vec) const; - - void MakeUnitX(); - void MakeUnitY(); - void MakeUnitZ(); - void MakeZero(); - - void Maximize(const NzVector4& vec); - void Minimize(const NzVector4& vec); - - void Normalize(); - - void Set(T X, T Y, T Z, T W = 1.0); - void Set(T scale); - void Set(T vec[4]); - void Set(const NzVector3& vec, T W = 1.0); - template void Set(const NzVector4& vec); - - NzString ToString() const; - - operator NzString() const; - - operator T*(); - operator const T*() const; - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - const NzVector4& operator+() const; - NzVector4 operator-() const; - - NzVector4 operator+(const NzVector4& vec) const; - NzVector4 operator-(const NzVector4& vec) const; - NzVector4 operator*(const NzVector4& vec) const; - NzVector4 operator*(T scale) const; - NzVector4 operator/(const NzVector4& vec) const; - NzVector4 operator/(T scale) const; - - NzVector4& operator+=(const NzVector4& vec); - NzVector4& operator-=(const NzVector4& vec); - NzVector4& operator*=(const NzVector4& vec); - NzVector4& operator*=(T scale); - NzVector4& operator/=(const NzVector4& vec); - NzVector4& operator/=(T scale); - - bool operator==(const NzVector4& vec) const; - bool operator!=(const NzVector4& vec) const; - bool operator<(const NzVector4& vec) const; - bool operator<=(const NzVector4& vec) const; - bool operator>(const NzVector4& vec) const; - bool operator>=(const NzVector4& vec) const; - - static NzVector4 UnitX(); - static NzVector4 UnitY(); - static NzVector4 UnitZ(); - static NzVector4 Zero(); - - T x, y, z, w; -}; - -template std::ostream& operator<<(std::ostream& out, const NzVector4& vec); - -template NzVector4 operator*(T scale, const NzVector4& vec); -template NzVector4 operator/(T scale, const NzVector4& vec); - -typedef NzVector4 NzVector4d; -typedef NzVector4 NzVector4f; -typedef NzVector4 NzVector4i; - -#include - -#endif // NAZARA_VECTOR4_HPP +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VECTOR4_HPP +#define NAZARA_VECTOR4_HPP + +#include +#include + +template class NzVector4 +{ + public: + NzVector4(); + NzVector4(T X, T Y, T Z, T W = 1.0); + explicit NzVector4(T scale); + NzVector4(T vec[4]); + NzVector4(const NzVector3& vec, T W = 1.0); + template explicit NzVector4(const NzVector4& vec); + NzVector4(const NzVector4& vec) = default; + ~NzVector4() = default; + + T AbsDotProduct(const NzVector4& vec) const; + + T DotProduct(const NzVector4& vec) const; + + void MakeUnitX(); + void MakeUnitY(); + void MakeUnitZ(); + void MakeZero(); + + void Maximize(const NzVector4& vec); + void Minimize(const NzVector4& vec); + + void Normalize(); + + void Set(T X, T Y, T Z, T W = 1.0); + void Set(T scale); + void Set(T vec[4]); + void Set(const NzVector3& vec, T W = 1.0); + template void Set(const NzVector4& vec); + + NzString ToString() const; + + operator NzString() const; + + operator T*(); + operator const T*() const; + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + const NzVector4& operator+() const; + NzVector4 operator-() const; + + NzVector4 operator+(const NzVector4& vec) const; + NzVector4 operator-(const NzVector4& vec) const; + NzVector4 operator*(const NzVector4& vec) const; + NzVector4 operator*(T scale) const; + NzVector4 operator/(const NzVector4& vec) const; + NzVector4 operator/(T scale) const; + + NzVector4& operator+=(const NzVector4& vec); + NzVector4& operator-=(const NzVector4& vec); + NzVector4& operator*=(const NzVector4& vec); + NzVector4& operator*=(T scale); + NzVector4& operator/=(const NzVector4& vec); + NzVector4& operator/=(T scale); + + bool operator==(const NzVector4& vec) const; + bool operator!=(const NzVector4& vec) const; + bool operator<(const NzVector4& vec) const; + bool operator<=(const NzVector4& vec) const; + bool operator>(const NzVector4& vec) const; + bool operator>=(const NzVector4& vec) const; + + static NzVector4 UnitX(); + static NzVector4 UnitY(); + static NzVector4 UnitZ(); + static NzVector4 Zero(); + + T x, y, z, w; +}; + +template std::ostream& operator<<(std::ostream& out, const NzVector4& vec); + +template NzVector4 operator*(T scale, const NzVector4& vec); +template NzVector4 operator/(T scale, const NzVector4& vec); + +typedef NzVector4 NzVector4d; +typedef NzVector4 NzVector4f; +typedef NzVector4 NzVector4i; + +#include + +#endif // NAZARA_VECTOR4_HPP diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index e3245c0ac..9d67e56ec 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -1,503 +1,503 @@ -// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D - -#define F(a) static_cast(a) - -template -NzVector4::NzVector4() -{ -} - -template -NzVector4::NzVector4(T X, T Y, T Z, T W) -{ - Set(X, Y, Z, W); -} - -template -NzVector4::NzVector4(T scale) -{ - Set(scale); -} - -template -NzVector4::NzVector4(T vec[4]) -{ - Set(vec); -} - -template -NzVector4::NzVector4(const NzVector3& vec, T W) -{ - Set(vec, W); -} - -template -template -NzVector4::NzVector4(const NzVector4& vec) -{ - Set(vec); -} - -template -T NzVector4::AbsDotProduct(const NzVector4& vec) const -{ - return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z) + std::fabs(w * vec.w); -} - -template<> -inline int NzVector4::AbsDotProduct(const NzVector4& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); -} - -template<> -inline unsigned int NzVector4::AbsDotProduct(const NzVector4& vec) const -{ - return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); -} - -template -T NzVector4::DotProduct(const NzVector4& vec) const -{ - return x*vec.x + y*vec.y + z*vec.z + w*vec.w; -} - -template -void NzVector4::MakeUnitX() -{ - Set(F(1.0), F(0.0), F(0.0), F(1.0)); -} - -template -void NzVector4::MakeUnitY() -{ - Set(F(0.0), F(1.0), F(0.0), F(1.0)); -} - -template -void NzVector4::MakeUnitZ() -{ - Set(F(0.0), F(0.0), F(1.0), F(1.0)); -} - -template -void NzVector4::MakeZero() -{ - Set(F(0.0), F(0.0), F(0.0), F(0.0)); -} - -template -void NzVector4::Maximize(const NzVector4& vec) -{ - if (vec.x > x) - x = vec.x; - - if (vec.y > y) - y = vec.y; - - if (vec.z > z) - z = vec.z; - - if (vec.w > w) - w = vec.w; -} - -template -void NzVector4::Minimize(const NzVector4& vec) -{ - if (vec.x < x) - x = vec.x; - - if (vec.y < y) - y = vec.y; - - if (vec.z < z) - z = vec.z; - - if (vec.w < w) - w = vec.w; -} - -template -void NzVector4::Normalize() -{ - if (!NzNumberEquals(w, F(0.0))) - { - x /= w; - y /= w; - z /= w; - } -} - -template -void NzVector4::Set(T X, T Y, T Z, T W) -{ - w = W; - x = X; - y = Y; - z = Z; -} - -template -void NzVector4::Set(T scale) -{ - w = scale; - x = scale; - y = scale; - z = scale; -} - -template -void NzVector4::Set(T vec[4]) -{ - std::memcpy(&x, vec, 4*sizeof(T)); -} - -template -void NzVector4::Set(const NzVector3& vec, T W) -{ - w = W; - x = vec.x; - y = vec.y; - z = vec.z; -} - -template -template -void NzVector4::Set(const NzVector4& vec) -{ - w = F(vec.w); - x = F(vec.x); - y = F(vec.y); - z = F(vec.z); -} - -template -NzString NzVector4::ToString() const -{ - NzStringStream ss; - - return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')'; -} - -template -NzVector4::operator NzString() const -{ - return ToString(); -} - -template -NzVector4::operator T*() -{ - return &x; -} - -template -NzVector4::operator const T*() const -{ - return &x; -} - -template -T& NzVector4::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 4) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector4::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 4) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -const NzVector4& NzVector4::operator+() const -{ - return *this; -} - -template -NzVector4 NzVector4::operator-() const -{ - return NzVector4(-x, -y, -z, -w); -} - -template -NzVector4 NzVector4::operator+(const NzVector4& vec) const -{ - return NzVector4(x + vec.x, y + vec.y, z + vec.z, w + vec.w); -} - -template -NzVector4 NzVector4::operator-(const NzVector4& vec) const -{ - return NzVector4(x - vec.x, y - vec.y, z - vec.z, w - vec.w); -} - -template -NzVector4 NzVector4::operator*(const NzVector4& vec) const -{ - return NzVector4(x * vec.x, y * vec.y, z * vec.z, w * vec.w); -} - -template -NzVector4 NzVector4::operator*(T scale) const -{ - return NzVector4(x * scale, y * scale, z * scale, w * scale); -} - -template -NzVector4 NzVector4::operator/(const NzVector4& vec) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w); -} - -template -NzVector4 NzVector4::operator/(T scale) const -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector4(x / scale, y / scale, z / scale, w / scale); -} - -template -NzVector4& NzVector4::operator+=(const NzVector4& vec) -{ - x += vec.x; - y += vec.y; - z += vec.z; - w += vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator-=(const NzVector4& vec) -{ - x -= vec.x; - y -= vec.y; - z -= vec.z; - w -= vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator*=(const NzVector4& vec) -{ - x *= vec.x; - y *= vec.y; - z *= vec.z; - w *= vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator*=(T scale) -{ - x *= scale; - y *= scale; - z *= scale; - w *= scale; - - return *this; -} - -template -NzVector4& NzVector4::operator/=(const NzVector4& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= vec.x; - y /= vec.y; - z /= vec.z; - w /= vec.w; - - return *this; -} - -template -NzVector4& NzVector4::operator/=(T scale) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(scale, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - x /= scale; - y /= scale; - z /= scale; - w /= scale; - - return *this; -} - -template -bool NzVector4::operator==(const NzVector4& vec) const -{ - return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y) && - NzNumberEquals(z, vec.z) && - NzNumberEquals(w, vec.w); -} - -template -bool NzVector4::operator!=(const NzVector4& vec) const -{ - return !operator==(vec); -} - -template -bool NzVector4::operator<(const NzVector4& vec) const -{ - return x < vec.x && y < vec.y && z < vec.z && w < vec.w; -} - -template -bool NzVector4::operator<=(const NzVector4& vec) const -{ - return operator<(vec) || operator==(vec); -} - -template -bool NzVector4::operator>(const NzVector4& vec) const -{ - return !operator<=(vec); -} - -template -bool NzVector4::operator>=(const NzVector4& vec) const -{ - return !operator<(vec); -} - -template -NzVector4 NzVector4::UnitX() -{ - NzVector4 vector; - vector.MakeUnitX(); - - return vector; -} - -template -NzVector4 NzVector4::UnitY() -{ - NzVector4 vector; - vector.MakeUnitY(); - - return vector; -} - -template -NzVector4 NzVector4::UnitZ() -{ - NzVector4 vector; - vector.MakeUnitZ(); - - return vector; -} - -template -NzVector4 NzVector4::Zero() -{ - NzVector4 vector; - vector.MakeZero(); - - return vector; -} - -template -std::ostream& operator<<(std::ostream& out, const NzVector4& vec) -{ - return out << vec.ToString(); -} - -template -NzVector4 operator*(T scale, const NzVector4& vec) -{ - return NzVector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); -} - -template -NzVector4 operator/(T scale, const NzVector4& vec) -{ - #if NAZARA_MATH_SAFE - if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) - { - NzStringStream ss; - ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; - - throw std::domain_error(ss.ToString()); - } - #endif - - return NzVector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); -} - -#undef F - -#include +// Copyright (C) 2012 Rémi Bèges - Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D + +#define F(a) static_cast(a) + +template +NzVector4::NzVector4() +{ +} + +template +NzVector4::NzVector4(T X, T Y, T Z, T W) +{ + Set(X, Y, Z, W); +} + +template +NzVector4::NzVector4(T scale) +{ + Set(scale); +} + +template +NzVector4::NzVector4(T vec[4]) +{ + Set(vec); +} + +template +NzVector4::NzVector4(const NzVector3& vec, T W) +{ + Set(vec, W); +} + +template +template +NzVector4::NzVector4(const NzVector4& vec) +{ + Set(vec); +} + +template +T NzVector4::AbsDotProduct(const NzVector4& vec) const +{ + return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z) + std::fabs(w * vec.w); +} + +template<> +inline int NzVector4::AbsDotProduct(const NzVector4& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); +} + +template<> +inline unsigned int NzVector4::AbsDotProduct(const NzVector4& vec) const +{ + return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w); +} + +template +T NzVector4::DotProduct(const NzVector4& vec) const +{ + return x*vec.x + y*vec.y + z*vec.z + w*vec.w; +} + +template +void NzVector4::MakeUnitX() +{ + Set(F(1.0), F(0.0), F(0.0), F(1.0)); +} + +template +void NzVector4::MakeUnitY() +{ + Set(F(0.0), F(1.0), F(0.0), F(1.0)); +} + +template +void NzVector4::MakeUnitZ() +{ + Set(F(0.0), F(0.0), F(1.0), F(1.0)); +} + +template +void NzVector4::MakeZero() +{ + Set(F(0.0), F(0.0), F(0.0), F(0.0)); +} + +template +void NzVector4::Maximize(const NzVector4& vec) +{ + if (vec.x > x) + x = vec.x; + + if (vec.y > y) + y = vec.y; + + if (vec.z > z) + z = vec.z; + + if (vec.w > w) + w = vec.w; +} + +template +void NzVector4::Minimize(const NzVector4& vec) +{ + if (vec.x < x) + x = vec.x; + + if (vec.y < y) + y = vec.y; + + if (vec.z < z) + z = vec.z; + + if (vec.w < w) + w = vec.w; +} + +template +void NzVector4::Normalize() +{ + if (!NzNumberEquals(w, F(0.0))) + { + x /= w; + y /= w; + z /= w; + } +} + +template +void NzVector4::Set(T X, T Y, T Z, T W) +{ + w = W; + x = X; + y = Y; + z = Z; +} + +template +void NzVector4::Set(T scale) +{ + w = scale; + x = scale; + y = scale; + z = scale; +} + +template +void NzVector4::Set(T vec[4]) +{ + std::memcpy(&x, vec, 4*sizeof(T)); +} + +template +void NzVector4::Set(const NzVector3& vec, T W) +{ + w = W; + x = vec.x; + y = vec.y; + z = vec.z; +} + +template +template +void NzVector4::Set(const NzVector4& vec) +{ + w = F(vec.w); + x = F(vec.x); + y = F(vec.y); + z = F(vec.z); +} + +template +NzString NzVector4::ToString() const +{ + NzStringStream ss; + + return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')'; +} + +template +NzVector4::operator NzString() const +{ + return ToString(); +} + +template +NzVector4::operator T*() +{ + return &x; +} + +template +NzVector4::operator const T*() const +{ + return &x; +} + +template +T& NzVector4::operator[](unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i >= 4) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +T NzVector4::operator[](unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i >= 4) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return *(&x+i); +} + +template +const NzVector4& NzVector4::operator+() const +{ + return *this; +} + +template +NzVector4 NzVector4::operator-() const +{ + return NzVector4(-x, -y, -z, -w); +} + +template +NzVector4 NzVector4::operator+(const NzVector4& vec) const +{ + return NzVector4(x + vec.x, y + vec.y, z + vec.z, w + vec.w); +} + +template +NzVector4 NzVector4::operator-(const NzVector4& vec) const +{ + return NzVector4(x - vec.x, y - vec.y, z - vec.z, w - vec.w); +} + +template +NzVector4 NzVector4::operator*(const NzVector4& vec) const +{ + return NzVector4(x * vec.x, y * vec.y, z * vec.z, w * vec.w); +} + +template +NzVector4 NzVector4::operator*(T scale) const +{ + return NzVector4(x * scale, y * scale, z * scale, w * scale); +} + +template +NzVector4 NzVector4::operator/(const NzVector4& vec) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w); +} + +template +NzVector4 NzVector4::operator/(T scale) const +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector4(x / scale, y / scale, z / scale, w / scale); +} + +template +NzVector4& NzVector4::operator+=(const NzVector4& vec) +{ + x += vec.x; + y += vec.y; + z += vec.z; + w += vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator-=(const NzVector4& vec) +{ + x -= vec.x; + y -= vec.y; + z -= vec.z; + w -= vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator*=(const NzVector4& vec) +{ + x *= vec.x; + y *= vec.y; + z *= vec.z; + w *= vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator*=(T scale) +{ + x *= scale; + y *= scale; + z *= scale; + w *= scale; + + return *this; +} + +template +NzVector4& NzVector4::operator/=(const NzVector4& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= vec.x; + y /= vec.y; + z /= vec.z; + w /= vec.w; + + return *this; +} + +template +NzVector4& NzVector4::operator/=(T scale) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(scale, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + x /= scale; + y /= scale; + z /= scale; + w /= scale; + + return *this; +} + +template +bool NzVector4::operator==(const NzVector4& vec) const +{ + return NzNumberEquals(x, vec.x) && + NzNumberEquals(y, vec.y) && + NzNumberEquals(z, vec.z) && + NzNumberEquals(w, vec.w); +} + +template +bool NzVector4::operator!=(const NzVector4& vec) const +{ + return !operator==(vec); +} + +template +bool NzVector4::operator<(const NzVector4& vec) const +{ + return x < vec.x && y < vec.y && z < vec.z && w < vec.w; +} + +template +bool NzVector4::operator<=(const NzVector4& vec) const +{ + return operator<(vec) || operator==(vec); +} + +template +bool NzVector4::operator>(const NzVector4& vec) const +{ + return !operator<=(vec); +} + +template +bool NzVector4::operator>=(const NzVector4& vec) const +{ + return !operator<(vec); +} + +template +NzVector4 NzVector4::UnitX() +{ + NzVector4 vector; + vector.MakeUnitX(); + + return vector; +} + +template +NzVector4 NzVector4::UnitY() +{ + NzVector4 vector; + vector.MakeUnitY(); + + return vector; +} + +template +NzVector4 NzVector4::UnitZ() +{ + NzVector4 vector; + vector.MakeUnitZ(); + + return vector; +} + +template +NzVector4 NzVector4::Zero() +{ + NzVector4 vector; + vector.MakeZero(); + + return vector; +} + +template +std::ostream& operator<<(std::ostream& out, const NzVector4& vec) +{ + return out << vec.ToString(); +} + +template +NzVector4 operator*(T scale, const NzVector4& vec) +{ + return NzVector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); +} + +template +NzVector4 operator/(T scale, const NzVector4& vec) +{ + #if NAZARA_MATH_SAFE + if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0))) + { + NzStringStream ss; + ss << __FILE__ << ':' << __LINE__ << ": Division by zero"; + + throw std::domain_error(ss.ToString()); + } + #endif + + return NzVector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); +} + +#undef F + +#include diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index 1b9a4dd0b..1b6342e47 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -1,41 +1,41 @@ -// This file was automatically generated by Nazara - -/* - Nazara Engine - Renderer module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// This file was automatically generated by Nazara + +/* + Nazara Engine - Renderer module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/Nazara/Renderer/Config.hpp b/include/Nazara/Renderer/Config.hpp index 1fafa11e6..dab42a297 100644 --- a/include/Nazara/Renderer/Config.hpp +++ b/include/Nazara/Renderer/Config.hpp @@ -1,41 +1,41 @@ -/* - Nazara Engine - Renderer module - - Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_RENDERER_HPP -#define NAZARA_CONFIG_RENDERER_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 - -// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL) -#define NAZARA_RENDERER_OPENGL_DEBUG 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_RENDERER_SAFE 1 - -#endif // NAZARA_CONFIG_MODULENAME_HPP +/* + Nazara Engine - Renderer module + + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_RENDERER_HPP +#define NAZARA_CONFIG_RENDERER_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0 + +// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL) +#define NAZARA_RENDERER_OPENGL_DEBUG 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_RENDERER_SAFE 1 + +#endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/Renderer/Context.hpp b/include/Nazara/Renderer/Context.hpp index f4bb5be7c..cd368ac94 100644 --- a/include/Nazara/Renderer/Context.hpp +++ b/include/Nazara/Renderer/Context.hpp @@ -1,49 +1,49 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_CONTEXT_HPP -#define NAZARA_CONTEXT_HPP - -#ifdef NAZARA_RENDERER_OPENGL - -#include -#include - -class NzContextImpl; - -class NAZARA_API NzContext : public NzResource -{ - friend NzContextImpl; - - public: - NzContext(); - ~NzContext(); - - bool Create(const NzContextParameters& parameters = NzContextParameters()); - void Destroy(); - - const NzContextParameters& GetParameters() const; - bool IsActive() const; - bool SetActive(bool active); - void SwapBuffers(); - - static bool EnsureContext(); - static NzContext* GetCurrent(); - static const NzContext* GetReference(); - static NzContext* GetThreadContext(); - static bool Initialize(); - static void Uninitialize(); - - private: - NzContextParameters m_parameters; - NzContextImpl* m_impl; - - static NzContext* s_reference; -}; - -#endif // NAZARA_RENDERER_OPENGL - -#endif // NAZARA_CONTEXT_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CONTEXT_HPP +#define NAZARA_CONTEXT_HPP + +#ifdef NAZARA_RENDERER_OPENGL + +#include +#include + +class NzContextImpl; + +class NAZARA_API NzContext : public NzResource +{ + friend NzContextImpl; + + public: + NzContext(); + ~NzContext(); + + bool Create(const NzContextParameters& parameters = NzContextParameters()); + void Destroy(); + + const NzContextParameters& GetParameters() const; + bool IsActive() const; + bool SetActive(bool active); + void SwapBuffers(); + + static bool EnsureContext(); + static NzContext* GetCurrent(); + static const NzContext* GetReference(); + static NzContext* GetThreadContext(); + static bool Initialize(); + static void Uninitialize(); + + private: + NzContextParameters m_parameters; + NzContextImpl* m_impl; + + static NzContext* s_reference; +}; + +#endif // NAZARA_RENDERER_OPENGL + +#endif // NAZARA_CONTEXT_HPP diff --git a/include/Nazara/Renderer/Enums.hpp b/include/Nazara/Renderer/Enums.hpp index 7abeca5ec..e3ca65d6a 100644 --- a/include/Nazara/Renderer/Enums.hpp +++ b/include/Nazara/Renderer/Enums.hpp @@ -1,174 +1,174 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_RENDERER_HPP -#define NAZARA_ENUMS_RENDERER_HPP - -enum nzAttachmentPoint -{ - nzAttachmentPoint_Color, - nzAttachmentPoint_Depth, - nzAttachmentPoint_DepthStencil, - nzAttachmentPoint_Stencil, - - nzAttachmentPoint_Max = nzAttachmentPoint_Stencil -}; - -enum nzBlendFunc -{ - nzBlendFunc_DestAlpha, - nzBlendFunc_DestColor, - nzBlendFunc_SrcAlpha, - nzBlendFunc_SrcColor, - nzBlendFunc_InvDestAlpha, - nzBlendFunc_InvDestColor, - nzBlendFunc_InvSrcAlpha, - nzBlendFunc_InvSrcColor, - nzBlendFunc_One, - nzBlendFunc_Zero, - - nzBlendFunc_Max = nzBlendFunc_Zero -}; - -enum nzFaceCulling -{ - nzFaceCulling_Back, - nzFaceCulling_Front, - nzFaceCulling_FrontAndBack, - - nzFaceCulling_Max = nzFaceCulling_FrontAndBack -}; - -enum nzFaceFilling -{ - nzFaceFilling_Point, - nzFaceFilling_Line, - nzFaceFilling_Fill, - - nzFaceFilling_Max = nzFaceFilling_Fill -}; - -enum nzMatrixType -{ - nzMatrixType_Projection, - nzMatrixType_View, - nzMatrixType_World, - - nzMatrixType_Max = nzMatrixType_World -}; - -enum nzPixelBufferType -{ - nzPixelBufferType_Pack, - nzPixelBufferType_Unpack, - - nzPixelBufferType_Max = nzPixelBufferType_Unpack -}; - -enum nzRendererCap -{ - nzRendererCap_AnisotropicFilter, - nzRendererCap_FP64, - nzRendererCap_HardwareBuffer, - nzRendererCap_MultipleRenderTargets, - nzRendererCap_OcclusionQuery, - nzRendererCap_PixelBufferObject, - nzRendererCap_RenderTexture, - nzRendererCap_Texture3D, - nzRendererCap_TextureCubemap, - nzRendererCap_TextureMulti, - nzRendererCap_TextureNPOT, - - nzRendererCap_Max = nzRendererCap_TextureNPOT -}; - -enum nzRendererClearFlags -{ - nzRendererClear_Color = 0x01, - nzRendererClear_Depth = 0x02, - nzRendererClear_Stencil = 0x04 -}; - -enum nzRendererComparison -{ - nzRendererComparison_Always, - nzRendererComparison_Equal, - nzRendererComparison_Greater, - nzRendererComparison_GreaterOrEqual, - nzRendererComparison_Less, - nzRendererComparison_LessOrEqual, - nzRendererComparison_Never, - - nzRendererComparison_Max = nzRendererComparison_Never -}; - -enum nzRendererParameter -{ - nzRendererParameter_Blend, - nzRendererParameter_ColorWrite, - nzRendererParameter_DepthTest, - nzRendererParameter_DepthWrite, - nzRendererParameter_FaceCulling, - nzRendererParameter_Stencil, - - nzRendererParameter_Max = nzRendererParameter_Stencil -}; - -enum nzShaderLanguage -{ - nzShaderLanguage_Unknown = -1, - - nzShaderLanguage_Cg, - nzShaderLanguage_GLSL, - - nzShaderLanguage_Max = nzShaderLanguage_GLSL -}; - -enum nzShaderType -{ - nzShaderType_Fragment, - nzShaderType_Geometry, - nzShaderType_Vertex, - - nzShaderType_Max = nzShaderType_Vertex -}; - -enum nzStencilOperation -{ - nzStencilOperation_Decrement, - nzStencilOperation_DecrementToSaturation, - nzStencilOperation_Increment, - nzStencilOperation_IncrementToSaturation, - nzStencilOperation_Invert, - nzStencilOperation_Keep, - nzStencilOperation_Replace, - nzStencilOperation_Zero, - - nzStencilOperation_Max = nzStencilOperation_Zero -}; - -enum nzTextureFilter -{ - nzTextureFilter_Unknown = -1, - - nzTextureFilter_Bilinear, - nzTextureFilter_Nearest, - nzTextureFilter_Trilinear, - - nzTextureFilter_Max = nzTextureFilter_Trilinear -}; - -enum nzTextureWrap -{ - nzTextureWrap_Unknown = -1, - - nzTextureWrap_Clamp, - nzTextureWrap_Repeat, - - nzTextureWrap_Max = nzTextureWrap_Repeat -}; - -#endif // NAZARA_ENUMS_RENDERER_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_RENDERER_HPP +#define NAZARA_ENUMS_RENDERER_HPP + +enum nzAttachmentPoint +{ + nzAttachmentPoint_Color, + nzAttachmentPoint_Depth, + nzAttachmentPoint_DepthStencil, + nzAttachmentPoint_Stencil, + + nzAttachmentPoint_Max = nzAttachmentPoint_Stencil +}; + +enum nzBlendFunc +{ + nzBlendFunc_DestAlpha, + nzBlendFunc_DestColor, + nzBlendFunc_SrcAlpha, + nzBlendFunc_SrcColor, + nzBlendFunc_InvDestAlpha, + nzBlendFunc_InvDestColor, + nzBlendFunc_InvSrcAlpha, + nzBlendFunc_InvSrcColor, + nzBlendFunc_One, + nzBlendFunc_Zero, + + nzBlendFunc_Max = nzBlendFunc_Zero +}; + +enum nzFaceCulling +{ + nzFaceCulling_Back, + nzFaceCulling_Front, + nzFaceCulling_FrontAndBack, + + nzFaceCulling_Max = nzFaceCulling_FrontAndBack +}; + +enum nzFaceFilling +{ + nzFaceFilling_Point, + nzFaceFilling_Line, + nzFaceFilling_Fill, + + nzFaceFilling_Max = nzFaceFilling_Fill +}; + +enum nzMatrixType +{ + nzMatrixType_Projection, + nzMatrixType_View, + nzMatrixType_World, + + nzMatrixType_Max = nzMatrixType_World +}; + +enum nzPixelBufferType +{ + nzPixelBufferType_Pack, + nzPixelBufferType_Unpack, + + nzPixelBufferType_Max = nzPixelBufferType_Unpack +}; + +enum nzRendererCap +{ + nzRendererCap_AnisotropicFilter, + nzRendererCap_FP64, + nzRendererCap_HardwareBuffer, + nzRendererCap_MultipleRenderTargets, + nzRendererCap_OcclusionQuery, + nzRendererCap_PixelBufferObject, + nzRendererCap_RenderTexture, + nzRendererCap_Texture3D, + nzRendererCap_TextureCubemap, + nzRendererCap_TextureMulti, + nzRendererCap_TextureNPOT, + + nzRendererCap_Max = nzRendererCap_TextureNPOT +}; + +enum nzRendererClearFlags +{ + nzRendererClear_Color = 0x01, + nzRendererClear_Depth = 0x02, + nzRendererClear_Stencil = 0x04 +}; + +enum nzRendererComparison +{ + nzRendererComparison_Always, + nzRendererComparison_Equal, + nzRendererComparison_Greater, + nzRendererComparison_GreaterOrEqual, + nzRendererComparison_Less, + nzRendererComparison_LessOrEqual, + nzRendererComparison_Never, + + nzRendererComparison_Max = nzRendererComparison_Never +}; + +enum nzRendererParameter +{ + nzRendererParameter_Blend, + nzRendererParameter_ColorWrite, + nzRendererParameter_DepthTest, + nzRendererParameter_DepthWrite, + nzRendererParameter_FaceCulling, + nzRendererParameter_Stencil, + + nzRendererParameter_Max = nzRendererParameter_Stencil +}; + +enum nzShaderLanguage +{ + nzShaderLanguage_Unknown = -1, + + nzShaderLanguage_Cg, + nzShaderLanguage_GLSL, + + nzShaderLanguage_Max = nzShaderLanguage_GLSL +}; + +enum nzShaderType +{ + nzShaderType_Fragment, + nzShaderType_Geometry, + nzShaderType_Vertex, + + nzShaderType_Max = nzShaderType_Vertex +}; + +enum nzStencilOperation +{ + nzStencilOperation_Decrement, + nzStencilOperation_DecrementToSaturation, + nzStencilOperation_Increment, + nzStencilOperation_IncrementToSaturation, + nzStencilOperation_Invert, + nzStencilOperation_Keep, + nzStencilOperation_Replace, + nzStencilOperation_Zero, + + nzStencilOperation_Max = nzStencilOperation_Zero +}; + +enum nzTextureFilter +{ + nzTextureFilter_Unknown = -1, + + nzTextureFilter_Bilinear, + nzTextureFilter_Nearest, + nzTextureFilter_Trilinear, + + nzTextureFilter_Max = nzTextureFilter_Trilinear +}; + +enum nzTextureWrap +{ + nzTextureWrap_Unknown = -1, + + nzTextureWrap_Clamp, + nzTextureWrap_Repeat, + + nzTextureWrap_Max = nzTextureWrap_Repeat +}; + +#endif // NAZARA_ENUMS_RENDERER_HPP diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index ce4468096..411627e93 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -1,233 +1,233 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_OPENGL_HPP -#define NAZARA_OPENGL_HPP - -#ifdef NAZARA_RENDERER_OPENGL - -// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier -#include -#include -#include -#include -#include - -// Inclusion des extensions -#include -#if defined(NAZARA_PLATFORM_WINDOWS) - #include -#elif defined(NAZARA_PLATFORM_LINUX) - #include -#endif - -enum nzOpenGLExtension -{ - nzOpenGLExtension_AnisotropicFilter, - nzOpenGLExtension_DebugOutput, - nzOpenGLExtension_FP64, - nzOpenGLExtension_FrameBufferObject, - nzOpenGLExtension_PixelBufferObject, - nzOpenGLExtension_SeparateShaderObjects, - nzOpenGLExtension_TextureArray, - nzOpenGLExtension_TextureCompression_s3tc, - nzOpenGLExtension_TextureStorage, - nzOpenGLExtension_VertexArrayObject, - - nzOpenGLExtension_Max = nzOpenGLExtension_VertexArrayObject -}; - -using NzOpenGLFunc = void (*)(); - -namespace NzOpenGL -{ - enum FormatType - { - FormatType_RenderBuffer, -// FormatType_MultisampleTexture, - FormatType_Texture - }; - - struct Format - { - GLenum dataFormat; - GLenum dataType; - GLint internalFormat; - }; - - NzOpenGLFunc GetEntry(const NzString& entryPoint); - unsigned int GetVersion(); - bool Initialize(); - bool IsSupported(nzOpenGLExtension extension); - bool IsSupported(const NzString& string); - bool TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType target); - void Uninitialize(); - - extern GLenum Attachment[nzAttachmentPoint_Max+1]; - extern nzUInt8 AttributeIndex[nzElementUsage_Max+1]; - extern GLenum BlendFunc[nzBlendFunc_Max+1]; - extern GLenum BufferLock[nzBufferAccess_Max+1]; - extern GLenum BufferLockRange[nzBufferAccess_Max+1]; - extern GLenum BufferTarget[nzBufferType_Max+1]; - extern GLenum BufferTargetBinding[nzBufferType_Max+1]; - extern GLenum BufferUsage[nzBufferUsage_Max+1]; - extern GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas prêt de changer - extern GLenum ElementType[nzElementType_Max+1]; - extern GLenum FaceCulling[nzFaceCulling_Max+1]; - extern GLenum FaceFilling[nzFaceFilling_Max+1]; - extern GLenum PrimitiveType[nzPrimitiveType_Max+1]; - extern GLenum RendererComparison[nzRendererComparison_Max+1]; - extern GLenum RendererParameter[nzRendererParameter_Max+1]; - extern GLenum ShaderType[nzShaderType_Max+1]; - extern GLenum StencilOperation[nzStencilOperation_Max+1]; - extern GLenum TextureTarget[nzImageType_Max+1]; - extern GLenum TextureTargetBinding[nzImageType_Max+1]; - extern GLenum TextureTargetProxy[nzImageType_Max+1]; -} - -NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; -NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader; -NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery; -NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; -NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer; -NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -NAZARA_API extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; -NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; -NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture; -NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; -NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc; -NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData; -NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; -NAZARA_API extern PFNGLCLEARPROC glClear; -NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor; -NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth; -NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil; -NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; -NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader; -NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; -NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; -NAZARA_API extern PFNGLCULLFACEPROC glCullFace; -NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; -NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; -NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; -NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; -NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; -NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; -NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; -NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; -NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; -NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; -NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader; -NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; -NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; -NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc; -NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask; -NAZARA_API extern PFNGLDISABLEPROC glDisable; -NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; -NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays; -NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; -NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; -NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements; -NAZARA_API extern PFNGLENDQUERYPROC glEndQuery; -NAZARA_API extern PFNGLFLUSHPROC glFlush; -NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; -NAZARA_API extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; -NAZARA_API extern PFNGLENABLEPROC glEnable; -NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; -NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; -NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers; -NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; -NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries; -NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; -NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures; -NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; -NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; -NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; -NAZARA_API extern PFNGLGETERRORPROC glGetError; -NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv; -NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; -NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; -NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv; -NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; -NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; -NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; -NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv; -NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; -NAZARA_API extern PFNGLGETSTRINGPROC glGetString; -NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi; -NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; -NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; -NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; -NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; -NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; -NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; -NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram; -NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer; -NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; -NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei; -NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode; -NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; -NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; -NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; -NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; -NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; -NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; -NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; -NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; -NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; -NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels; -NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; -NAZARA_API extern PFNGLSCISSORPROC glScissor; -NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource; -NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc; -NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp; -NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; -NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; -NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; -NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; -NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; -NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; -NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; -NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; -NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; -NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; -NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; -NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d; -NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f; -NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i; -NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv; -NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv; -NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv; -NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv; -NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv; -NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv; -NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; -NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; -NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; -NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram; -NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; -NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; -NAZARA_API extern PFNGLVIEWPORTPROC glViewport; -#if defined(NAZARA_PLATFORM_WINDOWS) -NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; -NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; -NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; -NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; -NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; -#elif defined(NAZARA_PLATFORM_LINUX) -NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; -NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval; -#endif - -#endif // NAZARA_RENDERER_OPENGL - -#endif // NAZARA_OPENGL_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_OPENGL_HPP +#define NAZARA_OPENGL_HPP + +#ifdef NAZARA_RENDERER_OPENGL + +// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier +#include +#include +#include +#include +#include + +// Inclusion des extensions +#include +#if defined(NAZARA_PLATFORM_WINDOWS) + #include +#elif defined(NAZARA_PLATFORM_LINUX) + #include +#endif + +enum nzOpenGLExtension +{ + nzOpenGLExtension_AnisotropicFilter, + nzOpenGLExtension_DebugOutput, + nzOpenGLExtension_FP64, + nzOpenGLExtension_FrameBufferObject, + nzOpenGLExtension_PixelBufferObject, + nzOpenGLExtension_SeparateShaderObjects, + nzOpenGLExtension_TextureArray, + nzOpenGLExtension_TextureCompression_s3tc, + nzOpenGLExtension_TextureStorage, + nzOpenGLExtension_VertexArrayObject, + + nzOpenGLExtension_Max = nzOpenGLExtension_VertexArrayObject +}; + +using NzOpenGLFunc = void (*)(); + +namespace NzOpenGL +{ + enum FormatType + { + FormatType_RenderBuffer, +// FormatType_MultisampleTexture, + FormatType_Texture + }; + + struct Format + { + GLenum dataFormat; + GLenum dataType; + GLint internalFormat; + }; + + NzOpenGLFunc GetEntry(const NzString& entryPoint); + unsigned int GetVersion(); + bool Initialize(); + bool IsSupported(nzOpenGLExtension extension); + bool IsSupported(const NzString& string); + bool TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType target); + void Uninitialize(); + + extern GLenum Attachment[nzAttachmentPoint_Max+1]; + extern nzUInt8 AttributeIndex[nzElementUsage_Max+1]; + extern GLenum BlendFunc[nzBlendFunc_Max+1]; + extern GLenum BufferLock[nzBufferAccess_Max+1]; + extern GLenum BufferLockRange[nzBufferAccess_Max+1]; + extern GLenum BufferTarget[nzBufferType_Max+1]; + extern GLenum BufferTargetBinding[nzBufferType_Max+1]; + extern GLenum BufferUsage[nzBufferUsage_Max+1]; + extern GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas prêt de changer + extern GLenum ElementType[nzElementType_Max+1]; + extern GLenum FaceCulling[nzFaceCulling_Max+1]; + extern GLenum FaceFilling[nzFaceFilling_Max+1]; + extern GLenum PrimitiveType[nzPrimitiveType_Max+1]; + extern GLenum RendererComparison[nzRendererComparison_Max+1]; + extern GLenum RendererParameter[nzRendererParameter_Max+1]; + extern GLenum ShaderType[nzShaderType_Max+1]; + extern GLenum StencilOperation[nzStencilOperation_Max+1]; + extern GLenum TextureTarget[nzImageType_Max+1]; + extern GLenum TextureTargetBinding[nzImageType_Max+1]; + extern GLenum TextureTargetProxy[nzImageType_Max+1]; +} + +NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; +NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader; +NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery; +NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; +NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer; +NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +NAZARA_API extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation; +NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; +NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture; +NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; +NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc; +NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData; +NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData; +NAZARA_API extern PFNGLCLEARPROC glClear; +NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor; +NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth; +NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil; +NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram; +NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader; +NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; +NAZARA_API extern PFNGLCOLORMASKPROC glColorMask; +NAZARA_API extern PFNGLCULLFACEPROC glCullFace; +NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader; +NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D; +NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback; +NAZARA_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl; +NAZARA_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert; +NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; +NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; +NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram; +NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries; +NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers; +NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader; +NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures; +NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; +NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc; +NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask; +NAZARA_API extern PFNGLDISABLEPROC glDisable; +NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; +NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays; +NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer; +NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers; +NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements; +NAZARA_API extern PFNGLENDQUERYPROC glEndQuery; +NAZARA_API extern PFNGLFLUSHPROC glFlush; +NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D; +NAZARA_API extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer; +NAZARA_API extern PFNGLENABLEPROC glEnable; +NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; +NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; +NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers; +NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries; +NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; +NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures; +NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; +NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv; +NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog; +NAZARA_API extern PFNGLGETERRORPROC glGetError; +NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv; +NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv; +NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; +NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv; +NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv; +NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv; +NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; +NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv; +NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource; +NAZARA_API extern PFNGLGETSTRINGPROC glGetString; +NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi; +NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage; +NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv; +NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv; +NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv; +NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv; +NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; +NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram; +NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer; +NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei; +NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode; +NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d; +NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f; +NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i; +NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv; +NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv; +NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv; +NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv; +NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv; +NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv; +NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels; +NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage; +NAZARA_API extern PFNGLSCISSORPROC glScissor; +NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource; +NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc; +NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp; +NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D; +NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D; +NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D; +NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf; +NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri; +NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; +NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; +NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; +NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D; +NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D; +NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D; +NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d; +NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f; +NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i; +NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv; +NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv; +NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv; +NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv; +NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv; +NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv; +NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv; +NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; +NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; +NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram; +NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f; +NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; +NAZARA_API extern PFNGLVIEWPORTPROC glViewport; +#if defined(NAZARA_PLATFORM_WINDOWS) +NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; +NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; +NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; +NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT; +NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval; +#elif defined(NAZARA_PLATFORM_LINUX) +NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs; +NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval; +#endif + +#endif // NAZARA_RENDERER_OPENGL + +#endif // NAZARA_OPENGL_HPP diff --git a/include/Nazara/Renderer/RenderTarget.hpp b/include/Nazara/Renderer/RenderTarget.hpp index 1c7ddaab9..82779c649 100644 --- a/include/Nazara/Renderer/RenderTarget.hpp +++ b/include/Nazara/Renderer/RenderTarget.hpp @@ -1,41 +1,41 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RENDERTARGET_HPP -#define NAZARA_RENDERTARGET_HPP - -#include -#include -#include - -class NzRenderer; - -class NAZARA_API NzRenderTarget -{ - friend class NzRenderer; - - public: - NzRenderTarget() = default; - virtual ~NzRenderTarget(); - - virtual unsigned int GetHeight() const = 0; - virtual NzRenderTargetParameters GetParameters() const = 0; - virtual unsigned int GetWidth() const = 0; - - bool IsActive() const; - virtual bool IsRenderable() const = 0; - - bool SetActive(bool active); - - // Fonctions OpenGL - virtual bool HasContext() const = 0; - - protected: - virtual bool Activate() = 0; - virtual void Desactivate(); -}; - -#endif // NAZARA_RENDERTARGET_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RENDERTARGET_HPP +#define NAZARA_RENDERTARGET_HPP + +#include +#include +#include + +class NzRenderer; + +class NAZARA_API NzRenderTarget +{ + friend class NzRenderer; + + public: + NzRenderTarget() = default; + virtual ~NzRenderTarget(); + + virtual unsigned int GetHeight() const = 0; + virtual NzRenderTargetParameters GetParameters() const = 0; + virtual unsigned int GetWidth() const = 0; + + bool IsActive() const; + virtual bool IsRenderable() const = 0; + + bool SetActive(bool active); + + // Fonctions OpenGL + virtual bool HasContext() const = 0; + + protected: + virtual bool Activate() = 0; + virtual void Desactivate(); +}; + +#endif // NAZARA_RENDERTARGET_HPP diff --git a/include/Nazara/Renderer/RenderTexture.hpp b/include/Nazara/Renderer/RenderTexture.hpp index e7be88f88..1007dd281 100644 --- a/include/Nazara/Renderer/RenderTexture.hpp +++ b/include/Nazara/Renderer/RenderTexture.hpp @@ -1,60 +1,60 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RENDERTEXTURE_HPP -#define NAZARA_RENDERTEXTURE_HPP - -#include -#include -#include -#include -#include -#include - -struct NzRenderTextureImpl; - -class NAZARA_API NzRenderTexture : public NzRenderTarget, NzResourceListener, NzNonCopyable -{ - public: - NzRenderTexture() = default; - ~NzRenderTexture(); - - bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format); - bool AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture); - bool AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z); - - bool Create(unsigned int width, unsigned int height, bool lock = false); - void Destroy(); - - void Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index); - - unsigned int GetHeight() const; - NzRenderTargetParameters GetParameters() const; - unsigned int GetWidth() const; - - bool IsComplete() const; - bool IsRenderable() const; - bool IsValid() const; - - bool Lock() const; - void Unlock() const; - - // Fonctions OpenGL - bool HasContext() const; - - static bool IsSupported(); - - protected: - bool Activate() override; - void Desactivate() override; - - private: - void OnResourceDestroy(const NzResource* resource, int index) override; - - NzRenderTextureImpl* m_impl = nullptr; -}; - -#endif // NAZARA_RENDERTEXTURE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_RENDERTEXTURE_HPP +#define NAZARA_RENDERTEXTURE_HPP + +#include +#include +#include +#include +#include +#include + +struct NzRenderTextureImpl; + +class NAZARA_API NzRenderTexture : public NzRenderTarget, NzResourceListener, NzNonCopyable +{ + public: + NzRenderTexture() = default; + ~NzRenderTexture(); + + bool AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format); + bool AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture); + bool AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z); + + bool Create(unsigned int width, unsigned int height, bool lock = false); + void Destroy(); + + void Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index); + + unsigned int GetHeight() const; + NzRenderTargetParameters GetParameters() const; + unsigned int GetWidth() const; + + bool IsComplete() const; + bool IsRenderable() const; + bool IsValid() const; + + bool Lock() const; + void Unlock() const; + + // Fonctions OpenGL + bool HasContext() const; + + static bool IsSupported(); + + protected: + bool Activate() override; + void Desactivate() override; + + private: + void OnResourceDestroy(const NzResource* resource, int index) override; + + NzRenderTextureImpl* m_impl = nullptr; +}; + +#endif // NAZARA_RENDERTEXTURE_HPP diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index fdef4b2c0..7df1bfb4d 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -1,68 +1,68 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// Interface inspirée de la SFML par Laurent Gomila - -#pragma once - -#ifndef NAZARA_RENDERWINDOW_HPP -#define NAZARA_RENDERWINDOW_HPP - -#include -#include -#include -#include -#include -#include - -class NzContext; -class NzImage; -class NzTexture; -struct NzContextParameters; - -class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow -{ - public: - NzRenderWindow() = default; - NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); - NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); - virtual ~NzRenderWindow(); - - bool CopyToImage(NzImage* image); ///TODO: Const - bool CopyToTexture(NzTexture* texture); ///TODO: Const - - bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); - bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); - - void Display(); - - void EnableVerticalSync(bool enabled); - - unsigned int GetHeight() const; - NzRenderTargetParameters GetParameters() const; - unsigned int GetWidth() const; - - bool IsRenderable() const; - bool IsValid() const; - - void SetFramerateLimit(unsigned int limit); - - // Fonctions OpenGL - NzContextParameters GetContextParameters() const; - bool HasContext() const; - - protected: - bool Activate() override; - - private: - bool OnWindowCreated() override; - void OnWindowDestroy() override; - - NzClock m_clock; - NzContextParameters m_parameters; - NzContext* m_context = nullptr; - unsigned int m_framerateLimit = 0; -}; - -#endif // NAZARA_RENDERWINDOW_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Interface inspirée de la SFML par Laurent Gomila + +#pragma once + +#ifndef NAZARA_RENDERWINDOW_HPP +#define NAZARA_RENDERWINDOW_HPP + +#include +#include +#include +#include +#include +#include + +class NzContext; +class NzImage; +class NzTexture; +struct NzContextParameters; + +class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow +{ + public: + NzRenderWindow() = default; + NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); + NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); + virtual ~NzRenderWindow(); + + bool CopyToImage(NzImage* image); ///TODO: Const + bool CopyToTexture(NzTexture* texture); ///TODO: Const + + bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters()); + bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters()); + + void Display(); + + void EnableVerticalSync(bool enabled); + + unsigned int GetHeight() const; + NzRenderTargetParameters GetParameters() const; + unsigned int GetWidth() const; + + bool IsRenderable() const; + bool IsValid() const; + + void SetFramerateLimit(unsigned int limit); + + // Fonctions OpenGL + NzContextParameters GetContextParameters() const; + bool HasContext() const; + + protected: + bool Activate() override; + + private: + bool OnWindowCreated() override; + void OnWindowDestroy() override; + + NzClock m_clock; + NzContextParameters m_parameters; + NzContext* m_context = nullptr; + unsigned int m_framerateLimit = 0; +}; + +#endif // NAZARA_RENDERWINDOW_HPP diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index 9dc2e6222..9a849146e 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -1,92 +1,92 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_TEXTURE_HPP -#define NAZARA_TEXTURE_HPP - -#include -#include -#include -#include -#include - -class NzRenderTexture; -struct NzTextureImpl; - -class NAZARA_API NzTexture : public NzResource, NzNonCopyable -{ - friend NzRenderTexture; - friend class NzShader; - - public: - NzTexture(); - explicit NzTexture(const NzImage& image); - ~NzTexture(); - - bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false); - void Destroy(); - - bool Download(NzImage* image) const; - - bool EnableMipmapping(bool enable); - - unsigned int GetAnisotropyLevel() const; - nzUInt8 GetBPP() const; - unsigned int GetDepth() const; - nzTextureFilter GetFilterMode() const; - nzPixelFormat GetFormat() const; - unsigned int GetHeight() const; - nzImageType GetType() const; - unsigned int GetWidth() const; - nzTextureWrap GetWrapMode() const; - - bool IsCompressed() const; - bool IsCubemap() const; - bool IsTarget() const; - bool IsValid() const; - - bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams()); - bool LoadFromImage(const NzImage& image); - bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams()); - bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams()); - - bool Lock(); - - bool SetAnisotropyLevel(unsigned int anistropyLevel); - bool SetFilterMode(nzTextureFilter filter); - bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel); - bool SetWrapMode(nzTextureWrap wrap); - - bool Update(const NzImage& image, nzUInt8 level = 0); - bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); - bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0); - bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0); - - void Unlock(); - - // Fonctions OpenGL - unsigned int GetOpenGLID() const; - bool Prepare() const; - - static unsigned int GetValidSize(unsigned int size); - static bool IsFormatSupported(nzPixelFormat format); - static bool IsMipmappingSupported(); - static bool IsTypeSupported(nzImageType type); - - private: - NzRenderTexture* GetRenderTexture() const; - void SetRenderTexture(NzRenderTexture* renderTexture); - - NzTextureImpl* m_impl; -}; - -#endif // NAZARA_TEXTURE_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_TEXTURE_HPP +#define NAZARA_TEXTURE_HPP + +#include +#include +#include +#include +#include + +class NzRenderTexture; +struct NzTextureImpl; + +class NAZARA_API NzTexture : public NzResource, NzNonCopyable +{ + friend NzRenderTexture; + friend class NzShader; + + public: + NzTexture(); + explicit NzTexture(const NzImage& image); + ~NzTexture(); + + bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false); + void Destroy(); + + bool Download(NzImage* image) const; + + bool EnableMipmapping(bool enable); + + unsigned int GetAnisotropyLevel() const; + nzUInt8 GetBPP() const; + unsigned int GetDepth() const; + nzTextureFilter GetFilterMode() const; + nzPixelFormat GetFormat() const; + unsigned int GetHeight() const; + nzImageType GetType() const; + unsigned int GetWidth() const; + nzTextureWrap GetWrapMode() const; + + bool IsCompressed() const; + bool IsCubemap() const; + bool IsTarget() const; + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams()); + bool LoadFromImage(const NzImage& image); + bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams()); + bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams()); + + bool Lock(); + + bool SetAnisotropyLevel(unsigned int anistropyLevel); + bool SetFilterMode(nzTextureFilter filter); + bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel); + bool SetWrapMode(nzTextureWrap wrap); + + bool Update(const NzImage& image, nzUInt8 level = 0); + bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); + bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0); + bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0); + + void Unlock(); + + // Fonctions OpenGL + unsigned int GetOpenGLID() const; + bool Prepare() const; + + static unsigned int GetValidSize(unsigned int size); + static bool IsFormatSupported(nzPixelFormat format); + static bool IsMipmappingSupported(); + static bool IsTypeSupported(nzImageType type); + + private: + NzRenderTexture* GetRenderTexture() const; + void SetRenderTexture(NzRenderTexture* renderTexture); + + NzTextureImpl* m_impl; +}; + +#endif // NAZARA_TEXTURE_HPP diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index c5403b9f3..f39931ec9 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -1,78 +1,78 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ANIMATION_HPP -#define NAZARA_ANIMATION_HPP - -#include -#include -#include -#include -#include - -struct NzAnimationParams -{ - unsigned int endFrame = static_cast(-1); - unsigned int startFrame = 0; - - bool IsValid() const; -}; - -struct NzSequence -{ - NzString name; - unsigned int firstFrame; - unsigned int lastFrame; - unsigned int framePerSecond; -}; - -class NzAnimation; - -using NzAnimationLoader = NzResourceLoader; - -struct NzAnimationImpl; - -class NAZARA_API NzAnimation : public NzResource -{ - friend NzAnimationLoader; - - public: - NzAnimation() = default; - ~NzAnimation(); - - bool AddSequence(const NzSequence& sequence); - - bool Create(nzAnimationType type, unsigned int frameCount); - void Destroy(); - - unsigned int GetFrameCount() const; - NzSequence* GetSequence(const NzString& sequenceName); - NzSequence* GetSequence(unsigned int index); - const NzSequence* GetSequence(const NzString& sequenceName) const; - const NzSequence* GetSequence(unsigned int index) const; - unsigned int GetSequenceCount() const; - int GetSequenceIndex(const NzString& sequenceName) const; - nzAnimationType GetType() const; - - bool HasSequence(const NzString& sequenceName) const; - bool HasSequence(unsigned int index = 0) const; - - bool IsValid() const; - - bool LoadFromFile(const NzString& filePath, const NzAnimationParams& params = NzAnimationParams()); - bool LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params = NzAnimationParams()); - bool LoadFromStream(NzInputStream& stream, const NzAnimationParams& params = NzAnimationParams()); - - void RemoveSequence(const NzString& sequenceName); - void RemoveSequence(unsigned int index); - - private: - NzAnimationImpl* m_impl = nullptr; - - static NzAnimationLoader::LoaderList s_loaders; -}; - -#endif // NAZARA_ANIMATION_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ANIMATION_HPP +#define NAZARA_ANIMATION_HPP + +#include +#include +#include +#include +#include + +struct NzAnimationParams +{ + unsigned int endFrame = static_cast(-1); + unsigned int startFrame = 0; + + bool IsValid() const; +}; + +struct NzSequence +{ + NzString name; + unsigned int firstFrame; + unsigned int lastFrame; + unsigned int framePerSecond; +}; + +class NzAnimation; + +using NzAnimationLoader = NzResourceLoader; + +struct NzAnimationImpl; + +class NAZARA_API NzAnimation : public NzResource +{ + friend NzAnimationLoader; + + public: + NzAnimation() = default; + ~NzAnimation(); + + bool AddSequence(const NzSequence& sequence); + + bool Create(nzAnimationType type, unsigned int frameCount); + void Destroy(); + + unsigned int GetFrameCount() const; + NzSequence* GetSequence(const NzString& sequenceName); + NzSequence* GetSequence(unsigned int index); + const NzSequence* GetSequence(const NzString& sequenceName) const; + const NzSequence* GetSequence(unsigned int index) const; + unsigned int GetSequenceCount() const; + int GetSequenceIndex(const NzString& sequenceName) const; + nzAnimationType GetType() const; + + bool HasSequence(const NzString& sequenceName) const; + bool HasSequence(unsigned int index = 0) const; + + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzAnimationParams& params = NzAnimationParams()); + bool LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params = NzAnimationParams()); + bool LoadFromStream(NzInputStream& stream, const NzAnimationParams& params = NzAnimationParams()); + + void RemoveSequence(const NzString& sequenceName); + void RemoveSequence(unsigned int index); + + private: + NzAnimationImpl* m_impl = nullptr; + + static NzAnimationLoader::LoaderList s_loaders; +}; + +#endif // NAZARA_ANIMATION_HPP diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index 4fbe7dc8e..39dd17751 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -1,250 +1,250 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_UTILITY_HPP -#define NAZARA_ENUMS_UTILITY_HPP - -enum nzAnimationType -{ - nzAnimationType_Keyframe, - nzAnimationType_Skeletal, - nzAnimationType_Static, - - nzAnimationType_Max = nzAnimationType_Static -}; - -enum nzBufferAccess -{ - nzBufferAccess_DiscardAndWrite, - nzBufferAccess_ReadOnly, - nzBufferAccess_ReadWrite, - nzBufferAccess_WriteOnly, - - nzBufferAccess_Max = nzBufferAccess_WriteOnly -}; - -enum nzBufferStorage -{ - //nzBufferStorage_Both, - nzBufferStorage_Hardware, - nzBufferStorage_Software, - - nzBufferStorage_Max = nzBufferStorage_Software -}; - -enum nzBufferType -{ - nzBufferType_Index, - nzBufferType_Vertex, - - nzBufferType_Max = nzBufferType_Vertex -}; - -enum nzBufferUsage -{ - nzBufferUsage_Dynamic, - nzBufferUsage_Static, - - nzBufferUsage_Max = nzBufferUsage_Static -}; - -enum nzCubemapFace -{ - // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap - // L'ordre est X, -X, Y, -Y, Z, -Z - nzCubemapFace_PositiveX = 0, - nzCubemapFace_PositiveY = 2, - nzCubemapFace_PositiveZ = 4, - nzCubemapFace_NegativeX = 1, - nzCubemapFace_NegativeY = 3, - nzCubemapFace_NegativeZ = 5, - - nzCubemapFace_Max = nzCubemapFace_NegativeZ -}; - -enum nzElementStream -{ - nzElementStream_VertexData, - nzElementStream_InstancedData, - - nzElementStream_Max = nzElementStream_InstancedData -}; - -enum nzElementType -{ - nzElementType_Color, - nzElementType_Double1, - nzElementType_Double2, - nzElementType_Double3, - nzElementType_Double4, - nzElementType_Float1, - nzElementType_Float2, - nzElementType_Float3, - nzElementType_Float4, - - nzElementType_Max = nzElementType_Float4 -}; - -enum nzElementUsage -{ - nzElementUsage_Diffuse, - nzElementUsage_Normal, - nzElementUsage_Position, - nzElementUsage_Tangent, - nzElementUsage_TexCoord, - - nzElementUsage_Max = nzElementUsage_TexCoord -}; - -enum nzEventType -{ - nzEventType_GainedFocus, - nzEventType_LostFocus, - nzEventType_KeyPressed, - nzEventType_KeyReleased, - nzEventType_MouseButtonDoubleClicked, - nzEventType_MouseButtonPressed, - nzEventType_MouseButtonReleased, - nzEventType_MouseEntered, - nzEventType_MouseLeft, - nzEventType_MouseMoved, - nzEventType_MouseWheelMoved, - nzEventType_Moved, - nzEventType_Quit, - nzEventType_Resized, - nzEventType_TextEntered, - - nzEventType_Max = nzEventType_TextEntered -}; - -enum nzExtend -{ - nzExtend_Finite, - nzExtend_Infinite, - nzExtend_Null, - - nzExtend_Max = nzExtend_Null -}; - -enum nzImageType -{ - nzImageType_1D, - nzImageType_1D_Array, - nzImageType_2D, - nzImageType_2D_Array, - nzImageType_3D, - nzImageType_Cubemap, - - nzImageType_Max = nzImageType_Cubemap -}; - -enum nzPixelFormat -{ - nzPixelFormat_Undefined = -1, - - nzPixelFormat_BGR8, // 3*nzUInt8 - nzPixelFormat_BGRA8, // 4*nzUInt8 - nzPixelFormat_DXT1, - nzPixelFormat_DXT3, - nzPixelFormat_DXT5, - nzPixelFormat_L8, // 1*nzUInt8 - nzPixelFormat_LA8, // 2*nzUInt8 - /* - nzPixelFormat_RGB16F, - nzPixelFormat_RGB16I, // 4*nzUInt16 - nzPixelFormat_RGB32F, - nzPixelFormat_RGB32I, // 4*nzUInt32 - nzPixelFormat_RGBA16F, - nzPixelFormat_RGBA16I, // 4*nzUInt16 - nzPixelFormat_RGBA32F, - nzPixelFormat_RGBA32I, // 4*nzUInt32 - */ - nzPixelFormat_RGBA4, // 1*nzUInt16 - nzPixelFormat_RGB5A1, // 1*nzUInt16 - nzPixelFormat_RGB8, // 3*nzUInt8 - nzPixelFormat_RGBA8, // 4*nzUInt8 - nzPixelFormat_Depth16, - nzPixelFormat_Depth24, - nzPixelFormat_Depth24Stencil8, - nzPixelFormat_Depth32, - nzPixelFormat_Stencil1, - nzPixelFormat_Stencil4, - nzPixelFormat_Stencil8, - nzPixelFormat_Stencil16, - - nzPixelFormat_Max = nzPixelFormat_Stencil16 -}; - -enum nzPixelFormatType -{ - nzPixelFormatType_Undefined = -1, - - nzPixelFormatType_Color, - nzPixelFormatType_Depth, - nzPixelFormatType_DepthStencil, - nzPixelFormatType_Stencil, - - nzPixelFormatType_Max = nzPixelFormatType_Stencil -}; - -enum nzPixelFlipping -{ - nzPixelFlipping_Horizontally, - nzPixelFlipping_Vertically, - - nzPixelFlipping_Max = nzPixelFlipping_Vertically -}; - -enum nzPrimitiveType -{ - nzPrimitiveType_LineList, - nzPrimitiveType_LineStrip, - nzPrimitiveType_PointList, - nzPrimitiveType_TriangleList, - nzPrimitiveType_TriangleStrip, - nzPrimitiveType_TriangleFan, - - nzPrimitiveType_Max = nzPrimitiveType_TriangleFan -}; - -enum nzWindowCursor -{ - nzWindowCursor_None, - nzWindowCursor_Default, - - nzWindowCursor_Crosshair, - nzWindowCursor_Hand, - nzWindowCursor_Help, - nzWindowCursor_Move, - nzWindowCursor_Pointer, - nzWindowCursor_Progress, - nzWindowCursor_ResizeE, - nzWindowCursor_ResizeN, - nzWindowCursor_ResizeNE, - nzWindowCursor_ResizeNW, - nzWindowCursor_ResizeS, - nzWindowCursor_ResizeSE, - nzWindowCursor_ResizeSW, - nzWindowCursor_ResizeW, - nzWindowCursor_Text, - nzWindowCursor_Wait, - - nzWindowCursor_Max = nzWindowCursor_Wait -}; - -enum nzWindowStyleFlags -{ - nzWindowStyle_None = 0x0, - nzWindowStyle_Fullscreen = 0x1, - - nzWindowStyle_Closable = 0x2, - nzWindowStyle_Resizable = 0x4, - nzWindowStyle_Titlebar = 0x8, - - nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar -}; - -#endif // NAZARA_ENUMS_UTILITY_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ENUMS_UTILITY_HPP +#define NAZARA_ENUMS_UTILITY_HPP + +enum nzAnimationType +{ + nzAnimationType_Keyframe, + nzAnimationType_Skeletal, + nzAnimationType_Static, + + nzAnimationType_Max = nzAnimationType_Static +}; + +enum nzBufferAccess +{ + nzBufferAccess_DiscardAndWrite, + nzBufferAccess_ReadOnly, + nzBufferAccess_ReadWrite, + nzBufferAccess_WriteOnly, + + nzBufferAccess_Max = nzBufferAccess_WriteOnly +}; + +enum nzBufferStorage +{ + //nzBufferStorage_Both, + nzBufferStorage_Hardware, + nzBufferStorage_Software, + + nzBufferStorage_Max = nzBufferStorage_Software +}; + +enum nzBufferType +{ + nzBufferType_Index, + nzBufferType_Vertex, + + nzBufferType_Max = nzBufferType_Vertex +}; + +enum nzBufferUsage +{ + nzBufferUsage_Dynamic, + nzBufferUsage_Static, + + nzBufferUsage_Max = nzBufferUsage_Static +}; + +enum nzCubemapFace +{ + // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap + // L'ordre est X, -X, Y, -Y, Z, -Z + nzCubemapFace_PositiveX = 0, + nzCubemapFace_PositiveY = 2, + nzCubemapFace_PositiveZ = 4, + nzCubemapFace_NegativeX = 1, + nzCubemapFace_NegativeY = 3, + nzCubemapFace_NegativeZ = 5, + + nzCubemapFace_Max = nzCubemapFace_NegativeZ +}; + +enum nzElementStream +{ + nzElementStream_VertexData, + nzElementStream_InstancedData, + + nzElementStream_Max = nzElementStream_InstancedData +}; + +enum nzElementType +{ + nzElementType_Color, + nzElementType_Double1, + nzElementType_Double2, + nzElementType_Double3, + nzElementType_Double4, + nzElementType_Float1, + nzElementType_Float2, + nzElementType_Float3, + nzElementType_Float4, + + nzElementType_Max = nzElementType_Float4 +}; + +enum nzElementUsage +{ + nzElementUsage_Diffuse, + nzElementUsage_Normal, + nzElementUsage_Position, + nzElementUsage_Tangent, + nzElementUsage_TexCoord, + + nzElementUsage_Max = nzElementUsage_TexCoord +}; + +enum nzEventType +{ + nzEventType_GainedFocus, + nzEventType_LostFocus, + nzEventType_KeyPressed, + nzEventType_KeyReleased, + nzEventType_MouseButtonDoubleClicked, + nzEventType_MouseButtonPressed, + nzEventType_MouseButtonReleased, + nzEventType_MouseEntered, + nzEventType_MouseLeft, + nzEventType_MouseMoved, + nzEventType_MouseWheelMoved, + nzEventType_Moved, + nzEventType_Quit, + nzEventType_Resized, + nzEventType_TextEntered, + + nzEventType_Max = nzEventType_TextEntered +}; + +enum nzExtend +{ + nzExtend_Finite, + nzExtend_Infinite, + nzExtend_Null, + + nzExtend_Max = nzExtend_Null +}; + +enum nzImageType +{ + nzImageType_1D, + nzImageType_1D_Array, + nzImageType_2D, + nzImageType_2D_Array, + nzImageType_3D, + nzImageType_Cubemap, + + nzImageType_Max = nzImageType_Cubemap +}; + +enum nzPixelFormat +{ + nzPixelFormat_Undefined = -1, + + nzPixelFormat_BGR8, // 3*nzUInt8 + nzPixelFormat_BGRA8, // 4*nzUInt8 + nzPixelFormat_DXT1, + nzPixelFormat_DXT3, + nzPixelFormat_DXT5, + nzPixelFormat_L8, // 1*nzUInt8 + nzPixelFormat_LA8, // 2*nzUInt8 + /* + nzPixelFormat_RGB16F, + nzPixelFormat_RGB16I, // 4*nzUInt16 + nzPixelFormat_RGB32F, + nzPixelFormat_RGB32I, // 4*nzUInt32 + nzPixelFormat_RGBA16F, + nzPixelFormat_RGBA16I, // 4*nzUInt16 + nzPixelFormat_RGBA32F, + nzPixelFormat_RGBA32I, // 4*nzUInt32 + */ + nzPixelFormat_RGBA4, // 1*nzUInt16 + nzPixelFormat_RGB5A1, // 1*nzUInt16 + nzPixelFormat_RGB8, // 3*nzUInt8 + nzPixelFormat_RGBA8, // 4*nzUInt8 + nzPixelFormat_Depth16, + nzPixelFormat_Depth24, + nzPixelFormat_Depth24Stencil8, + nzPixelFormat_Depth32, + nzPixelFormat_Stencil1, + nzPixelFormat_Stencil4, + nzPixelFormat_Stencil8, + nzPixelFormat_Stencil16, + + nzPixelFormat_Max = nzPixelFormat_Stencil16 +}; + +enum nzPixelFormatType +{ + nzPixelFormatType_Undefined = -1, + + nzPixelFormatType_Color, + nzPixelFormatType_Depth, + nzPixelFormatType_DepthStencil, + nzPixelFormatType_Stencil, + + nzPixelFormatType_Max = nzPixelFormatType_Stencil +}; + +enum nzPixelFlipping +{ + nzPixelFlipping_Horizontally, + nzPixelFlipping_Vertically, + + nzPixelFlipping_Max = nzPixelFlipping_Vertically +}; + +enum nzPrimitiveType +{ + nzPrimitiveType_LineList, + nzPrimitiveType_LineStrip, + nzPrimitiveType_PointList, + nzPrimitiveType_TriangleList, + nzPrimitiveType_TriangleStrip, + nzPrimitiveType_TriangleFan, + + nzPrimitiveType_Max = nzPrimitiveType_TriangleFan +}; + +enum nzWindowCursor +{ + nzWindowCursor_None, + nzWindowCursor_Default, + + nzWindowCursor_Crosshair, + nzWindowCursor_Hand, + nzWindowCursor_Help, + nzWindowCursor_Move, + nzWindowCursor_Pointer, + nzWindowCursor_Progress, + nzWindowCursor_ResizeE, + nzWindowCursor_ResizeN, + nzWindowCursor_ResizeNE, + nzWindowCursor_ResizeNW, + nzWindowCursor_ResizeS, + nzWindowCursor_ResizeSE, + nzWindowCursor_ResizeSW, + nzWindowCursor_ResizeW, + nzWindowCursor_Text, + nzWindowCursor_Wait, + + nzWindowCursor_Max = nzWindowCursor_Wait +}; + +enum nzWindowStyleFlags +{ + nzWindowStyle_None = 0x0, + nzWindowStyle_Fullscreen = 0x1, + + nzWindowStyle_Closable = 0x2, + nzWindowStyle_Resizable = 0x4, + nzWindowStyle_Titlebar = 0x8, + + nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar +}; + +#endif // NAZARA_ENUMS_UTILITY_HPP diff --git a/include/Nazara/Utility/KeyframeMesh.hpp b/include/Nazara/Utility/KeyframeMesh.hpp index eec42bbb9..47988cf1d 100644 --- a/include/Nazara/Utility/KeyframeMesh.hpp +++ b/include/Nazara/Utility/KeyframeMesh.hpp @@ -11,7 +11,6 @@ #include class NzMesh; -struct NzAnimation; class NAZARA_API NzKeyframeMesh : public NzSubMesh { diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index de8f071f7..6f101fd38 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -1,98 +1,98 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MESH_HPP -#define NAZARA_MESH_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class NzVertexDeclaration; - -struct NzMeshParams -{ - NzAnimationParams animation; - //const NzVertexDeclaration* declaration = nullptr; - nzBufferStorage storage = nzBufferStorage_Hardware; - bool loadAnimations = true; - - bool IsValid() const; -}; - -class NzMesh; - -using NzMeshLoader = NzResourceLoader; - -struct NzMeshImpl; - -class NAZARA_API NzMesh : public NzResource, NzResourceListener -{ - friend NzMeshLoader; - - public: - NzMesh() = default; - ~NzMesh(); - - bool AddSkin(const NzString& skin, bool setDefault = false); - bool AddSubMesh(NzSubMesh* subMesh); - bool AddSubMesh(const NzString& identifier, NzSubMesh* subMesh); - - void Animate(unsigned int frameA, unsigned int frameB, float interpolation); - - bool Create(nzAnimationType type); - void Destroy(); - - const NzAxisAlignedBox& GetAABB() const; - const NzAnimation* GetAnimation() const; - nzAnimationType GetAnimationType() const; - unsigned int GetFrameCount() const; - NzString GetSkin(unsigned int index = 0) const; - unsigned int GetSkinCount() const; - NzSubMesh* GetSubMesh(const NzString& identifier); - NzSubMesh* GetSubMesh(unsigned int index); - const NzSubMesh* GetSubMesh(const NzString& identifier) const; - const NzSubMesh* GetSubMesh(unsigned int index) const; - unsigned int GetSubMeshCount() const; - int GetSubMeshIndex(const NzString& identifier) const; - unsigned int GetVertexCount() const; - - bool HasAnimation() const; - bool HasSkin(unsigned int index = 0) const; - bool HasSubMesh(const NzString& identifier) const; - bool HasSubMesh(unsigned int index = 0) const; - - void InvalidateAABB() const; - - bool IsAnimable() const; - bool IsValid() const; - - bool LoadFromFile(const NzString& filePath, const NzMeshParams& params = NzMeshParams()); - bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams()); - bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams()); - - void RemoveSkin(unsigned int index = 0); - void RemoveSubMesh(const NzString& identifier); - void RemoveSubMesh(unsigned int index = 0); - - bool SetAnimation(const NzAnimation* animation); - - private: - void OnResourceCreated(const NzResource* resource, int index) override; - void OnResourceReleased(const NzResource* resource, int index) override; - - NzMeshImpl* m_impl = nullptr; - - static NzMeshLoader::LoaderList s_loaders; -}; - -#endif // NAZARA_MESH_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_MESH_HPP +#define NAZARA_MESH_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class NzVertexDeclaration; + +struct NzMeshParams +{ + NzAnimationParams animation; + //const NzVertexDeclaration* declaration = nullptr; + nzBufferStorage storage = nzBufferStorage_Hardware; + bool loadAnimations = true; + + bool IsValid() const; +}; + +class NzMesh; + +using NzMeshLoader = NzResourceLoader; + +struct NzMeshImpl; + +class NAZARA_API NzMesh : public NzResource, NzResourceListener +{ + friend NzMeshLoader; + + public: + NzMesh() = default; + ~NzMesh(); + + bool AddSkin(const NzString& skin, bool setDefault = false); + bool AddSubMesh(NzSubMesh* subMesh); + bool AddSubMesh(const NzString& identifier, NzSubMesh* subMesh); + + void Animate(unsigned int frameA, unsigned int frameB, float interpolation); + + bool Create(nzAnimationType type); + void Destroy(); + + const NzAxisAlignedBox& GetAABB() const; + const NzAnimation* GetAnimation() const; + nzAnimationType GetAnimationType() const; + unsigned int GetFrameCount() const; + NzString GetSkin(unsigned int index = 0) const; + unsigned int GetSkinCount() const; + NzSubMesh* GetSubMesh(const NzString& identifier); + NzSubMesh* GetSubMesh(unsigned int index); + const NzSubMesh* GetSubMesh(const NzString& identifier) const; + const NzSubMesh* GetSubMesh(unsigned int index) const; + unsigned int GetSubMeshCount() const; + int GetSubMeshIndex(const NzString& identifier) const; + unsigned int GetVertexCount() const; + + bool HasAnimation() const; + bool HasSkin(unsigned int index = 0) const; + bool HasSubMesh(const NzString& identifier) const; + bool HasSubMesh(unsigned int index = 0) const; + + void InvalidateAABB() const; + + bool IsAnimable() const; + bool IsValid() const; + + bool LoadFromFile(const NzString& filePath, const NzMeshParams& params = NzMeshParams()); + bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams()); + bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams()); + + void RemoveSkin(unsigned int index = 0); + void RemoveSubMesh(const NzString& identifier); + void RemoveSubMesh(unsigned int index = 0); + + bool SetAnimation(const NzAnimation* animation); + + private: + void OnResourceCreated(const NzResource* resource, int index) override; + void OnResourceReleased(const NzResource* resource, int index) override; + + NzMeshImpl* m_impl = nullptr; + + static NzMeshLoader::LoaderList s_loaders; +}; + +#endif // NAZARA_MESH_HPP diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 646f91e55..7d46d82ef 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -1,54 +1,54 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PIXELFORMAT_HPP -#define NAZARA_PIXELFORMAT_HPP - -#include -#include -#include -#include - -class NzUtility; - -class NzPixelFormat -{ - friend class NzUtility; - - public: - using ConvertFunction = nzUInt8* (*)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst); - using FlipFunction = void (*)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst); - - static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst); - static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst); - - static bool Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); - - static nzUInt8 GetBPP(nzPixelFormat format); - static nzPixelFormatType GetType(nzPixelFormat format); - - static bool HasAlpha(nzPixelFormat format); - - static bool IsCompressed(nzPixelFormat format); - static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat); - static bool IsValid(nzPixelFormat format); - - static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func); - static void SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func); - - static NzString ToString(nzPixelFormat format); - - private: - static bool Initialize(); - static void Uninitialize(); - - static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1]; - static NAZARA_API std::map s_flipFunctions[nzPixelFlipping_Max+1]; -}; - -#include - -#endif // NAZARA_PIXELFORMAT_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_PIXELFORMAT_HPP +#define NAZARA_PIXELFORMAT_HPP + +#include +#include +#include +#include + +class NzUtility; + +class NzPixelFormat +{ + friend class NzUtility; + + public: + using ConvertFunction = nzUInt8* (*)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst); + using FlipFunction = void (*)(unsigned int width, unsigned int height, unsigned int depth, const nzUInt8* src, nzUInt8* dst); + + static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst); + static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst); + + static bool Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); + + static nzUInt8 GetBPP(nzPixelFormat format); + static nzPixelFormatType GetType(nzPixelFormat format); + + static bool HasAlpha(nzPixelFormat format); + + static bool IsCompressed(nzPixelFormat format); + static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat); + static bool IsValid(nzPixelFormat format); + + static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func); + static void SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func); + + static NzString ToString(nzPixelFormat format); + + private: + static bool Initialize(); + static void Uninitialize(); + + static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Max+1][nzPixelFormat_Max+1]; + static NAZARA_API std::map s_flipFunctions[nzPixelFlipping_Max+1]; +}; + +#include + +#endif // NAZARA_PIXELFORMAT_HPP diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index 8f3335af0..b48af518c 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -1,487 +1,487 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst) -{ - if (srcFormat == dstFormat) - { - std::memcpy(dst, src, GetBPP(srcFormat)); - return true; - } - - #if NAZARA_UTILITY_SAFE - if (IsCompressed(srcFormat)) - { - NazaraError("Cannot convert single pixel from compressed format"); - return false; - } - - if (IsCompressed(dstFormat)) - { - NazaraError("Cannot convert single pixel to compressed format"); - return false; - } - #endif - - ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; - if (!func) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); - return false; - } - - if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBPP(srcFormat), reinterpret_cast(dst))) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); - return false; - } - - return true; -} - -inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst) -{ - if (srcFormat == dstFormat) - { - std::memcpy(dst, start, reinterpret_cast(end)-reinterpret_cast(start)); - return true; - } - - ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; - if (!func) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); - return false; - } - - if (!func(reinterpret_cast(start), reinterpret_cast(end), reinterpret_cast(dst))) - { - NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); - return false; - } - - return true; -} - -inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst) -{ - #if NAZARA_UTILITY_SAFE - if (!IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - #endif - - auto it = s_flipFunctions[flipping].find(format); - if (it != s_flipFunctions[flipping].end()) - it->second(width, height, depth, reinterpret_cast(src), reinterpret_cast(dst)); - else - { - // Flipping générique - - #if NAZARA_UTILITY_SAFE - if (IsCompressed(format)) - { - NazaraError("No function to flip compressed format"); - return false; - } - #endif - - nzUInt8 bpp = GetBPP(format); - unsigned int lineStride = width*bpp; - switch (flipping) - { - case nzPixelFlipping_Horizontally: - { - if (src == dst) - { - for (unsigned int z = 0; z < depth; ++z) - { - nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; - for (unsigned int y = 0; y < height; ++y) - { - for (unsigned int x = 0; x < width/2; ++x) - std::swap_ranges(&ptr[x*bpp], &ptr[(x+1)*bpp], &ptr[(width-x)*bpp]); - - ptr += lineStride; - } - } - } - else - { - for (unsigned int z = 0; z < depth; ++z) - { - nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; - for (unsigned int y = 0; y < height; ++y) - { - for (unsigned int x = 0; x < width; ++x) - std::memcpy(&ptr[x*bpp], &ptr[(width-x)*bpp], bpp); - - ptr += lineStride; - } - } - } - break; - } - - case nzPixelFlipping_Vertically: - { - if (src == dst) - { - for (unsigned int z = 0; z < depth; ++z) - { - nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; - for (unsigned int y = 0; y < height/2; ++y) - std::swap_ranges(&ptr[y*lineStride], &ptr[(y+1)*lineStride-1], &ptr[(height-y-1)*lineStride]); - } - } - else - { - for (unsigned int z = 0; z < depth; ++z) - { - const nzUInt8* srcPtr = reinterpret_cast(src); - nzUInt8* dstPtr = reinterpret_cast(dst) + (width-1)*height*depth*bpp; - for (unsigned int y = 0; y < height; ++y) - { - std::memcpy(dstPtr, srcPtr, lineStride); - - srcPtr += lineStride; - dstPtr -= lineStride; - } - } - } - break; - } - } - } - - return true; -} - -inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGR8: - return 3; - - case nzPixelFormat_BGRA8: - return 4; - - case nzPixelFormat_DXT1: - return 1; - - case nzPixelFormat_DXT3: - return 2; - - case nzPixelFormat_DXT5: - return 2; - - case nzPixelFormat_L8: - return 1; - - case nzPixelFormat_LA8: - return 2; -/* - case nzPixelFormat_RGB16F: - return 6; - - case nzPixelFormat_RGB16I: - return 6; - - case nzPixelFormat_RGB32F: - return 12; - - case nzPixelFormat_RGB32I: - return 12; - - case nzPixelFormat_RGBA16F: - return 8; - - case nzPixelFormat_RGBA16I: - return 8; - - case nzPixelFormat_RGBA32F: - return 16; - - case nzPixelFormat_RGBA32I: - return 16; -*/ - case nzPixelFormat_RGBA4: - return 2; - - case nzPixelFormat_RGB5A1: - return 2; - - case nzPixelFormat_RGB8: - return 3; - - case nzPixelFormat_RGBA8: - return 4; - - case nzPixelFormat_Depth16: - return 2; - - case nzPixelFormat_Depth24: - return 3; - - case nzPixelFormat_Depth24Stencil8: - return 4; - - case nzPixelFormat_Depth32: - return 4; - - case nzPixelFormat_Stencil1: - NazaraWarning("This format uses less than one byte per pixel"); - return 0; - - case nzPixelFormat_Stencil4: - NazaraWarning("This format uses less than one byte per pixel"); - return 0; - - case nzPixelFormat_Stencil8: - return 1; - - case nzPixelFormat_Stencil16: - return 2; - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return 0; -} - -inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGR8: - case nzPixelFormat_BGRA8: - case nzPixelFormat_DXT1: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - case nzPixelFormat_L8: - case nzPixelFormat_LA8: - case nzPixelFormat_RGB5A1: - case nzPixelFormat_RGB8: - case nzPixelFormat_RGBA4: - case nzPixelFormat_RGBA8: - return nzPixelFormatType_Color; - - case nzPixelFormat_Depth16: - case nzPixelFormat_Depth24: - case nzPixelFormat_Depth32: - return nzPixelFormatType_Depth; - - case nzPixelFormat_Depth24Stencil8: - return nzPixelFormatType_DepthStencil; - - case nzPixelFormat_Stencil1: - case nzPixelFormat_Stencil4: - case nzPixelFormat_Stencil8: - case nzPixelFormat_Stencil16: - return nzPixelFormatType_Stencil; - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return nzPixelFormatType_Undefined; -} - -inline bool NzPixelFormat::HasAlpha(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGRA8: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - case nzPixelFormat_LA8: - case nzPixelFormat_RGB5A1: - case nzPixelFormat_RGBA4: - case nzPixelFormat_RGBA8: - return true; - - case nzPixelFormat_BGR8: - case nzPixelFormat_DXT1: - case nzPixelFormat_L8: - case nzPixelFormat_RGB8: - case nzPixelFormat_Depth16: - case nzPixelFormat_Depth24: - case nzPixelFormat_Depth24Stencil8: - case nzPixelFormat_Depth32: - case nzPixelFormat_Stencil1: - case nzPixelFormat_Stencil4: - case nzPixelFormat_Stencil8: - case nzPixelFormat_Stencil16: - return false; - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return false; -} - -inline bool NzPixelFormat::IsCompressed(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_DXT1: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - return true; - - case nzPixelFormat_BGRA8: - case nzPixelFormat_LA8: - case nzPixelFormat_RGB5A1: - case nzPixelFormat_RGBA4: - case nzPixelFormat_RGBA8: - case nzPixelFormat_BGR8: - case nzPixelFormat_L8: - case nzPixelFormat_RGB8: - case nzPixelFormat_Depth16: - case nzPixelFormat_Depth24: - case nzPixelFormat_Depth24Stencil8: - case nzPixelFormat_Depth32: - case nzPixelFormat_Stencil1: - case nzPixelFormat_Stencil4: - case nzPixelFormat_Stencil8: - case nzPixelFormat_Stencil16: - return false; - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return false; -} - -inline bool NzPixelFormat::IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat) -{ - if (srcFormat == dstFormat) - return true; - - return s_convertFunctions[srcFormat][dstFormat] != nullptr; -} - -inline bool NzPixelFormat::IsValid(nzPixelFormat format) -{ - return format != nzPixelFormat_Undefined; -} - -inline void NzPixelFormat::SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func) -{ - s_convertFunctions[srcFormat][dstFormat] = func; -} - -inline void NzPixelFormat::SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func) -{ - s_flipFunctions[flipping][format] = func; -} - -inline NzString NzPixelFormat::ToString(nzPixelFormat format) -{ - switch (format) - { - case nzPixelFormat_BGR8: - return "BGR8"; - - case nzPixelFormat_BGRA8: - return "BGRA8"; - - case nzPixelFormat_DXT1: - return "DXT1"; - - case nzPixelFormat_DXT3: - return "DXT3"; - - case nzPixelFormat_DXT5: - return "DXT5"; - - case nzPixelFormat_L8: - return "L8"; - - case nzPixelFormat_LA8: - return "LA8"; -/* - case nzPixelFormat_RGB16F: - return "RGB16F"; - - case nzPixelFormat_RGB16I: - return "RGB16I"; - - case nzPixelFormat_RGB32F: - return "RGB32F"; - - case nzPixelFormat_RGB32I: - return "RGB32I"; - - case nzPixelFormat_RGBA16F: - return "RGBA16F"; - - case nzPixelFormat_RGBA16I: - return "RGBA16I"; - - case nzPixelFormat_RGBA32F: - return "RGBA32F"; - - case nzPixelFormat_RGBA32I: - return "RGBA32I"; -*/ - case nzPixelFormat_RGBA4: - return "RGBA4"; - - case nzPixelFormat_RGB5A1: - return "RGB5A1"; - - case nzPixelFormat_RGB8: - return "RGB8"; - - case nzPixelFormat_RGBA8: - return "RGBA8"; - - case nzPixelFormat_Depth16: - return "Depth16"; - - case nzPixelFormat_Depth24: - return "Depth24"; - - case nzPixelFormat_Depth24Stencil8: - return "Depth24Stencil8"; - - case nzPixelFormat_Depth32: - return "Depth32"; - - case nzPixelFormat_Stencil1: - return "Stencil1"; - - case nzPixelFormat_Stencil4: - return "Stencil4"; - - case nzPixelFormat_Stencil8: - return "Stencil8"; - - case nzPixelFormat_Stencil16: - return "Stencil16"; - - case nzPixelFormat_Undefined: - return "Undefined"; - } - - NazaraError("Invalid pixel format"); - return "Invalid format"; -} - -#include +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst) +{ + if (srcFormat == dstFormat) + { + std::memcpy(dst, src, GetBPP(srcFormat)); + return true; + } + + #if NAZARA_UTILITY_SAFE + if (IsCompressed(srcFormat)) + { + NazaraError("Cannot convert single pixel from compressed format"); + return false; + } + + if (IsCompressed(dstFormat)) + { + NazaraError("Cannot convert single pixel to compressed format"); + return false; + } + #endif + + ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; + if (!func) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); + return false; + } + + if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBPP(srcFormat), reinterpret_cast(dst))) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); + return false; + } + + return true; +} + +inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst) +{ + if (srcFormat == dstFormat) + { + std::memcpy(dst, start, reinterpret_cast(end)-reinterpret_cast(start)); + return true; + } + + ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; + if (!func) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported"); + return false; + } + + if (!func(reinterpret_cast(start), reinterpret_cast(end), reinterpret_cast(dst))) + { + NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); + return false; + } + + return true; +} + +inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst) +{ + #if NAZARA_UTILITY_SAFE + if (!IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + #endif + + auto it = s_flipFunctions[flipping].find(format); + if (it != s_flipFunctions[flipping].end()) + it->second(width, height, depth, reinterpret_cast(src), reinterpret_cast(dst)); + else + { + // Flipping générique + + #if NAZARA_UTILITY_SAFE + if (IsCompressed(format)) + { + NazaraError("No function to flip compressed format"); + return false; + } + #endif + + nzUInt8 bpp = GetBPP(format); + unsigned int lineStride = width*bpp; + switch (flipping) + { + case nzPixelFlipping_Horizontally: + { + if (src == dst) + { + for (unsigned int z = 0; z < depth; ++z) + { + nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; + for (unsigned int y = 0; y < height; ++y) + { + for (unsigned int x = 0; x < width/2; ++x) + std::swap_ranges(&ptr[x*bpp], &ptr[(x+1)*bpp], &ptr[(width-x)*bpp]); + + ptr += lineStride; + } + } + } + else + { + for (unsigned int z = 0; z < depth; ++z) + { + nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; + for (unsigned int y = 0; y < height; ++y) + { + for (unsigned int x = 0; x < width; ++x) + std::memcpy(&ptr[x*bpp], &ptr[(width-x)*bpp], bpp); + + ptr += lineStride; + } + } + } + break; + } + + case nzPixelFlipping_Vertically: + { + if (src == dst) + { + for (unsigned int z = 0; z < depth; ++z) + { + nzUInt8* ptr = reinterpret_cast(dst) + width*height*z; + for (unsigned int y = 0; y < height/2; ++y) + std::swap_ranges(&ptr[y*lineStride], &ptr[(y+1)*lineStride-1], &ptr[(height-y-1)*lineStride]); + } + } + else + { + for (unsigned int z = 0; z < depth; ++z) + { + const nzUInt8* srcPtr = reinterpret_cast(src); + nzUInt8* dstPtr = reinterpret_cast(dst) + (width-1)*height*depth*bpp; + for (unsigned int y = 0; y < height; ++y) + { + std::memcpy(dstPtr, srcPtr, lineStride); + + srcPtr += lineStride; + dstPtr -= lineStride; + } + } + } + break; + } + } + } + + return true; +} + +inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGR8: + return 3; + + case nzPixelFormat_BGRA8: + return 4; + + case nzPixelFormat_DXT1: + return 1; + + case nzPixelFormat_DXT3: + return 2; + + case nzPixelFormat_DXT5: + return 2; + + case nzPixelFormat_L8: + return 1; + + case nzPixelFormat_LA8: + return 2; +/* + case nzPixelFormat_RGB16F: + return 6; + + case nzPixelFormat_RGB16I: + return 6; + + case nzPixelFormat_RGB32F: + return 12; + + case nzPixelFormat_RGB32I: + return 12; + + case nzPixelFormat_RGBA16F: + return 8; + + case nzPixelFormat_RGBA16I: + return 8; + + case nzPixelFormat_RGBA32F: + return 16; + + case nzPixelFormat_RGBA32I: + return 16; +*/ + case nzPixelFormat_RGBA4: + return 2; + + case nzPixelFormat_RGB5A1: + return 2; + + case nzPixelFormat_RGB8: + return 3; + + case nzPixelFormat_RGBA8: + return 4; + + case nzPixelFormat_Depth16: + return 2; + + case nzPixelFormat_Depth24: + return 3; + + case nzPixelFormat_Depth24Stencil8: + return 4; + + case nzPixelFormat_Depth32: + return 4; + + case nzPixelFormat_Stencil1: + NazaraWarning("This format uses less than one byte per pixel"); + return 0; + + case nzPixelFormat_Stencil4: + NazaraWarning("This format uses less than one byte per pixel"); + return 0; + + case nzPixelFormat_Stencil8: + return 1; + + case nzPixelFormat_Stencil16: + return 2; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return 0; +} + +inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGR8: + case nzPixelFormat_BGRA8: + case nzPixelFormat_DXT1: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGB8: + case nzPixelFormat_RGBA4: + case nzPixelFormat_RGBA8: + return nzPixelFormatType_Color; + + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth32: + return nzPixelFormatType_Depth; + + case nzPixelFormat_Depth24Stencil8: + return nzPixelFormatType_DepthStencil; + + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return nzPixelFormatType_Stencil; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return nzPixelFormatType_Undefined; +} + +inline bool NzPixelFormat::HasAlpha(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGRA8: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + case nzPixelFormat_LA8: + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGBA4: + case nzPixelFormat_RGBA8: + return true; + + case nzPixelFormat_BGR8: + case nzPixelFormat_DXT1: + case nzPixelFormat_L8: + case nzPixelFormat_RGB8: + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth24Stencil8: + case nzPixelFormat_Depth32: + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return false; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return false; +} + +inline bool NzPixelFormat::IsCompressed(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_DXT1: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + return true; + + case nzPixelFormat_BGRA8: + case nzPixelFormat_LA8: + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGBA4: + case nzPixelFormat_RGBA8: + case nzPixelFormat_BGR8: + case nzPixelFormat_L8: + case nzPixelFormat_RGB8: + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth24Stencil8: + case nzPixelFormat_Depth32: + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return false; + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return false; +} + +inline bool NzPixelFormat::IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat) +{ + if (srcFormat == dstFormat) + return true; + + return s_convertFunctions[srcFormat][dstFormat] != nullptr; +} + +inline bool NzPixelFormat::IsValid(nzPixelFormat format) +{ + return format != nzPixelFormat_Undefined; +} + +inline void NzPixelFormat::SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func) +{ + s_convertFunctions[srcFormat][dstFormat] = func; +} + +inline void NzPixelFormat::SetFlipFunction(nzPixelFlipping flipping, nzPixelFormat format, FlipFunction func) +{ + s_flipFunctions[flipping][format] = func; +} + +inline NzString NzPixelFormat::ToString(nzPixelFormat format) +{ + switch (format) + { + case nzPixelFormat_BGR8: + return "BGR8"; + + case nzPixelFormat_BGRA8: + return "BGRA8"; + + case nzPixelFormat_DXT1: + return "DXT1"; + + case nzPixelFormat_DXT3: + return "DXT3"; + + case nzPixelFormat_DXT5: + return "DXT5"; + + case nzPixelFormat_L8: + return "L8"; + + case nzPixelFormat_LA8: + return "LA8"; +/* + case nzPixelFormat_RGB16F: + return "RGB16F"; + + case nzPixelFormat_RGB16I: + return "RGB16I"; + + case nzPixelFormat_RGB32F: + return "RGB32F"; + + case nzPixelFormat_RGB32I: + return "RGB32I"; + + case nzPixelFormat_RGBA16F: + return "RGBA16F"; + + case nzPixelFormat_RGBA16I: + return "RGBA16I"; + + case nzPixelFormat_RGBA32F: + return "RGBA32F"; + + case nzPixelFormat_RGBA32I: + return "RGBA32I"; +*/ + case nzPixelFormat_RGBA4: + return "RGBA4"; + + case nzPixelFormat_RGB5A1: + return "RGB5A1"; + + case nzPixelFormat_RGB8: + return "RGB8"; + + case nzPixelFormat_RGBA8: + return "RGBA8"; + + case nzPixelFormat_Depth16: + return "Depth16"; + + case nzPixelFormat_Depth24: + return "Depth24"; + + case nzPixelFormat_Depth24Stencil8: + return "Depth24Stencil8"; + + case nzPixelFormat_Depth32: + return "Depth32"; + + case nzPixelFormat_Stencil1: + return "Stencil1"; + + case nzPixelFormat_Stencil4: + return "Stencil4"; + + case nzPixelFormat_Stencil8: + return "Stencil8"; + + case nzPixelFormat_Stencil16: + return "Stencil16"; + + case nzPixelFormat_Undefined: + return "Undefined"; + } + + NazaraError("Invalid pixel format"); + return "Invalid format"; +} + +#include diff --git a/include/Nazara/Utility/StaticMesh.hpp b/include/Nazara/Utility/StaticMesh.hpp index 745ec1471..d20c0626b 100644 --- a/include/Nazara/Utility/StaticMesh.hpp +++ b/include/Nazara/Utility/StaticMesh.hpp @@ -1,51 +1,51 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_STATICMESH_HPP -#define NAZARA_STATICMESH_HPP - -#include -#include -#include - -class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener -{ - public: - NzStaticMesh(const NzMesh* parent); - NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); - virtual ~NzStaticMesh(); - - bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); - void Destroy(); - - bool GenerateAABB(); - - const NzAxisAlignedBox& GetAABB() const; - nzAnimationType GetAnimationType() const; - unsigned int GetFrameCount() const; - const NzIndexBuffer* GetIndexBuffer() const; - nzPrimitiveType GetPrimitiveType() const; - const NzVertexBuffer* GetVertexBuffer() const; - const NzVertexDeclaration* GetVertexDeclaration() const; - - bool IsAnimated() const; - bool IsValid() const; - - void SetAABB(const NzAxisAlignedBox& aabb); - void SetPrimitiveType(nzPrimitiveType primitiveType); - - private: - void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation); - void OnResourceReleased(const NzResource* resource, int index) override; - - nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList; - NzAxisAlignedBox m_aabb; - NzIndexBuffer* m_indexBuffer = nullptr; - NzVertexBuffer* m_vertexBuffer = nullptr; - const NzVertexDeclaration* m_vertexDeclaration = nullptr; -}; - -#endif // NAZARA_STATICMESH_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_STATICMESH_HPP +#define NAZARA_STATICMESH_HPP + +#include +#include +#include + +class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener +{ + public: + NzStaticMesh(const NzMesh* parent); + NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); + virtual ~NzStaticMesh(); + + bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr); + void Destroy(); + + bool GenerateAABB(); + + const NzAxisAlignedBox& GetAABB() const; + nzAnimationType GetAnimationType() const; + unsigned int GetFrameCount() const; + const NzIndexBuffer* GetIndexBuffer() const; + nzPrimitiveType GetPrimitiveType() const; + const NzVertexBuffer* GetVertexBuffer() const; + const NzVertexDeclaration* GetVertexDeclaration() const; + + bool IsAnimated() const; + bool IsValid() const; + + void SetAABB(const NzAxisAlignedBox& aabb); + void SetPrimitiveType(nzPrimitiveType primitiveType); + + private: + void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation); + void OnResourceReleased(const NzResource* resource, int index) override; + + nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList; + NzAxisAlignedBox m_aabb; + NzIndexBuffer* m_indexBuffer = nullptr; + NzVertexBuffer* m_vertexBuffer = nullptr; + const NzVertexDeclaration* m_vertexDeclaration = nullptr; +}; + +#endif // NAZARA_STATICMESH_HPP diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index a13e40e00..0bb4f7f18 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -1,56 +1,56 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_VERTEXDECLARATION_HPP -#define NAZARA_VERTEXDECLARATION_HPP - -#include -#include -#include - -struct NzVertexElement -{ - unsigned int offset; - unsigned int usageIndex = 0; - nzElementStream stream = nzElementStream_VertexData; - nzElementType type; - nzElementUsage usage; -}; - -struct NzVertexDeclarationImpl; - -class NAZARA_API NzVertexDeclaration : public NzResource -{ - public: - NzVertexDeclaration() = default; - NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount); - NzVertexDeclaration(const NzVertexDeclaration& declaration); - NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept; - ~NzVertexDeclaration(); - - bool Create(const NzVertexElement* elements, unsigned int elementCount); - void Destroy(); - - const NzVertexElement* GetElement(unsigned int i) const; - const NzVertexElement* GetElement(nzElementStream stream, unsigned int i) const; - const NzVertexElement* GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const; - unsigned int GetElementCount() const; - unsigned int GetElementCount(nzElementStream stream) const; - unsigned int GetStride(nzElementStream stream) const; - - bool HasStream(nzElementStream stream) const; - - bool IsValid() const; - - NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); - NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept; - - static unsigned int GetElementCount(nzElementType type); - static unsigned int GetElementSize(nzElementType type); - - private: - NzVertexDeclarationImpl* m_sharedImpl = nullptr; -}; - -#endif // NAZARA_VERTEXDECLARATION_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#ifndef NAZARA_VERTEXDECLARATION_HPP +#define NAZARA_VERTEXDECLARATION_HPP + +#include +#include +#include + +struct NzVertexElement +{ + unsigned int offset; + unsigned int usageIndex = 0; + nzElementStream stream = nzElementStream_VertexData; + nzElementType type; + nzElementUsage usage; +}; + +struct NzVertexDeclarationImpl; + +class NAZARA_API NzVertexDeclaration : public NzResource +{ + public: + NzVertexDeclaration() = default; + NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount); + NzVertexDeclaration(const NzVertexDeclaration& declaration); + NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept; + ~NzVertexDeclaration(); + + bool Create(const NzVertexElement* elements, unsigned int elementCount); + void Destroy(); + + const NzVertexElement* GetElement(unsigned int i) const; + const NzVertexElement* GetElement(nzElementStream stream, unsigned int i) const; + const NzVertexElement* GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const; + unsigned int GetElementCount() const; + unsigned int GetElementCount(nzElementStream stream) const; + unsigned int GetStride(nzElementStream stream) const; + + bool HasStream(nzElementStream stream) const; + + bool IsValid() const; + + NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration); + NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept; + + static unsigned int GetElementCount(nzElementType type); + static unsigned int GetElementSize(nzElementType type); + + private: + NzVertexDeclarationImpl* m_sharedImpl = nullptr; +}; + +#endif // NAZARA_VERTEXDECLARATION_HPP diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index 7864d64a1..136d74eeb 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -1,112 +1,112 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// Interface inspirée de la SFML par Laurent Gomila - -#pragma once - -#ifndef NAZARA_WINDOW_HPP -#define NAZARA_WINDOW_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if NAZARA_UTILITY_THREADED_WINDOW -#include -#include -#endif - -class NzCursor; -class NzImage; -class NzIcon; -class NzWindowImpl; - -class NAZARA_API NzWindow : NzNonCopyable -{ - friend NzWindowImpl; - friend class NzMouse; - friend class NzUtility; - - public: - NzWindow(); - NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); - NzWindow(NzWindowHandle handle); - virtual ~NzWindow(); - - bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); - bool Create(NzWindowHandle handle); - - void Destroy(); - - void EnableKeyRepeat(bool enable); - void EnableSmoothScrolling(bool enable); - - NzWindowHandle GetHandle() const; - unsigned int GetHeight() const; - NzVector2i GetPosition() const; - NzVector2ui GetSize() const; - NzString GetTitle() const; - unsigned int GetWidth() const; - - bool HasFocus() const; - - bool IsMinimized() const; - bool IsOpen() const; - bool IsValid() const; - bool IsVisible() const; - - bool PollEvent(NzEvent* event); - - void SetCursor(nzWindowCursor cursor); - void SetCursor(const NzCursor& cursor); - void SetEventListener(bool listener); - void SetFocus(); - void SetIcon(const NzIcon& icon); - void SetMaximumSize(const NzVector2i& maxSize); - void SetMaximumSize(int width, int height); - void SetMinimumSize(const NzVector2i& minSize); - void SetMinimumSize(int width, int height); - void SetPosition(const NzVector2i& position); - void SetPosition(int x, int y); - void SetSize(const NzVector2i& size); - void SetSize(unsigned int width, unsigned int height); - void SetStayOnTop(bool stayOnTop); - void SetTitle(const NzString& title); - void SetVisible(bool visible); - - bool WaitEvent(NzEvent* event); - - protected: - virtual bool OnWindowCreated(); - virtual void OnWindowDestroy(); - - NzWindowImpl* m_impl; - - private: - void IgnoreNextMouseEvent(int mouseX, int mouseY) const; - void PushEvent(const NzEvent& event); - - static bool Initialize(); - static void Uninitialize(); - - std::queue m_events; - #if NAZARA_UTILITY_THREADED_WINDOW - NzConditionVariable m_eventCondition; - NzMutex m_eventMutex; - NzMutex m_eventConditionMutex; - bool m_eventListener; - bool m_waitForEvent; - #endif - bool m_ownsWindow; -}; - -#endif // NAZARA_WINDOW_HPP +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Interface inspirée de la SFML par Laurent Gomila + +#pragma once + +#ifndef NAZARA_WINDOW_HPP +#define NAZARA_WINDOW_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if NAZARA_UTILITY_THREADED_WINDOW +#include +#include +#endif + +class NzCursor; +class NzImage; +class NzIcon; +class NzWindowImpl; + +class NAZARA_API NzWindow : NzNonCopyable +{ + friend NzWindowImpl; + friend class NzMouse; + friend class NzUtility; + + public: + NzWindow(); + NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); + NzWindow(NzWindowHandle handle); + virtual ~NzWindow(); + + bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default); + bool Create(NzWindowHandle handle); + + void Destroy(); + + void EnableKeyRepeat(bool enable); + void EnableSmoothScrolling(bool enable); + + NzWindowHandle GetHandle() const; + unsigned int GetHeight() const; + NzVector2i GetPosition() const; + NzVector2ui GetSize() const; + NzString GetTitle() const; + unsigned int GetWidth() const; + + bool HasFocus() const; + + bool IsMinimized() const; + bool IsOpen() const; + bool IsValid() const; + bool IsVisible() const; + + bool PollEvent(NzEvent* event); + + void SetCursor(nzWindowCursor cursor); + void SetCursor(const NzCursor& cursor); + void SetEventListener(bool listener); + void SetFocus(); + void SetIcon(const NzIcon& icon); + void SetMaximumSize(const NzVector2i& maxSize); + void SetMaximumSize(int width, int height); + void SetMinimumSize(const NzVector2i& minSize); + void SetMinimumSize(int width, int height); + void SetPosition(const NzVector2i& position); + void SetPosition(int x, int y); + void SetSize(const NzVector2i& size); + void SetSize(unsigned int width, unsigned int height); + void SetStayOnTop(bool stayOnTop); + void SetTitle(const NzString& title); + void SetVisible(bool visible); + + bool WaitEvent(NzEvent* event); + + protected: + virtual bool OnWindowCreated(); + virtual void OnWindowDestroy(); + + NzWindowImpl* m_impl; + + private: + void IgnoreNextMouseEvent(int mouseX, int mouseY) const; + void PushEvent(const NzEvent& event); + + static bool Initialize(); + static void Uninitialize(); + + std::queue m_events; + #if NAZARA_UTILITY_THREADED_WINDOW + NzConditionVariable m_eventCondition; + NzMutex m_eventMutex; + NzMutex m_eventConditionMutex; + bool m_eventListener; + bool m_waitForEvent; + #endif + bool m_ownsWindow; +}; + +#endif // NAZARA_WINDOW_HPP diff --git a/src/Nazara/Audio/SoundBuffer.cpp b/src/Nazara/Audio/SoundBuffer.cpp index 950c57da1..7e6d11fec 100644 --- a/src/Nazara/Audio/SoundBuffer.cpp +++ b/src/Nazara/Audio/SoundBuffer.cpp @@ -1,229 +1,229 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Audio module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -///FIXME: Adapter la création - -bool NzSoundBufferParams::IsValid() const -{ - return true; -} - -struct NzSoundBufferImpl -{ - ALuint buffer; - nzAudioFormat format; - nzUInt32 duration; - nzInt16* samples; - unsigned int sampleCount; - unsigned int sampleRate; -}; - -NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) -{ - Create(format, sampleCount, sampleRate, samples); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create sound buffer"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzSoundBuffer::~NzSoundBuffer() -{ - Destroy(); -} - -bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) -{ - Destroy(); - - #if NAZARA_AUDIO_SAFE - if (!IsFormatSupported(format)) - { - NazaraError("Audio format is not supported"); - return false; - } - - if (sampleCount == 0) - { - NazaraError("Sample rate must be different from zero"); - return false; - } - - if (sampleRate == 0) - { - NazaraError("Sample rate must be different from zero"); - return false; - } - - if (!samples) - { - NazaraError("Invalid sample source"); - return false; - } - #endif - - // On vide le stack d'erreurs - while (alGetError() != AL_NO_ERROR); - - ALuint buffer; - alGenBuffers(1, &buffer); - - if (alGetError() != AL_NO_ERROR) - { - NazaraError("Failed to create OpenAL buffer"); - return false; - } - - alBufferData(buffer, NzAudio::GetOpenALFormat(format), samples, sampleCount*sizeof(nzInt16), sampleRate); - - if (alGetError() != AL_NO_ERROR) - { - NazaraError("Failed to set OpenAL buffer"); - alDeleteBuffers(1, &buffer); - - return false; - } - - m_impl = new NzSoundBufferImpl; - m_impl->buffer = buffer; - m_impl->duration = 1000 * (sampleCount / (format * sampleRate)); - m_impl->format = format; - m_impl->sampleCount = sampleCount; - m_impl->sampleRate = sampleRate; - m_impl->samples = new nzInt16[sampleCount]; - std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16)); - - NotifyCreated(); - return true; -} - -void NzSoundBuffer::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - delete[] m_impl->samples; - delete m_impl; - m_impl = nullptr; - } -} - -nzUInt32 NzSoundBuffer::GetDuration() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return 0; - } - #endif - - return m_impl->duration; -} - -nzAudioFormat NzSoundBuffer::GetFormat() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return nzAudioFormat_Unknown; - } - #endif - - return m_impl->format; -} - -const nzInt16* NzSoundBuffer::GetSamples() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return nullptr; - } - #endif - - return m_impl->samples; -} - -unsigned int NzSoundBuffer::GetSampleCount() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return 0; - } - #endif - - return m_impl->sampleCount; -} - -unsigned int NzSoundBuffer::GetSampleRate() const -{ - #if NAZARA_AUDIO_SAFE - if (!m_impl) - { - NazaraError("Sound buffer not created"); - return 0; - } - #endif - - return m_impl->sampleRate; -} - -bool NzSoundBuffer::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzSoundBuffer::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params) -{ - return NzSoundBufferLoader::LoadFromFile(this, filePath, params); -} - -bool NzSoundBuffer::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params) -{ - return NzSoundBufferLoader::LoadFromMemory(this, data, size, params); -} - -bool NzSoundBuffer::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params) -{ - return NzSoundBufferLoader::LoadFromStream(this, stream, params); -} - -bool NzSoundBuffer::IsFormatSupported(nzAudioFormat format) -{ - return NzAudio::IsFormatSupported(format); -} - -unsigned int NzSoundBuffer::GetOpenALBuffer() const -{ - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraInternalError("Sound buffer not created"); - return AL_NONE; - } - #endif - - return m_impl->buffer; -} - -NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Audio module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +///FIXME: Adapter la création + +bool NzSoundBufferParams::IsValid() const +{ + return true; +} + +struct NzSoundBufferImpl +{ + ALuint buffer; + nzAudioFormat format; + nzUInt32 duration; + nzInt16* samples; + unsigned int sampleCount; + unsigned int sampleRate; +}; + +NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) +{ + Create(format, sampleCount, sampleRate, samples); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create sound buffer"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzSoundBuffer::~NzSoundBuffer() +{ + Destroy(); +} + +bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const nzInt16* samples) +{ + Destroy(); + + #if NAZARA_AUDIO_SAFE + if (!IsFormatSupported(format)) + { + NazaraError("Audio format is not supported"); + return false; + } + + if (sampleCount == 0) + { + NazaraError("Sample rate must be different from zero"); + return false; + } + + if (sampleRate == 0) + { + NazaraError("Sample rate must be different from zero"); + return false; + } + + if (!samples) + { + NazaraError("Invalid sample source"); + return false; + } + #endif + + // On vide le stack d'erreurs + while (alGetError() != AL_NO_ERROR); + + ALuint buffer; + alGenBuffers(1, &buffer); + + if (alGetError() != AL_NO_ERROR) + { + NazaraError("Failed to create OpenAL buffer"); + return false; + } + + alBufferData(buffer, NzAudio::GetOpenALFormat(format), samples, sampleCount*sizeof(nzInt16), sampleRate); + + if (alGetError() != AL_NO_ERROR) + { + NazaraError("Failed to set OpenAL buffer"); + alDeleteBuffers(1, &buffer); + + return false; + } + + m_impl = new NzSoundBufferImpl; + m_impl->buffer = buffer; + m_impl->duration = 1000 * (sampleCount / (format * sampleRate)); + m_impl->format = format; + m_impl->sampleCount = sampleCount; + m_impl->sampleRate = sampleRate; + m_impl->samples = new nzInt16[sampleCount]; + std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16)); + + NotifyCreated(); + return true; +} + +void NzSoundBuffer::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + delete[] m_impl->samples; + delete m_impl; + m_impl = nullptr; + } +} + +nzUInt32 NzSoundBuffer::GetDuration() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->duration; +} + +nzAudioFormat NzSoundBuffer::GetFormat() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return nzAudioFormat_Unknown; + } + #endif + + return m_impl->format; +} + +const nzInt16* NzSoundBuffer::GetSamples() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return nullptr; + } + #endif + + return m_impl->samples; +} + +unsigned int NzSoundBuffer::GetSampleCount() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->sampleCount; +} + +unsigned int NzSoundBuffer::GetSampleRate() const +{ + #if NAZARA_AUDIO_SAFE + if (!m_impl) + { + NazaraError("Sound buffer not created"); + return 0; + } + #endif + + return m_impl->sampleRate; +} + +bool NzSoundBuffer::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzSoundBuffer::LoadFromFile(const NzString& filePath, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromFile(this, filePath, params); +} + +bool NzSoundBuffer::LoadFromMemory(const void* data, std::size_t size, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromMemory(this, data, size, params); +} + +bool NzSoundBuffer::LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params) +{ + return NzSoundBufferLoader::LoadFromStream(this, stream, params); +} + +bool NzSoundBuffer::IsFormatSupported(nzAudioFormat format) +{ + return NzAudio::IsFormatSupported(format); +} + +unsigned int NzSoundBuffer::GetOpenALBuffer() const +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Sound buffer not created"); + return AL_NONE; + } + #endif + + return m_impl->buffer; +} + +NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders; diff --git a/src/Nazara/Core/ByteArray.cpp b/src/Nazara/Core/ByteArray.cpp index f5508af3e..4b4b34baa 100644 --- a/src/Nazara/Core/ByteArray.cpp +++ b/src/Nazara/Core/ByteArray.cpp @@ -1,265 +1,265 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -/* -#include -#include -#include -#include - -inline unsigned int nzPow2(unsigned int n) -{ - unsigned int x = 1; - - while(x <= n) - x <<= 1; - - return x; -} -// Cet algorithme est inspiré de la documentation de Qt -inline unsigned int nzGetNewSize(unsigned int newSize) -{ - if (newSize < 20) - return newSize+4; - else - { - if (newSize < (1 << 12)-12) - return nzPow2(newSize << 1)-12; - else - return newSize + (1 << 11); - } -} - -NzByteArray::NzByteArray() : -m_sharedArray(&emptyArray) -{ -} - -NzByteArray::NzByteArray(const nzUInt8* buffer, unsigned int bufferLength) -{ - if (bufferLength > 0) - { - m_sharedArray = new SharedArray; - m_sharedArray->buffer = new nzUInt8[bufferLength]; - m_sharedArray->capacity = bufferLength; - m_sharedArray->size = bufferLength; - std::memcpy(m_sharedArray->buffer, buffer, bufferLength); - } - else - m_sharedArray = &emptyArray; -} - -NzByteArray::NzByteArray(const NzByteArray& buffer) : -m_sharedArray(buffer.m_sharedArray) -{ - if (m_sharedArray != &emptyArray) - { - NazaraMutexLock(m_sharedArray->mutex); - m_sharedArray->refCount++; - NazaraMutexUnlock(m_sharedArray->mutex); - } -} - -NzByteArray::NzByteArray(NzByteArray&& buffer) noexcept : -m_sharedArray(buffer.m_sharedArray) -{ - buffer.m_sharedArray = &emptyArray; -} - -NzByteArray::NzByteArray(SharedArray* sharedArray) : -m_sharedArray(sharedArray) -{ -} - -NzByteArray::~NzByteArray() -{ - ReleaseArray(); -} - -NzByteArray& NzByteArray::Append(const NzByteArray& byteArray) -{ - if (byteArray.m_sharedArray->size == 0) - return *this; - - if (m_sharedArray->size == 0 && m_sharedArray->capacity < byteArray.m_sharedArray->size) - return operator=(byteArray); - - if (m_sharedArray->capacity >= m_sharedArray->size + byteArray.m_sharedArray->size) - { - EnsureOwnership(); - - std::memcpy(&m_sharedArray->buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); - m_sharedArray->size += byteArray.m_sharedArray->size; - } - else - { - unsigned int newSize = m_sharedArray->size + byteArray.m_sharedArray->size; - unsigned int bufferSize = nzGetNewSize(newSize); - - nzUInt8* buffer = new nzUInt8[bufferSize+1]; - std::memcpy(buffer, m_sharedArray->buffer, m_sharedArray->size); - std::memcpy(&buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); - - ReleaseArray(); - m_sharedArray = new SharedArray; - m_sharedArray->buffer = buffer; - m_sharedArray->capacity = bufferSize; - m_sharedArray->size = newSize; - } - - return *this; -} - -void NzByteArray::Clear() -{ - ReleaseArray(); -} - -nzUInt8* NzByteArray::GetBuffer() -{ - EnsureOwnership(); - - return m_sharedArray->buffer; -} - -unsigned int NzByteArray::GetCapacity() const -{ - return m_sharedArray->capacity; -} - -const nzUInt8* NzByteArray::GetConstBuffer() const -{ - return m_sharedArray->buffer; -} - -unsigned int NzByteArray::GetSize() const -{ - return m_sharedArray->size; -} - -NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength) -{ - if (bufferLength == 0) - return *this; - - if (m_sharedArray->size == 0) - return operator=(string); - - if (pos < 0) - pos = std::max(static_cast(m_sharedArray->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedArray->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength) - { - EnsureOwnership(); - - std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size); - std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength); - - m_sharedArray->size += bufferLength; - } - else - { - unsigned int newSize = m_sharedArray->size+bufferLength; - nzUInt8* newBuffer = new nzUInt8[newSize+1]; - - nzUInt8* ptr = newBuffer; - const nzUInt8* s = m_sharedArray->buffer; - - while (ptr != &newBuffer[start]) - *ptr++ = *s++; - - while (ptr != &newBuffer[start+bufferLength]) - *ptr++ = *buffer++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedArray = new SharedString; - m_sharedArray->allocatedSize = newSize; - m_sharedArray->buffer = newBuffer; - m_sharedArray->size = newSize; - } - - return *this; -} - -NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray) -{ - if (string.m_sharedArray->size == 0) - return *this; - - if (m_sharedArray->size == 0 && m_sharedArray->capacity < string.m_sharedArray->size) - return operator=(string); - - if (pos < 0) - pos = std::max(static_cast(m_sharedArray->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedArray->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size) - { - EnsureOwnership(); - - std::memmove(&m_sharedArray->string[start+string.m_sharedArray->size], &m_sharedArray->string[start], m_sharedArray->size*sizeof(char)); - std::memcpy(&m_sharedArray->string[start], string.m_sharedArray->string, string.m_sharedArray->size*sizeof(char)); - - m_sharedArray->size += string.m_sharedArray->size; - } - else - { - unsigned int newSize = m_sharedArray->size+string.m_sharedArray->size; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedArray->string; - - while (ptr != &newString[start]) - *ptr++ = *s++; - - const char* p = string.m_sharedArray->string; - while (ptr != &newString[start+string.m_sharedArray->size]) - *ptr++ = *p++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedArray = new SharedString; - m_sharedArray->capacity = newSize; - m_sharedArray->size = newSize; - m_sharedArray->string = newString; - } - - return *this; -} - -bool NzByteArray::IsEmpty() const -{ - return m_sharedArray->size == 0; -} - -void NzByteArray::Reserve(unsigned int bufferSize) -{ - if (m_sharedArray->allocatedSize >= bufferSize) - return; - - nzUInt8* ptr = new nzUInt8[bufferSize+1]; - if (m_sharedArray->size > 0) - std::memcpy(ptr, m_sharedArray->buffer, m_sharedArray->size); - - unsigned int size = m_sharedArray->size; - - ReleaseArray(); - m_sharedArray = new SharedString; - m_sharedArray->allocatedSize = bufferSize; - m_sharedArray->buffer = ptr; - m_sharedArray->size = size; -} - -NzByteArray::SharedString NzByteArray::emptyArray(0, 0, 0, nullptr); -unsigned int NzByteArray::npos(static_cast(-1)); -*/ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +/* +#include +#include +#include +#include + +inline unsigned int nzPow2(unsigned int n) +{ + unsigned int x = 1; + + while(x <= n) + x <<= 1; + + return x; +} +// Cet algorithme est inspiré de la documentation de Qt +inline unsigned int nzGetNewSize(unsigned int newSize) +{ + if (newSize < 20) + return newSize+4; + else + { + if (newSize < (1 << 12)-12) + return nzPow2(newSize << 1)-12; + else + return newSize + (1 << 11); + } +} + +NzByteArray::NzByteArray() : +m_sharedArray(&emptyArray) +{ +} + +NzByteArray::NzByteArray(const nzUInt8* buffer, unsigned int bufferLength) +{ + if (bufferLength > 0) + { + m_sharedArray = new SharedArray; + m_sharedArray->buffer = new nzUInt8[bufferLength]; + m_sharedArray->capacity = bufferLength; + m_sharedArray->size = bufferLength; + std::memcpy(m_sharedArray->buffer, buffer, bufferLength); + } + else + m_sharedArray = &emptyArray; +} + +NzByteArray::NzByteArray(const NzByteArray& buffer) : +m_sharedArray(buffer.m_sharedArray) +{ + if (m_sharedArray != &emptyArray) + { + NazaraMutexLock(m_sharedArray->mutex); + m_sharedArray->refCount++; + NazaraMutexUnlock(m_sharedArray->mutex); + } +} + +NzByteArray::NzByteArray(NzByteArray&& buffer) noexcept : +m_sharedArray(buffer.m_sharedArray) +{ + buffer.m_sharedArray = &emptyArray; +} + +NzByteArray::NzByteArray(SharedArray* sharedArray) : +m_sharedArray(sharedArray) +{ +} + +NzByteArray::~NzByteArray() +{ + ReleaseArray(); +} + +NzByteArray& NzByteArray::Append(const NzByteArray& byteArray) +{ + if (byteArray.m_sharedArray->size == 0) + return *this; + + if (m_sharedArray->size == 0 && m_sharedArray->capacity < byteArray.m_sharedArray->size) + return operator=(byteArray); + + if (m_sharedArray->capacity >= m_sharedArray->size + byteArray.m_sharedArray->size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedArray->buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); + m_sharedArray->size += byteArray.m_sharedArray->size; + } + else + { + unsigned int newSize = m_sharedArray->size + byteArray.m_sharedArray->size; + unsigned int bufferSize = nzGetNewSize(newSize); + + nzUInt8* buffer = new nzUInt8[bufferSize+1]; + std::memcpy(buffer, m_sharedArray->buffer, m_sharedArray->size); + std::memcpy(&buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size); + + ReleaseArray(); + m_sharedArray = new SharedArray; + m_sharedArray->buffer = buffer; + m_sharedArray->capacity = bufferSize; + m_sharedArray->size = newSize; + } + + return *this; +} + +void NzByteArray::Clear() +{ + ReleaseArray(); +} + +nzUInt8* NzByteArray::GetBuffer() +{ + EnsureOwnership(); + + return m_sharedArray->buffer; +} + +unsigned int NzByteArray::GetCapacity() const +{ + return m_sharedArray->capacity; +} + +const nzUInt8* NzByteArray::GetConstBuffer() const +{ + return m_sharedArray->buffer; +} + +unsigned int NzByteArray::GetSize() const +{ + return m_sharedArray->size; +} + +NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength) +{ + if (bufferLength == 0) + return *this; + + if (m_sharedArray->size == 0) + return operator=(string); + + if (pos < 0) + pos = std::max(static_cast(m_sharedArray->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedArray->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength) + { + EnsureOwnership(); + + std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size); + std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength); + + m_sharedArray->size += bufferLength; + } + else + { + unsigned int newSize = m_sharedArray->size+bufferLength; + nzUInt8* newBuffer = new nzUInt8[newSize+1]; + + nzUInt8* ptr = newBuffer; + const nzUInt8* s = m_sharedArray->buffer; + + while (ptr != &newBuffer[start]) + *ptr++ = *s++; + + while (ptr != &newBuffer[start+bufferLength]) + *ptr++ = *buffer++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedArray = new SharedString; + m_sharedArray->allocatedSize = newSize; + m_sharedArray->buffer = newBuffer; + m_sharedArray->size = newSize; + } + + return *this; +} + +NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray) +{ + if (string.m_sharedArray->size == 0) + return *this; + + if (m_sharedArray->size == 0 && m_sharedArray->capacity < string.m_sharedArray->size) + return operator=(string); + + if (pos < 0) + pos = std::max(static_cast(m_sharedArray->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedArray->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size) + { + EnsureOwnership(); + + std::memmove(&m_sharedArray->string[start+string.m_sharedArray->size], &m_sharedArray->string[start], m_sharedArray->size*sizeof(char)); + std::memcpy(&m_sharedArray->string[start], string.m_sharedArray->string, string.m_sharedArray->size*sizeof(char)); + + m_sharedArray->size += string.m_sharedArray->size; + } + else + { + unsigned int newSize = m_sharedArray->size+string.m_sharedArray->size; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedArray->string; + + while (ptr != &newString[start]) + *ptr++ = *s++; + + const char* p = string.m_sharedArray->string; + while (ptr != &newString[start+string.m_sharedArray->size]) + *ptr++ = *p++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedArray = new SharedString; + m_sharedArray->capacity = newSize; + m_sharedArray->size = newSize; + m_sharedArray->string = newString; + } + + return *this; +} + +bool NzByteArray::IsEmpty() const +{ + return m_sharedArray->size == 0; +} + +void NzByteArray::Reserve(unsigned int bufferSize) +{ + if (m_sharedArray->allocatedSize >= bufferSize) + return; + + nzUInt8* ptr = new nzUInt8[bufferSize+1]; + if (m_sharedArray->size > 0) + std::memcpy(ptr, m_sharedArray->buffer, m_sharedArray->size); + + unsigned int size = m_sharedArray->size; + + ReleaseArray(); + m_sharedArray = new SharedString; + m_sharedArray->allocatedSize = bufferSize; + m_sharedArray->buffer = ptr; + m_sharedArray->size = size; +} + +NzByteArray::SharedString NzByteArray::emptyArray(0, 0, 0, nullptr); +unsigned int NzByteArray::npos(static_cast(-1)); +*/ diff --git a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp index c507ba42c..7050c540f 100644 --- a/src/Nazara/Core/Debug/MemoryLeakTracker.cpp +++ b/src/Nazara/Core/Debug/MemoryLeakTracker.cpp @@ -1,271 +1,271 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#elif defined(NAZARA_PLATFORM_POSIX) -#include -#endif - -namespace -{ - struct Block - { - std::size_t size; - const char* file; - Block* prev; - Block* next; - bool array; - unsigned int line; - unsigned int magic; - }; - - bool initialized = false; - const unsigned int magic = 0x51429EE; - const char* MLTFileName = "NazaraLeaks.log"; - const char* nextFreeFile = "Internal error"; - unsigned int nextFreeLine = 0; - - Block ptrList = - { - 0, - nullptr, - &ptrList, - &ptrList, - false, - 0, - magic - }; - - #if defined(NAZARA_PLATFORM_WINDOWS) - CRITICAL_SECTION mutex; - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - #endif -} - -NzMemoryManager::NzMemoryManager() -{ -} - -NzMemoryManager::~NzMemoryManager() -{ - Uninitialize(); -} - -void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file, unsigned int line) -{ - if (!initialized) - Initialize(); - - #if defined(NAZARA_PLATFORM_WINDOWS) - EnterCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_lock(&mutex); - #endif - - Block* ptr = reinterpret_cast(std::malloc(size+sizeof(Block))); - if (!ptr) - { - // Pas d'information de temps (Car nécessitant une allocation) - FILE* log = std::fopen(MLTFileName, "a"); - std::fprintf(log, "Failed to allocate memory (%d bytes)\n", size); - std::fclose(log); - - return nullptr; // Impossible d'envoyer une exception car cela allouerait de la mémoire avec new (boucle infinie) - } - - ptr->array = multi; - ptr->file = file; - ptr->line = line; - ptr->size = size; - ptr->magic = magic; - - ptr->prev = ptrList.prev; - ptr->next = &ptrList; - ptrList.prev->next = ptr; - ptrList.prev = ptr; - - #if defined(NAZARA_PLATFORM_WINDOWS) - LeaveCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_unlock(&mutex); - #endif - - return reinterpret_cast(ptr)+sizeof(Block); -} - -void NzMemoryManager::Free(void* pointer, bool multi) -{ - if (!pointer) - return; - - Block* ptr = reinterpret_cast(reinterpret_cast(pointer)-sizeof(Block)); - if (ptr->magic != magic) - return; - - #if defined(NAZARA_PLATFORM_WINDOWS) - EnterCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_lock(&mutex); - #endif - - if (ptr->array != multi) - { - char* time = TimeInfo(); - - FILE* log = std::fopen(MLTFileName, "a"); - - if (nextFreeFile) - { - if (multi) - std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine); - else - std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine); - } - else - { - if (multi) - std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time); - else - std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time); - } - - std::fclose(log); - - std::free(time); - } - - ptr->magic = 0; - ptr->prev->next = ptr->next; - ptr->next->prev = ptr->prev; - - std::free(ptr); - - nextFreeFile = nullptr; - nextFreeLine = 0; - - #if defined(NAZARA_PLATFORM_WINDOWS) - LeaveCriticalSection(&mutex); - #elif defined(NAZARA_PLATFORM_POSIX) - pthread_mutex_unlock(&mutex); - #endif -} - -void NzMemoryManager::NextFree(const char* file, unsigned int line) -{ - nextFreeFile = file; - nextFreeLine = line; -} - -void NzMemoryManager::Initialize() -{ - char* time = TimeInfo(); - - FILE* file = std::fopen(MLTFileName, "w"); - std::fprintf(file, "%s ==============================\n", time); - std::fprintf(file, "%s Nazara Memory Leak Tracker \n", time); - std::fprintf(file, "%s ==============================\n", time); - std::fclose(file); - - std::free(time); - - if (std::atexit(Uninitialize) != 0) - { - static NzMemoryManager manager; - } - - #ifdef NAZARA_PLATFORM_WINDOWS - InitializeCriticalSection(&mutex); - #endif - - initialized = true; -} - -char* NzMemoryManager::TimeInfo() -{ - char* buffer = reinterpret_cast(std::malloc(23*sizeof(char))); - - time_t currentTime = std::time(nullptr); - std::strftime(buffer, 23, "%d/%m/%Y - %H:%M:%S:", std::localtime(¤tTime)); - - return buffer; -} - -void NzMemoryManager::Uninitialize() -{ - #ifdef NAZARA_PLATFORM_WINDOWS - DeleteCriticalSection(&mutex); - #endif - - FILE* log = std::fopen(MLTFileName, "a"); - - char* time = TimeInfo(); - - std::fprintf(log, "%s Application finished, checking leaks...\n", time); - - if (ptrList.next == &ptrList) - { - std::fprintf(log, "%s ==============================\n", time); - std::fprintf(log, "%s No leak detected \n", time); - std::fprintf(log, "%s ==============================", time); - } - else - { - std::fprintf(log, "%s ==============================\n", time); - std::fprintf(log, "%s Leaks have been detected \n", time); - std::fprintf(log, "%s ==============================\n\n", time); - std::fputs("Leak list:\n", log); - - Block* ptr = ptrList.next; - unsigned int count = 0; - unsigned int totalSize = 0; - while (ptr != &ptrList) - { - count++; - totalSize += ptr->size; - if (ptr->file) - std::fprintf(log, "-0x%p -> %d bytes allocated at %s:%d\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size, ptr->file, ptr->line); - else - std::fprintf(log, "-0x%p -> %d bytes allocated at unknown position\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size); - - void* pointer = ptr; - ptr = ptr->next; - std::free(pointer); - } - - std::fprintf(log, "\n%d blocks leaked (%d bytes)", count, totalSize); - } - - std::free(time); - std::fclose(log); -} - -void* operator new(std::size_t size, const char* file, unsigned int line) -{ - return NzMemoryManager::Allocate(size, false, file, line); -} - -void* operator new[](std::size_t size, const char* file, unsigned int line) -{ - return NzMemoryManager::Allocate(size, true, file, line); -} - -void operator delete(void* ptr, const char* file, unsigned int line) throw() -{ - NzMemoryManager::NextFree(file, line); - NzMemoryManager::Free(ptr, false); -} - -void operator delete[](void* ptr, const char* file, unsigned int line) throw() -{ - NzMemoryManager::NextFree(file, line); - NzMemoryManager::Free(ptr, true); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) +#include +#elif defined(NAZARA_PLATFORM_POSIX) +#include +#endif + +namespace +{ + struct Block + { + std::size_t size; + const char* file; + Block* prev; + Block* next; + bool array; + unsigned int line; + unsigned int magic; + }; + + bool initialized = false; + const unsigned int magic = 0x51429EE; + const char* MLTFileName = "NazaraLeaks.log"; + const char* nextFreeFile = "Internal error"; + unsigned int nextFreeLine = 0; + + Block ptrList = + { + 0, + nullptr, + &ptrList, + &ptrList, + false, + 0, + magic + }; + + #if defined(NAZARA_PLATFORM_WINDOWS) + CRITICAL_SECTION mutex; + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + #endif +} + +NzMemoryManager::NzMemoryManager() +{ +} + +NzMemoryManager::~NzMemoryManager() +{ + Uninitialize(); +} + +void* NzMemoryManager::Allocate(std::size_t size, bool multi, const char* file, unsigned int line) +{ + if (!initialized) + Initialize(); + + #if defined(NAZARA_PLATFORM_WINDOWS) + EnterCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_lock(&mutex); + #endif + + Block* ptr = reinterpret_cast(std::malloc(size+sizeof(Block))); + if (!ptr) + { + // Pas d'information de temps (Car nécessitant une allocation) + FILE* log = std::fopen(MLTFileName, "a"); + std::fprintf(log, "Failed to allocate memory (%d bytes)\n", size); + std::fclose(log); + + return nullptr; // Impossible d'envoyer une exception car cela allouerait de la mémoire avec new (boucle infinie) + } + + ptr->array = multi; + ptr->file = file; + ptr->line = line; + ptr->size = size; + ptr->magic = magic; + + ptr->prev = ptrList.prev; + ptr->next = &ptrList; + ptrList.prev->next = ptr; + ptrList.prev = ptr; + + #if defined(NAZARA_PLATFORM_WINDOWS) + LeaveCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_unlock(&mutex); + #endif + + return reinterpret_cast(ptr)+sizeof(Block); +} + +void NzMemoryManager::Free(void* pointer, bool multi) +{ + if (!pointer) + return; + + Block* ptr = reinterpret_cast(reinterpret_cast(pointer)-sizeof(Block)); + if (ptr->magic != magic) + return; + + #if defined(NAZARA_PLATFORM_WINDOWS) + EnterCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_lock(&mutex); + #endif + + if (ptr->array != multi) + { + char* time = TimeInfo(); + + FILE* log = std::fopen(MLTFileName, "a"); + + if (nextFreeFile) + { + if (multi) + std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine); + else + std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine); + } + else + { + if (multi) + std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time); + else + std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time); + } + + std::fclose(log); + + std::free(time); + } + + ptr->magic = 0; + ptr->prev->next = ptr->next; + ptr->next->prev = ptr->prev; + + std::free(ptr); + + nextFreeFile = nullptr; + nextFreeLine = 0; + + #if defined(NAZARA_PLATFORM_WINDOWS) + LeaveCriticalSection(&mutex); + #elif defined(NAZARA_PLATFORM_POSIX) + pthread_mutex_unlock(&mutex); + #endif +} + +void NzMemoryManager::NextFree(const char* file, unsigned int line) +{ + nextFreeFile = file; + nextFreeLine = line; +} + +void NzMemoryManager::Initialize() +{ + char* time = TimeInfo(); + + FILE* file = std::fopen(MLTFileName, "w"); + std::fprintf(file, "%s ==============================\n", time); + std::fprintf(file, "%s Nazara Memory Leak Tracker \n", time); + std::fprintf(file, "%s ==============================\n", time); + std::fclose(file); + + std::free(time); + + if (std::atexit(Uninitialize) != 0) + { + static NzMemoryManager manager; + } + + #ifdef NAZARA_PLATFORM_WINDOWS + InitializeCriticalSection(&mutex); + #endif + + initialized = true; +} + +char* NzMemoryManager::TimeInfo() +{ + char* buffer = reinterpret_cast(std::malloc(23*sizeof(char))); + + time_t currentTime = std::time(nullptr); + std::strftime(buffer, 23, "%d/%m/%Y - %H:%M:%S:", std::localtime(¤tTime)); + + return buffer; +} + +void NzMemoryManager::Uninitialize() +{ + #ifdef NAZARA_PLATFORM_WINDOWS + DeleteCriticalSection(&mutex); + #endif + + FILE* log = std::fopen(MLTFileName, "a"); + + char* time = TimeInfo(); + + std::fprintf(log, "%s Application finished, checking leaks...\n", time); + + if (ptrList.next == &ptrList) + { + std::fprintf(log, "%s ==============================\n", time); + std::fprintf(log, "%s No leak detected \n", time); + std::fprintf(log, "%s ==============================", time); + } + else + { + std::fprintf(log, "%s ==============================\n", time); + std::fprintf(log, "%s Leaks have been detected \n", time); + std::fprintf(log, "%s ==============================\n\n", time); + std::fputs("Leak list:\n", log); + + Block* ptr = ptrList.next; + unsigned int count = 0; + unsigned int totalSize = 0; + while (ptr != &ptrList) + { + count++; + totalSize += ptr->size; + if (ptr->file) + std::fprintf(log, "-0x%p -> %d bytes allocated at %s:%d\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size, ptr->file, ptr->line); + else + std::fprintf(log, "-0x%p -> %d bytes allocated at unknown position\n", reinterpret_cast(ptr)+sizeof(Block), ptr->size); + + void* pointer = ptr; + ptr = ptr->next; + std::free(pointer); + } + + std::fprintf(log, "\n%d blocks leaked (%d bytes)", count, totalSize); + } + + std::free(time); + std::fclose(log); +} + +void* operator new(std::size_t size, const char* file, unsigned int line) +{ + return NzMemoryManager::Allocate(size, false, file, line); +} + +void* operator new[](std::size_t size, const char* file, unsigned int line) +{ + return NzMemoryManager::Allocate(size, true, file, line); +} + +void operator delete(void* ptr, const char* file, unsigned int line) throw() +{ + NzMemoryManager::NextFree(file, line); + NzMemoryManager::Free(ptr, false); +} + +void operator delete[](void* ptr, const char* file, unsigned int line) throw() +{ + NzMemoryManager::NextFree(file, line); + NzMemoryManager::Free(ptr, true); +} diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 7f9d117f1..5a2148569 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -1,760 +1,760 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) - #include -#elif defined(NAZARA_PLATFORM_POSIX) - #include -#else - #error OS not handled -#endif - -#include - -NzFile::NzFile() : -m_endianness(nzEndianness_Unknown), -m_impl(nullptr), -m_openMode(0) -{ -} - -NzFile::NzFile(const NzString& filePath) : -m_endianness(nzEndianness_Unknown), -m_impl(nullptr), -m_openMode(0) -{ - SetFile(filePath); -} - -NzFile::NzFile(const NzString& filePath, unsigned long openMode) : -m_endianness(nzEndianness_Unknown), -m_impl(nullptr), -m_openMode(0) -{ - SetFile(filePath); - Open(openMode); -} - -NzFile::NzFile(NzFile&& file) noexcept : -m_endianness(file.m_endianness), -m_filePath(std::move(file.m_filePath)), -m_impl(file.m_impl), -m_openMode(file.m_openMode) -{ - file.m_impl = nullptr; -} - -NzFile::~NzFile() -{ - Close(); -} - -bool NzFile::Copy(const NzString& newFilePath) -{ - return Copy(m_filePath, newFilePath); -} - -void NzFile::Close() -{ - NazaraLock(m_mutex) - - if (m_impl) - { - m_impl->Close(); - delete m_impl; - m_impl = nullptr; - } -} - -bool NzFile::Delete() -{ - NazaraLock(m_mutex) - - Close(); - - return Delete(m_filePath); -} - -bool NzFile::EndOfFile() const -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->EndOfFile(); -} - -bool NzFile::EndOfStream() const -{ - return EndOfFile(); -} - -bool NzFile::Exists() const -{ - NazaraLock(m_mutex) - - if (IsOpen()) - return true; // Le fichier est ouvert, donc il existe - else - return Exists(m_filePath); -} - -void NzFile::Flush() -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return; - } - - if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) - { - NazaraError("Cannot flush file without write access"); - return; - } - #endif - - m_impl->Flush(); -} - -time_t NzFile::GetCreationTime() const -{ - NazaraLock(m_mutex) - - return GetCreationTime(m_filePath); -} - -nzUInt64 NzFile::GetCursorPos() const -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->GetCursorPos(); -} - -NzString NzFile::GetDirectoryPath() const -{ - NazaraLock(m_mutex) - - return m_filePath.SubstrTo(NAZARA_DIRECTORY_SEPARATOR, -1, true); -} - -NzString NzFile::GetFilePath() const -{ - NazaraLock(m_mutex) - - return m_filePath; -} - -NzString NzFile::GetFileName() const -{ - NazaraLock(m_mutex) - - return m_filePath.SubstrFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); -} - -time_t NzFile::GetLastAccessTime() const -{ - NazaraLock(m_mutex) - - return GetLastAccessTime(m_filePath); -} - -time_t NzFile::GetLastWriteTime() const -{ - NazaraLock(m_mutex) - - return GetLastWriteTime(m_filePath); -} - -NzString NzFile::GetLine(unsigned int lineSize) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return NzString(); - } - - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) - { - NazaraError("File not opened with read access"); - return NzString(); - } - #endif - - NzString line = NzInputStream::GetLine(lineSize); - if (m_openMode & Text && !m_impl->EndOfFile() && line.EndsWith('\r')) - line.Resize(-1); - - return line; -} - -nzUInt64 NzFile::GetSize() const -{ - NazaraLock(m_mutex) - - return GetSize(m_filePath); -} - -bool NzFile::IsOpen() const -{ - NazaraLock(m_mutex) - - return m_impl != nullptr; -} - -std::size_t NzFile::Read(void* buffer, std::size_t size) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return 0; - } - - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) - { - NazaraError("File not opened with read access"); - return 0; - } - #endif - - if (size == 0) - return 0; - - if (buffer) - return m_impl->Read(buffer, size); - else - { - // Si nous ne devons rien lire, nous avançons simplement - nzUInt64 currentPos = m_impl->GetCursorPos(); - - m_impl->SetCursorPos(NzFile::AtCurrent, size); - - return m_impl->GetCursorPos()-currentPos; - } -} - -std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) -{ - std::size_t byteRead = Read(buffer, typeSize*count); - if (byteRead == 0) - return 0; - - if (buffer && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) - { - unsigned int typeCount = byteRead/typeSize; - for (unsigned int i = 0; i < typeCount; ++i) - NzByteSwap(reinterpret_cast(buffer) + i*typeSize, typeSize); - } - - return byteRead; -} - -bool NzFile::Rename(const NzString& newFilePath) -{ - NazaraLock(m_mutex) - - bool opened = IsOpen(); - Close(); - - bool success = Rename(m_filePath, newFilePath); - if (success) - m_filePath = NormalizePath(newFilePath); - - if (opened) - Open(); - - return success; -} - -bool NzFile::Open(unsigned long openMode) -{ - NazaraLock(m_mutex) - - Close(); - - if (m_filePath.IsEmpty()) - return false; - - if (openMode != 0) - m_openMode = openMode; - - if (m_openMode == 0) - return false; - - m_impl = new NzFileImpl(this); - if (!m_impl->Open(m_filePath, m_openMode)) - { - delete m_impl; - m_impl = nullptr; - - return false; - } - - return true; -} - -bool NzFile::SetCursorPos(CursorPosition pos, nzInt64 offset) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->SetCursorPos(pos, offset); -} - -bool NzFile::SetCursorPos(nzUInt64 offset) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return false; - } - #endif - - return m_impl->SetCursorPos(AtBegin, offset); -} - -void NzFile::SetEndianness(nzEndianness endianness) -{ - NazaraLock(m_mutex) - - m_endianness = endianness; -} - -bool NzFile::SetFile(const NzString& filePath) -{ - NazaraLock(m_mutex) - - if (IsOpen()) - { - if (filePath.IsEmpty()) - return false; - - NzFileImpl* impl = new NzFileImpl(this); - if (!impl->Open(filePath, m_openMode)) - { - delete impl; - return false; - } - - m_impl->Close(); - delete m_impl; - - m_impl = impl; - } - - m_filePath = AbsolutePath(filePath); - return true; -} - -bool NzFile::SetOpenMode(unsigned int openMode) -{ - NazaraLock(m_mutex) - - if (openMode == 0 || openMode == m_openMode) - return true; - - if (IsOpen()) - { - NzFileImpl* impl = new NzFileImpl(this); - if (!impl->Open(m_filePath, openMode)) - { - delete impl; - - return false; - } - - m_impl->Close(); - delete m_impl; - - m_impl = impl; - } - - m_openMode = openMode; - - return true; -} - -bool NzFile::Write(const NzString& string) -{ - NazaraLock(m_mutex) - - NzString temp(string); - - if (m_openMode & Text) - { - #if defined(NAZARA_PLATFORM_WINDOWS) - temp.Replace("\n", "\r\n"); - #elif defined(NAZARA_PLATFORM_LINUX) - // Rien à faire - #elif defined(NAZARA_PLATFORM_MACOS) - temp.Replace('\n', '\r'); - #else - #error OS not handled - #endif - } - - unsigned int size = temp.GetSize(); - std::size_t bytesWritten = Write(temp.GetBuffer(), sizeof(char), size); - - return bytesWritten == size*sizeof(char); -} - -std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int count) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return 0; - } - - if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) - { - NazaraError("File not opened with write access"); - return 0; - } - #endif - - if (!buffer || count == 0 || typeSize == 0) - return 0; - - std::size_t bytesWritten; - if (m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) - { - char* buf = new char[count*typeSize]; - std::memcpy(buf, buffer, count*typeSize); - - for (unsigned int i = 0; i < count; ++i) - NzByteSwap(&buf[i*typeSize], typeSize); - - bytesWritten = m_impl->Write(buf, count*typeSize); - - delete[] buf; - } - else - bytesWritten = m_impl->Write(buffer, count*typeSize); - - return bytesWritten; -} - -NzFile& NzFile::operator=(const NzString& filePath) -{ - SetFile(filePath); - - return *this; -} - -NzFile& NzFile::operator=(NzFile&& file) noexcept -{ - NazaraLock(m_mutex) - - std::swap(m_endianness, file.m_endianness); - std::swap(m_filePath, file.m_filePath); - std::swap(m_impl, file.m_impl); - std::swap(m_openMode, file.m_openMode); - - return *this; -} - -NzString NzFile::AbsolutePath(const NzString& filePath) -{ - // Je n'utilise pas les fonctions de l'OS car elles ne fonctionnent que pour un chemin existant - NzString path = NormalizePath(filePath); - if (path.IsEmpty()) - return NzString(); - - NzString base; - unsigned int start; - #ifdef NAZARA_PLATFORM_WINDOWS - if (path.Match("?:*")) - start = 1; - else if (path.Match("\\\\*")) - { - base = "\\\\"; - start = 2; - } - else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine - { - NzString drive = NzDirectory::GetCurrent().SubstrTo('\\'); - NzString end = path.Substr(1, -1); - if (end.IsEmpty()) - path = drive; - else - path = drive + '\\' + end; - - start = 1; - } - else - { - NazaraError("Path unrecognized"); - return path; - } - #elif defined(NAZARA_PLATEFORM_LINUX) - base = '/'; - start = 0; - #else - #error OS case not implemented - #endif - - static NzString upDir = NAZARA_DIRECTORY_SEPARATOR + NzString('.'); - - if (path.Find(upDir) == NzString::npos) - return path; - - std::vector sep; - if (path.Split(sep, NAZARA_DIRECTORY_SEPARATOR) <= 1) - return path; - - // Nous avons un chemin absolu, mais il nous faut un peu le nettoyer - unsigned int pathLen = base.GetSize(); - for (unsigned int i = 0; i < sep.size(); ++i) - { - if (sep[i] == '.') - sep.erase(sep.begin() + i--); - else if (sep[i] == "..") - { - if (i > start) // Si nous ne sommes pas dans la partie protégée - sep.erase(sep.begin() + i--); - - sep.erase(sep.begin() + i--); - } - else - pathLen += sep[i].GetSize(); - } - - pathLen += sep.size()-1; - - ///FIXME: Le destructeur de NzStringStream provoque un bug lors de la libération de son vector - - //NzStringStream stream(base); - NzString stream; - stream.Reserve(pathLen); - stream.Append(base); - for (unsigned int i = 0; i < sep.size(); ++i) - { - stream.Append(sep[i]); - if (i != sep.size()-1) - stream.Append(NAZARA_DIRECTORY_SEPARATOR); - /*if (i != sep.size()-1) - stream << sep[i] << NAZARA_DIRECTORY_SEPARATOR; - else - stream << sep[i];*/ - } - - return stream; -} - -bool NzFile::Copy(const NzString& sourcePath, const NzString& targetPath) -{ - if (sourcePath.IsEmpty() || targetPath.IsEmpty()) - return false; - - return NzFileImpl::Copy(NormalizePath(sourcePath), NormalizePath(targetPath)); -} - -bool NzFile::Delete(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return false; - - return NzFileImpl::Delete(NormalizePath(filePath)); -} - -bool NzFile::Exists(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return false; - - return NzFileImpl::Exists(NormalizePath(filePath)); -} - -time_t NzFile::GetCreationTime(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetCreationTime(NormalizePath(filePath)); -} - -time_t NzFile::GetLastAccessTime(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetLastAccessTime(NormalizePath(filePath)); -} - -time_t NzFile::GetLastWriteTime(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetLastWriteTime(NormalizePath(filePath)); -} - -NzHashDigest NzFile::GetHash(const NzString& filePath, nzHash hash) -{ - NzFile file(filePath); - - NzHash h(hash); - return h.Hash(file); -} - -NzHashDigest NzFile::GetHash(const NzString& filePath, NzHashImpl* hash) -{ - NzFile file(filePath); - - NzHash h(hash); - return h.Hash(file); -} - -nzUInt64 NzFile::GetSize(const NzString& filePath) -{ - if (filePath.IsEmpty()) - return 0; - - return NzFileImpl::GetSize(NormalizePath(filePath)); -} - -bool NzFile::IsAbsolute(const NzString& path) -{ - NzString wpath(path); - wpath.Trim(); - - if (wpath.IsEmpty()) - return false; - - #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS - wpath = NormalizeSeparators(wpath); - #endif - - #ifdef NAZARA_PLATFORM_WINDOWS - if (path.Match("?:*")) - return true; - else if (path.Match("\\\\*")) - return true; - else if (wpath.StartsWith('\\')) // Spécial : '\' fait référence au disque racine - return true; - else - return false; - #elif defined(NAZARA_PLATEFORM_LINUX) - return wpath.StartsWith('/'); - #else - #error OS case not implemented - #endif -} - -NzString NzFile::NormalizePath(const NzString& filePath) -{ - NzString path(filePath); - path.Trim(); - - #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS - path = NormalizeSeparators(path); - #endif - - if (!IsAbsolute(path)) - path = NzDirectory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR + path; - - while (path.EndsWith(NAZARA_DIRECTORY_SEPARATOR)) - path.Resize(-1); - - return path; -} - -NzString NzFile::NormalizeSeparators(const NzString& filePath) -{ - NzString path(filePath); - - #if defined(NAZARA_PLATFORM_WINDOWS) - path.Replace('/', '\\'); - #elif defined(NAZARA_PLATFORM_LINUX) - path.Replace('\\', '/'); - #else - #error OS case not implemented - #endif - - return path; -} - -bool NzFile::Rename(const NzString& sourcePath, const NzString& targetPath) -{ - if (sourcePath.IsEmpty() || targetPath.IsEmpty()) - return false; - - return NzFileImpl::Rename(NormalizePath(sourcePath), NormalizePath(targetPath)); -} - -bool NzFile::FillHash(NzHashImpl* hash) const -{ - NzFile file(m_filePath); - if (!file.Open(NzFile::ReadOnly)) - { - NazaraError("Unable to open file"); - return false; - } - - nzUInt64 remainingSize = file.GetSize(); - - char buffer[NAZARA_CORE_FILE_BUFFERSIZE]; - unsigned int size; - while (remainingSize > 0) - { - size = (remainingSize >= NAZARA_CORE_FILE_BUFFERSIZE) ? NAZARA_CORE_FILE_BUFFERSIZE : static_cast(remainingSize); - if (file.Read(&buffer[0], sizeof(char), size) != sizeof(char)*size) - { - NazaraError("Unable to read file"); - return false; - } - - remainingSize -= size; - hash->Append(reinterpret_cast(&buffer[0]), size); - } - - return true; -} // Fermeture automatique du fichier +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) + #include +#elif defined(NAZARA_PLATFORM_POSIX) + #include +#else + #error OS not handled +#endif + +#include + +NzFile::NzFile() : +m_endianness(nzEndianness_Unknown), +m_impl(nullptr), +m_openMode(0) +{ +} + +NzFile::NzFile(const NzString& filePath) : +m_endianness(nzEndianness_Unknown), +m_impl(nullptr), +m_openMode(0) +{ + SetFile(filePath); +} + +NzFile::NzFile(const NzString& filePath, unsigned long openMode) : +m_endianness(nzEndianness_Unknown), +m_impl(nullptr), +m_openMode(0) +{ + SetFile(filePath); + Open(openMode); +} + +NzFile::NzFile(NzFile&& file) noexcept : +m_endianness(file.m_endianness), +m_filePath(std::move(file.m_filePath)), +m_impl(file.m_impl), +m_openMode(file.m_openMode) +{ + file.m_impl = nullptr; +} + +NzFile::~NzFile() +{ + Close(); +} + +bool NzFile::Copy(const NzString& newFilePath) +{ + return Copy(m_filePath, newFilePath); +} + +void NzFile::Close() +{ + NazaraLock(m_mutex) + + if (m_impl) + { + m_impl->Close(); + delete m_impl; + m_impl = nullptr; + } +} + +bool NzFile::Delete() +{ + NazaraLock(m_mutex) + + Close(); + + return Delete(m_filePath); +} + +bool NzFile::EndOfFile() const +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->EndOfFile(); +} + +bool NzFile::EndOfStream() const +{ + return EndOfFile(); +} + +bool NzFile::Exists() const +{ + NazaraLock(m_mutex) + + if (IsOpen()) + return true; // Le fichier est ouvert, donc il existe + else + return Exists(m_filePath); +} + +void NzFile::Flush() +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return; + } + + if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) + { + NazaraError("Cannot flush file without write access"); + return; + } + #endif + + m_impl->Flush(); +} + +time_t NzFile::GetCreationTime() const +{ + NazaraLock(m_mutex) + + return GetCreationTime(m_filePath); +} + +nzUInt64 NzFile::GetCursorPos() const +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->GetCursorPos(); +} + +NzString NzFile::GetDirectoryPath() const +{ + NazaraLock(m_mutex) + + return m_filePath.SubstrTo(NAZARA_DIRECTORY_SEPARATOR, -1, true); +} + +NzString NzFile::GetFilePath() const +{ + NazaraLock(m_mutex) + + return m_filePath; +} + +NzString NzFile::GetFileName() const +{ + NazaraLock(m_mutex) + + return m_filePath.SubstrFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); +} + +time_t NzFile::GetLastAccessTime() const +{ + NazaraLock(m_mutex) + + return GetLastAccessTime(m_filePath); +} + +time_t NzFile::GetLastWriteTime() const +{ + NazaraLock(m_mutex) + + return GetLastWriteTime(m_filePath); +} + +NzString NzFile::GetLine(unsigned int lineSize) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return NzString(); + } + + if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) + { + NazaraError("File not opened with read access"); + return NzString(); + } + #endif + + NzString line = NzInputStream::GetLine(lineSize); + if (m_openMode & Text && !m_impl->EndOfFile() && line.EndsWith('\r')) + line.Resize(-1); + + return line; +} + +nzUInt64 NzFile::GetSize() const +{ + NazaraLock(m_mutex) + + return GetSize(m_filePath); +} + +bool NzFile::IsOpen() const +{ + NazaraLock(m_mutex) + + return m_impl != nullptr; +} + +std::size_t NzFile::Read(void* buffer, std::size_t size) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return 0; + } + + if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) + { + NazaraError("File not opened with read access"); + return 0; + } + #endif + + if (size == 0) + return 0; + + if (buffer) + return m_impl->Read(buffer, size); + else + { + // Si nous ne devons rien lire, nous avançons simplement + nzUInt64 currentPos = m_impl->GetCursorPos(); + + m_impl->SetCursorPos(NzFile::AtCurrent, size); + + return m_impl->GetCursorPos()-currentPos; + } +} + +std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) +{ + std::size_t byteRead = Read(buffer, typeSize*count); + if (byteRead == 0) + return 0; + + if (buffer && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) + { + unsigned int typeCount = byteRead/typeSize; + for (unsigned int i = 0; i < typeCount; ++i) + NzByteSwap(reinterpret_cast(buffer) + i*typeSize, typeSize); + } + + return byteRead; +} + +bool NzFile::Rename(const NzString& newFilePath) +{ + NazaraLock(m_mutex) + + bool opened = IsOpen(); + Close(); + + bool success = Rename(m_filePath, newFilePath); + if (success) + m_filePath = NormalizePath(newFilePath); + + if (opened) + Open(); + + return success; +} + +bool NzFile::Open(unsigned long openMode) +{ + NazaraLock(m_mutex) + + Close(); + + if (m_filePath.IsEmpty()) + return false; + + if (openMode != 0) + m_openMode = openMode; + + if (m_openMode == 0) + return false; + + m_impl = new NzFileImpl(this); + if (!m_impl->Open(m_filePath, m_openMode)) + { + delete m_impl; + m_impl = nullptr; + + return false; + } + + return true; +} + +bool NzFile::SetCursorPos(CursorPosition pos, nzInt64 offset) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->SetCursorPos(pos, offset); +} + +bool NzFile::SetCursorPos(nzUInt64 offset) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return false; + } + #endif + + return m_impl->SetCursorPos(AtBegin, offset); +} + +void NzFile::SetEndianness(nzEndianness endianness) +{ + NazaraLock(m_mutex) + + m_endianness = endianness; +} + +bool NzFile::SetFile(const NzString& filePath) +{ + NazaraLock(m_mutex) + + if (IsOpen()) + { + if (filePath.IsEmpty()) + return false; + + NzFileImpl* impl = new NzFileImpl(this); + if (!impl->Open(filePath, m_openMode)) + { + delete impl; + return false; + } + + m_impl->Close(); + delete m_impl; + + m_impl = impl; + } + + m_filePath = AbsolutePath(filePath); + return true; +} + +bool NzFile::SetOpenMode(unsigned int openMode) +{ + NazaraLock(m_mutex) + + if (openMode == 0 || openMode == m_openMode) + return true; + + if (IsOpen()) + { + NzFileImpl* impl = new NzFileImpl(this); + if (!impl->Open(m_filePath, openMode)) + { + delete impl; + + return false; + } + + m_impl->Close(); + delete m_impl; + + m_impl = impl; + } + + m_openMode = openMode; + + return true; +} + +bool NzFile::Write(const NzString& string) +{ + NazaraLock(m_mutex) + + NzString temp(string); + + if (m_openMode & Text) + { + #if defined(NAZARA_PLATFORM_WINDOWS) + temp.Replace("\n", "\r\n"); + #elif defined(NAZARA_PLATFORM_LINUX) + // Rien à faire + #elif defined(NAZARA_PLATFORM_MACOS) + temp.Replace('\n', '\r'); + #else + #error OS not handled + #endif + } + + unsigned int size = temp.GetSize(); + std::size_t bytesWritten = Write(temp.GetBuffer(), sizeof(char), size); + + return bytesWritten == size*sizeof(char); +} + +std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int count) +{ + NazaraLock(m_mutex) + + #if NAZARA_CORE_SAFE + if (!IsOpen()) + { + NazaraError("File not opened"); + return 0; + } + + if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) + { + NazaraError("File not opened with write access"); + return 0; + } + #endif + + if (!buffer || count == 0 || typeSize == 0) + return 0; + + std::size_t bytesWritten; + if (m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) + { + char* buf = new char[count*typeSize]; + std::memcpy(buf, buffer, count*typeSize); + + for (unsigned int i = 0; i < count; ++i) + NzByteSwap(&buf[i*typeSize], typeSize); + + bytesWritten = m_impl->Write(buf, count*typeSize); + + delete[] buf; + } + else + bytesWritten = m_impl->Write(buffer, count*typeSize); + + return bytesWritten; +} + +NzFile& NzFile::operator=(const NzString& filePath) +{ + SetFile(filePath); + + return *this; +} + +NzFile& NzFile::operator=(NzFile&& file) noexcept +{ + NazaraLock(m_mutex) + + std::swap(m_endianness, file.m_endianness); + std::swap(m_filePath, file.m_filePath); + std::swap(m_impl, file.m_impl); + std::swap(m_openMode, file.m_openMode); + + return *this; +} + +NzString NzFile::AbsolutePath(const NzString& filePath) +{ + // Je n'utilise pas les fonctions de l'OS car elles ne fonctionnent que pour un chemin existant + NzString path = NormalizePath(filePath); + if (path.IsEmpty()) + return NzString(); + + NzString base; + unsigned int start; + #ifdef NAZARA_PLATFORM_WINDOWS + if (path.Match("?:*")) + start = 1; + else if (path.Match("\\\\*")) + { + base = "\\\\"; + start = 2; + } + else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + { + NzString drive = NzDirectory::GetCurrent().SubstrTo('\\'); + NzString end = path.Substr(1, -1); + if (end.IsEmpty()) + path = drive; + else + path = drive + '\\' + end; + + start = 1; + } + else + { + NazaraError("Path unrecognized"); + return path; + } + #elif defined(NAZARA_PLATEFORM_LINUX) + base = '/'; + start = 0; + #else + #error OS case not implemented + #endif + + static NzString upDir = NAZARA_DIRECTORY_SEPARATOR + NzString('.'); + + if (path.Find(upDir) == NzString::npos) + return path; + + std::vector sep; + if (path.Split(sep, NAZARA_DIRECTORY_SEPARATOR) <= 1) + return path; + + // Nous avons un chemin absolu, mais il nous faut un peu le nettoyer + unsigned int pathLen = base.GetSize(); + for (unsigned int i = 0; i < sep.size(); ++i) + { + if (sep[i] == '.') + sep.erase(sep.begin() + i--); + else if (sep[i] == "..") + { + if (i > start) // Si nous ne sommes pas dans la partie protégée + sep.erase(sep.begin() + i--); + + sep.erase(sep.begin() + i--); + } + else + pathLen += sep[i].GetSize(); + } + + pathLen += sep.size()-1; + + ///FIXME: Le destructeur de NzStringStream provoque un bug lors de la libération de son vector + + //NzStringStream stream(base); + NzString stream; + stream.Reserve(pathLen); + stream.Append(base); + for (unsigned int i = 0; i < sep.size(); ++i) + { + stream.Append(sep[i]); + if (i != sep.size()-1) + stream.Append(NAZARA_DIRECTORY_SEPARATOR); + /*if (i != sep.size()-1) + stream << sep[i] << NAZARA_DIRECTORY_SEPARATOR; + else + stream << sep[i];*/ + } + + return stream; +} + +bool NzFile::Copy(const NzString& sourcePath, const NzString& targetPath) +{ + if (sourcePath.IsEmpty() || targetPath.IsEmpty()) + return false; + + return NzFileImpl::Copy(NormalizePath(sourcePath), NormalizePath(targetPath)); +} + +bool NzFile::Delete(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return false; + + return NzFileImpl::Delete(NormalizePath(filePath)); +} + +bool NzFile::Exists(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return false; + + return NzFileImpl::Exists(NormalizePath(filePath)); +} + +time_t NzFile::GetCreationTime(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetCreationTime(NormalizePath(filePath)); +} + +time_t NzFile::GetLastAccessTime(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetLastAccessTime(NormalizePath(filePath)); +} + +time_t NzFile::GetLastWriteTime(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetLastWriteTime(NormalizePath(filePath)); +} + +NzHashDigest NzFile::GetHash(const NzString& filePath, nzHash hash) +{ + NzFile file(filePath); + + NzHash h(hash); + return h.Hash(file); +} + +NzHashDigest NzFile::GetHash(const NzString& filePath, NzHashImpl* hash) +{ + NzFile file(filePath); + + NzHash h(hash); + return h.Hash(file); +} + +nzUInt64 NzFile::GetSize(const NzString& filePath) +{ + if (filePath.IsEmpty()) + return 0; + + return NzFileImpl::GetSize(NormalizePath(filePath)); +} + +bool NzFile::IsAbsolute(const NzString& path) +{ + NzString wpath(path); + wpath.Trim(); + + if (wpath.IsEmpty()) + return false; + + #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS + wpath = NormalizeSeparators(wpath); + #endif + + #ifdef NAZARA_PLATFORM_WINDOWS + if (path.Match("?:*")) + return true; + else if (path.Match("\\\\*")) + return true; + else if (wpath.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + return true; + else + return false; + #elif defined(NAZARA_PLATEFORM_LINUX) + return wpath.StartsWith('/'); + #else + #error OS case not implemented + #endif +} + +NzString NzFile::NormalizePath(const NzString& filePath) +{ + NzString path(filePath); + path.Trim(); + + #if NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS + path = NormalizeSeparators(path); + #endif + + if (!IsAbsolute(path)) + path = NzDirectory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR + path; + + while (path.EndsWith(NAZARA_DIRECTORY_SEPARATOR)) + path.Resize(-1); + + return path; +} + +NzString NzFile::NormalizeSeparators(const NzString& filePath) +{ + NzString path(filePath); + + #if defined(NAZARA_PLATFORM_WINDOWS) + path.Replace('/', '\\'); + #elif defined(NAZARA_PLATFORM_LINUX) + path.Replace('\\', '/'); + #else + #error OS case not implemented + #endif + + return path; +} + +bool NzFile::Rename(const NzString& sourcePath, const NzString& targetPath) +{ + if (sourcePath.IsEmpty() || targetPath.IsEmpty()) + return false; + + return NzFileImpl::Rename(NormalizePath(sourcePath), NormalizePath(targetPath)); +} + +bool NzFile::FillHash(NzHashImpl* hash) const +{ + NzFile file(m_filePath); + if (!file.Open(NzFile::ReadOnly)) + { + NazaraError("Unable to open file"); + return false; + } + + nzUInt64 remainingSize = file.GetSize(); + + char buffer[NAZARA_CORE_FILE_BUFFERSIZE]; + unsigned int size; + while (remainingSize > 0) + { + size = (remainingSize >= NAZARA_CORE_FILE_BUFFERSIZE) ? NAZARA_CORE_FILE_BUFFERSIZE : static_cast(remainingSize); + if (file.Read(&buffer[0], sizeof(char), size) != sizeof(char)*size) + { + NazaraError("Unable to read file"); + return false; + } + + remainingSize -= size; + hash->Append(reinterpret_cast(&buffer[0]), size); + } + + return true; +} // Fermeture automatique du fichier diff --git a/src/Nazara/Core/InputStream.cpp b/src/Nazara/Core/InputStream.cpp index f2ef22a25..76e4d46ea 100644 --- a/src/Nazara/Core/InputStream.cpp +++ b/src/Nazara/Core/InputStream.cpp @@ -1,49 +1,49 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -NzInputStream::~NzInputStream() = default; - -NzString NzInputStream::GetLine(unsigned int lineSize) -{ - NzString line; - if (lineSize == 0) // Taille maximale indéterminée - { - while (!EndOfStream()) - { - char c; - if (Read(&c, sizeof(char)) == sizeof(char)) - { - if (c == '\n') - break; - - line += c; - } - else - break; - } - } - else - { - line.Reserve(lineSize); - for (unsigned int i = 0; i < lineSize; ++i) - { - char c; - if (Read(&c, sizeof(char)) == sizeof(char)) - { - if (c == '\n') - break; - - line += c; - } - else - break; - } - } - - return line; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +NzInputStream::~NzInputStream() = default; + +NzString NzInputStream::GetLine(unsigned int lineSize) +{ + NzString line; + if (lineSize == 0) // Taille maximale indéterminée + { + while (!EndOfStream()) + { + char c; + if (Read(&c, sizeof(char)) == sizeof(char)) + { + if (c == '\n') + break; + + line += c; + } + else + break; + } + } + else + { + line.Reserve(lineSize); + for (unsigned int i = 0; i < lineSize; ++i) + { + char c; + if (Read(&c, sizeof(char)) == sizeof(char)) + { + if (c == '\n') + break; + + line += c; + } + else + break; + } + } + + return line; +} diff --git a/src/Nazara/Core/Resource.cpp b/src/Nazara/Core/Resource.cpp index 8014220e1..9bbc29b81 100644 --- a/src/Nazara/Core/Resource.cpp +++ b/src/Nazara/Core/Resource.cpp @@ -1,138 +1,138 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -NzResource::NzResource(bool persistent) : -m_resourcePersistent(persistent), -m_resourceReferenceCount(0) -{ -} - -NzResource::NzResource(const NzResource& resource) : -m_resourcePersistent(resource.m_resourcePersistent), -m_resourceReferenceCount(0) -{ -} - -NzResource::~NzResource() -{ - EnsureResourceListenerUpdate(); - - for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) - (*it).listener->OnResourceReleased(this, (*it).index); -} - -void NzResource::AddResourceListener(NzResourceListener* listener, int index) const -{ - NazaraLock(m_mutex) - - if (m_resourceListeners.insert(NzResourceEntry(listener, index)).second) - { - m_resourceListenerUpdated = false; - - // AddResourceReference() - m_resourceReferenceCount++; - } -} - -void NzResource::AddResourceReference() const -{ - NazaraLock(m_mutex) - - m_resourceReferenceCount++; -} - -bool NzResource::IsPersistent() const -{ - NazaraLock(m_mutex) - - return m_resourcePersistent; -} - -void NzResource::RemoveResourceListener(NzResourceListener* listener) const -{ - NazaraLock(m_mutex) - - if (m_resourceListeners.erase(listener) != 0) - m_resourceListenerUpdated = false; - else - NazaraError(NzString::Pointer(listener) + " is not listening to " + NzString::Pointer(this)); - - RemoveResourceReference(); -} - -void NzResource::RemoveResourceReference() const -{ - NazaraMutexLock(m_mutex); - - #if NAZARA_CORE_SAFE - if (m_resourceReferenceCount == 0) - { - NazaraError("Impossible to remove reference (Ref. counter is already 0)"); - return; - } - #endif - - if (--m_resourceReferenceCount == 0 && !m_resourcePersistent) - { - NazaraMutexUnlock(m_mutex); - delete this; - } - else - { - NazaraMutexUnlock(m_mutex); - } -} - -void NzResource::SetPersistent(bool persistent) -{ - NazaraMutexLock(m_mutex); - - m_resourcePersistent = persistent; - - if (!persistent && m_resourceReferenceCount == 0) - { - NazaraMutexUnlock(m_mutex); - delete this; - } - else - { - NazaraMutexUnlock(m_mutex); - } -} - -void NzResource::NotifyCreated() -{ - NazaraLock(m_mutex) - - EnsureResourceListenerUpdate(); - - for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) - (*it).listener->OnResourceCreated(this, (*it).index); -} - -void NzResource::NotifyDestroy() -{ - NazaraLock(m_mutex) - - EnsureResourceListenerUpdate(); - - for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) - (*it).listener->OnResourceDestroy(this, (*it).index); -} - -void NzResource::EnsureResourceListenerUpdate() const -{ - // Déjà bloqué par une mutex - if (!m_resourceListenerUpdated) - { - m_resourceListenersCache = m_resourceListeners; - m_resourceListenerUpdated = true; - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include + +NzResource::NzResource(bool persistent) : +m_resourcePersistent(persistent), +m_resourceReferenceCount(0) +{ +} + +NzResource::NzResource(const NzResource& resource) : +m_resourcePersistent(resource.m_resourcePersistent), +m_resourceReferenceCount(0) +{ +} + +NzResource::~NzResource() +{ + EnsureResourceListenerUpdate(); + + for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) + (*it).listener->OnResourceReleased(this, (*it).index); +} + +void NzResource::AddResourceListener(NzResourceListener* listener, int index) const +{ + NazaraLock(m_mutex) + + if (m_resourceListeners.insert(NzResourceEntry(listener, index)).second) + { + m_resourceListenerUpdated = false; + + // AddResourceReference() + m_resourceReferenceCount++; + } +} + +void NzResource::AddResourceReference() const +{ + NazaraLock(m_mutex) + + m_resourceReferenceCount++; +} + +bool NzResource::IsPersistent() const +{ + NazaraLock(m_mutex) + + return m_resourcePersistent; +} + +void NzResource::RemoveResourceListener(NzResourceListener* listener) const +{ + NazaraLock(m_mutex) + + if (m_resourceListeners.erase(listener) != 0) + m_resourceListenerUpdated = false; + else + NazaraError(NzString::Pointer(listener) + " is not listening to " + NzString::Pointer(this)); + + RemoveResourceReference(); +} + +void NzResource::RemoveResourceReference() const +{ + NazaraMutexLock(m_mutex); + + #if NAZARA_CORE_SAFE + if (m_resourceReferenceCount == 0) + { + NazaraError("Impossible to remove reference (Ref. counter is already 0)"); + return; + } + #endif + + if (--m_resourceReferenceCount == 0 && !m_resourcePersistent) + { + NazaraMutexUnlock(m_mutex); + delete this; + } + else + { + NazaraMutexUnlock(m_mutex); + } +} + +void NzResource::SetPersistent(bool persistent) +{ + NazaraMutexLock(m_mutex); + + m_resourcePersistent = persistent; + + if (!persistent && m_resourceReferenceCount == 0) + { + NazaraMutexUnlock(m_mutex); + delete this; + } + else + { + NazaraMutexUnlock(m_mutex); + } +} + +void NzResource::NotifyCreated() +{ + NazaraLock(m_mutex) + + EnsureResourceListenerUpdate(); + + for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) + (*it).listener->OnResourceCreated(this, (*it).index); +} + +void NzResource::NotifyDestroy() +{ + NazaraLock(m_mutex) + + EnsureResourceListenerUpdate(); + + for (auto it = m_resourceListenersCache.begin(); it != m_resourceListenersCache.end(); ++it) + (*it).listener->OnResourceDestroy(this, (*it).index); +} + +void NzResource::EnsureResourceListenerUpdate() const +{ + // Déjà bloqué par une mutex + if (!m_resourceListenerUpdated) + { + m_resourceListenersCache = m_resourceListeners; + m_resourceListenerUpdated = true; + } +} diff --git a/src/Nazara/Core/ResourceListener.cpp b/src/Nazara/Core/ResourceListener.cpp index 981872bb6..16e2e6b4c 100644 --- a/src/Nazara/Core/ResourceListener.cpp +++ b/src/Nazara/Core/ResourceListener.cpp @@ -1,26 +1,26 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -NzResourceListener::~NzResourceListener() = default; - -void NzResourceListener::OnResourceCreated(const NzResource* resource, int index) -{ - NazaraUnused(resource); - NazaraUnused(index); -} - -void NzResourceListener::OnResourceDestroy(const NzResource* resource, int index) -{ - NazaraUnused(resource); - NazaraUnused(index); -} - -void NzResourceListener::OnResourceReleased(const NzResource* resource, int index) -{ - NazaraUnused(resource); - NazaraUnused(index); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +NzResourceListener::~NzResourceListener() = default; + +void NzResourceListener::OnResourceCreated(const NzResource* resource, int index) +{ + NazaraUnused(resource); + NazaraUnused(index); +} + +void NzResourceListener::OnResourceDestroy(const NzResource* resource, int index) +{ + NazaraUnused(resource); + NazaraUnused(index); +} + +void NzResourceListener::OnResourceReleased(const NzResource* resource, int index) +{ + NazaraUnused(resource); + NazaraUnused(index); +} diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index e9c5b6e83..339e19976 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -1,5163 +1,5163 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -inline unsigned int nzPow2(unsigned int n) -{ - unsigned int x = 1; - - // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux - while(x <= n) - x <<= 1; - - return x; -} -// Cet algorithme est inspiré de la documentation de Qt -inline unsigned int nzGetNewSize(unsigned int newSize) -{ - if (newSize < 20) - return newSize+4; - else - { - if (newSize < (1 << 12)-12) - return nzPow2(newSize << 1)-12; - else - return newSize + (1 << 11); - } -} - -inline char nzToLower(char character) -{ - if (character >= 'A' && character <= 'Z') - return character + ('a' - 'A'); - else - return character; -} - -inline char nzToUpper(char character) -{ - if (character >= 'a' && character <= 'z') - return character + ('A' - 'a'); - else - return character; -} - -inline int nzStrcasecmp(const char* s1, const char* s2) -{ - int ret = 0; - - while (!(ret = static_cast(nzToLower(*s1)) - static_cast(nzToLower(*s2))) && *s2) - ++s1, ++s2; - - return ret != 0 ? (ret > 0 ? 1 : -1) : 0; -} - -inline int nzUnicodecasecmp(const char* s1, const char* s2) -{ - int ret = 0; - utf8::unchecked::iterator it1(s1); - utf8::unchecked::iterator it2(s2); - - while (!(ret = NzUnicode::GetLowercase(*it1) - NzUnicode::GetLowercase(*it2)) && *it2) - ++it1, ++it2; - - return ret != 0 ? (ret > 0 ? 1 : -1) : 0; -} - -NzString::NzString() : -m_sharedString(&emptyString) -{ -} - -NzString::NzString(char character) -{ - if (character == '\0') - m_sharedString = &emptyString; - else - { - m_sharedString = new SharedString; - m_sharedString->capacity = 1; - m_sharedString->size = 1; - m_sharedString->string = new char[2]; - m_sharedString->string[0] = character; - m_sharedString->string[1] = '\0'; - } -} - -NzString::NzString(const char* string) -{ - if (string) - { - unsigned int size = std::strlen(string); - if (size > 0) - { - m_sharedString = new SharedString; - m_sharedString->capacity = size; - m_sharedString->size = size; - m_sharedString->string = new char[size+1]; - std::memcpy(m_sharedString->string, string, size+1); - } - else - m_sharedString = &emptyString; - } - else - m_sharedString = &emptyString; -} - -NzString::NzString(const std::string& string) -{ - if (string.size() > 0) - { - m_sharedString = new SharedString; - m_sharedString->capacity = string.capacity(); - m_sharedString->size = string.size(); - m_sharedString->string = new char[string.capacity()+1]; - std::memcpy(m_sharedString->string, string.c_str(), string.size()+1); - } - else - m_sharedString = &emptyString; -} - -NzString::NzString(const NzString& string) : -m_sharedString(string.m_sharedString) -{ - if (m_sharedString != &emptyString) - { - NazaraMutexLock(m_sharedString->mutex); - m_sharedString->refCount++; - NazaraMutexUnlock(m_sharedString->mutex); - } -} - -NzString::NzString(NzString&& string) noexcept : -m_sharedString(string.m_sharedString) -{ - string.m_sharedString = &emptyString; -} - -NzString::NzString(SharedString* sharedString) : -m_sharedString(sharedString) -{ -} - -NzString::~NzString() -{ - ReleaseString(); -} - -NzString& NzString::Append(char character) -{ - if (character == '\0') - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity == 0) - return operator=(character); - - if (m_sharedString->capacity > m_sharedString->size) - { - EnsureOwnership(); - - m_sharedString->string[m_sharedString->size] = character; - m_sharedString->string[m_sharedString->size+1] = '\0'; - m_sharedString->size++; - } - else - { - unsigned int newSize = m_sharedString->size+1; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - str[m_sharedString->size] = character; - str[newSize] = '\0'; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::Append(const char* string) -{ - if (!string || !string[0]) - return *this; - - unsigned int length = std::strlen(string); - if (length == 0) - return *this; - - if (m_sharedString->capacity >= m_sharedString->size + length) - { - EnsureOwnership(); - - std::memcpy(&m_sharedString->string[m_sharedString->size], string, length+1); - m_sharedString->size += length; - } - else - { - unsigned int newSize = m_sharedString->size + length; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string, length+1); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::Append(const NzString& string) -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) - return operator=(string); - - if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) - { - EnsureOwnership(); - - std::memcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); - m_sharedString->size += string.m_sharedString->size; - } - else - { - unsigned int newSize = m_sharedString->size + string.m_sharedString->size; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -void NzString::Clear(bool keepBuffer) -{ - if (keepBuffer) - { - EnsureOwnership(); - m_sharedString->size = 0; - } - else - ReleaseString(); -} - -bool NzString::Contains(char character, int start, nzUInt32 flags) const -{ - return Find(character, start, flags) != npos; -} - -bool NzString::Contains(const char* string, int start, nzUInt32 flags) const -{ - return Find(string, start, flags) != npos; -} - -bool NzString::Contains(const NzString& string, int start, nzUInt32 flags) const -{ - return Find(string, start, flags) != npos; -} - -unsigned int NzString::Count(char character, int start, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - char character_lower = nzToLower(character); - char character_upper = nzToUpper(character); - do - { - if (*str == character_lower || *str == character_upper) - count++; - } - while (*++str); - } - else - { - while ((str = std::strchr(str, character))) - { - count++; - str++; - } - } - - return count; -} - -unsigned int NzString::Count(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - { - count++; - break; - } - - if (*it == '\0') - return count; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*str) == c) - { - str++; - - const char* ptr = &string[1]; - while (true) - { - if (*ptr == '\0') - { - count++; - break; - } - - if (*str == '\0') - return count; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - while ((str = std::strstr(str, string))) - { - count++; - str++; - } - } - - return count; -} - -unsigned int NzString::Count(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string.m_sharedString->string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - { - count++; - break; - } - - if (*it == '\0') - return count; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string.m_sharedString->string[0]); - do - { - if (nzToLower(*str) == c) - { - str++; - - const char* ptr = &string.m_sharedString->string[1]; - while (true) - { - if (*ptr == '\0') - { - count++; - break; - } - - if (*str == '\0') - return count; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - while ((str = std::strstr(str, string.m_sharedString->string))) - { - count++; - str++; - } - } - - return count; -} - -unsigned int NzString::CountAny(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - do - { - if (nzToLower(*str) == nzToLower(*c)) - { - count++; - break; - } - } - while (*++c); - } - while (*++str); - } - else - { - while ((str = std::strpbrk(str, string))) - { - count++; - str++; - } - } - } - - return count; -} - -unsigned int NzString::CountAny(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - else - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it == *it2) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string.m_sharedString->string; - do - { - if (nzToLower(*str) == nzToLower(*c)) - { - count++; - break; - } - } - while (*++c); - } - while (*++str); - } - else - { - while ((str = std::strpbrk(str, string.m_sharedString->string))) - { - count++; - str++; - } - } - } - - return count; -} - -bool NzString::EndsWith(char character, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - - if (flags & CaseInsensitive) - return nzToLower(m_sharedString->string[m_sharedString->size-1]) == nzToLower(character); - else - return m_sharedString->string[m_sharedString->size-1] == character; // character == '\0' sera toujours faux -} - -bool NzString::EndsWith(const char* string, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return false; - - unsigned int len = std::strlen(string); - if (len > m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; - else - return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; - } - else - return std::strcmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; -} - -bool NzString::EndsWith(const NzString& string, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; - else - return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; - } - else - return std::strcmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; -} - -unsigned int NzString::Find(char character, int start, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - if (flags & CaseInsensitive) - { - char ch = nzToLower(character); - const char* str = m_sharedString->string; - do - { - if (nzToLower(*str) == ch) - return static_cast(str - m_sharedString->string); - } - while (*++str); - - return npos; - } - else - { - char* ch = std::strchr(&m_sharedString->string[pos], character); - if (ch) - return static_cast(ch - m_sharedString->string); - else - return npos; - } -} - -unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - const char* ptrPos = it.base(); - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*it == '\0') - return npos; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*str) == c) - { - char* ptrPos = str; - str++; - - const char* ptr = &string[1]; - while (true) - { - if (*ptr == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*str == '\0') - return npos; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - char* ch = std::strstr(&m_sharedString->string[pos], string); - if (ch) - return static_cast(ch - m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string.m_sharedString->string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - const char* ptrPos = it.base(); - ++it; - - utf8::unchecked::iterator it2(t); - while (true) - { - if (*it2 == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*it == '\0') - return npos; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = nzToLower(string.m_sharedString->string[0]); - do - { - if (nzToLower(*str) == c) - { - char* ptrPos = str; - str++; - - const char* ptr = &string.m_sharedString->string[1]; - while (true) - { - if (*ptr == '\0') - return static_cast(ptrPos - m_sharedString->string); - - if (*str == '\0') - return npos; - - if (nzToLower(*str) != nzToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - char* ch = std::strstr(&m_sharedString->string[pos], string.m_sharedString->string); - if (ch) - return static_cast(ch - m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::FindAny(const char* string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || !string || !string[0]) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (*++str); - } - else - { - str = std::strpbrk(str, string); - if (str) - return str - m_sharedString->string; - } - } - - return npos; -} - -unsigned int NzString::FindAny(const NzString& string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || string.m_sharedString->size == 0) - return npos; - - if (string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - else - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (*++it); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string.m_sharedString->string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (*++str); - } - else - { - str = std::strpbrk(str, string.m_sharedString->string); - if (str) - return str - m_sharedString->string; - } - } - - return npos; -} - -unsigned int NzString::FindLast(char character, int start, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* ptr = &m_sharedString->string[m_sharedString->size-1]; - - if (flags & CaseInsensitive) - { - character = nzToLower(character); - do - { - if (nzToLower(*ptr) == character) - return static_cast(ptr - m_sharedString->string); - } - while (ptr-- != m_sharedString->string); - } - else - { - // strrchr ? - do - { - if (*ptr == character) - return static_cast(ptr - m_sharedString->string); - } - while (ptr-- != m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::FindLast(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] ||m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 1.FindLast#3 (Taille du pattern inconnue) - const char* ptr = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - const char* t = string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - utf8::unchecked::iterator it2(t); - utf8::unchecked::iterator tIt(it); - ++tIt; - - while (true) - { - if (*it2 == '\0') - return it.base() - m_sharedString->string; - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) - break; - - ++it2; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - else - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*ptr) == c) - { - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - return ptr - m_sharedString->string; - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - } - else - { - do - { - if (*ptr == string[0]) - { - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - return ptr - m_sharedString->string; - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - - return npos; -} - -unsigned int NzString::FindLast(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size || string.m_sharedString->size > m_sharedString->size) - return npos; - - const char* ptr = &m_sharedString->string[pos]; - const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - ///Algo 1.FindLast#3 (Itérateur non-adapté) - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - const char* t = string.m_sharedString->string; - char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - utf8::unchecked::iterator it2(t); - utf8::unchecked::iterator tIt(it); - ++tIt; - - while (true) - { - if (*it2 == '\0') - return it.base() - m_sharedString->string; - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) - break; - - ++it2; - ++tIt; - } - } - } - while (it--.base() != limit); - } - else - { - ///Algo 1.FindLast#4 (Taille du pattern connue) - char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); - while (true) - { - if (nzToLower(*ptr) == c) - { - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (nzToLower(*ptr) != nzToLower(*p)) - break; - - if (p == &string.m_sharedString->string[0]) - return ptr-m_sharedString->string; - - if (ptr == m_sharedString->string) - return npos; - } - } - else if (ptr-- <= limit) - break; - } - } - } - else - { - ///Algo 1.FindLast#4 (Taille du pattern connue) - while (true) - { - if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) - { - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (*ptr != *p) - break; - - if (p == &string.m_sharedString->string[0]) - return ptr-m_sharedString->string; - - if (ptr == m_sharedString->string) - return npos; - } - } - else if (ptr-- <= limit) - break; - } - } - - return npos; -} - -unsigned int NzString::FindLastAny(const char* string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || !string || !string[0]) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - else - { - do - { - const char* c = string; - do - { - if (*str == *c) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - } - - return npos; -} - -unsigned int NzString::FindLastAny(const NzString& string, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0 || string.m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size+start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - char32_t character = NzUnicode::GetLowercase(*it); - do - { - if (character == NzUnicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - else - { - do - { - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string; - } - while (*++it2); - } - while (it--.base() != m_sharedString->string); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string.m_sharedString->string; - char character = nzToLower(*str); - do - { - if (character == nzToLower(*c)) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - else - { - do - { - const char* c = string.m_sharedString->string; - do - { - if (*str == *c) - return str - m_sharedString->string; - } - while (*++c); - } - while (str-- != m_sharedString->string); - } - } - - return npos; -} - -unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 2.FindLastWord#1 (Taille du pattern inconnue) - const char* ptr = &m_sharedString->string[pos]; - - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - else - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = utf8::unchecked::next(t); - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - } - else - { - if (flags & CaseInsensitive) - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*ptr) == c) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr-m_sharedString->string; - else - break; - } - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - else - { - do - { - if (*ptr == string[0]) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr-m_sharedString->string; - else - break; - } - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string); - } - } - - return npos; -} - -unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - const char* ptr = &m_sharedString->string[pos]; - const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; - - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (NzUnicode::GetLowercase(*it) == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - else - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = utf8::unchecked::next(t); - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string); - } - } - else - { - ///Algo 2.FindLastWord#2 (Taille du pattern connue) - if (flags & CaseInsensitive) - { - char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); - do - { - if (nzToLower(*ptr) == c) - { - if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) - continue; - - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (nzToLower(*ptr) != nzToLower(*p)) - break; - - if (p == &string.m_sharedString->string[0]) - { - if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) - return ptr-m_sharedString->string; - else - break; - } - - if (ptr == m_sharedString->string) - return npos; - } - } - } - while (ptr-- > limit); - } - else - { - do - { - if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) - { - if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) - continue; - - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (*ptr != *p) - break; - - if (p == &string.m_sharedString->string[0]) - { - if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) - return ptr-m_sharedString->string; - else - break; - } - - if (ptr == m_sharedString->string) - return npos; - } - } - } - while (ptr-- > limit); - } - } - - return npos; -} - -unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 3.FindWord#3 (Taille du pattern inconnue) - const char* ptr = m_sharedString->string; - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - else - { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (*tIt != *p) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - } - else - { - if (flags & CaseInsensitive) - { - char c = nzToLower(string[0]); - do - { - if (nzToLower(*ptr) == c) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr - m_sharedString->string; - else - break; - } - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - else - { - do - { - if (*ptr == string[0]) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr - m_sharedString->string; - else - break; - } - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - } - - return npos; -} - -unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(static_cast(m_sharedString->size + start), 0); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* ptr = m_sharedString->string; - if (flags & HandleUtf8) - { - ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - else - { - const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument - nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string) - { - it--; - if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - while (true) - { - if (*p == '\0') - { - if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) - return it.base() - m_sharedString->string; - else - break; - } - - if (*tIt != *p) - break; - - p++; - tIt++; - } - } - } - while (*++ptr); - } - } - else - { - ///Algo 3.FindWord#2 (Taille du pattern connue) - if (flags & CaseInsensitive) - { - char c = nzToLower(string.m_sharedString->string[0]); - do - { - if (nzToLower(*ptr) == c) - { - if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) - continue; - - const char* p = &string.m_sharedString->string[1]; - const char* tPtr = ptr+1; - while (true) - { - if (*p == '\0') - { - if (*tPtr == '\0' || std::isspace(*tPtr)) - return ptr - m_sharedString->string; - else - break; - } - - if (nzToLower(*tPtr) != nzToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - else - { - while ((ptr = std::strstr(ptr, string.m_sharedString->string))) - { - // Si le mot est bien isolé - if ((ptr == m_sharedString->string || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) - return ptr - m_sharedString->string; - - ptr++; - } - } - } - - return npos; -} - -char* NzString::GetBuffer() -{ - EnsureOwnership(); - - return m_sharedString->string; -} - -unsigned int NzString::GetCapacity() const -{ - return m_sharedString->capacity; -} - -const char* NzString::GetConstBuffer() const -{ - return m_sharedString->string; -} - -unsigned int NzString::GetLength() const -{ - #if NAZARA_CORE_SAFE - try - { - #endif - return utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return 0; - } - #endif -} - -unsigned int NzString::GetSize() const -{ - return m_sharedString->size; -} - -char* NzString::GetUtf8Buffer(unsigned int* size) const -{ - if (m_sharedString->size == 0) - return nullptr; - - char* buffer = new char[m_sharedString->size+1]; - std::memcpy(buffer, m_sharedString->string, m_sharedString->size+1); - - if (size) - *size = m_sharedString->size; - - return buffer; -} - -char16_t* NzString::GetUtf16Buffer(unsigned int* size) const -{ - if (m_sharedString->size == 0) - return nullptr; - - std::vector utf16; - utf16.reserve(m_sharedString->size); - #if NAZARA_CORE_SAFE - try - { - #endif - utf8::utf8to16(m_sharedString->string, &m_sharedString->string[m_sharedString->size], std::back_inserter(utf16)); - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return nullptr; - } - #endif - - unsigned int bufferSize = utf16.size(); - if (bufferSize == 0) - return nullptr; - - char16_t* buffer = new char16_t[bufferSize+1]; - std::memcpy(buffer, &utf16[0], bufferSize*sizeof(char16_t)); - buffer[bufferSize] ='\0'; - - if (size) - *size = bufferSize; - - return buffer; -} - -char32_t* NzString::GetUtf32Buffer(unsigned int* size) const -{ - if (m_sharedString->size == 0) - return nullptr; - - #if NAZARA_CORE_SAFE - try - { - #endif - unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); - if (bufferSize == 0) - return nullptr; - - char32_t* buffer = new char32_t[bufferSize+1]; - utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); - buffer[bufferSize] ='\0'; - - if (size) - *size = bufferSize; - - return buffer; - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return nullptr; - } - #endif -} - -wchar_t* NzString::GetWideBuffer(unsigned int* size) const -{ - static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t size is not supported"); - if (m_sharedString->size == 0) - return nullptr; - - #if NAZARA_CORE_SAFE - try - { - #endif - unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); - if (bufferSize == 0) - return nullptr; - - wchar_t* buffer = new wchar_t[bufferSize+1]; - if (sizeof(wchar_t) == 4) - utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); - else - { - wchar_t* ptr = buffer; - - utf8::unchecked::iterator it(m_sharedString->string); - do - { - char32_t cp = *it; - if (cp <= 0xFFFF && (cp < 0xD800 || cp > 0xDFFF)) // @Laurent Gomila - *ptr++ = static_cast(cp); - else - *ptr++ = L'?'; - } - while (*it++); - } - - if (size) - *size = bufferSize; - - return buffer; - #if NAZARA_CORE_SAFE - } - catch (const utf8::exception& exception) - { - NazaraError("UTF-8 error : " + NzString(exception.what())); - return nullptr; - } - #endif -} - -NzString NzString::GetWord(unsigned int index, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return NzString(); - - NzString temp = Simplified(flags); // Évitons les mauvaises surprises - if (temp.IsEmpty()) - return NzString(); - - unsigned int foundPos = temp.Find(' '); // Simplified nous assure que nous n'avons plus que des espaces comme séparation - unsigned int lastPos = 0; - for (; index > 0; --index) - { - if (foundPos == npos) - return NzString(); - - lastPos = foundPos; - foundPos = temp.Find(' ', foundPos+1); - } - return temp.Substr((lastPos == 0) ? 0 : lastPos+1, (foundPos == npos) ? -1 : static_cast(foundPos-1)); -} - -unsigned int NzString::GetWordPosition(unsigned int index, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return npos; - - unsigned int currentWord = 0; - bool inWord = false; - - const char* ptr = m_sharedString->string; - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - inWord = false; - else - { - if (!inWord) - { - inWord = true; - if (++currentWord > index) - return static_cast(it.base() - m_sharedString->string); - } - } - } - while (*++it); - } - else - { - while (ptr != &m_sharedString->string[m_sharedString->size]) - { - if (!std::isspace(*ptr++)) - { - if (!inWord) - { - inWord = true; - if (++currentWord > index) - return ptr-m_sharedString->string; - } - } - else - inWord = false; - } - } - - return npos; -} - -NzString& NzString::Insert(int pos, char character) -{ - if (character == '\0') - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity == 0) - return operator=(character); - - if (pos < 0) - pos = std::max(static_cast(m_sharedString->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedString->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedString->capacity >= m_sharedString->size+1) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+1], &m_sharedString->string[start], m_sharedString->size); - m_sharedString->string[start] = character; - - m_sharedString->size += 1; - } - else - { - unsigned int newSize = m_sharedString->size+1; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedString->string; - while (ptr != &newString[start]) - *ptr++ = *s++; - - *ptr++ = character; - - std::strcpy(ptr, s); - - ReleaseString(); - - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -NzString& NzString::Insert(int pos, const char* string) -{ - if (!string || !string[0]) - return *this; - - if (pos < 0) - pos = std::max(static_cast(m_sharedString->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedString->size); - - // Si le buffer est déjà suffisamment grand - unsigned int len = std::strlen(string); - if (m_sharedString->capacity >= m_sharedString->size+len) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+len], &m_sharedString->string[start], m_sharedString->size); - std::memcpy(&m_sharedString->string[start], string, len+1); - - m_sharedString->size += len; - } - else - { - unsigned int newSize = m_sharedString->size+len; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedString->string; - - while (ptr != &newString[start]) - *ptr++ = *s++; - - const char* p = string; - while (ptr != &newString[start+len]) - *ptr++ = *p++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -NzString& NzString::Insert(int pos, const NzString& string) -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) - return operator=(string); - - if (pos < 0) - pos = std::max(static_cast(m_sharedString->size + pos), 0); - - unsigned int start = std::min(static_cast(pos), m_sharedString->size); - - // Si le buffer est déjà suffisamment grand - if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+string.m_sharedString->size], &m_sharedString->string[start], m_sharedString->size); - std::memcpy(&m_sharedString->string[start], string.m_sharedString->string, string.m_sharedString->size+1); - - m_sharedString->size += string.m_sharedString->size; - } - else - { - unsigned int newSize = m_sharedString->size+string.m_sharedString->size; - char* newString = new char[newSize+1]; - - char* ptr = newString; - const char* s = m_sharedString->string; - - while (ptr != &newString[start]) - *ptr++ = *s++; - - const char* p = string.m_sharedString->string; - while (ptr != &newString[start+string.m_sharedString->size]) - *ptr++ = *p++; - - std::strcpy(ptr, s); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -bool NzString::IsEmpty() const -{ - return m_sharedString->size == 0; -} - -bool NzString::IsNull() const -{ - return m_sharedString == &emptyString; -} - -bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const -{ - #if NAZARA_CORE_SAFE - if (base < 2 || base > 36) - { - NazaraError("Base must be between 2 and 36"); - return false; - } - #endif - - if (m_sharedString->size == 0) - return false; - - NzString check = Simplified(); - if (check.m_sharedString->size) - return false; - - char* ptr = (check.m_sharedString->string[0] == '-') ? &check.m_sharedString->string[1] : check.m_sharedString->string; - - if (base > 10) - { - if (flags & CaseInsensitive) - { - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || (c > '9' && c < 'A') || (c > 'A'+base-1 && c < 'a') || c > 'a'+base-1)) - return false; - } - while (*++ptr); - } - else - { - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || (c > '9' && c < 'a') || c > 'a'+base-1)) - return false; - } - while (*++ptr); - } - } - else - { - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || c > '0'+base-1)) - return false; - } - while (*++ptr); - } - - return true; -} - -bool NzString::Match(const char* pattern) const -{ - if (m_sharedString->size == 0 || !pattern) - return false; - - // Par Jack Handy - akkhandy@hotmail.com - // From : http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing - const char* str = m_sharedString->string; - while (*str && *pattern != '*') - { - if (*pattern != *str && *pattern != '?') - return false; - - pattern++; - str++; - } - - const char* cp = nullptr; - const char* mp = nullptr; - while (*str) - { - if (*pattern == '*') - { - if (!*++pattern) - return true; - - mp = pattern; - cp = str+1; - } - else if (*pattern == *str || *pattern == '?') - { - pattern++; - str++; - } - else - { - pattern = mp; - str = cp++; - } - } - - while (*pattern == '*') - pattern++; - - return !*pattern; -} - -bool NzString::Match(const NzString& pattern) const -{ - return Match(pattern.m_sharedString->string); -} - -NzString& NzString::Prepend(char character) -{ - return Insert(0, character); -} - -NzString& NzString::Prepend(const char* string) -{ - return Insert(0, string); -} - -NzString& NzString::Prepend(const NzString& string) -{ - return Insert(0, string); -} - -unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start, nzUInt32 flags) -{ - if (oldCharacter == '\0' || oldCharacter == newCharacter) - return 0; - - if (newCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe - return Replace(NzString(oldCharacter), NzString(), start); - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - unsigned int count = 0; - char* ptr = &m_sharedString->string[pos]; - bool found = false; - if (flags & CaseInsensitive) - { - char character_lower = nzToLower(oldCharacter); - char character_upper = nzToUpper(oldCharacter); - do - { - if (*ptr == character_lower || *ptr == character_upper) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = newCharacter; - ++count; - } - } - while (*++ptr); - } - else - { - while ((ptr = std::strchr(ptr, oldCharacter))) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = newCharacter; - ++count; - } - } - - return count; -} - -unsigned int NzString::Replace(const char* oldString, const char* replaceString, int start, nzUInt32 flags) -{ - if (!oldString || !oldString[0]) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - unsigned int oSize = std::strlen(oldString); - if (oSize == 0) - return 0; - - unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; - - unsigned int count = 0; - if (oSize == rSize) - { - bool found = false; - - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide - while ((pos = Find(oldString, pos, flags)) != npos) - { - if (!found) - { - EnsureOwnership(); - found = true; - } - - std::memcpy(&m_sharedString->string[pos], replaceString, oSize); - pos += oSize; - - ++count; - } - } - else ///TODO: Algorithme de remplacement sans changement de buffer (si rSize < oSize) - { - unsigned int newSize = m_sharedString->size + Count(oldString)*(rSize - oSize); - if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 - return 0; - - char* newString = new char[newSize+1]; - - ///Algo 4.Replace#2 - char* ptr = newString; - const char* p = m_sharedString->string; - - while ((pos = Find(oldString, pos, flags)) != npos) - { - const char* r = &m_sharedString->string[pos]; - - std::memcpy(ptr, p, r-p); - ptr += r-p; - std::memcpy(ptr, replaceString, rSize); - ptr += rSize; - p = r+oSize; - pos += oSize; - - count++; - } - - std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; -} - -unsigned int NzString::Replace(const NzString& oldString, const NzString& replaceString, int start, nzUInt32 flags) -{ - if (oldString.m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size || oldString.m_sharedString->size == 0) - return 0; - - unsigned int count = 0; - if (oldString.m_sharedString->size == replaceString.m_sharedString->size) - { - bool found = false; - - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide - while ((pos = Find(oldString, pos, flags)) != npos) - { - if (!found) - { - EnsureOwnership(); - found = true; - } - - std::memcpy(&m_sharedString->string[pos], replaceString.m_sharedString->string, oldString.m_sharedString->size); - pos += oldString.m_sharedString->size; - - ++count; - } - } - else - { - unsigned int newSize = m_sharedString->size + Count(oldString)*(replaceString.m_sharedString->size - oldString.m_sharedString->size); - if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 - return 0; - - char* newString = new char[newSize+1]; - - ///Algo 4.Replace#2 - char* ptr = newString; - const char* p = m_sharedString->string; - - while ((pos = Find(oldString, pos, flags)) != npos) - { - const char* r = &m_sharedString->string[pos]; - - std::memcpy(ptr, p, r-p); - ptr += r-p; - std::memcpy(ptr, replaceString.m_sharedString->string, replaceString.m_sharedString->size); - ptr += replaceString.m_sharedString->size; - p = r+oldString.m_sharedString->size; - pos += oldString.m_sharedString->size; - - count++; - } - - std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; -} - -unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags) -{ - ///FIXME: Ne gère pas l'UTF-8 - if (!oldCharacters || !oldCharacters[0]) - return 0; - - /*if (replaceCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe - return ReplaceAny(NzString(oldCharacters), NzString(), start);*/ - - if (start < 0) - start = std::max(m_sharedString->size + start, 0U); - - unsigned int pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - unsigned int count = 0; - char* ptr = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - do - { - const char* c = oldCharacters; - char character = nzToLower(*ptr); - bool found = false; - do - { - if (character == nzToLower(*c)) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = replaceCharacter; - ++count; - break; - } - } - while (*++c); - } - while (*++ptr); - } - else - { - bool found = false; - while ((ptr = std::strpbrk(ptr, oldCharacters))) - { - if (!found) - { - unsigned int offset = ptr-m_sharedString->string; - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr++ = replaceCharacter; - ++count; - } - } - - return count; -} -/* - unsigned int NzString::ReplaceAny(const char* oldCharacters, const char* replaceString, int start, nzUInt32 flags) - { - if (start < 0) - { - start = m_sharedString->size+start; - if (start < 0) - start = 0; - } - - unsigned int pos = static_cast(start); - unsigned int oSize = (oldCharacters) ? std::strlen(oldCharacters) : 0; - unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; - - if (pos >= m_sharedString->size || m_sharedString->size == 0 || oSize == 0) - return 0; - - unsigned int count = 0; - - if (rSize == 1) // On utilise un algorithme optimisé - { - EnsureOwnership(); - - f or (; pos < m_sharedString->size; ++pos) - { - for (unsigned int i = 0; i < oSize; ++i) - { - if (m_sharedString->string[pos] == oldCharacters[i]) - { - m_sharedString->string[pos] = replaceString[0]; - ++count; - - break; - } - } - } - } - else - { - unsigned int newSize; - { - unsigned int count = CountAny(oldCharacters); - newSize = m_sharedString->size - count + count*rSize; - } - char* newString = new char[newSize+1]; - - unsigned int j = 0; - for (unsigned int i = 0; i < m_sharedString->size; ++i) - { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier - newString[j++] = m_sharedString->string[i]; - else - { - bool found = false; - for (unsigned int l = 0; l < oSize; ++l) - { - if (m_sharedString->string[i] == oldCharacters[l]) - { - for (unsigned int k = 0; k < rSize; ++k) - newString[j++] = replaceString[k]; - - ++count; - found = true; - break; // Simple façon d'éviter la ligne après la boucle - } - } - - if (!found) - newString[j++] = m_sharedString->string[i]; - } - } - newString[newSize] = '\0'; - - ReleaseString(); - - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; - } - - unsigned int NzString::ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start, nzUInt32 flags) - { - if (start < 0) - { - start = m_sharedString->size+start; - if (start < 0) - start = 0; - } - - unsigned int pos = static_cast(start); - - if (pos >= m_sharedString->size || m_sharedString->size == 0 || oldCharacters.m_sharedString->size == 0) - return 0; - - unsigned int count = 0; - - if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé - { - EnsureOwnership(); - - char character = replaceString[0]; - for (; pos < m_sharedString->size; ++pos) - { - for (unsigned int i = 0; i < oldCharacters.m_sharedString->size; ++i) - { - if (m_sharedString->string[pos] == oldCharacters[i]) - { - m_sharedString->string[pos] = character; - ++count; - break; - } - } - } - } - else - { - unsigned int newSize; - { - unsigned int count = CountAny(oldCharacters); - newSize = m_sharedString->size - count + count*replaceString.m_sharedString->size; - } - char* newString = new char[newSize+1]; - - unsigned int j = 0; - for (unsigned int i = 0; i < m_sharedString->size; ++i) - { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier - newString[j++] = m_sharedString->string[i]; - else - { - bool found = false; - for (unsigned int l = 0; l < oldCharacters.m_sharedString->size; ++l) - { - if (m_sharedString->string[i] == oldCharacters[l]) - { - for (unsigned int k = 0; k < replaceString.m_sharedString->size; ++k) - newString[j++] = replaceString[k]; - - ++count; - found = true; - break; // Simple façon d'éviter la ligne après la boucle - } - } - - if (!found) - newString[j++] = m_sharedString->string[i]; - } - } - newString[newSize] = '\0'; - - ReleaseString(); - - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; - } -*/ -void NzString::Reserve(unsigned int bufferSize) -{ - if (m_sharedString->capacity >= bufferSize) - return; - - char* ptr = new char[bufferSize+1]; - if (m_sharedString->size > 0) - std::memcpy(ptr, m_sharedString->string, m_sharedString->size+1); - - unsigned int size = m_sharedString->size; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = size; - m_sharedString->string = ptr; -} - -NzString& NzString::Resize(int size, char character) -{ - if (size == 0) - { - Clear(true); - return *this; - } - - if (size < 0) - size = std::max(static_cast(m_sharedString->size + size), 0); - - unsigned int newSize = static_cast(size); - - if (m_sharedString->capacity >= newSize) - { - EnsureOwnership(); - - // Nous avons déjà la place requise, contentons-nous de remplir le buffer - if (character != '\0' && newSize > m_sharedString->size) - { - char* ptr = &m_sharedString->string[m_sharedString->size]; - char* limit = &m_sharedString->string[newSize]; - while (ptr != limit) - *ptr++ = character; - } - - m_sharedString->size = newSize; - m_sharedString->string[newSize] = '\0'; - } - else // On veut forcément agrandir la chaine - { - char* newString = new char[newSize+1]; - if (m_sharedString->size != 0) - std::memcpy(newString, m_sharedString->string, newSize); - - char* ptr = &newString[m_sharedString->size]; - char* limit = &newString[newSize]; - while (ptr != limit) - *ptr++ = character; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = newSize; - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return *this; -} - -NzString NzString::Resized(int size, char character) const -{ - if (size < 0) - size = m_sharedString->size + size; - - if (size <= 0) - return NzString(); - - unsigned int newSize = static_cast(size); - if (newSize == m_sharedString->size) - return *this; - - char* str = new char[newSize+1]; - if (newSize > m_sharedString->size) - { - std::memcpy(str, m_sharedString->string, m_sharedString->size); - if (character != '\0') - { - char* ptr = &str[m_sharedString->size]; - char* limit = &str[newSize]; - while (ptr != limit) - *ptr++ = character; - } - } - else - std::memcpy(str, m_sharedString->string, newSize); - - str[newSize] = '\0'; - - return NzString(new SharedString(1, newSize, newSize, str)); -} - -NzString& NzString::Reverse() -{ - if (m_sharedString->size != 0) - { - unsigned int i = 0; - unsigned int j = m_sharedString->size-1; - - while (i < j) - std::swap(m_sharedString->string[i++], m_sharedString->string[j--]); - } - - return *this; -} - -NzString NzString::Reversed() const -{ - if (m_sharedString->size == 0) - return NzString(); - - char* str = new char[m_sharedString->size+1]; - - char* ptr = &str[m_sharedString->size-1]; - char* p = m_sharedString->string; - - do - *ptr-- = *p; - while (*(++p)); - - str[m_sharedString->size] = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); -} - -NzString NzString::Simplified(nzUInt32 flags) const -{ - char* str = new char[m_sharedString->size+1]; - char* p = str; - - const char* ptr = m_sharedString->string; - bool inword = false; - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - { - if (inword) - { - *p++ = ' '; - inword = false; - } - } - else - { - p = utf8::append(*it, p); - inword = true; - } - } - while (*++it); - } - else - { - const char* limit = &m_sharedString->string[m_sharedString->size]; - do - { - if (std::isspace(*ptr)) - { - if (inword) - { - *p++ = ' '; - inword = false; - } - } - else - { - *p++ = *ptr; - inword = true; - } - } - while (++ptr != limit); - } - - if (!inword) - p--; - - *p = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, p-str, str)); -} - -NzString& NzString::Simplify(nzUInt32 flags) -{ - return operator=(Simplified(flags)); -} - -unsigned int NzString::Split(std::vector& result, char separation, int start, nzUInt32 flags) const -{ - if (separation == '\0' || m_sharedString->size == 0) - return 0; - - unsigned int lastSep = Find(separation, start, flags); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - while (true) - { - unsigned int sep = Find(separation, lastSep+1, flags); - if (sep == npos) - break; - - if (sep-lastSep > 1) - result.push_back(Substr(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(Substr(lastSep+1)); - - return result.size(); -} - -unsigned int NzString::Split(std::vector& result, const char* separation, int start, nzUInt32 flags) const -{ - unsigned int size = (separation) ? std::strlen(separation) : 0; - if (m_sharedString->size == 0) - return 0; - else if (size == 0) - { - result.reserve(m_sharedString->size); - for (unsigned int i = 0; i < m_sharedString->size; ++i) - result.push_back(NzString(m_sharedString->string[i])); - - return m_sharedString->size; - } - else if (size > m_sharedString->size) - { - result.push_back(*this); - return 1; - } - - unsigned int lastSep = Find(separation, start, flags); - unsigned int oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = Find(separation, lastSep+size, flags)) != npos) - { - if (sep-lastSep > size) - result.push_back(Substr(lastSep+size, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-size) - result.push_back(Substr(lastSep+size)); - - return result.size()-oldSize; -} - -unsigned int NzString::Split(std::vector& result, const NzString& separation, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - else if (separation.m_sharedString->size == 0) - { - result.reserve(m_sharedString->size); - for (unsigned int i = 0; i < m_sharedString->size; ++i) - result.push_back(NzString(m_sharedString->string[i])); - - return m_sharedString->size; - } - else if (separation.m_sharedString->size > m_sharedString->size) - { - result.push_back(*this); - return 1; - } - - unsigned int lastSep = Find(separation, start, flags); - unsigned int oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = Find(separation, lastSep+separation.m_sharedString->size, flags)) != npos) - { - if (sep-lastSep > separation.m_sharedString->size) - result.push_back(Substr(lastSep+separation.m_sharedString->size, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-separation.m_sharedString->size) - result.push_back(Substr(lastSep+separation.m_sharedString->size)); - - return result.size()-oldSize; -} - -unsigned int NzString::SplitAny(std::vector& result, const char* separations, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - - unsigned int oldSize = result.size(); - - unsigned int lastSep = FindAny(separations, start, flags); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = FindAny(separations, lastSep+1, flags)) != npos) - { - if (sep-lastSep > 1) - result.push_back(Substr(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(Substr(lastSep+1)); - - return result.size()-oldSize; -} - -unsigned int NzString::SplitAny(std::vector& result, const NzString& separations, int start, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return 0; - - unsigned int lastSep = FindAny(separations, start, flags); - unsigned int oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(Substr(0, lastSep-1)); - - unsigned int sep; - while ((sep = FindAny(separations, lastSep+1, flags)) != npos) - { - if (sep-lastSep > 1) - result.push_back(Substr(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(Substr(lastSep+1)); - - return result.size()-oldSize; -} - -bool NzString::StartsWith(char character, nzUInt32 flags) const -{ - if (character == '\0' || m_sharedString->size == 0) - return false; - - if (flags & CaseInsensitive) - return nzToLower(m_sharedString->string[0]) == nzToLower(character); - else - return m_sharedString->string[0] == character; -} - -bool NzString::StartsWith(const char* string, nzUInt32 flags) const -{ - if (!string || !string[0] || m_sharedString->size == 0) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(m_sharedString->string); - utf8::unchecked::iterator it2(string); - do - { - if (*it2 == '\0') - return true; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - return false; - - ++it2; - } - while (*it++); - } - else - { - char* ptr = m_sharedString->string; - const char* s = string; - do - { - if (*s == '\0') - return true; - - if (nzToLower(*ptr) != nzToLower(*s)) - return false; - - s++; - } - while (*ptr++); - } - } - else - { - char* ptr = m_sharedString->string; - const char* s = string; - do - { - if (*s == '\0') - return true; - - if (*ptr != *s) - return false; - - s++; - } - while (*ptr++); - } - - return false; -} - -bool NzString::StartsWith(const NzString& string, nzUInt32 flags) const -{ - if (string.m_sharedString->size == 0) - return false; - - if (m_sharedString->size < string.m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(m_sharedString->string); - utf8::unchecked::iterator it2(string.m_sharedString->string); - do - { - if (*it2 == '\0') - return true; - - if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) - return false; - - ++it2; - } - while (*it++); - } - else - { - char* ptr = m_sharedString->string; - const char* s = string.m_sharedString->string; - do - { - if (*s == '\0') - return true; - - if (nzToLower(*ptr) != nzToLower(*s)) - return false; - - s++; - } - while (*ptr++); - } - } - else - return std::memcmp(m_sharedString->string, string.m_sharedString->string, string.m_sharedString->size) == 0; - - return false; -} - -NzString NzString::Substr(int startPos, int endPos) const -{ - if (startPos < 0) - startPos = std::max(m_sharedString->size+startPos, 0U); - - unsigned int start = static_cast(startPos); - - if (endPos < 0) - { - endPos = m_sharedString->size+endPos; - if (endPos < 0) - return NzString(); - } - - unsigned int minEnd = std::min(static_cast(endPos), m_sharedString->size-1); - - if (start > minEnd || start >= m_sharedString->size) - return NzString(); - - unsigned int size = minEnd-start+1; - char* str = new char[size+1]; - std::memcpy(str, &m_sharedString->string[start], size); - str[size] = '\0'; - - return NzString(new SharedString(1, size, size, str)); -} - -NzString NzString::SubstrFrom(char character, int startPos, bool fromLast, bool include, nzUInt32 flags) const -{ - if (character == '\0') - return *this; - - unsigned int pos; - if (fromLast) - pos = FindLast(character, startPos, flags); - else - pos = Find(character, startPos, flags); - - if (pos == 0 and include) - return *this; - else if (pos == npos) - return NzString(); - - return Substr(pos+((include) ? 0 : 1)); -} - -NzString NzString::SubstrFrom(const char* string, int startPos, bool fromLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (fromLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0 && include) - return *this; - else if (pos == npos) - return NzString(); - - return Substr(pos+((include) ? 0 : std::strlen(string))); -} - -NzString NzString::SubstrFrom(const NzString& string, int startPos, bool fromLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (fromLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0 && include) - return *this; - else if (pos == npos) - return NzString(); - - return Substr(pos+((include) ? 0 : string.m_sharedString->size)); -} - -NzString NzString::SubstrTo(char character, int startPos, bool toLast, bool include, nzUInt32 flags) const -{ - if (character == '\0') - return *this; - - unsigned int pos; - if (toLast) - pos = FindLast(character, startPos); - else - pos = Find(character, startPos, flags); - - if (pos == 0) - return (include) ? character : NzString(); - else if (pos == npos) - return *this; - - return Substr(0, pos+((include) ? 1 : 0)-1); -} - -NzString NzString::SubstrTo(const char* string, int startPos, bool toLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (toLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0) - return (include) ? string : NzString(); - else if (pos == npos) - return *this; - - return Substr(0, pos+((include) ? std::strlen(string) : 0)-1); -} - -NzString NzString::SubstrTo(const NzString& string, int startPos, bool toLast, bool include, nzUInt32 flags) const -{ - unsigned int pos; - if (toLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0) - return (include) ? string : NzString(); - else if (pos == npos) - return *this; - - return Substr(0, pos+((include) ? string.m_sharedString->size : 0)-1); -} - -void NzString::Swap(NzString& str) -{ - std::swap(m_sharedString, str.m_sharedString); -} - -bool NzString::ToBool(bool* value, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return false; - - NzString word = GetWord(0); - - if (word[0] == '1') - { - if (value) - *value = true; - } - else if (word[0] == '0') - { - if (value) - *value = false; - } - else - { - if (flags & CaseInsensitive) - word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode - - if (word == "true") - { - if (value) - *value = true; - } - else if (word == "false") - { - if (value) - *value = false; - } - else - return false; - } - - return true; -} - -bool NzString::ToDouble(double* value) const -{ - if (m_sharedString->size == 0) - return false; - - if (value) - *value = std::atof(m_sharedString->string); - - return true; -} - -bool NzString::ToInteger(long long* value, nzUInt8 base) const -{ - if (value) - { - bool ok; - *value = NzStringToNumber(*this, base, &ok); - - return ok; - } - else - return IsNumber(base); -} - -NzString NzString::ToLower(nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - if (flags & HandleUtf8) - { - NzString lower; - lower.Reserve(m_sharedString->size); - utf8::unchecked::iterator it(m_sharedString->string); - do - utf8::append(NzUnicode::GetLowercase(*it), std::back_inserter(lower)); - while (*++it); - - return lower; - } - else - { - char* str = new char[m_sharedString->size+1]; - - char* ptr = m_sharedString->string; - char* s = str; - do - *s++ = nzToLower(*ptr); - while (*++ptr); - - *s = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); - } -} - -NzString NzString::ToUpper(nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - if (flags & HandleUtf8) - { - NzString upper; - upper.Reserve(m_sharedString->size); - utf8::unchecked::iterator it(m_sharedString->string); - do - utf8::append(NzUnicode::GetUppercase(*it), std::back_inserter(upper)); - while (*++it); - - return upper; - } - else - { - char* str = new char[m_sharedString->size+1]; - - char* ptr = m_sharedString->string; - char* s = str; - do - *s++ = nzToUpper(*ptr); - while (*++ptr); - - *s = '\0'; - - return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); - } -} - -NzString& NzString::Trim(nzUInt32 flags) -{ - return operator=(Trimmed(flags)); -} - -NzString& NzString::Trim(char character, nzUInt32 flags) -{ - return operator=(Trimmed(character, flags)); -} - -NzString NzString::Trimmed(nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - unsigned int startPos; - unsigned int endPos; - if (flags & HandleUtf8) - { - if ((flags & TrimOnlyRight) == 0) - { - utf8::unchecked::iterator it(m_sharedString->string); - do - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - break; - } - while (*++it); - - startPos = it.base() - m_sharedString->string; - } - else - startPos = 0; - - if ((flags & TrimOnlyLeft) == 0) - { - utf8::unchecked::iterator it(&m_sharedString->string[m_sharedString->size]); - while ((it--).base() != m_sharedString->string) - { - if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) - break; - } - - endPos = it.base() - m_sharedString->string; - } - else - endPos = m_sharedString->size-1; - } - else - { - startPos = 0; - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (!std::isspace(m_sharedString->string[startPos])) - break; - } - } - - endPos = m_sharedString->size-1; - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (!std::isspace(m_sharedString->string[endPos])) - break; - } - } - } - - return Substr(startPos, endPos); -} - -NzString NzString::Trimmed(char character, nzUInt32 flags) const -{ - if (m_sharedString->size == 0) - return *this; - - unsigned int startPos = 0; - unsigned int endPos = m_sharedString->size-1; - if (flags & CaseInsensitive) - { - char ch = nzToLower(character); - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (nzToLower(m_sharedString->string[startPos]) != ch) - break; - } - } - - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (nzToLower(m_sharedString->string[startPos]) != ch) - break; - } - } - } - else - { - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (m_sharedString->string[startPos] != character) - break; - } - } - - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (m_sharedString->string[startPos] != character) - break; - } - } - } - - return Substr(startPos, endPos); -} - -char* NzString::begin() -{ - return m_sharedString->string; -} - -const char* NzString::begin() const -{ - return m_sharedString->string; -} - -char* NzString::end() -{ - return &m_sharedString->string[m_sharedString->size]; -} - -const char* NzString::end() const -{ - return &m_sharedString->string[m_sharedString->size]; -} - -void NzString::push_front(char c) -{ - operator=(c + *this); -} - -void NzString::push_back(char c) -{ - operator+=(c); -} -/* -char* NzString::rbegin() -{ - return &m_sharedString->string[m_sharedString->size-1]; -} - -const char* NzString::rbegin() const -{ - return &m_sharedString->string[m_sharedString->size-1]; -} - -char* NzString::rend() -{ - return &m_sharedString->string[-1]; -} - -const char* NzString::rend() const -{ - return &m_sharedString->string[-1]; -} -*/ - -NzString::operator std::string() const -{ - return std::string(m_sharedString->string, m_sharedString->size); -} - -char& NzString::operator[](unsigned int pos) -{ - EnsureOwnership(); - - if (pos >= m_sharedString->size) - Resize(pos+1); - - return m_sharedString->string[pos]; -} - -char NzString::operator[](unsigned int pos) const -{ - #if NAZARA_CORE_SAFE - if (pos >= m_sharedString->size) - { - NazaraError("Index out of range (" + Number(pos) + " >= " + Number(m_sharedString->size) + ')'); - return 0; - } - #endif - - return m_sharedString->string[pos]; -} - -NzString& NzString::operator=(char character) -{ - if (character != '\0') - { - if (m_sharedString->capacity >= 1) - EnsureOwnership(); - else - { - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = 1; - m_sharedString->string = new char[2]; - } - - m_sharedString->size = 1; - m_sharedString->string[0] = character; - m_sharedString->string[1] = '\0'; - } - else - ReleaseString(); - - return *this; -} - -NzString& NzString::operator=(const char* string) -{ - if (string && string[0] != '\0') - { - unsigned int size = std::strlen(string); - if (m_sharedString->capacity >= size) - EnsureOwnership(); - else - { - ReleaseString(); - - m_sharedString = new SharedString; - m_sharedString->capacity = size; - m_sharedString->string = new char[size+1]; - } - - m_sharedString->size = size; - std::memcpy(m_sharedString->string, string, size+1); - } - else - ReleaseString(); - - return *this; -} - -NzString& NzString::operator=(const std::string& string) -{ - if (string.size() > 0) - { - if (m_sharedString->capacity >= string.size()) - EnsureOwnership(); - else - { - ReleaseString(); - - m_sharedString = new SharedString; - m_sharedString->capacity = string.size(); - m_sharedString->string = new char[string.size()+1]; - } - - m_sharedString->size = string.size(); - std::memcpy(m_sharedString->string, string.c_str(), string.size()+1); - } - else - ReleaseString(); - - return *this; -} - -NzString& NzString::operator=(const NzString& string) -{ - ReleaseString(); - - m_sharedString = string.m_sharedString; - if (m_sharedString != &emptyString) - { - NazaraMutexLock(m_sharedString->mutex); - m_sharedString->refCount++; - NazaraMutexUnlock(m_sharedString->mutex); - } - - return *this; -} - -NzString& NzString::operator=(NzString&& string) noexcept -{ - std::swap(m_sharedString, string.m_sharedString); - - return *this; -} - -NzString NzString::operator+(char character) const -{ - if (character == '\0') - return *this; - - unsigned int totalSize = m_sharedString->size+1; - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - - str[m_sharedString->size] = character; - str[totalSize] = '\0'; - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString NzString::operator+(const char* string) const -{ - if (!string || !string[0]) - return *this; - - if (m_sharedString->size == 0) - return string; - - unsigned int length = std::strlen(string); - if (length == 0) - return *this; - - unsigned int totalSize = m_sharedString->size + length; - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string, length+1); - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString NzString::operator+(const std::string& string) const -{ - if (string.empty()) - return *this; - - if (m_sharedString->size == 0) - return string; - - unsigned int totalSize = m_sharedString->size + string.size(); - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string.c_str(), string.size()+1); - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString NzString::operator+(const NzString& string) const -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0) - return string; - - unsigned int totalSize = m_sharedString->size + string.m_sharedString->size; - char* str = new char[totalSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); - - return NzString(new SharedString(1, totalSize, totalSize, str)); -} - -NzString& NzString::operator+=(char character) -{ - if (character == '\0') - return *this; - - if (m_sharedString->size == 0) - return operator=(character); - - if (m_sharedString->capacity > m_sharedString->size) - { - EnsureOwnership(); - - m_sharedString->string[m_sharedString->size] = character; - m_sharedString->string[m_sharedString->size+1] = '\0'; - m_sharedString->size++; - } - else - { - unsigned int newSize = m_sharedString->size+1; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - str[m_sharedString->size] = character; - str[newSize] = '\0'; - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::operator+=(const char* string) -{ - if (!string || !string[0]) - return *this; - - if (m_sharedString->size == 0) - return operator=(string); - - unsigned int size = std::strlen(string); - if (size == 0) - return *this; - - if (m_sharedString->capacity >= m_sharedString->size + size) - { - EnsureOwnership(); - - std::memcpy(&m_sharedString->string[m_sharedString->size], string, size+1); - m_sharedString->size += size; - } - else - { - unsigned int newSize = m_sharedString->size + size; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string, size+1); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::operator+=(const std::string& string) -{ - if (string.empty()) - return *this; - - if (m_sharedString->size == 0) - return operator=(string); - - if (m_sharedString->capacity >= m_sharedString->size + string.size()) - { - EnsureOwnership(); - - std::memcpy(&m_sharedString->string[m_sharedString->size], string.c_str(), string.size()+1); - m_sharedString->size += string.size(); - } - else - { - unsigned int newSize = m_sharedString->size + string.size(); - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string.c_str(), string.size()+1); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -NzString& NzString::operator+=(const NzString& string) -{ - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0) - return operator=(string); - - if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) - { - EnsureOwnership(); - - std::memcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); - m_sharedString->size += string.m_sharedString->size; - } - else - { - unsigned int newSize = m_sharedString->size + string.m_sharedString->size; - unsigned int bufferSize = nzGetNewSize(newSize); - - char* str = new char[bufferSize+1]; - std::memcpy(str, m_sharedString->string, m_sharedString->size); - std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); - - ReleaseString(); - m_sharedString = new SharedString; - m_sharedString->capacity = bufferSize; - m_sharedString->size = newSize; - m_sharedString->string = str; - } - - return *this; -} - -bool NzString::operator==(char character) const -{ - if (m_sharedString->size == 0) - return character == '\0'; - - if (m_sharedString->size > 1) - return false; - - return m_sharedString->string[0] == character; -} - -bool NzString::operator==(const char* string) const -{ - if (m_sharedString->size == 0) - return !string || !string[0]; - - if (!string || !string[0]) - return false; - - return std::strcmp(m_sharedString->string, string) == 0; -} - -bool NzString::operator==(const std::string& string) const -{ - if (m_sharedString->size == 0 || string.empty()) - return m_sharedString->size == string.size(); - - if (m_sharedString->size != string.size()) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) == 0; -} - -bool NzString::operator!=(char character) const -{ - if (m_sharedString->size == 0) - return character != '\0'; - - if (character == '\0' || m_sharedString->size != 1) - return true; - - if (m_sharedString->size != 1) - return true; - - return m_sharedString->string[0] != character; -} - -bool NzString::operator!=(const char* string) const -{ - if (m_sharedString->size == 0) - return string && string[0]; - - if (!string || !string[0]) - return true; - - return std::strcmp(m_sharedString->string, string) != 0; -} - -bool NzString::operator!=(const std::string& string) const -{ - if (m_sharedString->size == 0 || string.empty()) - return m_sharedString->size == string.size(); - - if (m_sharedString->size != string.size()) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) != 0; -} - -bool NzString::operator<(char character) const -{ - if (character == '\0') - return false; - - if (m_sharedString->size == 0) - return true; - - return m_sharedString->string[0] < character; -} - -bool NzString::operator<(const char* string) const -{ - if (!string || !string[0]) - return false; - - if (m_sharedString->size == 0) - return true; - - return std::strcmp(m_sharedString->string, string) < 0; -} - -bool NzString::operator<(const std::string& string) const -{ - if (string.empty()) - return false; - - if (m_sharedString->size == 0) - return true; - - return std::strcmp(m_sharedString->string, string.c_str()) < 0; -} - -bool NzString::operator<=(char character) const -{ - if (m_sharedString->size == 0) - return true; - - if (character == '\0') - return false; - - return m_sharedString->string[0] < character || (m_sharedString->string[0] == character && m_sharedString->size == 1); -} - -bool NzString::operator<=(const char* string) const -{ - if (m_sharedString->size == 0) - return true; - - if (!string || !string[0]) - return false; - - return std::strcmp(m_sharedString->string, string) <= 0; -} - -bool NzString::operator<=(const std::string& string) const -{ - if (m_sharedString->size == 0) - return true; - - if (string.empty()) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) <= 0; -} - -bool NzString::operator>(char character) const -{ - if (m_sharedString->size == 0) - return false; - - if (character == '\0') - return true; - - return m_sharedString->string[0] > character; -} - -bool NzString::operator>(const char* string) const -{ - if (m_sharedString->size == 0) - return false; - - if (!string || !string[0]) - return true; - - return std::strcmp(m_sharedString->string, string) > 0; -} - -bool NzString::operator>(const std::string& string) const -{ - if (m_sharedString->size == 0) - return false; - - if (string.empty()) - return true; - - return std::strcmp(m_sharedString->string, string.c_str()) > 0; -} - -bool NzString::operator>=(char character) const -{ - if (character == '\0') - return true; - - if (m_sharedString->size == 0) - return false; - - return m_sharedString->string[0] > character || (m_sharedString->string[0] == character && m_sharedString->size == 1); -} - -bool NzString::operator>=(const char* string) const -{ - if (!string || !string[0]) - return true; - - if (m_sharedString->size == 0) - return false; - - return std::strcmp(m_sharedString->string, string) >= 0; -} - -bool NzString::operator>=(const std::string& string) const -{ - if (string.empty()) - return true; - - if (m_sharedString->size == 0) - return false; - - return std::strcmp(m_sharedString->string, string.c_str()) >= 0; -} - -NzString NzString::Boolean(bool boolean) -{ - unsigned int size = (boolean) ? 4 : 5; - char* str = new char[size+1]; - std::strcpy(str, (boolean) ? "true" : "false"); - - return NzString(new SharedString(1, size, size, str)); -} - -int NzString::Compare(const NzString& first, const NzString& second) -{ - if (first.m_sharedString->size == 0) - return (second.m_sharedString->size == 0) ? 0 : -1; - - if (second.m_sharedString->size == 0) - return 1; - - return std::strcmp(first.m_sharedString->string, second.m_sharedString->string); -} - -NzString NzString::Number(float number) -{ - std::ostringstream oss; - oss.precision(NAZARA_CORE_REAL_PRECISION); - oss << number; - - return NzString(oss.str()); -} - -NzString NzString::Number(double number) -{ - std::ostringstream oss; - oss.precision(NAZARA_CORE_REAL_PRECISION); - oss << number; - - return NzString(oss.str()); -} - -NzString NzString::Number(long double number) -{ - std::ostringstream oss; - oss.precision(NAZARA_CORE_REAL_PRECISION); - oss << number; - - return NzString(oss.str()); -} - -NzString NzString::Number(signed char number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned char number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(short number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned short number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(int number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned int number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(long long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Number(unsigned long long number, nzUInt8 radix) -{ - return NzNumberToString(number, radix); -} - -NzString NzString::Pointer(const void* ptr) -{ - unsigned int size = sizeof(ptr)*2+2; - char* str = new char[size+1]; - std::sprintf(str, "0x%p", ptr); - - return NzString(new SharedString(1, size, size, str)); -} - -NzString NzString::Unicode(char32_t character) -{ - if (character == '\0') - return NzString(); - - unsigned int count = 0; - if (character < 0x80) - count = 1; - else if (character < 0x800) - count = 2; - else if (character < 0x10000) - count = 3; - else - count = 4; - - char* str = new char[count+1]; - utf8::append(character, str); - str[count] = '\0'; - - return NzString(new SharedString(1, count, count, str)); -} - -NzString NzString::Unicode(const char* u8String) -{ - return NzString(u8String); -} - -NzString NzString::Unicode(const char16_t* u16String) -{ - if (!u16String || !u16String[0]) - return NzString(); - - const char16_t* ptr = u16String; - unsigned int count = 0; - do - count++; - while (*++ptr); - - count *= 2; // On s'assure d'avoir la place suffisante - - char* str = new char[count+1]; - char* r = utf8::utf16to8(u16String, ptr, str); - *r = '\0'; - - return NzString(new SharedString(1, count, r-str, str)); -} - -NzString NzString::Unicode(const char32_t* u32String) -{ - if (!u32String || !u32String[0]) - return NzString(); - - const char32_t* ptr = u32String; - unsigned int count = 0; - do - { - char32_t cp = *ptr; - if (cp < 0x80) - count += 1; - else if (cp < 0x800) - count += 2; - else if (cp < 0x10000) - count += 3; - else - count += 4; - } - while (*++ptr); - - char* str = new char[count+1]; - char* r = utf8::utf32to8(u32String, ptr, str); - *r = '\0'; - - return NzString(new SharedString(1, count, count, str)); -} - -NzString NzString::Unicode(const wchar_t* wString) -{ - if (!wString || !wString[0]) - return NzString(); - - const wchar_t* ptr = wString; - unsigned int count = 0; - do - { - char32_t cp = *ptr; - if (cp < 0x80) - count += 1; - else if (cp < 0x800) - count += 2; - else if (cp < 0x10000) - count += 3; - else - count += 4; - } - while (*++ptr); - - char* str = new char[count+1]; - char* r = utf8::utf32to8(wString, ptr, str); - *r = '\0'; - - return NzString(new SharedString(1, count, count, str)); -} - -std::istream& operator>>(std::istream& is, NzString& str) -{ - str.Clear(); - - char c; - do - { - is.get(c); - if (c == '\0') - break; - else if (std::isspace(c)) - { - if (str.IsNull()) - continue; - else - break; - } - else - str += c; - } - while (true); - - return is; -} - -std::ostream& operator<<(std::ostream& os, const NzString& str) -{ - if (str.IsEmpty()) - return os; - - return operator<<(os, str.m_sharedString->string); -} - -NzString operator+(char character, const NzString& string) -{ - if (character == '\0') - return string; - - if (string.IsEmpty()) - return character; - - unsigned int totalSize = string.m_sharedString->size+1; - char* str = new char[totalSize+1]; - str[0] = character; - std::memcpy(str, string.m_sharedString->string, string.m_sharedString->size+1); - - return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); -} - -NzString operator+(const char* string, const NzString& nstring) -{ - if (!string || !string[0]) - return nstring; - - if (nstring.IsEmpty()) - return string; - - unsigned int size = std::strlen(string); - unsigned int totalSize = size + nstring.m_sharedString->size; - char* str = new char[totalSize+1]; - std::memcpy(str, string, size); - std::memcpy(&str[size], nstring.m_sharedString->string, nstring.m_sharedString->size+1); - - return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); -} - -NzString operator+(const std::string& string, const NzString& nstring) -{ - if (string.empty()) - return nstring; - - if (nstring.m_sharedString->size == 0) - return string; - - unsigned int totalSize = string.size() + nstring.m_sharedString->size; - char* str = new char[totalSize+1]; - std::memcpy(str, string.c_str(), string.size()); - std::memcpy(&str[string.size()], nstring.m_sharedString->string, nstring.m_sharedString->size+1); - - return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); -} - -bool operator==(const NzString& first, const NzString& second) -{ - if (first.m_sharedString->size == 0 || second.m_sharedString->size == 0) - return first.m_sharedString->size == second.m_sharedString->size; - - if (first.m_sharedString->size != second.m_sharedString->size) - return false; - - return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) == 0; -} - -bool operator!=(const NzString& first, const NzString& second) -{ - return !operator==(first, second); -} - -bool operator<(const NzString& first, const NzString& second) -{ - if (second.m_sharedString->size == 0) - return false; - - if (first.m_sharedString->size == 0) - return true; - - return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) < 0; -} - -bool operator<=(const NzString& first, const NzString& second) -{ - return !operator<(second, first); -} - -bool operator>(const NzString& first, const NzString& second) -{ - return second < first; -} - -bool operator>=(const NzString& first, const NzString& second) -{ - return !operator<(first, second); -} - -bool operator==(char character, const NzString& nstring) -{ - return nstring == character; -} - -bool operator==(const char* string, const NzString& nstring) -{ - return nstring == string; -} - -bool operator==(const std::string& string, const NzString& nstring) -{ - return nstring == string; -} - -bool operator!=(char character, const NzString& nstring) -{ - return !operator==(character, nstring); -} - -bool operator!=(const char* string, const NzString& nstring) -{ - return !operator==(string, nstring); -} - -bool operator!=(const std::string& string, const NzString& nstring) -{ - return !operator==(string, nstring); -} - -bool operator<(char character, const NzString& nstring) -{ - return nstring > character; -} - -bool operator<(const char* string, const NzString& nstring) -{ - return nstring > string; -} - -bool operator<(const std::string& string, const NzString& nstring) -{ - return nstring > string; -} - -bool operator<=(char character, const NzString& nstring) -{ - return !operator<(nstring, character); -} - -bool operator<=(const char* string, const NzString& nstring) -{ - return !operator<(nstring, string); -} - -bool operator<=(const std::string& string, const NzString& nstring) -{ - return !operator<(nstring, string); -} - -bool operator>(char character, const NzString& nstring) -{ - return nstring < character; -} - -bool operator>(const char* string, const NzString& nstring) -{ - return nstring < string; -} - -bool operator>(const std::string& string, const NzString& nstring) -{ - return nstring < string; -} - -bool operator>=(char character, const NzString& nstring) -{ - return !operator<(character, nstring); -} - -bool operator>=(const char* string, const NzString& nstring) -{ - return !operator<(string, nstring); -} - -bool operator>=(const std::string& string, const NzString& nstring) -{ - return !operator<(string, nstring); -} - -void NzString::EnsureOwnership() -{ - if (m_sharedString == &emptyString) - return; - - NazaraLock(m_sharedString->mutex); - if (m_sharedString->refCount > 1) - { - m_sharedString->refCount--; - - char* string = new char[m_sharedString->capacity+1]; - std::memcpy(string, m_sharedString->string, m_sharedString->size+1); - - m_sharedString = new SharedString(1, m_sharedString->capacity, m_sharedString->size, string); - } -} - -bool NzString::FillHash(NzHashImpl* hazh) const -{ - hazh->Append(reinterpret_cast(m_sharedString->string), m_sharedString->size); - - return true; -} - -void NzString::ReleaseString() -{ - if (m_sharedString == &emptyString) - return; - - NazaraMutexLock(m_sharedString->mutex); - bool freeSharedString = (--m_sharedString->refCount == 0); - NazaraMutexUnlock(m_sharedString->mutex); - - if (freeSharedString) - { - delete[] m_sharedString->string; - delete m_sharedString; - } - - m_sharedString = &emptyString; -} - -NzString::SharedString NzString::emptyString(0, 0, 0, nullptr); -const unsigned int NzString::npos(std::numeric_limits::max()); - -namespace std -{ - istream& getline(istream& is, NzString& str) - { - str.Clear(); - - char c; - do - { - is.get(c); - if (c != '\n' && c != '\0') - str += c; - else - break; - } - while (true); - - return is; - } - - istream& getline(istream& is, NzString& str, char delim) - { - str.Clear(); - - char c; - do - { - is.get(c); - if (c != delim && c != '\0') - str += c; - else - break; - } - while (true); - - return is; - } - - void swap(NzString& lhs, NzString& rhs) - { - lhs.Swap(rhs); - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +inline unsigned int nzPow2(unsigned int n) +{ + unsigned int x = 1; + + // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux + while(x <= n) + x <<= 1; + + return x; +} +// Cet algorithme est inspiré de la documentation de Qt +inline unsigned int nzGetNewSize(unsigned int newSize) +{ + if (newSize < 20) + return newSize+4; + else + { + if (newSize < (1 << 12)-12) + return nzPow2(newSize << 1)-12; + else + return newSize + (1 << 11); + } +} + +inline char nzToLower(char character) +{ + if (character >= 'A' && character <= 'Z') + return character + ('a' - 'A'); + else + return character; +} + +inline char nzToUpper(char character) +{ + if (character >= 'a' && character <= 'z') + return character + ('A' - 'a'); + else + return character; +} + +inline int nzStrcasecmp(const char* s1, const char* s2) +{ + int ret = 0; + + while (!(ret = static_cast(nzToLower(*s1)) - static_cast(nzToLower(*s2))) && *s2) + ++s1, ++s2; + + return ret != 0 ? (ret > 0 ? 1 : -1) : 0; +} + +inline int nzUnicodecasecmp(const char* s1, const char* s2) +{ + int ret = 0; + utf8::unchecked::iterator it1(s1); + utf8::unchecked::iterator it2(s2); + + while (!(ret = NzUnicode::GetLowercase(*it1) - NzUnicode::GetLowercase(*it2)) && *it2) + ++it1, ++it2; + + return ret != 0 ? (ret > 0 ? 1 : -1) : 0; +} + +NzString::NzString() : +m_sharedString(&emptyString) +{ +} + +NzString::NzString(char character) +{ + if (character == '\0') + m_sharedString = &emptyString; + else + { + m_sharedString = new SharedString; + m_sharedString->capacity = 1; + m_sharedString->size = 1; + m_sharedString->string = new char[2]; + m_sharedString->string[0] = character; + m_sharedString->string[1] = '\0'; + } +} + +NzString::NzString(const char* string) +{ + if (string) + { + unsigned int size = std::strlen(string); + if (size > 0) + { + m_sharedString = new SharedString; + m_sharedString->capacity = size; + m_sharedString->size = size; + m_sharedString->string = new char[size+1]; + std::memcpy(m_sharedString->string, string, size+1); + } + else + m_sharedString = &emptyString; + } + else + m_sharedString = &emptyString; +} + +NzString::NzString(const std::string& string) +{ + if (string.size() > 0) + { + m_sharedString = new SharedString; + m_sharedString->capacity = string.capacity(); + m_sharedString->size = string.size(); + m_sharedString->string = new char[string.capacity()+1]; + std::memcpy(m_sharedString->string, string.c_str(), string.size()+1); + } + else + m_sharedString = &emptyString; +} + +NzString::NzString(const NzString& string) : +m_sharedString(string.m_sharedString) +{ + if (m_sharedString != &emptyString) + { + NazaraMutexLock(m_sharedString->mutex); + m_sharedString->refCount++; + NazaraMutexUnlock(m_sharedString->mutex); + } +} + +NzString::NzString(NzString&& string) noexcept : +m_sharedString(string.m_sharedString) +{ + string.m_sharedString = &emptyString; +} + +NzString::NzString(SharedString* sharedString) : +m_sharedString(sharedString) +{ +} + +NzString::~NzString() +{ + ReleaseString(); +} + +NzString& NzString::Append(char character) +{ + if (character == '\0') + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity == 0) + return operator=(character); + + if (m_sharedString->capacity > m_sharedString->size) + { + EnsureOwnership(); + + m_sharedString->string[m_sharedString->size] = character; + m_sharedString->string[m_sharedString->size+1] = '\0'; + m_sharedString->size++; + } + else + { + unsigned int newSize = m_sharedString->size+1; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + str[m_sharedString->size] = character; + str[newSize] = '\0'; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::Append(const char* string) +{ + if (!string || !string[0]) + return *this; + + unsigned int length = std::strlen(string); + if (length == 0) + return *this; + + if (m_sharedString->capacity >= m_sharedString->size + length) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string, length+1); + m_sharedString->size += length; + } + else + { + unsigned int newSize = m_sharedString->size + length; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string, length+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::Append(const NzString& string) +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) + return operator=(string); + + if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + m_sharedString->size += string.m_sharedString->size; + } + else + { + unsigned int newSize = m_sharedString->size + string.m_sharedString->size; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +void NzString::Clear(bool keepBuffer) +{ + if (keepBuffer) + { + EnsureOwnership(); + m_sharedString->size = 0; + } + else + ReleaseString(); +} + +bool NzString::Contains(char character, int start, nzUInt32 flags) const +{ + return Find(character, start, flags) != npos; +} + +bool NzString::Contains(const char* string, int start, nzUInt32 flags) const +{ + return Find(string, start, flags) != npos; +} + +bool NzString::Contains(const NzString& string, int start, nzUInt32 flags) const +{ + return Find(string, start, flags) != npos; +} + +unsigned int NzString::Count(char character, int start, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & CaseInsensitive) + { + char character_lower = nzToLower(character); + char character_upper = nzToUpper(character); + do + { + if (*str == character_lower || *str == character_upper) + count++; + } + while (*++str); + } + else + { + while ((str = std::strchr(str, character))) + { + count++; + str++; + } + } + + return count; +} + +unsigned int NzString::Count(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + { + count++; + break; + } + + if (*it == '\0') + return count; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*str) == c) + { + str++; + + const char* ptr = &string[1]; + while (true) + { + if (*ptr == '\0') + { + count++; + break; + } + + if (*str == '\0') + return count; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + while ((str = std::strstr(str, string))) + { + count++; + str++; + } + } + + return count; +} + +unsigned int NzString::Count(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string.m_sharedString->string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + { + count++; + break; + } + + if (*it == '\0') + return count; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string.m_sharedString->string[0]); + do + { + if (nzToLower(*str) == c) + { + str++; + + const char* ptr = &string.m_sharedString->string[1]; + while (true) + { + if (*ptr == '\0') + { + count++; + break; + } + + if (*str == '\0') + return count; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + while ((str = std::strstr(str, string.m_sharedString->string))) + { + count++; + str++; + } + } + + return count; +} + +unsigned int NzString::CountAny(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + else + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (*it == *it2) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string; + do + { + if (nzToLower(*str) == nzToLower(*c)) + { + count++; + break; + } + } + while (*++c); + } + while (*++str); + } + else + { + while ((str = std::strpbrk(str, string))) + { + count++; + str++; + } + } + } + + return count; +} + +unsigned int NzString::CountAny(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + char* str = &m_sharedString->string[pos]; + unsigned int count = 0; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (NzUnicode::GetLowercase(*it) == NzUnicode::GetLowercase(*it2)) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + else + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it == *it2) + { + count++; + break; + } + } + while (*++it2); + } + while (*++str); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string.m_sharedString->string; + do + { + if (nzToLower(*str) == nzToLower(*c)) + { + count++; + break; + } + } + while (*++c); + } + while (*++str); + } + else + { + while ((str = std::strpbrk(str, string.m_sharedString->string))) + { + count++; + str++; + } + } + } + + return count; +} + +bool NzString::EndsWith(char character, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + + if (flags & CaseInsensitive) + return nzToLower(m_sharedString->string[m_sharedString->size-1]) == nzToLower(character); + else + return m_sharedString->string[m_sharedString->size-1] == character; // character == '\0' sera toujours faux +} + +bool NzString::EndsWith(const char* string, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return false; + + unsigned int len = std::strlen(string); + if (len > m_sharedString->size) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; + else + return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; + } + else + return std::strcmp(&m_sharedString->string[m_sharedString->size - len], string) == 0; +} + +bool NzString::EndsWith(const NzString& string, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + return nzUnicodecasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; + else + return nzStrcasecmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; + } + else + return std::strcmp(&m_sharedString->string[m_sharedString->size - string.m_sharedString->size], string.m_sharedString->string) == 0; +} + +unsigned int NzString::Find(char character, int start, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + if (flags & CaseInsensitive) + { + char ch = nzToLower(character); + const char* str = m_sharedString->string; + do + { + if (nzToLower(*str) == ch) + return static_cast(str - m_sharedString->string); + } + while (*++str); + + return npos; + } + else + { + char* ch = std::strchr(&m_sharedString->string[pos], character); + if (ch) + return static_cast(ch - m_sharedString->string); + else + return npos; + } +} + +unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + const char* ptrPos = it.base(); + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*it == '\0') + return npos; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*str) == c) + { + char* ptrPos = str; + str++; + + const char* ptr = &string[1]; + while (true) + { + if (*ptr == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*str == '\0') + return npos; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + char* ch = std::strstr(&m_sharedString->string[pos], string); + if (ch) + return static_cast(ch - m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + const char* t = string.m_sharedString->string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + const char* ptrPos = it.base(); + ++it; + + utf8::unchecked::iterator it2(t); + while (true) + { + if (*it2 == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*it == '\0') + return npos; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + break; + + ++it; + ++it2; + } + } + } + while (*++it); + } + else + { + char c = nzToLower(string.m_sharedString->string[0]); + do + { + if (nzToLower(*str) == c) + { + char* ptrPos = str; + str++; + + const char* ptr = &string.m_sharedString->string[1]; + while (true) + { + if (*ptr == '\0') + return static_cast(ptrPos - m_sharedString->string); + + if (*str == '\0') + return npos; + + if (nzToLower(*str) != nzToLower(*ptr)) + break; + + ptr++; + str++; + } + } + } + while (*++str); + } + } + else + { + char* ch = std::strstr(&m_sharedString->string[pos], string.m_sharedString->string); + if (ch) + return static_cast(ch - m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::FindAny(const char* string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || !string || !string[0]) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + else + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (*++str); + } + else + { + str = std::strpbrk(str, string); + if (str) + return str - m_sharedString->string; + } + } + + return npos; +} + +unsigned int NzString::FindAny(const NzString& string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || string.m_sharedString->size == 0) + return npos; + + if (string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + else + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (*++it); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string.m_sharedString->string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (*++str); + } + else + { + str = std::strpbrk(str, string.m_sharedString->string); + if (str) + return str - m_sharedString->string; + } + } + + return npos; +} + +unsigned int NzString::FindLast(char character, int start, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* ptr = &m_sharedString->string[m_sharedString->size-1]; + + if (flags & CaseInsensitive) + { + character = nzToLower(character); + do + { + if (nzToLower(*ptr) == character) + return static_cast(ptr - m_sharedString->string); + } + while (ptr-- != m_sharedString->string); + } + else + { + // strrchr ? + do + { + if (*ptr == character) + return static_cast(ptr - m_sharedString->string); + } + while (ptr-- != m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::FindLast(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] ||m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + ///Algo 1.FindLast#3 (Taille du pattern inconnue) + const char* ptr = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + const char* t = string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + utf8::unchecked::iterator it2(t); + utf8::unchecked::iterator tIt(it); + ++tIt; + + while (true) + { + if (*it2 == '\0') + return it.base() - m_sharedString->string; + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) + break; + + ++it2; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + else + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*ptr) == c) + { + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + return ptr - m_sharedString->string; + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + } + else + { + do + { + if (*ptr == string[0]) + { + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + return ptr - m_sharedString->string; + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (*tPtr != *p) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + + return npos; +} + +unsigned int NzString::FindLast(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size || string.m_sharedString->size > m_sharedString->size) + return npos; + + const char* ptr = &m_sharedString->string[pos]; + const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + ///Algo 1.FindLast#3 (Itérateur non-adapté) + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + const char* t = string.m_sharedString->string; + char32_t c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + utf8::unchecked::iterator it2(t); + utf8::unchecked::iterator tIt(it); + ++tIt; + + while (true) + { + if (*it2 == '\0') + return it.base() - m_sharedString->string; + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*it2)) + break; + + ++it2; + ++tIt; + } + } + } + while (it--.base() != limit); + } + else + { + ///Algo 1.FindLast#4 (Taille du pattern connue) + char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); + while (true) + { + if (nzToLower(*ptr) == c) + { + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (nzToLower(*ptr) != nzToLower(*p)) + break; + + if (p == &string.m_sharedString->string[0]) + return ptr-m_sharedString->string; + + if (ptr == m_sharedString->string) + return npos; + } + } + else if (ptr-- <= limit) + break; + } + } + } + else + { + ///Algo 1.FindLast#4 (Taille du pattern connue) + while (true) + { + if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) + { + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (*ptr != *p) + break; + + if (p == &string.m_sharedString->string[0]) + return ptr-m_sharedString->string; + + if (ptr == m_sharedString->string) + return npos; + } + } + else if (ptr-- <= limit) + break; + } + } + + return npos; +} + +unsigned int NzString::FindLastAny(const char* string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || !string || !string[0]) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + else + { + do + { + utf8::unchecked::iterator it2(string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + else + { + do + { + const char* c = string; + do + { + if (*str == *c) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + } + + return npos; +} + +unsigned int NzString::FindLastAny(const NzString& string, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0 || string.m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(m_sharedString->size+start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* str = &m_sharedString->string[pos]; + if (flags & HandleUtf8) + { + while (utf8::internal::is_trail(*str)) + str++; + + utf8::unchecked::iterator it(str); + + if (flags & CaseInsensitive) + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + char32_t character = NzUnicode::GetLowercase(*it); + do + { + if (character == NzUnicode::GetLowercase(*it2)) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + else + { + do + { + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it == *it2) + return it.base() - m_sharedString->string; + } + while (*++it2); + } + while (it--.base() != m_sharedString->string); + } + } + else + { + if (flags & CaseInsensitive) + { + do + { + const char* c = string.m_sharedString->string; + char character = nzToLower(*str); + do + { + if (character == nzToLower(*c)) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + else + { + do + { + const char* c = string.m_sharedString->string; + do + { + if (*str == *c) + return str - m_sharedString->string; + } + while (*++c); + } + while (str-- != m_sharedString->string); + } + } + + return npos; +} + +unsigned int NzString::FindLastWord(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + ///Algo 2.FindLastWord#1 (Taille du pattern inconnue) + const char* ptr = &m_sharedString->string[pos]; + + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + else + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = utf8::unchecked::next(t); + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (*tIt != *p) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + } + else + { + if (flags & CaseInsensitive) + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*ptr) == c) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr-m_sharedString->string; + else + break; + } + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + else + { + do + { + if (*ptr == string[0]) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr-m_sharedString->string; + else + break; + } + + if (tPtr > &m_sharedString->string[pos]) + break; + + if (*tPtr != *p) + break; + + p++; + tPtr++; + } + } + } + while (ptr-- != m_sharedString->string); + } + } + + return npos; +} + +unsigned int NzString::FindLastWord(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + const char* ptr = &m_sharedString->string[pos]; + const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; + + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + do + { + if (NzUnicode::GetLowercase(*it) == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + else + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = utf8::unchecked::next(t); + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*tIt) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (tIt.base() > &m_sharedString->string[pos]) + break; + + if (*tIt != *p) + break; + + ++p; + ++tIt; + } + } + } + while (it--.base() != m_sharedString->string); + } + } + else + { + ///Algo 2.FindLastWord#2 (Taille du pattern connue) + if (flags & CaseInsensitive) + { + char c = nzToLower(string.m_sharedString->string[string.m_sharedString->size-1]); + do + { + if (nzToLower(*ptr) == c) + { + if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) + continue; + + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (nzToLower(*ptr) != nzToLower(*p)) + break; + + if (p == &string.m_sharedString->string[0]) + { + if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) + return ptr-m_sharedString->string; + else + break; + } + + if (ptr == m_sharedString->string) + return npos; + } + } + } + while (ptr-- > limit); + } + else + { + do + { + if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) + { + if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) + continue; + + const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; + for (; p >= &string.m_sharedString->string[0]; --p, --ptr) + { + if (*ptr != *p) + break; + + if (p == &string.m_sharedString->string[0]) + { + if (ptr == m_sharedString->string || std::isspace(*(ptr-1))) + return ptr-m_sharedString->string; + else + break; + } + + if (ptr == m_sharedString->string) + return npos; + } + } + } + while (ptr-- > limit); + } + } + + return npos; +} + +unsigned int NzString::FindWord(const char* string, int start, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + ///Algo 3.FindWord#3 (Taille du pattern inconnue) + const char* ptr = m_sharedString->string; + if (flags & HandleUtf8) + { + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + else + { + const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (*tIt != *p) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + } + else + { + if (flags & CaseInsensitive) + { + char c = nzToLower(string[0]); + do + { + if (nzToLower(*ptr) == c) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr - m_sharedString->string; + else + break; + } + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (*++ptr); + } + else + { + do + { + if (*ptr == string[0]) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr - m_sharedString->string; + else + break; + } + + if (*tPtr != *p) + break; + + p++; + tPtr++; + } + } + } + while (*++ptr); + } + } + + return npos; +} + +unsigned int NzString::FindWord(const NzString& string, int start, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) + return npos; + + if (start < 0) + start = std::max(static_cast(m_sharedString->size + start), 0); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + char* ptr = m_sharedString->string; + if (flags & HandleUtf8) + { + ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) + if (utf8::internal::is_trail(*ptr)) + utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + + utf8::unchecked::iterator it(ptr); + + if (flags & CaseInsensitive) + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (NzUnicode::GetLowercase(*tIt) != NzUnicode::GetLowercase(*p)) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + else + { + const char* t = string.m_sharedString->string; // utf8(::unchecked)::next affecte l'itérateur en argument + nzUInt32 c = NzUnicode::GetLowercase(utf8::unchecked::next(t)); + + do + { + if (*it == c) + { + if (it.base() != m_sharedString->string) + { + it--; + if (!(NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator)) + continue; + } + + utf8::unchecked::iterator p(t); + utf8::unchecked::iterator tIt = it; + ++tIt; + + while (true) + { + if (*p == '\0') + { + if (*tIt == '\0' || NzUnicode::GetCategory(*it++) & NzUnicode::Category_Separator) + return it.base() - m_sharedString->string; + else + break; + } + + if (*tIt != *p) + break; + + p++; + tIt++; + } + } + } + while (*++ptr); + } + } + else + { + ///Algo 3.FindWord#2 (Taille du pattern connue) + if (flags & CaseInsensitive) + { + char c = nzToLower(string.m_sharedString->string[0]); + do + { + if (nzToLower(*ptr) == c) + { + if (ptr != m_sharedString->string && !std::isspace(*(ptr-1))) + continue; + + const char* p = &string.m_sharedString->string[1]; + const char* tPtr = ptr+1; + while (true) + { + if (*p == '\0') + { + if (*tPtr == '\0' || std::isspace(*tPtr)) + return ptr - m_sharedString->string; + else + break; + } + + if (nzToLower(*tPtr) != nzToLower(*p)) + break; + + p++; + tPtr++; + } + } + } + while (*++ptr); + } + else + { + while ((ptr = std::strstr(ptr, string.m_sharedString->string))) + { + // Si le mot est bien isolé + if ((ptr == m_sharedString->string || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) + return ptr - m_sharedString->string; + + ptr++; + } + } + } + + return npos; +} + +char* NzString::GetBuffer() +{ + EnsureOwnership(); + + return m_sharedString->string; +} + +unsigned int NzString::GetCapacity() const +{ + return m_sharedString->capacity; +} + +const char* NzString::GetConstBuffer() const +{ + return m_sharedString->string; +} + +unsigned int NzString::GetLength() const +{ + #if NAZARA_CORE_SAFE + try + { + #endif + return utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return 0; + } + #endif +} + +unsigned int NzString::GetSize() const +{ + return m_sharedString->size; +} + +char* NzString::GetUtf8Buffer(unsigned int* size) const +{ + if (m_sharedString->size == 0) + return nullptr; + + char* buffer = new char[m_sharedString->size+1]; + std::memcpy(buffer, m_sharedString->string, m_sharedString->size+1); + + if (size) + *size = m_sharedString->size; + + return buffer; +} + +char16_t* NzString::GetUtf16Buffer(unsigned int* size) const +{ + if (m_sharedString->size == 0) + return nullptr; + + std::vector utf16; + utf16.reserve(m_sharedString->size); + #if NAZARA_CORE_SAFE + try + { + #endif + utf8::utf8to16(m_sharedString->string, &m_sharedString->string[m_sharedString->size], std::back_inserter(utf16)); + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return nullptr; + } + #endif + + unsigned int bufferSize = utf16.size(); + if (bufferSize == 0) + return nullptr; + + char16_t* buffer = new char16_t[bufferSize+1]; + std::memcpy(buffer, &utf16[0], bufferSize*sizeof(char16_t)); + buffer[bufferSize] ='\0'; + + if (size) + *size = bufferSize; + + return buffer; +} + +char32_t* NzString::GetUtf32Buffer(unsigned int* size) const +{ + if (m_sharedString->size == 0) + return nullptr; + + #if NAZARA_CORE_SAFE + try + { + #endif + unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); + if (bufferSize == 0) + return nullptr; + + char32_t* buffer = new char32_t[bufferSize+1]; + utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); + buffer[bufferSize] ='\0'; + + if (size) + *size = bufferSize; + + return buffer; + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return nullptr; + } + #endif +} + +wchar_t* NzString::GetWideBuffer(unsigned int* size) const +{ + static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t size is not supported"); + if (m_sharedString->size == 0) + return nullptr; + + #if NAZARA_CORE_SAFE + try + { + #endif + unsigned int bufferSize = utf8::distance(m_sharedString->string, &m_sharedString->string[m_sharedString->size]); + if (bufferSize == 0) + return nullptr; + + wchar_t* buffer = new wchar_t[bufferSize+1]; + if (sizeof(wchar_t) == 4) + utf8::utf8to32(m_sharedString->string, &m_sharedString->string[m_sharedString->size], buffer); + else + { + wchar_t* ptr = buffer; + + utf8::unchecked::iterator it(m_sharedString->string); + do + { + char32_t cp = *it; + if (cp <= 0xFFFF && (cp < 0xD800 || cp > 0xDFFF)) // @Laurent Gomila + *ptr++ = static_cast(cp); + else + *ptr++ = L'?'; + } + while (*it++); + } + + if (size) + *size = bufferSize; + + return buffer; + #if NAZARA_CORE_SAFE + } + catch (const utf8::exception& exception) + { + NazaraError("UTF-8 error : " + NzString(exception.what())); + return nullptr; + } + #endif +} + +NzString NzString::GetWord(unsigned int index, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return NzString(); + + NzString temp = Simplified(flags); // Évitons les mauvaises surprises + if (temp.IsEmpty()) + return NzString(); + + unsigned int foundPos = temp.Find(' '); // Simplified nous assure que nous n'avons plus que des espaces comme séparation + unsigned int lastPos = 0; + for (; index > 0; --index) + { + if (foundPos == npos) + return NzString(); + + lastPos = foundPos; + foundPos = temp.Find(' ', foundPos+1); + } + return temp.Substr((lastPos == 0) ? 0 : lastPos+1, (foundPos == npos) ? -1 : static_cast(foundPos-1)); +} + +unsigned int NzString::GetWordPosition(unsigned int index, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return npos; + + unsigned int currentWord = 0; + bool inWord = false; + + const char* ptr = m_sharedString->string; + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(ptr); + do + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + inWord = false; + else + { + if (!inWord) + { + inWord = true; + if (++currentWord > index) + return static_cast(it.base() - m_sharedString->string); + } + } + } + while (*++it); + } + else + { + while (ptr != &m_sharedString->string[m_sharedString->size]) + { + if (!std::isspace(*ptr++)) + { + if (!inWord) + { + inWord = true; + if (++currentWord > index) + return ptr-m_sharedString->string; + } + } + else + inWord = false; + } + } + + return npos; +} + +NzString& NzString::Insert(int pos, char character) +{ + if (character == '\0') + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity == 0) + return operator=(character); + + if (pos < 0) + pos = std::max(static_cast(m_sharedString->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedString->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedString->capacity >= m_sharedString->size+1) + { + EnsureOwnership(); + + std::memmove(&m_sharedString->string[start+1], &m_sharedString->string[start], m_sharedString->size); + m_sharedString->string[start] = character; + + m_sharedString->size += 1; + } + else + { + unsigned int newSize = m_sharedString->size+1; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedString->string; + while (ptr != &newString[start]) + *ptr++ = *s++; + + *ptr++ = character; + + std::strcpy(ptr, s); + + ReleaseString(); + + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +NzString& NzString::Insert(int pos, const char* string) +{ + if (!string || !string[0]) + return *this; + + if (pos < 0) + pos = std::max(static_cast(m_sharedString->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedString->size); + + // Si le buffer est déjà suffisamment grand + unsigned int len = std::strlen(string); + if (m_sharedString->capacity >= m_sharedString->size+len) + { + EnsureOwnership(); + + std::memmove(&m_sharedString->string[start+len], &m_sharedString->string[start], m_sharedString->size); + std::memcpy(&m_sharedString->string[start], string, len+1); + + m_sharedString->size += len; + } + else + { + unsigned int newSize = m_sharedString->size+len; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedString->string; + + while (ptr != &newString[start]) + *ptr++ = *s++; + + const char* p = string; + while (ptr != &newString[start+len]) + *ptr++ = *p++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +NzString& NzString::Insert(int pos, const NzString& string) +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size) + return operator=(string); + + if (pos < 0) + pos = std::max(static_cast(m_sharedString->size + pos), 0); + + unsigned int start = std::min(static_cast(pos), m_sharedString->size); + + // Si le buffer est déjà suffisamment grand + if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) + { + EnsureOwnership(); + + std::memmove(&m_sharedString->string[start+string.m_sharedString->size], &m_sharedString->string[start], m_sharedString->size); + std::memcpy(&m_sharedString->string[start], string.m_sharedString->string, string.m_sharedString->size+1); + + m_sharedString->size += string.m_sharedString->size; + } + else + { + unsigned int newSize = m_sharedString->size+string.m_sharedString->size; + char* newString = new char[newSize+1]; + + char* ptr = newString; + const char* s = m_sharedString->string; + + while (ptr != &newString[start]) + *ptr++ = *s++; + + const char* p = string.m_sharedString->string; + while (ptr != &newString[start+string.m_sharedString->size]) + *ptr++ = *p++; + + std::strcpy(ptr, s); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +bool NzString::IsEmpty() const +{ + return m_sharedString->size == 0; +} + +bool NzString::IsNull() const +{ + return m_sharedString == &emptyString; +} + +bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const +{ + #if NAZARA_CORE_SAFE + if (base < 2 || base > 36) + { + NazaraError("Base must be between 2 and 36"); + return false; + } + #endif + + if (m_sharedString->size == 0) + return false; + + NzString check = Simplified(); + if (check.m_sharedString->size) + return false; + + char* ptr = (check.m_sharedString->string[0] == '-') ? &check.m_sharedString->string[1] : check.m_sharedString->string; + + if (base > 10) + { + if (flags & CaseInsensitive) + { + do + { + char c = *ptr; + if (c != ' ' && (c < '0' || (c > '9' && c < 'A') || (c > 'A'+base-1 && c < 'a') || c > 'a'+base-1)) + return false; + } + while (*++ptr); + } + else + { + do + { + char c = *ptr; + if (c != ' ' && (c < '0' || (c > '9' && c < 'a') || c > 'a'+base-1)) + return false; + } + while (*++ptr); + } + } + else + { + do + { + char c = *ptr; + if (c != ' ' && (c < '0' || c > '0'+base-1)) + return false; + } + while (*++ptr); + } + + return true; +} + +bool NzString::Match(const char* pattern) const +{ + if (m_sharedString->size == 0 || !pattern) + return false; + + // Par Jack Handy - akkhandy@hotmail.com + // From : http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing + const char* str = m_sharedString->string; + while (*str && *pattern != '*') + { + if (*pattern != *str && *pattern != '?') + return false; + + pattern++; + str++; + } + + const char* cp = nullptr; + const char* mp = nullptr; + while (*str) + { + if (*pattern == '*') + { + if (!*++pattern) + return true; + + mp = pattern; + cp = str+1; + } + else if (*pattern == *str || *pattern == '?') + { + pattern++; + str++; + } + else + { + pattern = mp; + str = cp++; + } + } + + while (*pattern == '*') + pattern++; + + return !*pattern; +} + +bool NzString::Match(const NzString& pattern) const +{ + return Match(pattern.m_sharedString->string); +} + +NzString& NzString::Prepend(char character) +{ + return Insert(0, character); +} + +NzString& NzString::Prepend(const char* string) +{ + return Insert(0, string); +} + +NzString& NzString::Prepend(const NzString& string) +{ + return Insert(0, string); +} + +unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start, nzUInt32 flags) +{ + if (oldCharacter == '\0' || oldCharacter == newCharacter) + return 0; + + if (newCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe + return Replace(NzString(oldCharacter), NzString(), start); + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + unsigned int count = 0; + char* ptr = &m_sharedString->string[pos]; + bool found = false; + if (flags & CaseInsensitive) + { + char character_lower = nzToLower(oldCharacter); + char character_upper = nzToUpper(oldCharacter); + do + { + if (*ptr == character_lower || *ptr == character_upper) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr = newCharacter; + ++count; + } + } + while (*++ptr); + } + else + { + while ((ptr = std::strchr(ptr, oldCharacter))) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr = newCharacter; + ++count; + } + } + + return count; +} + +unsigned int NzString::Replace(const char* oldString, const char* replaceString, int start, nzUInt32 flags) +{ + if (!oldString || !oldString[0]) + return 0; + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return 0; + + unsigned int oSize = std::strlen(oldString); + if (oSize == 0) + return 0; + + unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; + + unsigned int count = 0; + if (oSize == rSize) + { + bool found = false; + + // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + while ((pos = Find(oldString, pos, flags)) != npos) + { + if (!found) + { + EnsureOwnership(); + found = true; + } + + std::memcpy(&m_sharedString->string[pos], replaceString, oSize); + pos += oSize; + + ++count; + } + } + else ///TODO: Algorithme de remplacement sans changement de buffer (si rSize < oSize) + { + unsigned int newSize = m_sharedString->size + Count(oldString)*(rSize - oSize); + if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 + return 0; + + char* newString = new char[newSize+1]; + + ///Algo 4.Replace#2 + char* ptr = newString; + const char* p = m_sharedString->string; + + while ((pos = Find(oldString, pos, flags)) != npos) + { + const char* r = &m_sharedString->string[pos]; + + std::memcpy(ptr, p, r-p); + ptr += r-p; + std::memcpy(ptr, replaceString, rSize); + ptr += rSize; + p = r+oSize; + pos += oSize; + + count++; + } + + std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; +} + +unsigned int NzString::Replace(const NzString& oldString, const NzString& replaceString, int start, nzUInt32 flags) +{ + if (oldString.m_sharedString->size == 0) + return 0; + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size || oldString.m_sharedString->size == 0) + return 0; + + unsigned int count = 0; + if (oldString.m_sharedString->size == replaceString.m_sharedString->size) + { + bool found = false; + + // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + while ((pos = Find(oldString, pos, flags)) != npos) + { + if (!found) + { + EnsureOwnership(); + found = true; + } + + std::memcpy(&m_sharedString->string[pos], replaceString.m_sharedString->string, oldString.m_sharedString->size); + pos += oldString.m_sharedString->size; + + ++count; + } + } + else + { + unsigned int newSize = m_sharedString->size + Count(oldString)*(replaceString.m_sharedString->size - oldString.m_sharedString->size); + if (newSize == m_sharedString->size) // Alors c'est que Count(oldString) == 0 + return 0; + + char* newString = new char[newSize+1]; + + ///Algo 4.Replace#2 + char* ptr = newString; + const char* p = m_sharedString->string; + + while ((pos = Find(oldString, pos, flags)) != npos) + { + const char* r = &m_sharedString->string[pos]; + + std::memcpy(ptr, p, r-p); + ptr += r-p; + std::memcpy(ptr, replaceString.m_sharedString->string, replaceString.m_sharedString->size); + ptr += replaceString.m_sharedString->size; + p = r+oldString.m_sharedString->size; + pos += oldString.m_sharedString->size; + + count++; + } + + std::strcpy(ptr, p); // Ajoute le caractère de fin par la même occasion + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; +} + +unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags) +{ + ///FIXME: Ne gère pas l'UTF-8 + if (!oldCharacters || !oldCharacters[0]) + return 0; + + /*if (replaceCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe + return ReplaceAny(NzString(oldCharacters), NzString(), start);*/ + + if (start < 0) + start = std::max(m_sharedString->size + start, 0U); + + unsigned int pos = static_cast(start); + if (pos >= m_sharedString->size) + return npos; + + unsigned int count = 0; + char* ptr = &m_sharedString->string[pos]; + if (flags & CaseInsensitive) + { + do + { + const char* c = oldCharacters; + char character = nzToLower(*ptr); + bool found = false; + do + { + if (character == nzToLower(*c)) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr = replaceCharacter; + ++count; + break; + } + } + while (*++c); + } + while (*++ptr); + } + else + { + bool found = false; + while ((ptr = std::strpbrk(ptr, oldCharacters))) + { + if (!found) + { + unsigned int offset = ptr-m_sharedString->string; + + EnsureOwnership(); + + ptr = &m_sharedString->string[offset]; + found = true; + } + + *ptr++ = replaceCharacter; + ++count; + } + } + + return count; +} +/* + unsigned int NzString::ReplaceAny(const char* oldCharacters, const char* replaceString, int start, nzUInt32 flags) + { + if (start < 0) + { + start = m_sharedString->size+start; + if (start < 0) + start = 0; + } + + unsigned int pos = static_cast(start); + unsigned int oSize = (oldCharacters) ? std::strlen(oldCharacters) : 0; + unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; + + if (pos >= m_sharedString->size || m_sharedString->size == 0 || oSize == 0) + return 0; + + unsigned int count = 0; + + if (rSize == 1) // On utilise un algorithme optimisé + { + EnsureOwnership(); + + f or (; pos < m_sharedString->size; ++pos) + { + for (unsigned int i = 0; i < oSize; ++i) + { + if (m_sharedString->string[pos] == oldCharacters[i]) + { + m_sharedString->string[pos] = replaceString[0]; + ++count; + + break; + } + } + } + } + else + { + unsigned int newSize; + { + unsigned int count = CountAny(oldCharacters); + newSize = m_sharedString->size - count + count*rSize; + } + char* newString = new char[newSize+1]; + + unsigned int j = 0; + for (unsigned int i = 0; i < m_sharedString->size; ++i) + { + if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier + newString[j++] = m_sharedString->string[i]; + else + { + bool found = false; + for (unsigned int l = 0; l < oSize; ++l) + { + if (m_sharedString->string[i] == oldCharacters[l]) + { + for (unsigned int k = 0; k < rSize; ++k) + newString[j++] = replaceString[k]; + + ++count; + found = true; + break; // Simple façon d'éviter la ligne après la boucle + } + } + + if (!found) + newString[j++] = m_sharedString->string[i]; + } + } + newString[newSize] = '\0'; + + ReleaseString(); + + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; + } + + unsigned int NzString::ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start, nzUInt32 flags) + { + if (start < 0) + { + start = m_sharedString->size+start; + if (start < 0) + start = 0; + } + + unsigned int pos = static_cast(start); + + if (pos >= m_sharedString->size || m_sharedString->size == 0 || oldCharacters.m_sharedString->size == 0) + return 0; + + unsigned int count = 0; + + if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé + { + EnsureOwnership(); + + char character = replaceString[0]; + for (; pos < m_sharedString->size; ++pos) + { + for (unsigned int i = 0; i < oldCharacters.m_sharedString->size; ++i) + { + if (m_sharedString->string[pos] == oldCharacters[i]) + { + m_sharedString->string[pos] = character; + ++count; + break; + } + } + } + } + else + { + unsigned int newSize; + { + unsigned int count = CountAny(oldCharacters); + newSize = m_sharedString->size - count + count*replaceString.m_sharedString->size; + } + char* newString = new char[newSize+1]; + + unsigned int j = 0; + for (unsigned int i = 0; i < m_sharedString->size; ++i) + { + if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier + newString[j++] = m_sharedString->string[i]; + else + { + bool found = false; + for (unsigned int l = 0; l < oldCharacters.m_sharedString->size; ++l) + { + if (m_sharedString->string[i] == oldCharacters[l]) + { + for (unsigned int k = 0; k < replaceString.m_sharedString->size; ++k) + newString[j++] = replaceString[k]; + + ++count; + found = true; + break; // Simple façon d'éviter la ligne après la boucle + } + } + + if (!found) + newString[j++] = m_sharedString->string[i]; + } + } + newString[newSize] = '\0'; + + ReleaseString(); + + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return count; + } +*/ +void NzString::Reserve(unsigned int bufferSize) +{ + if (m_sharedString->capacity >= bufferSize) + return; + + char* ptr = new char[bufferSize+1]; + if (m_sharedString->size > 0) + std::memcpy(ptr, m_sharedString->string, m_sharedString->size+1); + + unsigned int size = m_sharedString->size; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = size; + m_sharedString->string = ptr; +} + +NzString& NzString::Resize(int size, char character) +{ + if (size == 0) + { + Clear(true); + return *this; + } + + if (size < 0) + size = std::max(static_cast(m_sharedString->size + size), 0); + + unsigned int newSize = static_cast(size); + + if (m_sharedString->capacity >= newSize) + { + EnsureOwnership(); + + // Nous avons déjà la place requise, contentons-nous de remplir le buffer + if (character != '\0' && newSize > m_sharedString->size) + { + char* ptr = &m_sharedString->string[m_sharedString->size]; + char* limit = &m_sharedString->string[newSize]; + while (ptr != limit) + *ptr++ = character; + } + + m_sharedString->size = newSize; + m_sharedString->string[newSize] = '\0'; + } + else // On veut forcément agrandir la chaine + { + char* newString = new char[newSize+1]; + if (m_sharedString->size != 0) + std::memcpy(newString, m_sharedString->string, newSize); + + char* ptr = &newString[m_sharedString->size]; + char* limit = &newString[newSize]; + while (ptr != limit) + *ptr++ = character; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = newSize; + m_sharedString->size = newSize; + m_sharedString->string = newString; + } + + return *this; +} + +NzString NzString::Resized(int size, char character) const +{ + if (size < 0) + size = m_sharedString->size + size; + + if (size <= 0) + return NzString(); + + unsigned int newSize = static_cast(size); + if (newSize == m_sharedString->size) + return *this; + + char* str = new char[newSize+1]; + if (newSize > m_sharedString->size) + { + std::memcpy(str, m_sharedString->string, m_sharedString->size); + if (character != '\0') + { + char* ptr = &str[m_sharedString->size]; + char* limit = &str[newSize]; + while (ptr != limit) + *ptr++ = character; + } + } + else + std::memcpy(str, m_sharedString->string, newSize); + + str[newSize] = '\0'; + + return NzString(new SharedString(1, newSize, newSize, str)); +} + +NzString& NzString::Reverse() +{ + if (m_sharedString->size != 0) + { + unsigned int i = 0; + unsigned int j = m_sharedString->size-1; + + while (i < j) + std::swap(m_sharedString->string[i++], m_sharedString->string[j--]); + } + + return *this; +} + +NzString NzString::Reversed() const +{ + if (m_sharedString->size == 0) + return NzString(); + + char* str = new char[m_sharedString->size+1]; + + char* ptr = &str[m_sharedString->size-1]; + char* p = m_sharedString->string; + + do + *ptr-- = *p; + while (*(++p)); + + str[m_sharedString->size] = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); +} + +NzString NzString::Simplified(nzUInt32 flags) const +{ + char* str = new char[m_sharedString->size+1]; + char* p = str; + + const char* ptr = m_sharedString->string; + bool inword = false; + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(ptr); + do + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + { + if (inword) + { + *p++ = ' '; + inword = false; + } + } + else + { + p = utf8::append(*it, p); + inword = true; + } + } + while (*++it); + } + else + { + const char* limit = &m_sharedString->string[m_sharedString->size]; + do + { + if (std::isspace(*ptr)) + { + if (inword) + { + *p++ = ' '; + inword = false; + } + } + else + { + *p++ = *ptr; + inword = true; + } + } + while (++ptr != limit); + } + + if (!inword) + p--; + + *p = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, p-str, str)); +} + +NzString& NzString::Simplify(nzUInt32 flags) +{ + return operator=(Simplified(flags)); +} + +unsigned int NzString::Split(std::vector& result, char separation, int start, nzUInt32 flags) const +{ + if (separation == '\0' || m_sharedString->size == 0) + return 0; + + unsigned int lastSep = Find(separation, start, flags); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + while (true) + { + unsigned int sep = Find(separation, lastSep+1, flags); + if (sep == npos) + break; + + if (sep-lastSep > 1) + result.push_back(Substr(lastSep+1, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-1) + result.push_back(Substr(lastSep+1)); + + return result.size(); +} + +unsigned int NzString::Split(std::vector& result, const char* separation, int start, nzUInt32 flags) const +{ + unsigned int size = (separation) ? std::strlen(separation) : 0; + if (m_sharedString->size == 0) + return 0; + else if (size == 0) + { + result.reserve(m_sharedString->size); + for (unsigned int i = 0; i < m_sharedString->size; ++i) + result.push_back(NzString(m_sharedString->string[i])); + + return m_sharedString->size; + } + else if (size > m_sharedString->size) + { + result.push_back(*this); + return 1; + } + + unsigned int lastSep = Find(separation, start, flags); + unsigned int oldSize = result.size(); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = Find(separation, lastSep+size, flags)) != npos) + { + if (sep-lastSep > size) + result.push_back(Substr(lastSep+size, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-size) + result.push_back(Substr(lastSep+size)); + + return result.size()-oldSize; +} + +unsigned int NzString::Split(std::vector& result, const NzString& separation, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + else if (separation.m_sharedString->size == 0) + { + result.reserve(m_sharedString->size); + for (unsigned int i = 0; i < m_sharedString->size; ++i) + result.push_back(NzString(m_sharedString->string[i])); + + return m_sharedString->size; + } + else if (separation.m_sharedString->size > m_sharedString->size) + { + result.push_back(*this); + return 1; + } + + unsigned int lastSep = Find(separation, start, flags); + unsigned int oldSize = result.size(); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = Find(separation, lastSep+separation.m_sharedString->size, flags)) != npos) + { + if (sep-lastSep > separation.m_sharedString->size) + result.push_back(Substr(lastSep+separation.m_sharedString->size, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-separation.m_sharedString->size) + result.push_back(Substr(lastSep+separation.m_sharedString->size)); + + return result.size()-oldSize; +} + +unsigned int NzString::SplitAny(std::vector& result, const char* separations, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + + unsigned int oldSize = result.size(); + + unsigned int lastSep = FindAny(separations, start, flags); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = FindAny(separations, lastSep+1, flags)) != npos) + { + if (sep-lastSep > 1) + result.push_back(Substr(lastSep+1, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-1) + result.push_back(Substr(lastSep+1)); + + return result.size()-oldSize; +} + +unsigned int NzString::SplitAny(std::vector& result, const NzString& separations, int start, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return 0; + + unsigned int lastSep = FindAny(separations, start, flags); + unsigned int oldSize = result.size(); + if (lastSep == npos) + { + result.push_back(*this); + return 1; + } + else if (lastSep != 0) + result.push_back(Substr(0, lastSep-1)); + + unsigned int sep; + while ((sep = FindAny(separations, lastSep+1, flags)) != npos) + { + if (sep-lastSep > 1) + result.push_back(Substr(lastSep+1, sep-1)); + + lastSep = sep; + } + + if (lastSep != m_sharedString->size-1) + result.push_back(Substr(lastSep+1)); + + return result.size()-oldSize; +} + +bool NzString::StartsWith(char character, nzUInt32 flags) const +{ + if (character == '\0' || m_sharedString->size == 0) + return false; + + if (flags & CaseInsensitive) + return nzToLower(m_sharedString->string[0]) == nzToLower(character); + else + return m_sharedString->string[0] == character; +} + +bool NzString::StartsWith(const char* string, nzUInt32 flags) const +{ + if (!string || !string[0] || m_sharedString->size == 0) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(m_sharedString->string); + utf8::unchecked::iterator it2(string); + do + { + if (*it2 == '\0') + return true; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + return false; + + ++it2; + } + while (*it++); + } + else + { + char* ptr = m_sharedString->string; + const char* s = string; + do + { + if (*s == '\0') + return true; + + if (nzToLower(*ptr) != nzToLower(*s)) + return false; + + s++; + } + while (*ptr++); + } + } + else + { + char* ptr = m_sharedString->string; + const char* s = string; + do + { + if (*s == '\0') + return true; + + if (*ptr != *s) + return false; + + s++; + } + while (*ptr++); + } + + return false; +} + +bool NzString::StartsWith(const NzString& string, nzUInt32 flags) const +{ + if (string.m_sharedString->size == 0) + return false; + + if (m_sharedString->size < string.m_sharedString->size) + return false; + + if (flags & CaseInsensitive) + { + if (flags & HandleUtf8) + { + utf8::unchecked::iterator it(m_sharedString->string); + utf8::unchecked::iterator it2(string.m_sharedString->string); + do + { + if (*it2 == '\0') + return true; + + if (NzUnicode::GetLowercase(*it) != NzUnicode::GetLowercase(*it2)) + return false; + + ++it2; + } + while (*it++); + } + else + { + char* ptr = m_sharedString->string; + const char* s = string.m_sharedString->string; + do + { + if (*s == '\0') + return true; + + if (nzToLower(*ptr) != nzToLower(*s)) + return false; + + s++; + } + while (*ptr++); + } + } + else + return std::memcmp(m_sharedString->string, string.m_sharedString->string, string.m_sharedString->size) == 0; + + return false; +} + +NzString NzString::Substr(int startPos, int endPos) const +{ + if (startPos < 0) + startPos = std::max(m_sharedString->size+startPos, 0U); + + unsigned int start = static_cast(startPos); + + if (endPos < 0) + { + endPos = m_sharedString->size+endPos; + if (endPos < 0) + return NzString(); + } + + unsigned int minEnd = std::min(static_cast(endPos), m_sharedString->size-1); + + if (start > minEnd || start >= m_sharedString->size) + return NzString(); + + unsigned int size = minEnd-start+1; + char* str = new char[size+1]; + std::memcpy(str, &m_sharedString->string[start], size); + str[size] = '\0'; + + return NzString(new SharedString(1, size, size, str)); +} + +NzString NzString::SubstrFrom(char character, int startPos, bool fromLast, bool include, nzUInt32 flags) const +{ + if (character == '\0') + return *this; + + unsigned int pos; + if (fromLast) + pos = FindLast(character, startPos, flags); + else + pos = Find(character, startPos, flags); + + if (pos == 0 and include) + return *this; + else if (pos == npos) + return NzString(); + + return Substr(pos+((include) ? 0 : 1)); +} + +NzString NzString::SubstrFrom(const char* string, int startPos, bool fromLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (fromLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0 && include) + return *this; + else if (pos == npos) + return NzString(); + + return Substr(pos+((include) ? 0 : std::strlen(string))); +} + +NzString NzString::SubstrFrom(const NzString& string, int startPos, bool fromLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (fromLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0 && include) + return *this; + else if (pos == npos) + return NzString(); + + return Substr(pos+((include) ? 0 : string.m_sharedString->size)); +} + +NzString NzString::SubstrTo(char character, int startPos, bool toLast, bool include, nzUInt32 flags) const +{ + if (character == '\0') + return *this; + + unsigned int pos; + if (toLast) + pos = FindLast(character, startPos); + else + pos = Find(character, startPos, flags); + + if (pos == 0) + return (include) ? character : NzString(); + else if (pos == npos) + return *this; + + return Substr(0, pos+((include) ? 1 : 0)-1); +} + +NzString NzString::SubstrTo(const char* string, int startPos, bool toLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (toLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0) + return (include) ? string : NzString(); + else if (pos == npos) + return *this; + + return Substr(0, pos+((include) ? std::strlen(string) : 0)-1); +} + +NzString NzString::SubstrTo(const NzString& string, int startPos, bool toLast, bool include, nzUInt32 flags) const +{ + unsigned int pos; + if (toLast) + pos = FindLast(string, startPos, flags); + else + pos = Find(string, startPos, flags); + + if (pos == 0) + return (include) ? string : NzString(); + else if (pos == npos) + return *this; + + return Substr(0, pos+((include) ? string.m_sharedString->size : 0)-1); +} + +void NzString::Swap(NzString& str) +{ + std::swap(m_sharedString, str.m_sharedString); +} + +bool NzString::ToBool(bool* value, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return false; + + NzString word = GetWord(0); + + if (word[0] == '1') + { + if (value) + *value = true; + } + else if (word[0] == '0') + { + if (value) + *value = false; + } + else + { + if (flags & CaseInsensitive) + word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode + + if (word == "true") + { + if (value) + *value = true; + } + else if (word == "false") + { + if (value) + *value = false; + } + else + return false; + } + + return true; +} + +bool NzString::ToDouble(double* value) const +{ + if (m_sharedString->size == 0) + return false; + + if (value) + *value = std::atof(m_sharedString->string); + + return true; +} + +bool NzString::ToInteger(long long* value, nzUInt8 base) const +{ + if (value) + { + bool ok; + *value = NzStringToNumber(*this, base, &ok); + + return ok; + } + else + return IsNumber(base); +} + +NzString NzString::ToLower(nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + if (flags & HandleUtf8) + { + NzString lower; + lower.Reserve(m_sharedString->size); + utf8::unchecked::iterator it(m_sharedString->string); + do + utf8::append(NzUnicode::GetLowercase(*it), std::back_inserter(lower)); + while (*++it); + + return lower; + } + else + { + char* str = new char[m_sharedString->size+1]; + + char* ptr = m_sharedString->string; + char* s = str; + do + *s++ = nzToLower(*ptr); + while (*++ptr); + + *s = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); + } +} + +NzString NzString::ToUpper(nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + if (flags & HandleUtf8) + { + NzString upper; + upper.Reserve(m_sharedString->size); + utf8::unchecked::iterator it(m_sharedString->string); + do + utf8::append(NzUnicode::GetUppercase(*it), std::back_inserter(upper)); + while (*++it); + + return upper; + } + else + { + char* str = new char[m_sharedString->size+1]; + + char* ptr = m_sharedString->string; + char* s = str; + do + *s++ = nzToUpper(*ptr); + while (*++ptr); + + *s = '\0'; + + return NzString(new SharedString(1, m_sharedString->size, m_sharedString->size, str)); + } +} + +NzString& NzString::Trim(nzUInt32 flags) +{ + return operator=(Trimmed(flags)); +} + +NzString& NzString::Trim(char character, nzUInt32 flags) +{ + return operator=(Trimmed(character, flags)); +} + +NzString NzString::Trimmed(nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + unsigned int startPos; + unsigned int endPos; + if (flags & HandleUtf8) + { + if ((flags & TrimOnlyRight) == 0) + { + utf8::unchecked::iterator it(m_sharedString->string); + do + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + break; + } + while (*++it); + + startPos = it.base() - m_sharedString->string; + } + else + startPos = 0; + + if ((flags & TrimOnlyLeft) == 0) + { + utf8::unchecked::iterator it(&m_sharedString->string[m_sharedString->size]); + while ((it--).base() != m_sharedString->string) + { + if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator) + break; + } + + endPos = it.base() - m_sharedString->string; + } + else + endPos = m_sharedString->size-1; + } + else + { + startPos = 0; + if ((flags & TrimOnlyRight) == 0) + { + for (; startPos < m_sharedString->size; ++startPos) + { + if (!std::isspace(m_sharedString->string[startPos])) + break; + } + } + + endPos = m_sharedString->size-1; + if ((flags & TrimOnlyLeft) == 0) + { + for (; endPos > 0; --endPos) + { + if (!std::isspace(m_sharedString->string[endPos])) + break; + } + } + } + + return Substr(startPos, endPos); +} + +NzString NzString::Trimmed(char character, nzUInt32 flags) const +{ + if (m_sharedString->size == 0) + return *this; + + unsigned int startPos = 0; + unsigned int endPos = m_sharedString->size-1; + if (flags & CaseInsensitive) + { + char ch = nzToLower(character); + if ((flags & TrimOnlyRight) == 0) + { + for (; startPos < m_sharedString->size; ++startPos) + { + if (nzToLower(m_sharedString->string[startPos]) != ch) + break; + } + } + + if ((flags & TrimOnlyLeft) == 0) + { + for (; endPos > 0; --endPos) + { + if (nzToLower(m_sharedString->string[startPos]) != ch) + break; + } + } + } + else + { + if ((flags & TrimOnlyRight) == 0) + { + for (; startPos < m_sharedString->size; ++startPos) + { + if (m_sharedString->string[startPos] != character) + break; + } + } + + if ((flags & TrimOnlyLeft) == 0) + { + for (; endPos > 0; --endPos) + { + if (m_sharedString->string[startPos] != character) + break; + } + } + } + + return Substr(startPos, endPos); +} + +char* NzString::begin() +{ + return m_sharedString->string; +} + +const char* NzString::begin() const +{ + return m_sharedString->string; +} + +char* NzString::end() +{ + return &m_sharedString->string[m_sharedString->size]; +} + +const char* NzString::end() const +{ + return &m_sharedString->string[m_sharedString->size]; +} + +void NzString::push_front(char c) +{ + operator=(c + *this); +} + +void NzString::push_back(char c) +{ + operator+=(c); +} +/* +char* NzString::rbegin() +{ + return &m_sharedString->string[m_sharedString->size-1]; +} + +const char* NzString::rbegin() const +{ + return &m_sharedString->string[m_sharedString->size-1]; +} + +char* NzString::rend() +{ + return &m_sharedString->string[-1]; +} + +const char* NzString::rend() const +{ + return &m_sharedString->string[-1]; +} +*/ + +NzString::operator std::string() const +{ + return std::string(m_sharedString->string, m_sharedString->size); +} + +char& NzString::operator[](unsigned int pos) +{ + EnsureOwnership(); + + if (pos >= m_sharedString->size) + Resize(pos+1); + + return m_sharedString->string[pos]; +} + +char NzString::operator[](unsigned int pos) const +{ + #if NAZARA_CORE_SAFE + if (pos >= m_sharedString->size) + { + NazaraError("Index out of range (" + Number(pos) + " >= " + Number(m_sharedString->size) + ')'); + return 0; + } + #endif + + return m_sharedString->string[pos]; +} + +NzString& NzString::operator=(char character) +{ + if (character != '\0') + { + if (m_sharedString->capacity >= 1) + EnsureOwnership(); + else + { + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = 1; + m_sharedString->string = new char[2]; + } + + m_sharedString->size = 1; + m_sharedString->string[0] = character; + m_sharedString->string[1] = '\0'; + } + else + ReleaseString(); + + return *this; +} + +NzString& NzString::operator=(const char* string) +{ + if (string && string[0] != '\0') + { + unsigned int size = std::strlen(string); + if (m_sharedString->capacity >= size) + EnsureOwnership(); + else + { + ReleaseString(); + + m_sharedString = new SharedString; + m_sharedString->capacity = size; + m_sharedString->string = new char[size+1]; + } + + m_sharedString->size = size; + std::memcpy(m_sharedString->string, string, size+1); + } + else + ReleaseString(); + + return *this; +} + +NzString& NzString::operator=(const std::string& string) +{ + if (string.size() > 0) + { + if (m_sharedString->capacity >= string.size()) + EnsureOwnership(); + else + { + ReleaseString(); + + m_sharedString = new SharedString; + m_sharedString->capacity = string.size(); + m_sharedString->string = new char[string.size()+1]; + } + + m_sharedString->size = string.size(); + std::memcpy(m_sharedString->string, string.c_str(), string.size()+1); + } + else + ReleaseString(); + + return *this; +} + +NzString& NzString::operator=(const NzString& string) +{ + ReleaseString(); + + m_sharedString = string.m_sharedString; + if (m_sharedString != &emptyString) + { + NazaraMutexLock(m_sharedString->mutex); + m_sharedString->refCount++; + NazaraMutexUnlock(m_sharedString->mutex); + } + + return *this; +} + +NzString& NzString::operator=(NzString&& string) noexcept +{ + std::swap(m_sharedString, string.m_sharedString); + + return *this; +} + +NzString NzString::operator+(char character) const +{ + if (character == '\0') + return *this; + + unsigned int totalSize = m_sharedString->size+1; + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + + str[m_sharedString->size] = character; + str[totalSize] = '\0'; + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString NzString::operator+(const char* string) const +{ + if (!string || !string[0]) + return *this; + + if (m_sharedString->size == 0) + return string; + + unsigned int length = std::strlen(string); + if (length == 0) + return *this; + + unsigned int totalSize = m_sharedString->size + length; + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string, length+1); + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString NzString::operator+(const std::string& string) const +{ + if (string.empty()) + return *this; + + if (m_sharedString->size == 0) + return string; + + unsigned int totalSize = m_sharedString->size + string.size(); + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.c_str(), string.size()+1); + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString NzString::operator+(const NzString& string) const +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0) + return string; + + unsigned int totalSize = m_sharedString->size + string.m_sharedString->size; + char* str = new char[totalSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + + return NzString(new SharedString(1, totalSize, totalSize, str)); +} + +NzString& NzString::operator+=(char character) +{ + if (character == '\0') + return *this; + + if (m_sharedString->size == 0) + return operator=(character); + + if (m_sharedString->capacity > m_sharedString->size) + { + EnsureOwnership(); + + m_sharedString->string[m_sharedString->size] = character; + m_sharedString->string[m_sharedString->size+1] = '\0'; + m_sharedString->size++; + } + else + { + unsigned int newSize = m_sharedString->size+1; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + str[m_sharedString->size] = character; + str[newSize] = '\0'; + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::operator+=(const char* string) +{ + if (!string || !string[0]) + return *this; + + if (m_sharedString->size == 0) + return operator=(string); + + unsigned int size = std::strlen(string); + if (size == 0) + return *this; + + if (m_sharedString->capacity >= m_sharedString->size + size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string, size+1); + m_sharedString->size += size; + } + else + { + unsigned int newSize = m_sharedString->size + size; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string, size+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::operator+=(const std::string& string) +{ + if (string.empty()) + return *this; + + if (m_sharedString->size == 0) + return operator=(string); + + if (m_sharedString->capacity >= m_sharedString->size + string.size()) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string.c_str(), string.size()+1); + m_sharedString->size += string.size(); + } + else + { + unsigned int newSize = m_sharedString->size + string.size(); + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.c_str(), string.size()+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +NzString& NzString::operator+=(const NzString& string) +{ + if (string.m_sharedString->size == 0) + return *this; + + if (m_sharedString->size == 0) + return operator=(string); + + if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size) + { + EnsureOwnership(); + + std::memcpy(&m_sharedString->string[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + m_sharedString->size += string.m_sharedString->size; + } + else + { + unsigned int newSize = m_sharedString->size + string.m_sharedString->size; + unsigned int bufferSize = nzGetNewSize(newSize); + + char* str = new char[bufferSize+1]; + std::memcpy(str, m_sharedString->string, m_sharedString->size); + std::memcpy(&str[m_sharedString->size], string.m_sharedString->string, string.m_sharedString->size+1); + + ReleaseString(); + m_sharedString = new SharedString; + m_sharedString->capacity = bufferSize; + m_sharedString->size = newSize; + m_sharedString->string = str; + } + + return *this; +} + +bool NzString::operator==(char character) const +{ + if (m_sharedString->size == 0) + return character == '\0'; + + if (m_sharedString->size > 1) + return false; + + return m_sharedString->string[0] == character; +} + +bool NzString::operator==(const char* string) const +{ + if (m_sharedString->size == 0) + return !string || !string[0]; + + if (!string || !string[0]) + return false; + + return std::strcmp(m_sharedString->string, string) == 0; +} + +bool NzString::operator==(const std::string& string) const +{ + if (m_sharedString->size == 0 || string.empty()) + return m_sharedString->size == string.size(); + + if (m_sharedString->size != string.size()) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) == 0; +} + +bool NzString::operator!=(char character) const +{ + if (m_sharedString->size == 0) + return character != '\0'; + + if (character == '\0' || m_sharedString->size != 1) + return true; + + if (m_sharedString->size != 1) + return true; + + return m_sharedString->string[0] != character; +} + +bool NzString::operator!=(const char* string) const +{ + if (m_sharedString->size == 0) + return string && string[0]; + + if (!string || !string[0]) + return true; + + return std::strcmp(m_sharedString->string, string) != 0; +} + +bool NzString::operator!=(const std::string& string) const +{ + if (m_sharedString->size == 0 || string.empty()) + return m_sharedString->size == string.size(); + + if (m_sharedString->size != string.size()) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) != 0; +} + +bool NzString::operator<(char character) const +{ + if (character == '\0') + return false; + + if (m_sharedString->size == 0) + return true; + + return m_sharedString->string[0] < character; +} + +bool NzString::operator<(const char* string) const +{ + if (!string || !string[0]) + return false; + + if (m_sharedString->size == 0) + return true; + + return std::strcmp(m_sharedString->string, string) < 0; +} + +bool NzString::operator<(const std::string& string) const +{ + if (string.empty()) + return false; + + if (m_sharedString->size == 0) + return true; + + return std::strcmp(m_sharedString->string, string.c_str()) < 0; +} + +bool NzString::operator<=(char character) const +{ + if (m_sharedString->size == 0) + return true; + + if (character == '\0') + return false; + + return m_sharedString->string[0] < character || (m_sharedString->string[0] == character && m_sharedString->size == 1); +} + +bool NzString::operator<=(const char* string) const +{ + if (m_sharedString->size == 0) + return true; + + if (!string || !string[0]) + return false; + + return std::strcmp(m_sharedString->string, string) <= 0; +} + +bool NzString::operator<=(const std::string& string) const +{ + if (m_sharedString->size == 0) + return true; + + if (string.empty()) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) <= 0; +} + +bool NzString::operator>(char character) const +{ + if (m_sharedString->size == 0) + return false; + + if (character == '\0') + return true; + + return m_sharedString->string[0] > character; +} + +bool NzString::operator>(const char* string) const +{ + if (m_sharedString->size == 0) + return false; + + if (!string || !string[0]) + return true; + + return std::strcmp(m_sharedString->string, string) > 0; +} + +bool NzString::operator>(const std::string& string) const +{ + if (m_sharedString->size == 0) + return false; + + if (string.empty()) + return true; + + return std::strcmp(m_sharedString->string, string.c_str()) > 0; +} + +bool NzString::operator>=(char character) const +{ + if (character == '\0') + return true; + + if (m_sharedString->size == 0) + return false; + + return m_sharedString->string[0] > character || (m_sharedString->string[0] == character && m_sharedString->size == 1); +} + +bool NzString::operator>=(const char* string) const +{ + if (!string || !string[0]) + return true; + + if (m_sharedString->size == 0) + return false; + + return std::strcmp(m_sharedString->string, string) >= 0; +} + +bool NzString::operator>=(const std::string& string) const +{ + if (string.empty()) + return true; + + if (m_sharedString->size == 0) + return false; + + return std::strcmp(m_sharedString->string, string.c_str()) >= 0; +} + +NzString NzString::Boolean(bool boolean) +{ + unsigned int size = (boolean) ? 4 : 5; + char* str = new char[size+1]; + std::strcpy(str, (boolean) ? "true" : "false"); + + return NzString(new SharedString(1, size, size, str)); +} + +int NzString::Compare(const NzString& first, const NzString& second) +{ + if (first.m_sharedString->size == 0) + return (second.m_sharedString->size == 0) ? 0 : -1; + + if (second.m_sharedString->size == 0) + return 1; + + return std::strcmp(first.m_sharedString->string, second.m_sharedString->string); +} + +NzString NzString::Number(float number) +{ + std::ostringstream oss; + oss.precision(NAZARA_CORE_REAL_PRECISION); + oss << number; + + return NzString(oss.str()); +} + +NzString NzString::Number(double number) +{ + std::ostringstream oss; + oss.precision(NAZARA_CORE_REAL_PRECISION); + oss << number; + + return NzString(oss.str()); +} + +NzString NzString::Number(long double number) +{ + std::ostringstream oss; + oss.precision(NAZARA_CORE_REAL_PRECISION); + oss << number; + + return NzString(oss.str()); +} + +NzString NzString::Number(signed char number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned char number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(short number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned short number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(int number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned int number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(long long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Number(unsigned long long number, nzUInt8 radix) +{ + return NzNumberToString(number, radix); +} + +NzString NzString::Pointer(const void* ptr) +{ + unsigned int size = sizeof(ptr)*2+2; + char* str = new char[size+1]; + std::sprintf(str, "0x%p", ptr); + + return NzString(new SharedString(1, size, size, str)); +} + +NzString NzString::Unicode(char32_t character) +{ + if (character == '\0') + return NzString(); + + unsigned int count = 0; + if (character < 0x80) + count = 1; + else if (character < 0x800) + count = 2; + else if (character < 0x10000) + count = 3; + else + count = 4; + + char* str = new char[count+1]; + utf8::append(character, str); + str[count] = '\0'; + + return NzString(new SharedString(1, count, count, str)); +} + +NzString NzString::Unicode(const char* u8String) +{ + return NzString(u8String); +} + +NzString NzString::Unicode(const char16_t* u16String) +{ + if (!u16String || !u16String[0]) + return NzString(); + + const char16_t* ptr = u16String; + unsigned int count = 0; + do + count++; + while (*++ptr); + + count *= 2; // On s'assure d'avoir la place suffisante + + char* str = new char[count+1]; + char* r = utf8::utf16to8(u16String, ptr, str); + *r = '\0'; + + return NzString(new SharedString(1, count, r-str, str)); +} + +NzString NzString::Unicode(const char32_t* u32String) +{ + if (!u32String || !u32String[0]) + return NzString(); + + const char32_t* ptr = u32String; + unsigned int count = 0; + do + { + char32_t cp = *ptr; + if (cp < 0x80) + count += 1; + else if (cp < 0x800) + count += 2; + else if (cp < 0x10000) + count += 3; + else + count += 4; + } + while (*++ptr); + + char* str = new char[count+1]; + char* r = utf8::utf32to8(u32String, ptr, str); + *r = '\0'; + + return NzString(new SharedString(1, count, count, str)); +} + +NzString NzString::Unicode(const wchar_t* wString) +{ + if (!wString || !wString[0]) + return NzString(); + + const wchar_t* ptr = wString; + unsigned int count = 0; + do + { + char32_t cp = *ptr; + if (cp < 0x80) + count += 1; + else if (cp < 0x800) + count += 2; + else if (cp < 0x10000) + count += 3; + else + count += 4; + } + while (*++ptr); + + char* str = new char[count+1]; + char* r = utf8::utf32to8(wString, ptr, str); + *r = '\0'; + + return NzString(new SharedString(1, count, count, str)); +} + +std::istream& operator>>(std::istream& is, NzString& str) +{ + str.Clear(); + + char c; + do + { + is.get(c); + if (c == '\0') + break; + else if (std::isspace(c)) + { + if (str.IsNull()) + continue; + else + break; + } + else + str += c; + } + while (true); + + return is; +} + +std::ostream& operator<<(std::ostream& os, const NzString& str) +{ + if (str.IsEmpty()) + return os; + + return operator<<(os, str.m_sharedString->string); +} + +NzString operator+(char character, const NzString& string) +{ + if (character == '\0') + return string; + + if (string.IsEmpty()) + return character; + + unsigned int totalSize = string.m_sharedString->size+1; + char* str = new char[totalSize+1]; + str[0] = character; + std::memcpy(str, string.m_sharedString->string, string.m_sharedString->size+1); + + return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); +} + +NzString operator+(const char* string, const NzString& nstring) +{ + if (!string || !string[0]) + return nstring; + + if (nstring.IsEmpty()) + return string; + + unsigned int size = std::strlen(string); + unsigned int totalSize = size + nstring.m_sharedString->size; + char* str = new char[totalSize+1]; + std::memcpy(str, string, size); + std::memcpy(&str[size], nstring.m_sharedString->string, nstring.m_sharedString->size+1); + + return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); +} + +NzString operator+(const std::string& string, const NzString& nstring) +{ + if (string.empty()) + return nstring; + + if (nstring.m_sharedString->size == 0) + return string; + + unsigned int totalSize = string.size() + nstring.m_sharedString->size; + char* str = new char[totalSize+1]; + std::memcpy(str, string.c_str(), string.size()); + std::memcpy(&str[string.size()], nstring.m_sharedString->string, nstring.m_sharedString->size+1); + + return NzString(new NzString::SharedString(1, totalSize, totalSize, str)); +} + +bool operator==(const NzString& first, const NzString& second) +{ + if (first.m_sharedString->size == 0 || second.m_sharedString->size == 0) + return first.m_sharedString->size == second.m_sharedString->size; + + if (first.m_sharedString->size != second.m_sharedString->size) + return false; + + return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) == 0; +} + +bool operator!=(const NzString& first, const NzString& second) +{ + return !operator==(first, second); +} + +bool operator<(const NzString& first, const NzString& second) +{ + if (second.m_sharedString->size == 0) + return false; + + if (first.m_sharedString->size == 0) + return true; + + return std::strcmp(first.m_sharedString->string, second.m_sharedString->string) < 0; +} + +bool operator<=(const NzString& first, const NzString& second) +{ + return !operator<(second, first); +} + +bool operator>(const NzString& first, const NzString& second) +{ + return second < first; +} + +bool operator>=(const NzString& first, const NzString& second) +{ + return !operator<(first, second); +} + +bool operator==(char character, const NzString& nstring) +{ + return nstring == character; +} + +bool operator==(const char* string, const NzString& nstring) +{ + return nstring == string; +} + +bool operator==(const std::string& string, const NzString& nstring) +{ + return nstring == string; +} + +bool operator!=(char character, const NzString& nstring) +{ + return !operator==(character, nstring); +} + +bool operator!=(const char* string, const NzString& nstring) +{ + return !operator==(string, nstring); +} + +bool operator!=(const std::string& string, const NzString& nstring) +{ + return !operator==(string, nstring); +} + +bool operator<(char character, const NzString& nstring) +{ + return nstring > character; +} + +bool operator<(const char* string, const NzString& nstring) +{ + return nstring > string; +} + +bool operator<(const std::string& string, const NzString& nstring) +{ + return nstring > string; +} + +bool operator<=(char character, const NzString& nstring) +{ + return !operator<(nstring, character); +} + +bool operator<=(const char* string, const NzString& nstring) +{ + return !operator<(nstring, string); +} + +bool operator<=(const std::string& string, const NzString& nstring) +{ + return !operator<(nstring, string); +} + +bool operator>(char character, const NzString& nstring) +{ + return nstring < character; +} + +bool operator>(const char* string, const NzString& nstring) +{ + return nstring < string; +} + +bool operator>(const std::string& string, const NzString& nstring) +{ + return nstring < string; +} + +bool operator>=(char character, const NzString& nstring) +{ + return !operator<(character, nstring); +} + +bool operator>=(const char* string, const NzString& nstring) +{ + return !operator<(string, nstring); +} + +bool operator>=(const std::string& string, const NzString& nstring) +{ + return !operator<(string, nstring); +} + +void NzString::EnsureOwnership() +{ + if (m_sharedString == &emptyString) + return; + + NazaraLock(m_sharedString->mutex); + if (m_sharedString->refCount > 1) + { + m_sharedString->refCount--; + + char* string = new char[m_sharedString->capacity+1]; + std::memcpy(string, m_sharedString->string, m_sharedString->size+1); + + m_sharedString = new SharedString(1, m_sharedString->capacity, m_sharedString->size, string); + } +} + +bool NzString::FillHash(NzHashImpl* hazh) const +{ + hazh->Append(reinterpret_cast(m_sharedString->string), m_sharedString->size); + + return true; +} + +void NzString::ReleaseString() +{ + if (m_sharedString == &emptyString) + return; + + NazaraMutexLock(m_sharedString->mutex); + bool freeSharedString = (--m_sharedString->refCount == 0); + NazaraMutexUnlock(m_sharedString->mutex); + + if (freeSharedString) + { + delete[] m_sharedString->string; + delete m_sharedString; + } + + m_sharedString = &emptyString; +} + +NzString::SharedString NzString::emptyString(0, 0, 0, nullptr); +const unsigned int NzString::npos(std::numeric_limits::max()); + +namespace std +{ + istream& getline(istream& is, NzString& str) + { + str.Clear(); + + char c; + do + { + is.get(c); + if (c != '\n' && c != '\0') + str += c; + else + break; + } + while (true); + + return is; + } + + istream& getline(istream& is, NzString& str, char delim) + { + str.Clear(); + + char c; + do + { + is.get(c); + if (c != delim && c != '\0') + str += c; + else + break; + } + while (true); + + return is; + } + + void swap(NzString& lhs, NzString& rhs) + { + lhs.Swap(rhs); + } +} diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index e10588943..813bf66ef 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -1,359 +1,359 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) - #include -#elif defined(NAZARA_PLATFORM_LINUX) - #include -#else - #error Lack of implementation: Context -#endif - -#include - -namespace -{ - NAZARA_THREADLOCAL NzContext* currentContext = nullptr; - NAZARA_THREADLOCAL NzContext* threadContext = nullptr; - - std::vector contexts; - - void CALLBACK DebugCallback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, void* userParam) - { - NazaraUnused(length); - - NzStringStream ss; - ss << "OpenGL debug message (ID: 0x" << NzString::Number(id, 16) << "):\n"; - ss << "Sent by context: " << userParam; - ss << "\n-Source: "; - switch (source) - { - case GL_DEBUG_SOURCE_API_ARB: - ss << "OpenGL"; - break; - - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: - ss << "Operating system"; - break; - - case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: - ss << "Shader compiler"; - break; - - case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: - ss << "Shader compiler"; - break; - - case GL_DEBUG_SOURCE_APPLICATION_ARB: - ss << "Application"; - break; - - case GL_DEBUG_SOURCE_OTHER_ARB: - ss << "Other"; - break; - - default: - // Peut être rajouté par une extension - ss << "Unknown"; - break; - } - ss << '\n'; - - ss << "-Type: "; - switch (type) - { - case GL_DEBUG_TYPE_ERROR_ARB: - ss << "Error"; - break; - - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: - ss << "Deprecated behavior"; - break; - - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: - ss << "Undefined behavior"; - break; - - case GL_DEBUG_TYPE_PORTABILITY_ARB: - ss << "Portability"; - break; - - case GL_DEBUG_TYPE_PERFORMANCE_ARB: - ss << "Performance"; - break; - - case GL_DEBUG_TYPE_OTHER_ARB: - ss << "Other"; - break; - - default: - // Peut être rajouté par une extension - ss << "Unknown"; - break; - } - ss << '\n'; - - ss << "-Severity: "; - switch (severity) - { - case GL_DEBUG_SEVERITY_HIGH_ARB: - ss << "High"; - break; - - case GL_DEBUG_SEVERITY_MEDIUM_ARB: - ss << "Medium"; - break; - - case GL_DEBUG_SEVERITY_LOW_ARB: - ss << "Low"; - break; - - default: - // Peut être rajouté par une extension - ss << "Unknown"; - break; - } - ss << '\n'; - - ss << "Message: " << message << '\n'; - - NazaraNotice(ss); - } -} - -NzContext::NzContext() : -m_impl(nullptr) -{ -} - -NzContext::~NzContext() -{ - Destroy(); -} - -bool NzContext::Create(const NzContextParameters& parameters) -{ - Destroy(); - - m_parameters = parameters; - if (m_parameters.shared && !m_parameters.shareContext) - m_parameters.shareContext = s_reference; - - m_impl = new NzContextImpl; - if (!m_impl->Create(m_parameters)) - { - NazaraError("Failed to create context implementation"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - if (!m_impl->Activate()) - { - NazaraError("Failed to activate context"); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - - return false; - } - - if (m_parameters.antialiasingLevel > 0) - glEnable(GL_MULTISAMPLE); - - if (NzOpenGL::IsSupported(nzOpenGLExtension_DebugOutput) && m_parameters.debugMode) - { - glDebugMessageCallback(&DebugCallback, this); - - #ifdef NAZARA_DEBUG - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - #endif - } - - NotifyCreated(); - - return true; -} - -void NzContext::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - if (currentContext == this) - NzContextImpl::Desactivate(); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - } -} - -const NzContextParameters& NzContext::GetParameters() const -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - NazaraError("No context has been created"); - #endif - - return m_parameters; -} - -bool NzContext::IsActive() const -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("No context has been created"); - return false; - } - #endif - - return currentContext == this; -} - -bool NzContext::SetActive(bool active) -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("No context has been created"); - return false; - } - #endif - - // Si le contexte est déjà activé/désactivé - if ((currentContext == this) == active) - return true; - - if (active) - { - if (!m_impl->Activate()) - return false; - - currentContext = this; - } - else - { - if (!NzContextImpl::Desactivate()) - return false; - - currentContext = nullptr; - } - - return true; -} - -void NzContext::SwapBuffers() -{ - #ifdef NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("No context has been created"); - return; - } - - if (!m_parameters.doubleBuffered) - { - NazaraError("Context is not double buffered"); - return; - } - #endif - - m_impl->SwapBuffers(); -} - -bool NzContext::EnsureContext() -{ - if (!currentContext) - { - if (!threadContext) - { - NzContext* context = new NzContext; - if (!context->Create()) - { - NazaraError("Failed to create context"); - delete context; - - return false; - } - - contexts.push_back(context); - - threadContext = context; - } - - if (!threadContext->SetActive(true)) - { - NazaraError("Failed to active thread context"); - return false; - } - } - - return true; -} - -NzContext* NzContext::GetCurrent() -{ - return currentContext; -} - -const NzContext* NzContext::GetReference() -{ - return s_reference; -} - -NzContext* NzContext::GetThreadContext() -{ - EnsureContext(); - - return threadContext; -} - -bool NzContext::Initialize() -{ - NzContextParameters parameters; -// parameters.compatibilityProfile = true; - parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même - - s_reference = new NzContext; - if (!s_reference->Create(parameters)) - { - delete s_reference; - s_reference = nullptr; - - return false; - } - - // Le contexte de référence doit rester désactivé pour le partage - s_reference->SetActive(false); - - NzContextParameters::defaultShareContext = s_reference; - - return true; -} - -void NzContext::Uninitialize() -{ - for (NzContext* context : contexts) - delete context; - - contexts.clear(); // On supprime tous les contextes créés - - delete s_reference; - s_reference = nullptr; -} - -NzContext* NzContext::s_reference = nullptr; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) + #include +#elif defined(NAZARA_PLATFORM_LINUX) + #include +#else + #error Lack of implementation: Context +#endif + +#include + +namespace +{ + NAZARA_THREADLOCAL NzContext* currentContext = nullptr; + NAZARA_THREADLOCAL NzContext* threadContext = nullptr; + + std::vector contexts; + + void CALLBACK DebugCallback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, void* userParam) + { + NazaraUnused(length); + + NzStringStream ss; + ss << "OpenGL debug message (ID: 0x" << NzString::Number(id, 16) << "):\n"; + ss << "Sent by context: " << userParam; + ss << "\n-Source: "; + switch (source) + { + case GL_DEBUG_SOURCE_API_ARB: + ss << "OpenGL"; + break; + + case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: + ss << "Operating system"; + break; + + case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: + ss << "Shader compiler"; + break; + + case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: + ss << "Shader compiler"; + break; + + case GL_DEBUG_SOURCE_APPLICATION_ARB: + ss << "Application"; + break; + + case GL_DEBUG_SOURCE_OTHER_ARB: + ss << "Other"; + break; + + default: + // Peut être rajouté par une extension + ss << "Unknown"; + break; + } + ss << '\n'; + + ss << "-Type: "; + switch (type) + { + case GL_DEBUG_TYPE_ERROR_ARB: + ss << "Error"; + break; + + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: + ss << "Deprecated behavior"; + break; + + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: + ss << "Undefined behavior"; + break; + + case GL_DEBUG_TYPE_PORTABILITY_ARB: + ss << "Portability"; + break; + + case GL_DEBUG_TYPE_PERFORMANCE_ARB: + ss << "Performance"; + break; + + case GL_DEBUG_TYPE_OTHER_ARB: + ss << "Other"; + break; + + default: + // Peut être rajouté par une extension + ss << "Unknown"; + break; + } + ss << '\n'; + + ss << "-Severity: "; + switch (severity) + { + case GL_DEBUG_SEVERITY_HIGH_ARB: + ss << "High"; + break; + + case GL_DEBUG_SEVERITY_MEDIUM_ARB: + ss << "Medium"; + break; + + case GL_DEBUG_SEVERITY_LOW_ARB: + ss << "Low"; + break; + + default: + // Peut être rajouté par une extension + ss << "Unknown"; + break; + } + ss << '\n'; + + ss << "Message: " << message << '\n'; + + NazaraNotice(ss); + } +} + +NzContext::NzContext() : +m_impl(nullptr) +{ +} + +NzContext::~NzContext() +{ + Destroy(); +} + +bool NzContext::Create(const NzContextParameters& parameters) +{ + Destroy(); + + m_parameters = parameters; + if (m_parameters.shared && !m_parameters.shareContext) + m_parameters.shareContext = s_reference; + + m_impl = new NzContextImpl; + if (!m_impl->Create(m_parameters)) + { + NazaraError("Failed to create context implementation"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + if (!m_impl->Activate()) + { + NazaraError("Failed to activate context"); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + + return false; + } + + if (m_parameters.antialiasingLevel > 0) + glEnable(GL_MULTISAMPLE); + + if (NzOpenGL::IsSupported(nzOpenGLExtension_DebugOutput) && m_parameters.debugMode) + { + glDebugMessageCallback(&DebugCallback, this); + + #ifdef NAZARA_DEBUG + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + #endif + } + + NotifyCreated(); + + return true; +} + +void NzContext::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + if (currentContext == this) + NzContextImpl::Desactivate(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + } +} + +const NzContextParameters& NzContext::GetParameters() const +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + NazaraError("No context has been created"); + #endif + + return m_parameters; +} + +bool NzContext::IsActive() const +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("No context has been created"); + return false; + } + #endif + + return currentContext == this; +} + +bool NzContext::SetActive(bool active) +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("No context has been created"); + return false; + } + #endif + + // Si le contexte est déjà activé/désactivé + if ((currentContext == this) == active) + return true; + + if (active) + { + if (!m_impl->Activate()) + return false; + + currentContext = this; + } + else + { + if (!NzContextImpl::Desactivate()) + return false; + + currentContext = nullptr; + } + + return true; +} + +void NzContext::SwapBuffers() +{ + #ifdef NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("No context has been created"); + return; + } + + if (!m_parameters.doubleBuffered) + { + NazaraError("Context is not double buffered"); + return; + } + #endif + + m_impl->SwapBuffers(); +} + +bool NzContext::EnsureContext() +{ + if (!currentContext) + { + if (!threadContext) + { + NzContext* context = new NzContext; + if (!context->Create()) + { + NazaraError("Failed to create context"); + delete context; + + return false; + } + + contexts.push_back(context); + + threadContext = context; + } + + if (!threadContext->SetActive(true)) + { + NazaraError("Failed to active thread context"); + return false; + } + } + + return true; +} + +NzContext* NzContext::GetCurrent() +{ + return currentContext; +} + +const NzContext* NzContext::GetReference() +{ + return s_reference; +} + +NzContext* NzContext::GetThreadContext() +{ + EnsureContext(); + + return threadContext; +} + +bool NzContext::Initialize() +{ + NzContextParameters parameters; +// parameters.compatibilityProfile = true; + parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même + + s_reference = new NzContext; + if (!s_reference->Create(parameters)) + { + delete s_reference; + s_reference = nullptr; + + return false; + } + + // Le contexte de référence doit rester désactivé pour le partage + s_reference->SetActive(false); + + NzContextParameters::defaultShareContext = s_reference; + + return true; +} + +void NzContext::Uninitialize() +{ + for (NzContext* context : contexts) + delete context; + + contexts.clear(); // On supprime tous les contextes créés + + delete s_reference; + s_reference = nullptr; +} + +NzContext* NzContext::s_reference = nullptr; diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLShader.cpp index ecc0e6199..90198675a 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLShader.cpp @@ -1,712 +1,712 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - GLuint lockedPrevious = 0; - nzUInt8 lockedLevel = 0; -} - -NzGLSLShader::NzGLSLShader(NzShader* parent) : -m_parent(parent) -{ -} - -NzGLSLShader::~NzGLSLShader() -{ - for (auto it = m_textures.begin(); it != m_textures.end(); ++it) - it->second.texture->RemoveResourceListener(this); -} - -bool NzGLSLShader::Bind() -{ - #if NAZARA_RENDERER_SAFE - if (lockedLevel > 0) - { - NazaraError("Cannot bind shader while a shader is locked"); - return false; - } - #endif - - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return false; - } - #endif - - glUseProgram(m_program); - - return true; -} - -bool NzGLSLShader::BindTextures() -{ - for (auto it = m_textures.begin(); it != m_textures.end(); ++it) - { - TextureSlot& slot = it->second; - if (slot.enabled && !slot.updated) - { - glActiveTexture(GL_TEXTURE0 + slot.unit); - if (!slot.texture->Prepare()) - NazaraWarning("Failed to prepare texture"); - - slot.updated = true; - } - } - - return true; -} - -bool NzGLSLShader::Compile() -{ - NzContext::EnsureContext(); - - m_idCache.clear(); - m_textures.clear(); - - glLinkProgram(m_program); - - GLint success; - glGetProgramiv(m_program, GL_LINK_STATUS, &success); - - if (success == GL_TRUE) - { - static NzString successStr("Linkage successful"); - m_log = successStr; - - return true; - } - else - { - // On remplit le log avec l'erreur de compilation - GLint length = 0; - glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length); - if (length > 1) - { - m_log.Clear(true); - m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) - m_log.Prepend("Linkage error: "); - m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log - - glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]); - } - else - m_log = "Linkage failed but no info log found"; - - NazaraError(m_log); - - return false; - } -} - -bool NzGLSLShader::Create() -{ - NzContext::EnsureContext(); - - m_program = glCreateProgram(); - if (!m_program) - { - NazaraError("Failed to create program"); - return false; - } - - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Position], "Position"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Normal], "Normal"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Diffuse], "Diffuse"); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Tangent], "Tangent"); - - NzString uniform; - - static const unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits(); - - uniform.Reserve(10); // 8 + 2 - uniform = "TexCoord"; - for (unsigned int i = 0; i < maxTexCoords; ++i) - { - NzString uniformName = uniform + NzString::Number(i); - glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer()); - } - - static const bool mrtSupported = NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets); - if (mrtSupported) - { - static const unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets(); - - uniform.Reserve(14); // 12 + 2 - uniform = "RenderTarget"; - for (unsigned int i = 0; i < maxRenderTargets; ++i) - { - NzString uniformName = uniform + NzString::Number(i); - glBindFragDataLocation(m_program, i, uniformName.GetConstBuffer()); - } - } - - for (int i = 0; i <= nzShaderType_Max; ++i) - m_shaders[i] = 0; - - return true; -} - -void NzGLSLShader::Destroy() -{ - NzContext::EnsureContext(); - - for (auto it = m_textures.begin(); it != m_textures.end(); ++it) - it->second.texture->RemoveResourceReference(); - - for (GLuint shader : m_shaders) - if (shader) - glDeleteShader(shader); - - if (m_program) - glDeleteProgram(m_program); -} - -NzString NzGLSLShader::GetLog() const -{ - return m_log; -} - -nzShaderLanguage NzGLSLShader::GetLanguage() const -{ - return nzShaderLanguage_GLSL; -} - -NzString NzGLSLShader::GetSourceCode(nzShaderType type) const -{ - NzContext::EnsureContext(); - - NzString source; - - GLint length; - glGetShaderiv(m_shaders[type], GL_SHADER_SOURCE_LENGTH, &length); - if (length > 1) - { - source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin) - glGetShaderSource(m_shaders[type], length, nullptr, &source[0]); - } - - return source; -} - -int NzGLSLShader::GetUniformLocation(const NzString& name) const -{ - std::map::const_iterator it = m_idCache.find(name); - GLint id; - if (it == m_idCache.end()) - { - NzContext::EnsureContext(); - - id = glGetUniformLocation(m_program, name.GetConstBuffer()); - m_idCache[name] = id; - } - else - id = it->second; - - return id; -} - -bool NzGLSLShader::IsLoaded(nzShaderType type) const -{ - return m_shaders[type] != 0; -} - -bool NzGLSLShader::Load(nzShaderType type, const NzString& source) -{ - NzContext::EnsureContext(); - - GLuint shader = glCreateShader(NzOpenGL::ShaderType[type]); - if (!shader) - { - m_log = "Failed to create shader object"; - NazaraError(m_log); - - return false; - } - - const char* tmp = source.GetConstBuffer(); - GLint length = source.GetSize(); - glShaderSource(shader, 1, &tmp, &length); - - glCompileShader(shader); - - GLint success; - glGetShaderiv(shader, GL_COMPILE_STATUS, &success); - - if (success == GL_TRUE) - { - glAttachShader(m_program, shader); - m_shaders[type] = shader; - - static NzString successStr("Compilation successful"); - m_log = successStr; - - return true; - } - else - { - // On remplit le log avec l'erreur de compilation - length = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); - if (length > 1) - { - m_log.Clear(true); - m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) - m_log.Prepend("Compilation error: "); - m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log - - glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]); - } - else - m_log = "Compilation failed but no info log found"; - - NazaraError(m_log); - - glDeleteShader(shader); - - return false; - } -} - -bool NzGLSLShader::Lock() -{ - if (lockedLevel++ == 0) - { - NzContext::EnsureContext(); - - GLint previous; - glGetIntegerv(GL_CURRENT_PROGRAM, &previous); - - lockedPrevious = previous; - - if (lockedPrevious != m_program) - glUseProgram(m_program); - } - - return true; -} - -bool NzGLSLShader::SendBoolean(int location, bool value) -{ - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, value); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform1i(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendDouble(int location, double value) -{ - if (glProgramUniform1d) - glProgramUniform1d(m_program, location, value); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform1d(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendFloat(int location, float value) -{ - if (glProgramUniform1f) - glProgramUniform1f(m_program, location, value); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform1f(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendInteger(int location, int value) -{ - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, value); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform1i(location, value); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) -{ - if (glProgramUniformMatrix4dv) - glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniformMatrix4dv(location, 1, GL_FALSE, matrix); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) -{ - if (glProgramUniformMatrix4fv) - glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniformMatrix4fv(location, 1, GL_FALSE, matrix); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) -{ - auto it = m_textures.find(location); - if (it != m_textures.end()) - { - // Slot déjà utilisé - TextureSlot& slot = it->second; - if (slot.texture != texture) - { - slot.texture->RemoveResourceListener(this); - - if (texture) - { - slot.texture = texture; - slot.texture->AddResourceListener(this, location); - - slot.updated = false; - } - else - m_textures.erase(it); // On supprime le slot - } - } - else - { - static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits(); - - unsigned int unitUsed = m_textures.size(); - if (unitUsed >= maxUnits) - { - NazaraError("Unable to use texture for shader: all available texture units are used"); - return false; - } - - // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre - nzUInt8 unit; - if (unitUsed == 0) - // Pas d'unité utilisée, la tâche est simple - unit = 0; - else - { - auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map - unit = it2->second.unit; - if (unit == maxUnits-1) - { - // Il y a une place libre, mais pas à la fin - for (; it2 != m_textures.rend(); ++it2) - { - if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre - { - unit--; - break; - } - } - } - else - // Il y a une place libre à la fin - unit++; - } - - TextureSlot slot; - slot.enabled = texture->IsValid(); - slot.unit = unit; - slot.texture = texture; - texture->AddResourceListener(this, location); - - m_textures[location] = slot; - - if (slot.enabled) - { - if (glProgramUniform1i) - glProgramUniform1i(m_program, location, unit); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform1i(location, unit); - Unlock(); - } - } - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) -{ - if (glProgramUniform2dv) - glProgramUniform2dv(m_program, location, 1, vector); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform2dv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) -{ - if (glProgramUniform2fv) - glProgramUniform2fv(m_program, location, 1, vector); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform2fv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) -{ - if (glProgramUniform3dv) - glProgramUniform3dv(m_program, location, 1, vector); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform3dv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) -{ - if (glProgramUniform3fv) - glProgramUniform3fv(m_program, location, 1, vector); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform3fv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) -{ - if (glProgramUniform4dv) - glProgramUniform4dv(m_program, location, 1, vector); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform4dv(location, 1, vector); - Unlock(); - } - - return true; -} - -bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) -{ - if (glProgramUniform4fv) - glProgramUniform4fv(m_program, location, 1, vector); - else - { - if (!Lock()) - { - NazaraError("Failed to lock shader"); - return false; - } - - glUniform4fv(location, 1, vector); - Unlock(); - } - - return true; -} - -void NzGLSLShader::Unbind() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glUseProgram(0); -} - -void NzGLSLShader::Unlock() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (lockedLevel == 0) - { - NazaraWarning("Unlock called on non-locked texture"); - return; - } - #endif - - if (--lockedLevel == 0 && lockedPrevious != m_program) - glUseProgram(lockedPrevious); -} - -void NzGLSLShader::OnResourceCreated(const NzResource* resource, int index) -{ - NazaraUnused(resource); - - auto it = m_textures.find(index); - - #ifdef NAZARA_DEBUG - if (it == m_textures.end()) - { - NazaraInternalError("Invalid index (" + NzString::Number(index) + ')'); - return; - } - #endif - - TextureSlot& slot = it->second; - - #ifdef NAZARA_DEBUG - if (slot.texture != resource) - { - NazaraInternalError("Wrong texture at location #" + NzString::Number(index)); - return; - } - #endif - - slot.enabled = true; - slot.updated = false; -} - -void NzGLSLShader::OnResourceDestroy(const NzResource* resource, int index) -{ - NazaraUnused(resource); - - auto it = m_textures.find(index); - - #ifdef NAZARA_DEBUG - if (it == m_textures.end()) - { - NazaraInternalError("Invalid index (" + NzString::Number(index) + ')'); - return; - } - #endif - - TextureSlot& slot = it->second; - - #ifdef NAZARA_DEBUG - if (slot.texture != resource) - { - NazaraInternalError("Wrong texture at location #" + NzString::Number(index)); - return; - } - #endif - - slot.enabled = false; -} - -void NzGLSLShader::OnResourceReleased(const NzResource* resource, int index) -{ - if (m_textures.erase(index) == 0) - NazaraInternalError("Texture " + NzString::Pointer(resource) + " not found"); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + GLuint lockedPrevious = 0; + nzUInt8 lockedLevel = 0; +} + +NzGLSLShader::NzGLSLShader(NzShader* parent) : +m_parent(parent) +{ +} + +NzGLSLShader::~NzGLSLShader() +{ + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + it->second.texture->RemoveResourceListener(this); +} + +bool NzGLSLShader::Bind() +{ + #if NAZARA_RENDERER_SAFE + if (lockedLevel > 0) + { + NazaraError("Cannot bind shader while a shader is locked"); + return false; + } + #endif + + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return false; + } + #endif + + glUseProgram(m_program); + + return true; +} + +bool NzGLSLShader::BindTextures() +{ + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + { + TextureSlot& slot = it->second; + if (slot.enabled && !slot.updated) + { + glActiveTexture(GL_TEXTURE0 + slot.unit); + if (!slot.texture->Prepare()) + NazaraWarning("Failed to prepare texture"); + + slot.updated = true; + } + } + + return true; +} + +bool NzGLSLShader::Compile() +{ + NzContext::EnsureContext(); + + m_idCache.clear(); + m_textures.clear(); + + glLinkProgram(m_program); + + GLint success; + glGetProgramiv(m_program, GL_LINK_STATUS, &success); + + if (success == GL_TRUE) + { + static NzString successStr("Linkage successful"); + m_log = successStr; + + return true; + } + else + { + // On remplit le log avec l'erreur de compilation + GLint length = 0; + glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length); + if (length > 1) + { + m_log.Clear(true); + m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) + m_log.Prepend("Linkage error: "); + m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log + + glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]); + } + else + m_log = "Linkage failed but no info log found"; + + NazaraError(m_log); + + return false; + } +} + +bool NzGLSLShader::Create() +{ + NzContext::EnsureContext(); + + m_program = glCreateProgram(); + if (!m_program) + { + NazaraError("Failed to create program"); + return false; + } + + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Position], "Position"); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Normal], "Normal"); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Diffuse], "Diffuse"); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Tangent], "Tangent"); + + NzString uniform; + + static const unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits(); + + uniform.Reserve(10); // 8 + 2 + uniform = "TexCoord"; + for (unsigned int i = 0; i < maxTexCoords; ++i) + { + NzString uniformName = uniform + NzString::Number(i); + glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer()); + } + + static const bool mrtSupported = NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets); + if (mrtSupported) + { + static const unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets(); + + uniform.Reserve(14); // 12 + 2 + uniform = "RenderTarget"; + for (unsigned int i = 0; i < maxRenderTargets; ++i) + { + NzString uniformName = uniform + NzString::Number(i); + glBindFragDataLocation(m_program, i, uniformName.GetConstBuffer()); + } + } + + for (int i = 0; i <= nzShaderType_Max; ++i) + m_shaders[i] = 0; + + return true; +} + +void NzGLSLShader::Destroy() +{ + NzContext::EnsureContext(); + + for (auto it = m_textures.begin(); it != m_textures.end(); ++it) + it->second.texture->RemoveResourceReference(); + + for (GLuint shader : m_shaders) + if (shader) + glDeleteShader(shader); + + if (m_program) + glDeleteProgram(m_program); +} + +NzString NzGLSLShader::GetLog() const +{ + return m_log; +} + +nzShaderLanguage NzGLSLShader::GetLanguage() const +{ + return nzShaderLanguage_GLSL; +} + +NzString NzGLSLShader::GetSourceCode(nzShaderType type) const +{ + NzContext::EnsureContext(); + + NzString source; + + GLint length; + glGetShaderiv(m_shaders[type], GL_SHADER_SOURCE_LENGTH, &length); + if (length > 1) + { + source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin) + glGetShaderSource(m_shaders[type], length, nullptr, &source[0]); + } + + return source; +} + +int NzGLSLShader::GetUniformLocation(const NzString& name) const +{ + std::map::const_iterator it = m_idCache.find(name); + GLint id; + if (it == m_idCache.end()) + { + NzContext::EnsureContext(); + + id = glGetUniformLocation(m_program, name.GetConstBuffer()); + m_idCache[name] = id; + } + else + id = it->second; + + return id; +} + +bool NzGLSLShader::IsLoaded(nzShaderType type) const +{ + return m_shaders[type] != 0; +} + +bool NzGLSLShader::Load(nzShaderType type, const NzString& source) +{ + NzContext::EnsureContext(); + + GLuint shader = glCreateShader(NzOpenGL::ShaderType[type]); + if (!shader) + { + m_log = "Failed to create shader object"; + NazaraError(m_log); + + return false; + } + + const char* tmp = source.GetConstBuffer(); + GLint length = source.GetSize(); + glShaderSource(shader, 1, &tmp, &length); + + glCompileShader(shader); + + GLint success; + glGetShaderiv(shader, GL_COMPILE_STATUS, &success); + + if (success == GL_TRUE) + { + glAttachShader(m_program, shader); + m_shaders[type] = shader; + + static NzString successStr("Compilation successful"); + m_log = successStr; + + return true; + } + else + { + // On remplit le log avec l'erreur de compilation + length = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); + if (length > 1) + { + m_log.Clear(true); + m_log.Reserve(length+19-1); // La taille retournée est celle du buffer (Avec caractère de fin) + m_log.Prepend("Compilation error: "); + m_log.Resize(length+19-1); // Extension du buffer d'écriture pour ajouter le log + + glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]); + } + else + m_log = "Compilation failed but no info log found"; + + NazaraError(m_log); + + glDeleteShader(shader); + + return false; + } +} + +bool NzGLSLShader::Lock() +{ + if (lockedLevel++ == 0) + { + NzContext::EnsureContext(); + + GLint previous; + glGetIntegerv(GL_CURRENT_PROGRAM, &previous); + + lockedPrevious = previous; + + if (lockedPrevious != m_program) + glUseProgram(m_program); + } + + return true; +} + +bool NzGLSLShader::SendBoolean(int location, bool value) +{ + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1i(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendDouble(int location, double value) +{ + if (glProgramUniform1d) + glProgramUniform1d(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1d(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendFloat(int location, float value) +{ + if (glProgramUniform1f) + glProgramUniform1f(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1f(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendInteger(int location, int value) +{ + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, value); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1i(location, value); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) +{ + if (glProgramUniformMatrix4dv) + glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniformMatrix4dv(location, 1, GL_FALSE, matrix); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) +{ + if (glProgramUniformMatrix4fv) + glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniformMatrix4fv(location, 1, GL_FALSE, matrix); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) +{ + auto it = m_textures.find(location); + if (it != m_textures.end()) + { + // Slot déjà utilisé + TextureSlot& slot = it->second; + if (slot.texture != texture) + { + slot.texture->RemoveResourceListener(this); + + if (texture) + { + slot.texture = texture; + slot.texture->AddResourceListener(this, location); + + slot.updated = false; + } + else + m_textures.erase(it); // On supprime le slot + } + } + else + { + static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits(); + + unsigned int unitUsed = m_textures.size(); + if (unitUsed >= maxUnits) + { + NazaraError("Unable to use texture for shader: all available texture units are used"); + return false; + } + + // À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre + nzUInt8 unit; + if (unitUsed == 0) + // Pas d'unité utilisée, la tâche est simple + unit = 0; + else + { + auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map + unit = it2->second.unit; + if (unit == maxUnits-1) + { + // Il y a une place libre, mais pas à la fin + for (; it2 != m_textures.rend(); ++it2) + { + if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre + { + unit--; + break; + } + } + } + else + // Il y a une place libre à la fin + unit++; + } + + TextureSlot slot; + slot.enabled = texture->IsValid(); + slot.unit = unit; + slot.texture = texture; + texture->AddResourceListener(this, location); + + m_textures[location] = slot; + + if (slot.enabled) + { + if (glProgramUniform1i) + glProgramUniform1i(m_program, location, unit); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform1i(location, unit); + Unlock(); + } + } + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) +{ + if (glProgramUniform2dv) + glProgramUniform2dv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform2dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) +{ + if (glProgramUniform2fv) + glProgramUniform2fv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform2fv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) +{ + if (glProgramUniform3dv) + glProgramUniform3dv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform3dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) +{ + if (glProgramUniform3fv) + glProgramUniform3fv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform3fv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) +{ + if (glProgramUniform4dv) + glProgramUniform4dv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform4dv(location, 1, vector); + Unlock(); + } + + return true; +} + +bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) +{ + if (glProgramUniform4fv) + glProgramUniform4fv(m_program, location, 1, vector); + else + { + if (!Lock()) + { + NazaraError("Failed to lock shader"); + return false; + } + + glUniform4fv(location, 1, vector); + Unlock(); + } + + return true; +} + +void NzGLSLShader::Unbind() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glUseProgram(0); +} + +void NzGLSLShader::Unlock() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (lockedLevel == 0) + { + NazaraWarning("Unlock called on non-locked texture"); + return; + } + #endif + + if (--lockedLevel == 0 && lockedPrevious != m_program) + glUseProgram(lockedPrevious); +} + +void NzGLSLShader::OnResourceCreated(const NzResource* resource, int index) +{ + NazaraUnused(resource); + + auto it = m_textures.find(index); + + #ifdef NAZARA_DEBUG + if (it == m_textures.end()) + { + NazaraInternalError("Invalid index (" + NzString::Number(index) + ')'); + return; + } + #endif + + TextureSlot& slot = it->second; + + #ifdef NAZARA_DEBUG + if (slot.texture != resource) + { + NazaraInternalError("Wrong texture at location #" + NzString::Number(index)); + return; + } + #endif + + slot.enabled = true; + slot.updated = false; +} + +void NzGLSLShader::OnResourceDestroy(const NzResource* resource, int index) +{ + NazaraUnused(resource); + + auto it = m_textures.find(index); + + #ifdef NAZARA_DEBUG + if (it == m_textures.end()) + { + NazaraInternalError("Invalid index (" + NzString::Number(index) + ')'); + return; + } + #endif + + TextureSlot& slot = it->second; + + #ifdef NAZARA_DEBUG + if (slot.texture != resource) + { + NazaraInternalError("Wrong texture at location #" + NzString::Number(index)); + return; + } + #endif + + slot.enabled = false; +} + +void NzGLSLShader::OnResourceReleased(const NzResource* resource, int index) +{ + if (m_textures.erase(index) == 0) + NazaraInternalError("Texture " + NzString::Pointer(resource) + " not found"); +} diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLShader.hpp index 33ce45aff..35735c678 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLShader.hpp @@ -1,81 +1,81 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_GLSLSHADER_HPP -#define NAZARA_GLSLSHADER_HPP - -#include -#include -#include -#include -#include -#include - -class NzResource; - -class NzGLSLShader : public NzShaderImpl, NzResourceListener -{ - public: - NzGLSLShader(NzShader* parent); - ~NzGLSLShader(); - - bool Bind(); - bool BindTextures(); - - bool Compile(); - - bool Create(); - void Destroy(); - - NzString GetLog() const; - nzShaderLanguage GetLanguage() const; - NzString GetSourceCode(nzShaderType type) const; - int GetUniformLocation(const NzString& name) const; - - bool IsLoaded(nzShaderType type) const; - - bool Load(nzShaderType type, const NzString& source); - bool Lock(); - - bool SendBoolean(int location, bool value); - bool SendDouble(int location, double value); - bool SendFloat(int location, float value); - bool SendInteger(int location, int value); - bool SendMatrix(int location, const NzMatrix4d& matrix); - bool SendMatrix(int location, const NzMatrix4f& matrix); - bool SendTexture(int location, const NzTexture* texture); - bool SendVector(int location, const NzVector2d& vector); - bool SendVector(int location, const NzVector2f& vector); - bool SendVector(int location, const NzVector3d& vector); - bool SendVector(int location, const NzVector3f& vector); - bool SendVector(int location, const NzVector4d& vector); - bool SendVector(int location, const NzVector4f& vector); - - void Unbind(); - void Unlock(); - - private: - void OnResourceCreated(const NzResource* resource, int index) override; - void OnResourceDestroy(const NzResource* resource, int index) override; - void OnResourceReleased(const NzResource* resource, int index) override; - - struct TextureSlot - { - bool enabled; - bool updated = false; - nzUInt8 unit; - const NzTexture* texture; - }; - - mutable std::map m_idCache; - std::map m_textures; - GLuint m_program; - GLuint m_shaders[nzShaderType_Max+1]; - NzShader* m_parent; - NzString m_log; -}; - -#endif // NAZARA_GLSLSHADER_HPPs +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_GLSLSHADER_HPP +#define NAZARA_GLSLSHADER_HPP + +#include +#include +#include +#include +#include +#include + +class NzResource; + +class NzGLSLShader : public NzShaderImpl, NzResourceListener +{ + public: + NzGLSLShader(NzShader* parent); + ~NzGLSLShader(); + + bool Bind(); + bool BindTextures(); + + bool Compile(); + + bool Create(); + void Destroy(); + + NzString GetLog() const; + nzShaderLanguage GetLanguage() const; + NzString GetSourceCode(nzShaderType type) const; + int GetUniformLocation(const NzString& name) const; + + bool IsLoaded(nzShaderType type) const; + + bool Load(nzShaderType type, const NzString& source); + bool Lock(); + + bool SendBoolean(int location, bool value); + bool SendDouble(int location, double value); + bool SendFloat(int location, float value); + bool SendInteger(int location, int value); + bool SendMatrix(int location, const NzMatrix4d& matrix); + bool SendMatrix(int location, const NzMatrix4f& matrix); + bool SendTexture(int location, const NzTexture* texture); + bool SendVector(int location, const NzVector2d& vector); + bool SendVector(int location, const NzVector2f& vector); + bool SendVector(int location, const NzVector3d& vector); + bool SendVector(int location, const NzVector3f& vector); + bool SendVector(int location, const NzVector4d& vector); + bool SendVector(int location, const NzVector4f& vector); + + void Unbind(); + void Unlock(); + + private: + void OnResourceCreated(const NzResource* resource, int index) override; + void OnResourceDestroy(const NzResource* resource, int index) override; + void OnResourceReleased(const NzResource* resource, int index) override; + + struct TextureSlot + { + bool enabled; + bool updated = false; + nzUInt8 unit; + const NzTexture* texture; + }; + + mutable std::map m_idCache; + std::map m_textures; + GLuint m_program; + GLuint m_shaders[nzShaderType_Max+1]; + NzShader* m_parent; + NzString m_log; +}; + +#endif // NAZARA_GLSLSHADER_HPPs diff --git a/src/Nazara/Renderer/HardwareBuffer.cpp b/src/Nazara/Renderer/HardwareBuffer.cpp index 404382c7d..0804cfe4f 100644 --- a/src/Nazara/Renderer/HardwareBuffer.cpp +++ b/src/Nazara/Renderer/HardwareBuffer.cpp @@ -1,218 +1,218 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - using LockRoutine = nzUInt8* (*)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); - - nzUInt8* LockBuffer(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) - { - NazaraUnused(size); - - if (access == nzBufferAccess_DiscardAndWrite) - { - GLint bufSize; - glGetBufferParameteriv(NzOpenGL::BufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize); - - GLint bufUsage; - glGetBufferParameteriv(NzOpenGL::BufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage); - - // On discard le buffer - glBufferData(NzOpenGL::BufferTargetBinding[type], bufSize, nullptr, bufUsage); - } - - void* ptr = glMapBuffer(NzOpenGL::BufferTarget[type], NzOpenGL::BufferLock[access]); - if (ptr) - return reinterpret_cast(ptr) + offset; - else - return nullptr; - } - - nzUInt8* LockBufferRange(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) - { - return reinterpret_cast(glMapBufferRange(NzOpenGL::BufferTarget[type], offset, size, NzOpenGL::BufferLockRange[access])); - } - - nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); - - LockRoutine mapBuffer = LockBufferFirstRun; - - nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) - { - if (glMapBufferRange) - mapBuffer = LockBufferRange; - else - mapBuffer = LockBuffer; - - return mapBuffer(type, access, offset, size); - } -} - -NzHardwareBuffer::NzHardwareBuffer(NzBuffer* parent, nzBufferType type) : -m_type(type), -m_parent(parent) -{ -} - -NzHardwareBuffer::~NzHardwareBuffer() -{ -} - -void NzHardwareBuffer::Bind() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); -} - -bool NzHardwareBuffer::Create(unsigned int size, nzBufferUsage usage) -{ - NzContext::EnsureContext(); - - m_buffer = 0; - glGenBuffers(1, &m_buffer); - - GLint previous; - glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], &previous); - - glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); - glBufferData(NzOpenGL::BufferTarget[m_type], size, nullptr, NzOpenGL::BufferUsage[usage]); - - // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent - if (previous != 0) - glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); - - return true; -} - -void NzHardwareBuffer::Destroy() -{ - NzContext::EnsureContext(); - - glDeleteBuffers(1, &m_buffer); -} - -bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size) -{ - NzContext::EnsureContext(); - - GLuint previous; - glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); - - if (previous != m_buffer) - glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); - - // Il semblerait que glBuffer(Sub)Data soit plus performant que glMapBuffer(Range) en dessous d'un certain seuil - // http://www.stevestreeting.com/2007/03/17/glmapbuffer-vs-glbuffersubdata-the-return/ - if (size < 32*1024) - { - // http://www.opengl.org/wiki/Vertex_Specification_Best_Practices - if (size == m_parent->GetSize()) - glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetUsage()]); // Discard - - glBufferSubData(NzOpenGL::BufferTarget[m_type], offset, size, data); - } - else - { - nzUInt8* ptr = mapBuffer(m_type, (size == m_parent->GetSize()) ? nzBufferAccess_DiscardAndWrite : nzBufferAccess_WriteOnly, offset, size); - if (!ptr) - { - NazaraError("Failed to map buffer"); - return false; - } - - std::memcpy(ptr, data, size); - - if (glUnmapBuffer(NzOpenGL::BufferTarget[m_type]) != GL_TRUE) - { - // Une erreur rare est survenue, nous devons réinitialiser le buffer - NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); - - glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetStorage()]); - - return false; - } - } - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); - - return true; -} - -void* NzHardwareBuffer::GetPointer() -{ - return nullptr; -} - -bool NzHardwareBuffer::IsHardware() const -{ - return true; -} - -void* NzHardwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int size) -{ - NzContext::EnsureContext(); - - // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent - GLuint previous; - glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); - - if (previous != m_buffer) - glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); - - void* ptr = mapBuffer(m_type, access, offset, size); - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérrations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); - - return ptr; -} - -bool NzHardwareBuffer::Unmap() -{ - NzContext::EnsureContext(); - - GLuint previous; - glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); - - if (previous != m_buffer) - glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); - - if (glUnmapBuffer(NzOpenGL::BufferTarget[m_type]) != GL_TRUE) - { - // Une erreur rare est survenue, nous devons réinitialiser le buffer - NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); - - glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetStorage()]); - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); - - return false; - } - - // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) - if (previous != m_buffer && previous != 0) - glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); - - return true; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + using LockRoutine = nzUInt8* (*)(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); + + nzUInt8* LockBuffer(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) + { + NazaraUnused(size); + + if (access == nzBufferAccess_DiscardAndWrite) + { + GLint bufSize; + glGetBufferParameteriv(NzOpenGL::BufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize); + + GLint bufUsage; + glGetBufferParameteriv(NzOpenGL::BufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage); + + // On discard le buffer + glBufferData(NzOpenGL::BufferTargetBinding[type], bufSize, nullptr, bufUsage); + } + + void* ptr = glMapBuffer(NzOpenGL::BufferTarget[type], NzOpenGL::BufferLock[access]); + if (ptr) + return reinterpret_cast(ptr) + offset; + else + return nullptr; + } + + nzUInt8* LockBufferRange(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) + { + return reinterpret_cast(glMapBufferRange(NzOpenGL::BufferTarget[type], offset, size, NzOpenGL::BufferLockRange[access])); + } + + nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size); + + LockRoutine mapBuffer = LockBufferFirstRun; + + nzUInt8* LockBufferFirstRun(nzBufferType type, nzBufferAccess access, unsigned int offset, unsigned int size) + { + if (glMapBufferRange) + mapBuffer = LockBufferRange; + else + mapBuffer = LockBuffer; + + return mapBuffer(type, access, offset, size); + } +} + +NzHardwareBuffer::NzHardwareBuffer(NzBuffer* parent, nzBufferType type) : +m_type(type), +m_parent(parent) +{ +} + +NzHardwareBuffer::~NzHardwareBuffer() +{ +} + +void NzHardwareBuffer::Bind() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); +} + +bool NzHardwareBuffer::Create(unsigned int size, nzBufferUsage usage) +{ + NzContext::EnsureContext(); + + m_buffer = 0; + glGenBuffers(1, &m_buffer); + + GLint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], &previous); + + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + glBufferData(NzOpenGL::BufferTarget[m_type], size, nullptr, NzOpenGL::BufferUsage[usage]); + + // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent + if (previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return true; +} + +void NzHardwareBuffer::Destroy() +{ + NzContext::EnsureContext(); + + glDeleteBuffers(1, &m_buffer); +} + +bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size) +{ + NzContext::EnsureContext(); + + GLuint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); + + if (previous != m_buffer) + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + + // Il semblerait que glBuffer(Sub)Data soit plus performant que glMapBuffer(Range) en dessous d'un certain seuil + // http://www.stevestreeting.com/2007/03/17/glmapbuffer-vs-glbuffersubdata-the-return/ + if (size < 32*1024) + { + // http://www.opengl.org/wiki/Vertex_Specification_Best_Practices + if (size == m_parent->GetSize()) + glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetUsage()]); // Discard + + glBufferSubData(NzOpenGL::BufferTarget[m_type], offset, size, data); + } + else + { + nzUInt8* ptr = mapBuffer(m_type, (size == m_parent->GetSize()) ? nzBufferAccess_DiscardAndWrite : nzBufferAccess_WriteOnly, offset, size); + if (!ptr) + { + NazaraError("Failed to map buffer"); + return false; + } + + std::memcpy(ptr, data, size); + + if (glUnmapBuffer(NzOpenGL::BufferTarget[m_type]) != GL_TRUE) + { + // Une erreur rare est survenue, nous devons réinitialiser le buffer + NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); + + glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetStorage()]); + + return false; + } + } + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return true; +} + +void* NzHardwareBuffer::GetPointer() +{ + return nullptr; +} + +bool NzHardwareBuffer::IsHardware() const +{ + return true; +} + +void* NzHardwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int size) +{ + NzContext::EnsureContext(); + + // Pour ne pas perturber le rendu, on interfère pas avec le binding déjà présent + GLuint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); + + if (previous != m_buffer) + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + + void* ptr = mapBuffer(m_type, access, offset, size); + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérrations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return ptr; +} + +bool NzHardwareBuffer::Unmap() +{ + NzContext::EnsureContext(); + + GLuint previous; + glGetIntegerv(NzOpenGL::BufferTargetBinding[m_type], reinterpret_cast(&previous)); + + if (previous != m_buffer) + glBindBuffer(NzOpenGL::BufferTarget[m_type], m_buffer); + + if (glUnmapBuffer(NzOpenGL::BufferTarget[m_type]) != GL_TRUE) + { + // Une erreur rare est survenue, nous devons réinitialiser le buffer + NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + NzString::Number(glGetError(), 16) + ')'); + + glBufferData(NzOpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, NzOpenGL::BufferUsage[m_parent->GetStorage()]); + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return false; + } + + // Inutile de rebinder s'il n'y avait aucun buffer (Optimise les opérations chaînées) + if (previous != m_buffer && previous != 0) + glBindBuffer(NzOpenGL::BufferTarget[m_type], previous); + + return true; +} diff --git a/src/Nazara/Renderer/OcclusionQuery.cpp b/src/Nazara/Renderer/OcclusionQuery.cpp index 228caab8f..7d8daa81e 100644 --- a/src/Nazara/Renderer/OcclusionQuery.cpp +++ b/src/Nazara/Renderer/OcclusionQuery.cpp @@ -1,98 +1,98 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -NzOcclusionQuery::NzOcclusionQuery() : -m_id(0) -{ - if (IsSupported()) - { - NzContext::EnsureContext(); - - glGenQueries(1, reinterpret_cast(&m_id)); - } - else - { - NazaraError("Occlusion queries not supported"); - return; - } - - #ifdef NAZARA_DEBUG - if (!m_id) - { - NazaraError("Failed to create occlusion query"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzOcclusionQuery::~NzOcclusionQuery() -{ - if (m_id) - { - NzContext::EnsureContext(); - - GLuint query = static_cast(m_id); - glDeleteQueries(1, &query); - } -} - -void NzOcclusionQuery::Begin() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBeginQuery(GL_SAMPLES_PASSED, m_id); -} - -void NzOcclusionQuery::End() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glEndQuery(GL_SAMPLES_PASSED); -} - -unsigned int NzOcclusionQuery::GetResult() const -{ - NzContext::EnsureContext(); - - GLuint result; - glGetQueryObjectuiv(m_id, GL_QUERY_RESULT, &result); - - return result; -} - -bool NzOcclusionQuery::IsResultAvailable() const -{ - NzContext::EnsureContext(); - - GLint available; - glGetQueryObjectiv(m_id, GL_QUERY_RESULT_AVAILABLE, &available); - - return available == GL_TRUE; -} - -bool NzOcclusionQuery::IsSupported() -{ - return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +NzOcclusionQuery::NzOcclusionQuery() : +m_id(0) +{ + if (IsSupported()) + { + NzContext::EnsureContext(); + + glGenQueries(1, reinterpret_cast(&m_id)); + } + else + { + NazaraError("Occlusion queries not supported"); + return; + } + + #ifdef NAZARA_DEBUG + if (!m_id) + { + NazaraError("Failed to create occlusion query"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzOcclusionQuery::~NzOcclusionQuery() +{ + if (m_id) + { + NzContext::EnsureContext(); + + GLuint query = static_cast(m_id); + glDeleteQueries(1, &query); + } +} + +void NzOcclusionQuery::Begin() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glBeginQuery(GL_SAMPLES_PASSED, m_id); +} + +void NzOcclusionQuery::End() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glEndQuery(GL_SAMPLES_PASSED); +} + +unsigned int NzOcclusionQuery::GetResult() const +{ + NzContext::EnsureContext(); + + GLuint result; + glGetQueryObjectuiv(m_id, GL_QUERY_RESULT, &result); + + return result; +} + +bool NzOcclusionQuery::IsResultAvailable() const +{ + NzContext::EnsureContext(); + + GLint available; + glGetQueryObjectiv(m_id, GL_QUERY_RESULT_AVAILABLE, &available); + + return available == GL_TRUE; +} + +bool NzOcclusionQuery::IsSupported() +{ + return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery); +} diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 452db653b..4f4ffedf7 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1,1014 +1,1014 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - #ifdef NAZARA_PLATFORM_WINDOWS - HMODULE openGLlibrary; - #endif - - NzOpenGLFunc LoadEntry(const char* name, bool launchException = true) - { - #if defined(NAZARA_PLATFORM_WINDOWS) - NzOpenGLFunc entry = reinterpret_cast(wglGetProcAddress(name)); - if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 - entry = reinterpret_cast(GetProcAddress(openGLlibrary, name)); - #elif defined(NAZARA_PLATFORM_LINUX) - NzOpenGLFunc entry = reinterpret_cast(glXGetProcAddress(name)); - #else - #error OS not handled - #endif - - if (!entry && launchException) - { - std::ostringstream oss; - oss << "failed to load \"" << name << '"'; - - throw std::runtime_error(oss.str()); - } - - return entry; - } - - bool LoadLibrary() - { - #ifdef NAZARA_PLATFORM_WINDOWS - openGLlibrary = ::LoadLibraryA("opengl32.dll"); - - return openGLlibrary != nullptr; - #else - return true; - #endif - } - - void UnloadLibrary() - { - #ifdef NAZARA_PLATFORM_WINDOWS - FreeLibrary(openGLlibrary); - #endif - } - - std::set openGLextensionSet; - bool openGLextensions[nzOpenGLExtension_Max+1] = {false}; - unsigned int openGLversion = 0; - - bool LoadExtensionsString(const NzString& extensionString) - { - if (extensionString.IsEmpty()) - { - NazaraError("Unable to get extension string"); - return false; - } - - // On peut sûrement faire plus rapide mais comme ça ne se fait qu'une fois et que NzString implémente le COW... - std::vector ext; - extensionString.Split(ext); - - for (std::vector::iterator it = ext.begin(); it != ext.end(); ++it) - openGLextensionSet.insert(*it); - - return true; - } - - bool LoadExtensions3() - { - GLint extensionCount = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); - - if (extensionCount <= 0) - { - NazaraError("Unable to get extension count"); - return false; - } - - for (int i = 0; i < extensionCount; ++i) - { - NzString extension(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); - if (extension.IsEmpty()) - { - NazaraWarning("Unable to get extension #" + NzString::Number(i)); - continue; - } - - openGLextensionSet.insert(extension); - } - - return true; - } -} - -namespace NzOpenGL -{ - NzOpenGLFunc GetEntry(const NzString& entryPoint) - { - return LoadEntry(entryPoint.GetConstBuffer(), false); - } - - unsigned int GetVersion() - { - return openGLversion; - } - - bool Initialize() - { - if (!LoadLibrary()) - { - NazaraError("Failed to load OpenGL library"); - return false; - } - - // Le chargement des fonctions OpenGL nécessite un contexte OpenGL - NzContextParameters parameters; - parameters.majorVersion = 2; - parameters.minorVersion = 0; - parameters.shared = false; - - /* - Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser - Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant - de créer le second avec les bons paramètres. - - Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise. - */ - - /****************************************Initialisation****************************************/ - - NzContext loadContext; - if (!loadContext.Create(parameters)) - { - NazaraError("Failed to create load context"); - Uninitialize(); - - return false; - } - - #if defined(NAZARA_PLATFORM_WINDOWS) - wglCreateContextAttribs = reinterpret_cast(LoadEntry("wglCreateContextAttribsARB", false)); - wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatARB", false)); - if (!wglChoosePixelFormat) - wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatEXT", false)); - #elif defined(NAZARA_PLATFORM_LINUX) - glXCreateContextAttribs = reinterpret_cast(LoadEntry("glXCreateContextAttribsARB", false)); - #endif - - // Récupération de la version d'OpenGL - // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée - // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... - glGetString = reinterpret_cast(LoadEntry("glGetString", false)); - if (!glGetString) - { - NazaraError("Unable to load OpenGL: failed to load glGetString"); - Uninitialize(); - - return false; - } - - const GLubyte* version = glGetString(GL_VERSION); - if (!version) - { - NazaraError("Unable to retrieve OpenGL version"); - Uninitialize(); - - return false; - } - - unsigned int major = version[0] - '0'; - unsigned int minor = version[2] - '0'; - - if (major == 0 || major > 9) - { - NazaraError("Unable to retrieve OpenGL major version"); - return false; - } - - if (minor > 9) - { - NazaraWarning("Unable to retrieve OpenGL minor version (using 0)"); - minor = 0; - } - - openGLversion = major*100 + minor*10; - if (openGLversion < 200) - { - NazaraError("OpenGL version is too low, please upgrade your drivers or your video card"); - Uninitialize(); - - return false; - } - - parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output) - parameters.majorVersion = NzContextParameters::defaultMajorVersion = major; - parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor; - - if (!loadContext.Create(parameters)) // Destruction implicite du premier contexte - { - NazaraError("Failed to create load context"); - Uninitialize(); - - return false; - } - - /****************************************Noyau****************************************/ - - try - { - glActiveTexture = reinterpret_cast(LoadEntry("glActiveTexture")); - glAttachShader = reinterpret_cast(LoadEntry("glAttachShader")); - glBeginQuery = reinterpret_cast(LoadEntry("glBeginQuery")); - glBindAttribLocation = reinterpret_cast(LoadEntry("glBindAttribLocation")); - glBindBuffer = reinterpret_cast(LoadEntry("glBindBuffer")); - glBindTexture = reinterpret_cast(LoadEntry("glBindTexture")); - glBlendFunc = reinterpret_cast(LoadEntry("glBlendFunc")); - glBufferData = reinterpret_cast(LoadEntry("glBufferData")); - glBufferSubData = reinterpret_cast(LoadEntry("glBufferSubData")); - glClear = reinterpret_cast(LoadEntry("glClear")); - glClearColor = reinterpret_cast(LoadEntry("glClearColor")); - glClearDepth = reinterpret_cast(LoadEntry("glClearDepth")); - glClearStencil = reinterpret_cast(LoadEntry("glClearStencil")); - glCreateProgram = reinterpret_cast(LoadEntry("glCreateProgram")); - glCreateShader = reinterpret_cast(LoadEntry("glCreateShader")); - glColorMask = reinterpret_cast(LoadEntry("glColorMask")); - glCullFace = reinterpret_cast(LoadEntry("glCullFace")); - glCompileShader = reinterpret_cast(LoadEntry("glCompileShader")); - glCopyTexSubImage2D = reinterpret_cast(LoadEntry("glCopyTexSubImage2D")); - glDeleteBuffers = reinterpret_cast(LoadEntry("glDeleteBuffers")); - glDeleteQueries = reinterpret_cast(LoadEntry("glDeleteQueries")); - glDeleteProgram = reinterpret_cast(LoadEntry("glDeleteProgram")); - glDeleteShader = reinterpret_cast(LoadEntry("glDeleteShader")); - glDeleteTextures = reinterpret_cast(LoadEntry("glDeleteTextures")); - glDepthFunc = reinterpret_cast(LoadEntry("glDepthFunc")); - glDepthMask = reinterpret_cast(LoadEntry("glDepthMask")); - glDisable = reinterpret_cast(LoadEntry("glDisable")); - glDisableVertexAttribArray = reinterpret_cast(LoadEntry("glDisableVertexAttribArray")); - glDrawArrays = reinterpret_cast(LoadEntry("glDrawArrays")); - glDrawBuffer = reinterpret_cast(LoadEntry("glDrawBuffer")); - glDrawBuffers = reinterpret_cast(LoadEntry("glDrawBuffers")); - glDrawElements = reinterpret_cast(LoadEntry("glDrawElements")); - glFlush = reinterpret_cast(LoadEntry("glFlush")); - glEnable = reinterpret_cast(LoadEntry("glEnable")); - glEnableVertexAttribArray = reinterpret_cast(LoadEntry("glEnableVertexAttribArray")); - glEndQuery = reinterpret_cast(LoadEntry("glEndQuery")); - glGenBuffers = reinterpret_cast(LoadEntry("glGenBuffers")); - glGenQueries = reinterpret_cast(LoadEntry("glGenQueries")); - glGenTextures = reinterpret_cast(LoadEntry("glGenTextures")); - glGetBufferParameteriv = reinterpret_cast(LoadEntry("glGetBufferParameteriv")); - glGetError = reinterpret_cast(LoadEntry("glGetError")); - glGetQueryiv = reinterpret_cast(LoadEntry("glGetQueryiv")); - glGetQueryObjectiv = reinterpret_cast(LoadEntry("glGetQueryObjectiv")); - glGetQueryObjectuiv = reinterpret_cast(LoadEntry("glGetQueryObjectuiv")); - glGetIntegerv = reinterpret_cast(LoadEntry("glGetIntegerv")); - glGetProgramiv = reinterpret_cast(LoadEntry("glGetProgramiv")); - glGetProgramInfoLog = reinterpret_cast(LoadEntry("glGetProgramInfoLog")); - glGetShaderInfoLog = reinterpret_cast(LoadEntry("glGetShaderInfoLog")); - glGetShaderiv = reinterpret_cast(LoadEntry("glGetShaderiv")); - glGetShaderSource = reinterpret_cast(LoadEntry("glGetShaderSource")); - glGetTexImage = reinterpret_cast(LoadEntry("glGetTexImage")); - glGetTexLevelParameterfv = reinterpret_cast(LoadEntry("glGetTexLevelParameterfv")); - glGetTexLevelParameteriv = reinterpret_cast(LoadEntry("glGetTexLevelParameteriv")); - glGetTexParameterfv = reinterpret_cast(LoadEntry("glGetTexParameterfv")); - glGetTexParameteriv = reinterpret_cast(LoadEntry("glGetTexParameteriv")); - glGetUniformLocation = reinterpret_cast(LoadEntry("glGetUniformLocation")); - glLinkProgram = reinterpret_cast(LoadEntry("glLinkProgram")); - glMapBuffer = reinterpret_cast(LoadEntry("glMapBuffer")); - glPixelStorei = reinterpret_cast(LoadEntry("glPixelStorei")); - glPolygonMode = reinterpret_cast(LoadEntry("glPolygonMode")); - glReadPixels = reinterpret_cast(LoadEntry("glReadPixels")); - glScissor = reinterpret_cast(LoadEntry("glScissor")); - glShaderSource = reinterpret_cast(LoadEntry("glShaderSource")); - glStencilFunc = reinterpret_cast(LoadEntry("glStencilFunc")); - glStencilOp = reinterpret_cast(LoadEntry("glStencilOp")); - glTexImage2D = reinterpret_cast(LoadEntry("glTexImage2D")); - glTexImage3D = reinterpret_cast(LoadEntry("glTexImage3D")); - glTexParameterf = reinterpret_cast(LoadEntry("glTexParameterf")); - glTexParameteri = reinterpret_cast(LoadEntry("glTexParameteri")); - glTexSubImage2D = reinterpret_cast(LoadEntry("glTexSubImage2D")); - glTexSubImage3D = reinterpret_cast(LoadEntry("glTexSubImage3D")); - glUniform1f = reinterpret_cast(LoadEntry("glUniform1f")); - glUniform1i = reinterpret_cast(LoadEntry("glUniform1i")); - glUniform2fv = reinterpret_cast(LoadEntry("glUniform2fv")); - glUniform3fv = reinterpret_cast(LoadEntry("glUniform3fv")); - glUniform4fv = reinterpret_cast(LoadEntry("glUniform4fv")); - glUniformMatrix4fv = reinterpret_cast(LoadEntry("glUniformMatrix4fv")); - glUnmapBuffer = reinterpret_cast(LoadEntry("glUnmapBuffer")); - glUseProgram = reinterpret_cast(LoadEntry("glUseProgram")); - glVertexAttrib4f = reinterpret_cast(LoadEntry("glVertexAttrib4f")); - glVertexAttribPointer = reinterpret_cast(LoadEntry("glVertexAttribPointer")); - glViewport = reinterpret_cast(LoadEntry("glViewport")); - } - catch (const std::exception& e) - { - NazaraError("Unable to load OpenGL: " + NzString(e.what())); - Uninitialize(); - - return false; - } - - /****************************************Extensions****************************************/ - - // Fonctions optionnelles - glBindFragDataLocation = reinterpret_cast(LoadEntry("glBindFragDataLocation", false)); - if (!glBindFragDataLocation) - glBindFragDataLocation = reinterpret_cast(LoadEntry("glBindFragDataLocationEXT", false)); - - glGetStringi = reinterpret_cast(LoadEntry("glGetStringi", false)); - glMapBufferRange = reinterpret_cast(LoadEntry("glMapBufferRange", false)); - - #if defined(NAZARA_PLATFORM_WINDOWS) - wglGetExtensionsStringARB = reinterpret_cast(LoadEntry("wglGetExtensionsStringARB", false)); - wglGetExtensionsStringEXT = reinterpret_cast(LoadEntry("wglGetExtensionsStringEXT", false)); - wglSwapInterval = reinterpret_cast(LoadEntry("wglSwapIntervalEXT", false)); - #elif defined(NAZARA_PLATFORM_LINUX) - glXSwapInterval = reinterpret_cast(LoadEntry("glXSwapIntervalSGI", false)); - #endif - - if (!glGetStringi || !LoadExtensions3()) - { - if (openGLversion >= 300) // Dans le cas contraire c'est normal - NazaraWarning("Failed to load OpenGL 3 extension system, switching to OpenGL 2 extension system..."); - - if (!LoadExtensionsString(reinterpret_cast(glGetString(GL_EXTENSIONS)))) - NazaraWarning("Failed to load extension system"); - } - - #ifdef NAZARA_PLATFORM_WINDOWS - { - bool loaded; - if (wglGetExtensionsStringARB) - loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringARB(wglGetCurrentDC()))); - else if (wglGetExtensionsStringEXT) - loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringEXT())); - else - loaded = false; - - if (!loaded) - NazaraWarning("Failed to load wgl extension string"); - } - #endif - - // AnisotropicFilter - openGLextensions[nzOpenGLExtension_AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic"); - - // DebugOutput - if (openGLversion >= 430 || IsSupported("GL_KHR_debug")) - { - try - { - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); - glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); - glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); - glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); - - openGLextensions[nzOpenGLExtension_DebugOutput] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load GL_KHR_debug: " + NzString(e.what())); - } - } - - if (!openGLextensions[nzOpenGLExtension_DebugOutput] && IsSupported("GL_ARB_debug_output")) - { - try - { - glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); - glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControlARB")); - glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsertARB")); - glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLogARB")); - - openGLextensions[nzOpenGLExtension_DebugOutput] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load GL_ARB_debug_output: " + NzString(e.what())); - } - } - - // FP64 - if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) - { - try - { - glUniform1d = reinterpret_cast(LoadEntry("glUniform1d")); - glUniform2dv = reinterpret_cast(LoadEntry("glUniform2dv")); - glUniform3dv = reinterpret_cast(LoadEntry("glUniform3dv")); - glUniform4dv = reinterpret_cast(LoadEntry("glUniform4dv")); - - openGLextensions[nzOpenGLExtension_FP64] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_gpu_shader_fp64: " + NzString(e.what())); - } - } - - // FrameBufferObject - if (openGLversion >= 300 || IsSupported("GL_ARB_framebuffer_object")) - { - try - { - glBindFramebuffer = reinterpret_cast(LoadEntry("glBindFramebuffer")); - glBindRenderbuffer = reinterpret_cast(LoadEntry("glBindRenderbuffer")); - glCheckFramebufferStatus = reinterpret_cast(LoadEntry("glCheckFramebufferStatus")); - glDeleteFramebuffers = reinterpret_cast(LoadEntry("glDeleteFramebuffers")); - glDeleteRenderbuffers = reinterpret_cast(LoadEntry("glDeleteRenderbuffers")); - glFramebufferRenderbuffer = reinterpret_cast(LoadEntry("glFramebufferRenderbuffer")); - glFramebufferTexture = reinterpret_cast(LoadEntry("glFramebufferTexture")); - glFramebufferTexture1D = reinterpret_cast(LoadEntry("glFramebufferTexture1D")); - glFramebufferTexture2D = reinterpret_cast(LoadEntry("glFramebufferTexture2D")); - glFramebufferTexture3D = reinterpret_cast(LoadEntry("glFramebufferTexture3D")); - glFramebufferTextureLayer = reinterpret_cast(LoadEntry("glFramebufferTextureLayer")); - glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmap")); - glGenFramebuffers = reinterpret_cast(LoadEntry("glGenFramebuffers")); - glGenRenderbuffers = reinterpret_cast(LoadEntry("glGenRenderbuffers")); - glRenderbufferStorage = reinterpret_cast(LoadEntry("glRenderbufferStorage")); - - openGLextensions[nzOpenGLExtension_FrameBufferObject] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")"); - } - } - - // PixelBufferObject - openGLextensions[nzOpenGLExtension_PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object")); - - // SeparateShaderObjects - if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects")) - { - glProgramUniform1f = reinterpret_cast(LoadEntry("glProgramUniform1f")); - glProgramUniform1i = reinterpret_cast(LoadEntry("glProgramUniform1i")); - glProgramUniform2fv = reinterpret_cast(LoadEntry("glProgramUniform2fv")); - glProgramUniform3fv = reinterpret_cast(LoadEntry("glProgramUniform3fv")); - glProgramUniform4fv = reinterpret_cast(LoadEntry("glProgramUniform4fv")); - glProgramUniformMatrix4fv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4fv")); - - // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double - if (openGLextensions[nzOpenGLExtension_FP64]) - { - glProgramUniform1d = reinterpret_cast(LoadEntry("glProgramUniform1d")); - glProgramUniform2dv = reinterpret_cast(LoadEntry("glProgramUniform2dv")); - glProgramUniform3dv = reinterpret_cast(LoadEntry("glProgramUniform3dv")); - glProgramUniform4dv = reinterpret_cast(LoadEntry("glProgramUniform4dv")); - glProgramUniformMatrix4dv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4dv")); - } - - openGLextensions[nzOpenGLExtension_SeparateShaderObjects] = true; - } - - // TextureArray - openGLextensions[nzOpenGLExtension_TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array")); - - // TextureCompression_s3tc - openGLextensions[nzOpenGLExtension_TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc"); - - // TextureStorage - if (openGLversion >= 420 || IsSupported("GL_ARB_texture_storage")) - { - try - { - glTexStorage1D = reinterpret_cast(LoadEntry("glTexStorage1D")); - glTexStorage2D = reinterpret_cast(LoadEntry("glTexStorage2D")); - glTexStorage3D = reinterpret_cast(LoadEntry("glTexStorage3D")); - - openGLextensions[nzOpenGLExtension_TextureStorage] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_texture_storage: " + NzString(e.what())); - } - } - - // VertexArrayObject - if (openGLversion >= 300 || IsSupported("GL_ARB_vertex_array_object")) - { - try - { - glBindVertexArray = reinterpret_cast(LoadEntry("glBindVertexArray")); - glDeleteVertexArrays = reinterpret_cast(LoadEntry("glDeleteVertexArrays")); - glGenVertexArrays = reinterpret_cast(LoadEntry("glGenVertexArrays")); - - openGLextensions[nzOpenGLExtension_VertexArrayObject] = true; - } - catch (const std::exception& e) - { - NazaraWarning("Failed to load ARB_vertex_array_object: " + NzString(e.what())); - } - } - - // Fonctions de substitut - if (!glGenerateMipmap) - glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmapEXT", false)); - - /****************************************Contexte de référence****************************************/ - - ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) - if (!NzContext::Initialize()) - { - NazaraError("Failed to initialize contexts"); - Uninitialize(); - - return false; - } - - NzContextParameters::defaultShareContext = NzContext::GetReference(); - - return true; - } - - bool IsSupported(nzOpenGLExtension extension) - { - return openGLextensions[extension]; - } - - bool IsSupported(const NzString& string) - { - return openGLextensionSet.find(string) != openGLextensionSet.end(); - } - - bool TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType type) - { - switch (pixelFormat) - { - case nzPixelFormat_BGR8: - format->dataFormat = GL_BGR; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGB8; - return true; - - case nzPixelFormat_BGRA8: - format->dataFormat = GL_BGRA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGBA8; - return true; - - case nzPixelFormat_DXT1: - format->dataFormat = GL_RGB; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - return true; - - case nzPixelFormat_DXT3: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - return true; - - case nzPixelFormat_DXT5: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - return true; - - case nzPixelFormat_L8: - case nzPixelFormat_LA8: - return false; - - case nzPixelFormat_RGB5A1: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_SHORT_5_5_5_1; - format->internalFormat = GL_RGB5_A1; - return true; - - case nzPixelFormat_RGB8: - format->dataFormat = GL_RGB; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGB8; - return true; - - case nzPixelFormat_RGBA4: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_SHORT_4_4_4_4; - format->internalFormat = GL_RGBA4; - return true; - - case nzPixelFormat_RGBA8: - format->dataFormat = GL_RGBA; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_RGBA8; - return true; - - case nzPixelFormat_Depth16: - format->dataFormat = GL_DEPTH_COMPONENT; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_DEPTH_COMPONENT16; - return true; - - case nzPixelFormat_Depth24: - format->dataFormat = GL_DEPTH_COMPONENT; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_DEPTH_COMPONENT24; - return true; - - case nzPixelFormat_Depth24Stencil8: - format->dataFormat = GL_DEPTH_STENCIL; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_DEPTH24_STENCIL8; - return true; - - case nzPixelFormat_Depth32: - format->dataFormat = GL_DEPTH_COMPONENT; - format->dataType = GL_UNSIGNED_BYTE; - format->internalFormat = GL_DEPTH_COMPONENT32; - return true; - - case nzPixelFormat_Stencil1: - if (type == FormatType_Texture) // Les formats de stencil ne sont pas supportés par les textures - return false; - else - { - format->dataFormat = GL_NONE; - format->dataType = GL_NONE; - format->internalFormat = GL_STENCIL_INDEX1; - return true; - } - - case nzPixelFormat_Stencil4: - if (type == FormatType_Texture) - return false; - else - { - format->dataFormat = GL_NONE; - format->dataType = GL_NONE; - format->internalFormat = GL_STENCIL_INDEX4; - return true; - } - - case nzPixelFormat_Stencil8: - if (type == FormatType_Texture) - return false; - else - { - format->dataFormat = GL_NONE; - format->dataType = GL_NONE; - format->internalFormat = GL_STENCIL_INDEX8; - return true; - } - - case nzPixelFormat_Stencil16: - if (type == FormatType_Texture) - return false; - else - { - format->dataFormat = GL_NONE; - format->dataType = GL_NONE; - format->internalFormat = GL_STENCIL_INDEX16; - return true; - } - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - return false; - } - - void Uninitialize() - { - NzContext::Uninitialize(); - - for (bool& ext : openGLextensions) - ext = false; - - openGLextensionSet.clear(); - openGLversion = 0; - - UnloadLibrary(); - } - - GLenum Attachment[nzAttachmentPoint_Max+1] = - { - GL_COLOR_ATTACHMENT0, // nzAttachmentPoint_Color - GL_DEPTH_ATTACHMENT, // nzAttachmentPoint_Depth - GL_DEPTH_STENCIL_ATTACHMENT, // nzAttachmentPoint_DepthStencil - GL_STENCIL_ATTACHMENT // nzAttachmentPoint_Stencil - }; - - nzUInt8 AttributeIndex[nzElementUsage_Max+1] = - { - 2, // nzElementUsage_Diffuse - 1, // nzElementUsage_Normal - 0, // nzElementUsage_Position - 3, // nzElementUsage_Tangent - - 4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible) - }; - - GLenum BlendFunc[nzBlendFunc_Max+1] = - { - GL_DST_ALPHA, // nzBlendFunc_DestAlpha - GL_DST_COLOR, // nzBlendFunc_DestColor - GL_SRC_ALPHA, // nzBlendFunc_SrcAlpha - GL_SRC_COLOR, // nzBlendFunc_SrcColor - GL_ONE_MINUS_DST_ALPHA, // nzBlendFunc_InvDestAlpha - GL_ONE_MINUS_DST_COLOR, // nzBlendFunc_InvDestColor - GL_ONE_MINUS_SRC_ALPHA, // nzBlendFunc_InvSrcAlpha - GL_ONE_MINUS_SRC_COLOR, // nzBlendFunc_InvSrcColor - GL_ONE, // nzBlendFunc_One - GL_ZERO // nzBlendFunc_Zero - }; - - GLenum BufferLock[nzBufferAccess_Max+1] = - { - GL_WRITE_ONLY, // nzBufferAccess_DiscardAndWrite - GL_READ_ONLY, // nzBufferAccess_ReadOnly - GL_READ_WRITE, // nzBufferAccess_ReadWrite - GL_WRITE_ONLY // nzBufferAccess_WriteOnly - }; - - GLenum BufferLockRange[nzBufferAccess_Max+1] = - { - GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_DiscardAndWrite - GL_MAP_READ_BIT, // nzBufferAccess_ReadOnly - GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_ReadWrite - GL_MAP_WRITE_BIT // nzBufferAccess_WriteOnly - }; - - GLenum BufferTarget[nzBufferType_Max+1] = - { - GL_ELEMENT_ARRAY_BUFFER, // nzBufferType_Index, - GL_ARRAY_BUFFER, // nzBufferType_Vertex - }; - - GLenum BufferTargetBinding[nzBufferType_Max+1] = - { - GL_ELEMENT_ARRAY_BUFFER_BINDING, // nzBufferType_Index, - GL_ARRAY_BUFFER_BINDING, // nzBufferType_Vertex - }; - - GLenum BufferUsage[nzBufferUsage_Max+1] = - { - // J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus" - // Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?) - // Source: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=160839 - GL_DYNAMIC_DRAW, // nzBufferUsage_Dynamic - GL_STATIC_DRAW // nzBufferUsage_Static - }; - - GLenum CubemapFace[6] = - { - GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX - GL_TEXTURE_CUBE_MAP_NEGATIVE_X, // nzCubemapFace_NegativeX - GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // nzCubemapFace_PositiveY - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // nzCubemapFace_NegativeY - GL_TEXTURE_CUBE_MAP_POSITIVE_Z, // nzCubemapFace_PositiveZ - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z // nzCubemapFace_NegativeZ - }; - - GLenum ElementType[nzElementType_Max+1] = - { - GL_UNSIGNED_BYTE, // nzElementType_Color - GL_DOUBLE, // nzElementType_Double1 - GL_DOUBLE, // nzElementType_Double2 - GL_DOUBLE, // nzElementType_Double3 - GL_DOUBLE, // nzElementType_Double4 - GL_FLOAT, // nzElementType_Float1 - GL_FLOAT, // nzElementType_Float2 - GL_FLOAT, // nzElementType_Float3 - GL_FLOAT // nzElementType_Float4 - }; - - GLenum FaceCulling[nzFaceCulling_Max+1] = - { - GL_BACK, // nzFaceCulling_Back - GL_FRONT, // nzFaceCulling_Front - GL_FRONT_AND_BACK // nzFaceCulling_FrontAndBack - }; - - GLenum FaceFilling[nzFaceFilling_Max+1] = - { - GL_POINT, // nzFaceFilling_Point - GL_LINE, // nzFaceFilling_Line - GL_FILL // nzFaceFilling_Fill - }; - - GLenum PrimitiveType[nzPrimitiveType_Max+1] = - { - GL_LINES, // nzPrimitiveType_LineList, - GL_LINE_STRIP, // nzPrimitiveType_LineStrip, - GL_POINTS, // nzPrimitiveType_PointList, - GL_TRIANGLES, // nzPrimitiveType_TriangleList, - GL_TRIANGLE_STRIP, // nzPrimitiveType_TriangleStrip, - GL_TRIANGLE_FAN // nzPrimitiveType_TriangleFan - }; - - GLenum RendererComparison[nzRendererComparison_Max+1] = - { - GL_ALWAYS, // nzRendererComparison_Always - GL_EQUAL, // nzRendererComparison_Equal - GL_GREATER, // nzRendererComparison_Greater - GL_GEQUAL, // nzRendererComparison_GreaterOrEqual - GL_LESS, // nzRendererComparison_Less - GL_LEQUAL, // nzRendererComparison_LessOrEqual - GL_NEVER // nzRendererComparison_Never - }; - - GLenum RendererParameter[nzRendererParameter_Max+1] = - { - GL_BLEND, // nzRendererParameter_Blend - GL_NONE, // nzRendererParameter_ColorWrite - GL_DEPTH_TEST, // nzRendererParameter_DepthTest - GL_NONE, // nzRendererParameter_DepthWrite - GL_CULL_FACE, // nzRendererParameter_FaceCulling - GL_STENCIL_TEST // nzRendererParameter_Stencil - }; - - GLenum ShaderType[nzShaderType_Max+1] = - { - GL_FRAGMENT_SHADER, // nzShaderType_Fragment - GL_GEOMETRY_SHADER, // nzShaderType_Geometry - GL_VERTEX_SHADER // nzShaderType_Vertex - }; - - GLenum StencilOperation[nzStencilOperation_Max+1] = - { - GL_DECR, // nzStencilOperation_Decrement - GL_DECR_WRAP, // nzStencilOperation_DecrementToSaturation - GL_INCR, // nzStencilOperation_Increment - GL_INCR_WRAP, // nzStencilOperation_IncrementToSaturation - GL_INVERT, // nzStencilOperation_Invert - GL_KEEP, // nzStencilOperation_Keep - GL_REPLACE, // nzStencilOperation_Replace - GL_ZERO // nzStencilOperation_Zero - }; - - GLenum TextureTarget[nzImageType_Max+1] - { - GL_TEXTURE_1D, // nzImageType_1D - GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array - GL_TEXTURE_2D, // nzImageType_2D - GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array - GL_TEXTURE_3D, // nzImageType_3D - GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap - }; - - GLenum TextureTargetBinding[nzImageType_Max+1] - { - GL_TEXTURE_BINDING_1D, // nzImageType_1D - GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D_Array - GL_TEXTURE_BINDING_2D, // nzImageType_2D - GL_TEXTURE_BINDING_2D_ARRAY, // nzImageType_2D_Array - GL_TEXTURE_BINDING_3D, // nzImageType_3D - GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap - }; - - GLenum TextureTargetProxy[nzImageType_Max+1] - { - GL_PROXY_TEXTURE_1D, // nzImageType_1D - GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array - GL_PROXY_TEXTURE_2D, // nzImageType_2D - GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array - GL_PROXY_TEXTURE_3D, // nzImageType_3D - GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap - }; -} - -PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; -PFNGLATTACHSHADERPROC glAttachShader = nullptr; -PFNGLBEGINQUERYPROC glBeginQuery = nullptr; -PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; -PFNGLBINDBUFFERPROC glBindBuffer = nullptr; -PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; -PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr; -PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; -PFNGLBINDTEXTUREPROC glBindTexture = nullptr; -PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; -PFNGLBLENDFUNCPROC glBlendFunc = nullptr; -PFNGLBUFFERDATAPROC glBufferData = nullptr; -PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; -PFNGLCLEARPROC glClear = nullptr; -PFNGLCLEARCOLORPROC glClearColor = nullptr; -PFNGLCLEARDEPTHPROC glClearDepth = nullptr; -PFNGLCLEARSTENCILPROC glClearStencil = nullptr; -PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; -PFNGLCREATESHADERPROC glCreateShader = nullptr; -PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; -PFNGLCOLORMASKPROC glColorMask = nullptr; -PFNGLCULLFACEPROC glCullFace = nullptr; -PFNGLCOMPILESHADERPROC glCompileShader = nullptr; -PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; -PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; -PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; -PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; -PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; -PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; -PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; -PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; -PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; -PFNGLDELETESHADERPROC glDeleteShader = nullptr; -PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; -PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; -PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; -PFNGLDEPTHMASKPROC glDepthMask = nullptr; -PFNGLDISABLEPROC glDisable = nullptr; -PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; -PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; -PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; -PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; -PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; -PFNGLENDQUERYPROC glEndQuery = nullptr; -PFNGLFLUSHPROC glFlush = nullptr; -PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; -PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture = nullptr; -PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = nullptr; -PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; -PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = nullptr; -PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = nullptr; -PFNGLENABLEPROC glEnable = nullptr; -PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; -PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; -PFNGLGENBUFFERSPROC glGenBuffers = nullptr; -PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; -PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; -PFNGLGENQUERIESPROC glGenQueries = nullptr; -PFNGLGENTEXTURESPROC glGenTextures = nullptr; -PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; -PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; -PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; -PFNGLGETERRORPROC glGetError = nullptr; -PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; -PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; -PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; -PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; -PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; -PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; -PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; -PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; -PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; -PFNGLGETSTRINGPROC glGetString = nullptr; -PFNGLGETSTRINGIPROC glGetStringi = nullptr; -PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; -PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; -PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; -PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; -PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; -PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; -PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; -PFNGLMAPBUFFERPROC glMapBuffer = nullptr; -PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; -PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; -PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; -PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; -PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; -PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; -PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; -PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; -PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; -PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; -PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; -PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; -PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; -PFNGLREADPIXELSPROC glReadPixels = nullptr; -PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; -PFNGLSCISSORPROC glScissor = nullptr; -PFNGLSHADERSOURCEPROC glShaderSource = nullptr; -PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; -PFNGLSTENCILOPPROC glStencilOp = nullptr; -PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; -PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; -PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; -PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; -PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; -PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; -PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; -PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; -PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; -PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; -PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; -PFNGLUNIFORM1DPROC glUniform1d = nullptr; -PFNGLUNIFORM1FPROC glUniform1f = nullptr; -PFNGLUNIFORM1IPROC glUniform1i = nullptr; -PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; -PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; -PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; -PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; -PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; -PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; -PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; -PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; -PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; -PFNGLUSEPROGRAMPROC glUseProgram = nullptr; -PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; -PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; -PFNGLVIEWPORTPROC glViewport = nullptr; -#if defined(NAZARA_PLATFORM_WINDOWS) -PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; -PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; -PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; -PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; -PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; -#elif defined(NAZARA_PLATFORM_LINUX) -PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; -PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = nullptr; -#endif +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + #ifdef NAZARA_PLATFORM_WINDOWS + HMODULE openGLlibrary; + #endif + + NzOpenGLFunc LoadEntry(const char* name, bool launchException = true) + { + #if defined(NAZARA_PLATFORM_WINDOWS) + NzOpenGLFunc entry = reinterpret_cast(wglGetProcAddress(name)); + if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 + entry = reinterpret_cast(GetProcAddress(openGLlibrary, name)); + #elif defined(NAZARA_PLATFORM_LINUX) + NzOpenGLFunc entry = reinterpret_cast(glXGetProcAddress(name)); + #else + #error OS not handled + #endif + + if (!entry && launchException) + { + std::ostringstream oss; + oss << "failed to load \"" << name << '"'; + + throw std::runtime_error(oss.str()); + } + + return entry; + } + + bool LoadLibrary() + { + #ifdef NAZARA_PLATFORM_WINDOWS + openGLlibrary = ::LoadLibraryA("opengl32.dll"); + + return openGLlibrary != nullptr; + #else + return true; + #endif + } + + void UnloadLibrary() + { + #ifdef NAZARA_PLATFORM_WINDOWS + FreeLibrary(openGLlibrary); + #endif + } + + std::set openGLextensionSet; + bool openGLextensions[nzOpenGLExtension_Max+1] = {false}; + unsigned int openGLversion = 0; + + bool LoadExtensionsString(const NzString& extensionString) + { + if (extensionString.IsEmpty()) + { + NazaraError("Unable to get extension string"); + return false; + } + + // On peut sûrement faire plus rapide mais comme ça ne se fait qu'une fois et que NzString implémente le COW... + std::vector ext; + extensionString.Split(ext); + + for (std::vector::iterator it = ext.begin(); it != ext.end(); ++it) + openGLextensionSet.insert(*it); + + return true; + } + + bool LoadExtensions3() + { + GLint extensionCount = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); + + if (extensionCount <= 0) + { + NazaraError("Unable to get extension count"); + return false; + } + + for (int i = 0; i < extensionCount; ++i) + { + NzString extension(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); + if (extension.IsEmpty()) + { + NazaraWarning("Unable to get extension #" + NzString::Number(i)); + continue; + } + + openGLextensionSet.insert(extension); + } + + return true; + } +} + +namespace NzOpenGL +{ + NzOpenGLFunc GetEntry(const NzString& entryPoint) + { + return LoadEntry(entryPoint.GetConstBuffer(), false); + } + + unsigned int GetVersion() + { + return openGLversion; + } + + bool Initialize() + { + if (!LoadLibrary()) + { + NazaraError("Failed to load OpenGL library"); + return false; + } + + // Le chargement des fonctions OpenGL nécessite un contexte OpenGL + NzContextParameters parameters; + parameters.majorVersion = 2; + parameters.minorVersion = 0; + parameters.shared = false; + + /* + Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser + Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant + de créer le second avec les bons paramètres. + + Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise. + */ + + /****************************************Initialisation****************************************/ + + NzContext loadContext; + if (!loadContext.Create(parameters)) + { + NazaraError("Failed to create load context"); + Uninitialize(); + + return false; + } + + #if defined(NAZARA_PLATFORM_WINDOWS) + wglCreateContextAttribs = reinterpret_cast(LoadEntry("wglCreateContextAttribsARB", false)); + wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatARB", false)); + if (!wglChoosePixelFormat) + wglChoosePixelFormat = reinterpret_cast(LoadEntry("wglChoosePixelFormatEXT", false)); + #elif defined(NAZARA_PLATFORM_LINUX) + glXCreateContextAttribs = reinterpret_cast(LoadEntry("glXCreateContextAttribsARB", false)); + #endif + + // Récupération de la version d'OpenGL + // Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée + // Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ... + glGetString = reinterpret_cast(LoadEntry("glGetString", false)); + if (!glGetString) + { + NazaraError("Unable to load OpenGL: failed to load glGetString"); + Uninitialize(); + + return false; + } + + const GLubyte* version = glGetString(GL_VERSION); + if (!version) + { + NazaraError("Unable to retrieve OpenGL version"); + Uninitialize(); + + return false; + } + + unsigned int major = version[0] - '0'; + unsigned int minor = version[2] - '0'; + + if (major == 0 || major > 9) + { + NazaraError("Unable to retrieve OpenGL major version"); + return false; + } + + if (minor > 9) + { + NazaraWarning("Unable to retrieve OpenGL minor version (using 0)"); + minor = 0; + } + + openGLversion = major*100 + minor*10; + if (openGLversion < 200) + { + NazaraError("OpenGL version is too low, please upgrade your drivers or your video card"); + Uninitialize(); + + return false; + } + + parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output) + parameters.majorVersion = NzContextParameters::defaultMajorVersion = major; + parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor; + + if (!loadContext.Create(parameters)) // Destruction implicite du premier contexte + { + NazaraError("Failed to create load context"); + Uninitialize(); + + return false; + } + + /****************************************Noyau****************************************/ + + try + { + glActiveTexture = reinterpret_cast(LoadEntry("glActiveTexture")); + glAttachShader = reinterpret_cast(LoadEntry("glAttachShader")); + glBeginQuery = reinterpret_cast(LoadEntry("glBeginQuery")); + glBindAttribLocation = reinterpret_cast(LoadEntry("glBindAttribLocation")); + glBindBuffer = reinterpret_cast(LoadEntry("glBindBuffer")); + glBindTexture = reinterpret_cast(LoadEntry("glBindTexture")); + glBlendFunc = reinterpret_cast(LoadEntry("glBlendFunc")); + glBufferData = reinterpret_cast(LoadEntry("glBufferData")); + glBufferSubData = reinterpret_cast(LoadEntry("glBufferSubData")); + glClear = reinterpret_cast(LoadEntry("glClear")); + glClearColor = reinterpret_cast(LoadEntry("glClearColor")); + glClearDepth = reinterpret_cast(LoadEntry("glClearDepth")); + glClearStencil = reinterpret_cast(LoadEntry("glClearStencil")); + glCreateProgram = reinterpret_cast(LoadEntry("glCreateProgram")); + glCreateShader = reinterpret_cast(LoadEntry("glCreateShader")); + glColorMask = reinterpret_cast(LoadEntry("glColorMask")); + glCullFace = reinterpret_cast(LoadEntry("glCullFace")); + glCompileShader = reinterpret_cast(LoadEntry("glCompileShader")); + glCopyTexSubImage2D = reinterpret_cast(LoadEntry("glCopyTexSubImage2D")); + glDeleteBuffers = reinterpret_cast(LoadEntry("glDeleteBuffers")); + glDeleteQueries = reinterpret_cast(LoadEntry("glDeleteQueries")); + glDeleteProgram = reinterpret_cast(LoadEntry("glDeleteProgram")); + glDeleteShader = reinterpret_cast(LoadEntry("glDeleteShader")); + glDeleteTextures = reinterpret_cast(LoadEntry("glDeleteTextures")); + glDepthFunc = reinterpret_cast(LoadEntry("glDepthFunc")); + glDepthMask = reinterpret_cast(LoadEntry("glDepthMask")); + glDisable = reinterpret_cast(LoadEntry("glDisable")); + glDisableVertexAttribArray = reinterpret_cast(LoadEntry("glDisableVertexAttribArray")); + glDrawArrays = reinterpret_cast(LoadEntry("glDrawArrays")); + glDrawBuffer = reinterpret_cast(LoadEntry("glDrawBuffer")); + glDrawBuffers = reinterpret_cast(LoadEntry("glDrawBuffers")); + glDrawElements = reinterpret_cast(LoadEntry("glDrawElements")); + glFlush = reinterpret_cast(LoadEntry("glFlush")); + glEnable = reinterpret_cast(LoadEntry("glEnable")); + glEnableVertexAttribArray = reinterpret_cast(LoadEntry("glEnableVertexAttribArray")); + glEndQuery = reinterpret_cast(LoadEntry("glEndQuery")); + glGenBuffers = reinterpret_cast(LoadEntry("glGenBuffers")); + glGenQueries = reinterpret_cast(LoadEntry("glGenQueries")); + glGenTextures = reinterpret_cast(LoadEntry("glGenTextures")); + glGetBufferParameteriv = reinterpret_cast(LoadEntry("glGetBufferParameteriv")); + glGetError = reinterpret_cast(LoadEntry("glGetError")); + glGetQueryiv = reinterpret_cast(LoadEntry("glGetQueryiv")); + glGetQueryObjectiv = reinterpret_cast(LoadEntry("glGetQueryObjectiv")); + glGetQueryObjectuiv = reinterpret_cast(LoadEntry("glGetQueryObjectuiv")); + glGetIntegerv = reinterpret_cast(LoadEntry("glGetIntegerv")); + glGetProgramiv = reinterpret_cast(LoadEntry("glGetProgramiv")); + glGetProgramInfoLog = reinterpret_cast(LoadEntry("glGetProgramInfoLog")); + glGetShaderInfoLog = reinterpret_cast(LoadEntry("glGetShaderInfoLog")); + glGetShaderiv = reinterpret_cast(LoadEntry("glGetShaderiv")); + glGetShaderSource = reinterpret_cast(LoadEntry("glGetShaderSource")); + glGetTexImage = reinterpret_cast(LoadEntry("glGetTexImage")); + glGetTexLevelParameterfv = reinterpret_cast(LoadEntry("glGetTexLevelParameterfv")); + glGetTexLevelParameteriv = reinterpret_cast(LoadEntry("glGetTexLevelParameteriv")); + glGetTexParameterfv = reinterpret_cast(LoadEntry("glGetTexParameterfv")); + glGetTexParameteriv = reinterpret_cast(LoadEntry("glGetTexParameteriv")); + glGetUniformLocation = reinterpret_cast(LoadEntry("glGetUniformLocation")); + glLinkProgram = reinterpret_cast(LoadEntry("glLinkProgram")); + glMapBuffer = reinterpret_cast(LoadEntry("glMapBuffer")); + glPixelStorei = reinterpret_cast(LoadEntry("glPixelStorei")); + glPolygonMode = reinterpret_cast(LoadEntry("glPolygonMode")); + glReadPixels = reinterpret_cast(LoadEntry("glReadPixels")); + glScissor = reinterpret_cast(LoadEntry("glScissor")); + glShaderSource = reinterpret_cast(LoadEntry("glShaderSource")); + glStencilFunc = reinterpret_cast(LoadEntry("glStencilFunc")); + glStencilOp = reinterpret_cast(LoadEntry("glStencilOp")); + glTexImage2D = reinterpret_cast(LoadEntry("glTexImage2D")); + glTexImage3D = reinterpret_cast(LoadEntry("glTexImage3D")); + glTexParameterf = reinterpret_cast(LoadEntry("glTexParameterf")); + glTexParameteri = reinterpret_cast(LoadEntry("glTexParameteri")); + glTexSubImage2D = reinterpret_cast(LoadEntry("glTexSubImage2D")); + glTexSubImage3D = reinterpret_cast(LoadEntry("glTexSubImage3D")); + glUniform1f = reinterpret_cast(LoadEntry("glUniform1f")); + glUniform1i = reinterpret_cast(LoadEntry("glUniform1i")); + glUniform2fv = reinterpret_cast(LoadEntry("glUniform2fv")); + glUniform3fv = reinterpret_cast(LoadEntry("glUniform3fv")); + glUniform4fv = reinterpret_cast(LoadEntry("glUniform4fv")); + glUniformMatrix4fv = reinterpret_cast(LoadEntry("glUniformMatrix4fv")); + glUnmapBuffer = reinterpret_cast(LoadEntry("glUnmapBuffer")); + glUseProgram = reinterpret_cast(LoadEntry("glUseProgram")); + glVertexAttrib4f = reinterpret_cast(LoadEntry("glVertexAttrib4f")); + glVertexAttribPointer = reinterpret_cast(LoadEntry("glVertexAttribPointer")); + glViewport = reinterpret_cast(LoadEntry("glViewport")); + } + catch (const std::exception& e) + { + NazaraError("Unable to load OpenGL: " + NzString(e.what())); + Uninitialize(); + + return false; + } + + /****************************************Extensions****************************************/ + + // Fonctions optionnelles + glBindFragDataLocation = reinterpret_cast(LoadEntry("glBindFragDataLocation", false)); + if (!glBindFragDataLocation) + glBindFragDataLocation = reinterpret_cast(LoadEntry("glBindFragDataLocationEXT", false)); + + glGetStringi = reinterpret_cast(LoadEntry("glGetStringi", false)); + glMapBufferRange = reinterpret_cast(LoadEntry("glMapBufferRange", false)); + + #if defined(NAZARA_PLATFORM_WINDOWS) + wglGetExtensionsStringARB = reinterpret_cast(LoadEntry("wglGetExtensionsStringARB", false)); + wglGetExtensionsStringEXT = reinterpret_cast(LoadEntry("wglGetExtensionsStringEXT", false)); + wglSwapInterval = reinterpret_cast(LoadEntry("wglSwapIntervalEXT", false)); + #elif defined(NAZARA_PLATFORM_LINUX) + glXSwapInterval = reinterpret_cast(LoadEntry("glXSwapIntervalSGI", false)); + #endif + + if (!glGetStringi || !LoadExtensions3()) + { + if (openGLversion >= 300) // Dans le cas contraire c'est normal + NazaraWarning("Failed to load OpenGL 3 extension system, switching to OpenGL 2 extension system..."); + + if (!LoadExtensionsString(reinterpret_cast(glGetString(GL_EXTENSIONS)))) + NazaraWarning("Failed to load extension system"); + } + + #ifdef NAZARA_PLATFORM_WINDOWS + { + bool loaded; + if (wglGetExtensionsStringARB) + loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringARB(wglGetCurrentDC()))); + else if (wglGetExtensionsStringEXT) + loaded = LoadExtensionsString(reinterpret_cast(wglGetExtensionsStringEXT())); + else + loaded = false; + + if (!loaded) + NazaraWarning("Failed to load wgl extension string"); + } + #endif + + // AnisotropicFilter + openGLextensions[nzOpenGLExtension_AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic"); + + // DebugOutput + if (openGLversion >= 430 || IsSupported("GL_KHR_debug")) + { + try + { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallback")); + glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControl")); + glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsert")); + glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLog")); + + openGLextensions[nzOpenGLExtension_DebugOutput] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load GL_KHR_debug: " + NzString(e.what())); + } + } + + if (!openGLextensions[nzOpenGLExtension_DebugOutput] && IsSupported("GL_ARB_debug_output")) + { + try + { + glDebugMessageCallback = reinterpret_cast(LoadEntry("glDebugMessageCallbackARB")); + glDebugMessageControl = reinterpret_cast(LoadEntry("glDebugMessageControlARB")); + glDebugMessageInsert = reinterpret_cast(LoadEntry("glDebugMessageInsertARB")); + glGetDebugMessageLog = reinterpret_cast(LoadEntry("glGetDebugMessageLogARB")); + + openGLextensions[nzOpenGLExtension_DebugOutput] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load GL_ARB_debug_output: " + NzString(e.what())); + } + } + + // FP64 + if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) + { + try + { + glUniform1d = reinterpret_cast(LoadEntry("glUniform1d")); + glUniform2dv = reinterpret_cast(LoadEntry("glUniform2dv")); + glUniform3dv = reinterpret_cast(LoadEntry("glUniform3dv")); + glUniform4dv = reinterpret_cast(LoadEntry("glUniform4dv")); + + openGLextensions[nzOpenGLExtension_FP64] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_gpu_shader_fp64: " + NzString(e.what())); + } + } + + // FrameBufferObject + if (openGLversion >= 300 || IsSupported("GL_ARB_framebuffer_object")) + { + try + { + glBindFramebuffer = reinterpret_cast(LoadEntry("glBindFramebuffer")); + glBindRenderbuffer = reinterpret_cast(LoadEntry("glBindRenderbuffer")); + glCheckFramebufferStatus = reinterpret_cast(LoadEntry("glCheckFramebufferStatus")); + glDeleteFramebuffers = reinterpret_cast(LoadEntry("glDeleteFramebuffers")); + glDeleteRenderbuffers = reinterpret_cast(LoadEntry("glDeleteRenderbuffers")); + glFramebufferRenderbuffer = reinterpret_cast(LoadEntry("glFramebufferRenderbuffer")); + glFramebufferTexture = reinterpret_cast(LoadEntry("glFramebufferTexture")); + glFramebufferTexture1D = reinterpret_cast(LoadEntry("glFramebufferTexture1D")); + glFramebufferTexture2D = reinterpret_cast(LoadEntry("glFramebufferTexture2D")); + glFramebufferTexture3D = reinterpret_cast(LoadEntry("glFramebufferTexture3D")); + glFramebufferTextureLayer = reinterpret_cast(LoadEntry("glFramebufferTextureLayer")); + glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmap")); + glGenFramebuffers = reinterpret_cast(LoadEntry("glGenFramebuffers")); + glGenRenderbuffers = reinterpret_cast(LoadEntry("glGenRenderbuffers")); + glRenderbufferStorage = reinterpret_cast(LoadEntry("glRenderbufferStorage")); + + openGLextensions[nzOpenGLExtension_FrameBufferObject] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")"); + } + } + + // PixelBufferObject + openGLextensions[nzOpenGLExtension_PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object")); + + // SeparateShaderObjects + if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects")) + { + glProgramUniform1f = reinterpret_cast(LoadEntry("glProgramUniform1f")); + glProgramUniform1i = reinterpret_cast(LoadEntry("glProgramUniform1i")); + glProgramUniform2fv = reinterpret_cast(LoadEntry("glProgramUniform2fv")); + glProgramUniform3fv = reinterpret_cast(LoadEntry("glProgramUniform3fv")); + glProgramUniform4fv = reinterpret_cast(LoadEntry("glProgramUniform4fv")); + glProgramUniformMatrix4fv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4fv")); + + // Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double + if (openGLextensions[nzOpenGLExtension_FP64]) + { + glProgramUniform1d = reinterpret_cast(LoadEntry("glProgramUniform1d")); + glProgramUniform2dv = reinterpret_cast(LoadEntry("glProgramUniform2dv")); + glProgramUniform3dv = reinterpret_cast(LoadEntry("glProgramUniform3dv")); + glProgramUniform4dv = reinterpret_cast(LoadEntry("glProgramUniform4dv")); + glProgramUniformMatrix4dv = reinterpret_cast(LoadEntry("glProgramUniformMatrix4dv")); + } + + openGLextensions[nzOpenGLExtension_SeparateShaderObjects] = true; + } + + // TextureArray + openGLextensions[nzOpenGLExtension_TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array")); + + // TextureCompression_s3tc + openGLextensions[nzOpenGLExtension_TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc"); + + // TextureStorage + if (openGLversion >= 420 || IsSupported("GL_ARB_texture_storage")) + { + try + { + glTexStorage1D = reinterpret_cast(LoadEntry("glTexStorage1D")); + glTexStorage2D = reinterpret_cast(LoadEntry("glTexStorage2D")); + glTexStorage3D = reinterpret_cast(LoadEntry("glTexStorage3D")); + + openGLextensions[nzOpenGLExtension_TextureStorage] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_texture_storage: " + NzString(e.what())); + } + } + + // VertexArrayObject + if (openGLversion >= 300 || IsSupported("GL_ARB_vertex_array_object")) + { + try + { + glBindVertexArray = reinterpret_cast(LoadEntry("glBindVertexArray")); + glDeleteVertexArrays = reinterpret_cast(LoadEntry("glDeleteVertexArrays")); + glGenVertexArrays = reinterpret_cast(LoadEntry("glGenVertexArrays")); + + openGLextensions[nzOpenGLExtension_VertexArrayObject] = true; + } + catch (const std::exception& e) + { + NazaraWarning("Failed to load ARB_vertex_array_object: " + NzString(e.what())); + } + } + + // Fonctions de substitut + if (!glGenerateMipmap) + glGenerateMipmap = reinterpret_cast(LoadEntry("glGenerateMipmapEXT", false)); + + /****************************************Contexte de référence****************************************/ + + ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) + if (!NzContext::Initialize()) + { + NazaraError("Failed to initialize contexts"); + Uninitialize(); + + return false; + } + + NzContextParameters::defaultShareContext = NzContext::GetReference(); + + return true; + } + + bool IsSupported(nzOpenGLExtension extension) + { + return openGLextensions[extension]; + } + + bool IsSupported(const NzString& string) + { + return openGLextensionSet.find(string) != openGLextensionSet.end(); + } + + bool TranslateFormat(nzPixelFormat pixelFormat, Format* format, FormatType type) + { + switch (pixelFormat) + { + case nzPixelFormat_BGR8: + format->dataFormat = GL_BGR; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGB8; + return true; + + case nzPixelFormat_BGRA8: + format->dataFormat = GL_BGRA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGBA8; + return true; + + case nzPixelFormat_DXT1: + format->dataFormat = GL_RGB; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + return true; + + case nzPixelFormat_DXT3: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + return true; + + case nzPixelFormat_DXT5: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + return true; + + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + return false; + + case nzPixelFormat_RGB5A1: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_SHORT_5_5_5_1; + format->internalFormat = GL_RGB5_A1; + return true; + + case nzPixelFormat_RGB8: + format->dataFormat = GL_RGB; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGB8; + return true; + + case nzPixelFormat_RGBA4: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_SHORT_4_4_4_4; + format->internalFormat = GL_RGBA4; + return true; + + case nzPixelFormat_RGBA8: + format->dataFormat = GL_RGBA; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_RGBA8; + return true; + + case nzPixelFormat_Depth16: + format->dataFormat = GL_DEPTH_COMPONENT; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH_COMPONENT16; + return true; + + case nzPixelFormat_Depth24: + format->dataFormat = GL_DEPTH_COMPONENT; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH_COMPONENT24; + return true; + + case nzPixelFormat_Depth24Stencil8: + format->dataFormat = GL_DEPTH_STENCIL; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH24_STENCIL8; + return true; + + case nzPixelFormat_Depth32: + format->dataFormat = GL_DEPTH_COMPONENT; + format->dataType = GL_UNSIGNED_BYTE; + format->internalFormat = GL_DEPTH_COMPONENT32; + return true; + + case nzPixelFormat_Stencil1: + if (type == FormatType_Texture) // Les formats de stencil ne sont pas supportés par les textures + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX1; + return true; + } + + case nzPixelFormat_Stencil4: + if (type == FormatType_Texture) + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX4; + return true; + } + + case nzPixelFormat_Stencil8: + if (type == FormatType_Texture) + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX8; + return true; + } + + case nzPixelFormat_Stencil16: + if (type == FormatType_Texture) + return false; + else + { + format->dataFormat = GL_NONE; + format->dataType = GL_NONE; + format->internalFormat = GL_STENCIL_INDEX16; + return true; + } + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + return false; + } + + void Uninitialize() + { + NzContext::Uninitialize(); + + for (bool& ext : openGLextensions) + ext = false; + + openGLextensionSet.clear(); + openGLversion = 0; + + UnloadLibrary(); + } + + GLenum Attachment[nzAttachmentPoint_Max+1] = + { + GL_COLOR_ATTACHMENT0, // nzAttachmentPoint_Color + GL_DEPTH_ATTACHMENT, // nzAttachmentPoint_Depth + GL_DEPTH_STENCIL_ATTACHMENT, // nzAttachmentPoint_DepthStencil + GL_STENCIL_ATTACHMENT // nzAttachmentPoint_Stencil + }; + + nzUInt8 AttributeIndex[nzElementUsage_Max+1] = + { + 2, // nzElementUsage_Diffuse + 1, // nzElementUsage_Normal + 0, // nzElementUsage_Position + 3, // nzElementUsage_Tangent + + 4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible) + }; + + GLenum BlendFunc[nzBlendFunc_Max+1] = + { + GL_DST_ALPHA, // nzBlendFunc_DestAlpha + GL_DST_COLOR, // nzBlendFunc_DestColor + GL_SRC_ALPHA, // nzBlendFunc_SrcAlpha + GL_SRC_COLOR, // nzBlendFunc_SrcColor + GL_ONE_MINUS_DST_ALPHA, // nzBlendFunc_InvDestAlpha + GL_ONE_MINUS_DST_COLOR, // nzBlendFunc_InvDestColor + GL_ONE_MINUS_SRC_ALPHA, // nzBlendFunc_InvSrcAlpha + GL_ONE_MINUS_SRC_COLOR, // nzBlendFunc_InvSrcColor + GL_ONE, // nzBlendFunc_One + GL_ZERO // nzBlendFunc_Zero + }; + + GLenum BufferLock[nzBufferAccess_Max+1] = + { + GL_WRITE_ONLY, // nzBufferAccess_DiscardAndWrite + GL_READ_ONLY, // nzBufferAccess_ReadOnly + GL_READ_WRITE, // nzBufferAccess_ReadWrite + GL_WRITE_ONLY // nzBufferAccess_WriteOnly + }; + + GLenum BufferLockRange[nzBufferAccess_Max+1] = + { + GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_DiscardAndWrite + GL_MAP_READ_BIT, // nzBufferAccess_ReadOnly + GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, // nzBufferAccess_ReadWrite + GL_MAP_WRITE_BIT // nzBufferAccess_WriteOnly + }; + + GLenum BufferTarget[nzBufferType_Max+1] = + { + GL_ELEMENT_ARRAY_BUFFER, // nzBufferType_Index, + GL_ARRAY_BUFFER, // nzBufferType_Vertex + }; + + GLenum BufferTargetBinding[nzBufferType_Max+1] = + { + GL_ELEMENT_ARRAY_BUFFER_BINDING, // nzBufferType_Index, + GL_ARRAY_BUFFER_BINDING, // nzBufferType_Vertex + }; + + GLenum BufferUsage[nzBufferUsage_Max+1] = + { + // J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus" + // Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?) + // Source: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=160839 + GL_DYNAMIC_DRAW, // nzBufferUsage_Dynamic + GL_STATIC_DRAW // nzBufferUsage_Static + }; + + GLenum CubemapFace[6] = + { + GL_TEXTURE_CUBE_MAP_POSITIVE_X, // nzCubemapFace_PositiveX + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, // nzCubemapFace_NegativeX + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // nzCubemapFace_PositiveY + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // nzCubemapFace_NegativeY + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, // nzCubemapFace_PositiveZ + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z // nzCubemapFace_NegativeZ + }; + + GLenum ElementType[nzElementType_Max+1] = + { + GL_UNSIGNED_BYTE, // nzElementType_Color + GL_DOUBLE, // nzElementType_Double1 + GL_DOUBLE, // nzElementType_Double2 + GL_DOUBLE, // nzElementType_Double3 + GL_DOUBLE, // nzElementType_Double4 + GL_FLOAT, // nzElementType_Float1 + GL_FLOAT, // nzElementType_Float2 + GL_FLOAT, // nzElementType_Float3 + GL_FLOAT // nzElementType_Float4 + }; + + GLenum FaceCulling[nzFaceCulling_Max+1] = + { + GL_BACK, // nzFaceCulling_Back + GL_FRONT, // nzFaceCulling_Front + GL_FRONT_AND_BACK // nzFaceCulling_FrontAndBack + }; + + GLenum FaceFilling[nzFaceFilling_Max+1] = + { + GL_POINT, // nzFaceFilling_Point + GL_LINE, // nzFaceFilling_Line + GL_FILL // nzFaceFilling_Fill + }; + + GLenum PrimitiveType[nzPrimitiveType_Max+1] = + { + GL_LINES, // nzPrimitiveType_LineList, + GL_LINE_STRIP, // nzPrimitiveType_LineStrip, + GL_POINTS, // nzPrimitiveType_PointList, + GL_TRIANGLES, // nzPrimitiveType_TriangleList, + GL_TRIANGLE_STRIP, // nzPrimitiveType_TriangleStrip, + GL_TRIANGLE_FAN // nzPrimitiveType_TriangleFan + }; + + GLenum RendererComparison[nzRendererComparison_Max+1] = + { + GL_ALWAYS, // nzRendererComparison_Always + GL_EQUAL, // nzRendererComparison_Equal + GL_GREATER, // nzRendererComparison_Greater + GL_GEQUAL, // nzRendererComparison_GreaterOrEqual + GL_LESS, // nzRendererComparison_Less + GL_LEQUAL, // nzRendererComparison_LessOrEqual + GL_NEVER // nzRendererComparison_Never + }; + + GLenum RendererParameter[nzRendererParameter_Max+1] = + { + GL_BLEND, // nzRendererParameter_Blend + GL_NONE, // nzRendererParameter_ColorWrite + GL_DEPTH_TEST, // nzRendererParameter_DepthTest + GL_NONE, // nzRendererParameter_DepthWrite + GL_CULL_FACE, // nzRendererParameter_FaceCulling + GL_STENCIL_TEST // nzRendererParameter_Stencil + }; + + GLenum ShaderType[nzShaderType_Max+1] = + { + GL_FRAGMENT_SHADER, // nzShaderType_Fragment + GL_GEOMETRY_SHADER, // nzShaderType_Geometry + GL_VERTEX_SHADER // nzShaderType_Vertex + }; + + GLenum StencilOperation[nzStencilOperation_Max+1] = + { + GL_DECR, // nzStencilOperation_Decrement + GL_DECR_WRAP, // nzStencilOperation_DecrementToSaturation + GL_INCR, // nzStencilOperation_Increment + GL_INCR_WRAP, // nzStencilOperation_IncrementToSaturation + GL_INVERT, // nzStencilOperation_Invert + GL_KEEP, // nzStencilOperation_Keep + GL_REPLACE, // nzStencilOperation_Replace + GL_ZERO // nzStencilOperation_Zero + }; + + GLenum TextureTarget[nzImageType_Max+1] + { + GL_TEXTURE_1D, // nzImageType_1D + GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array + GL_TEXTURE_2D, // nzImageType_2D + GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array + GL_TEXTURE_3D, // nzImageType_3D + GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap + }; + + GLenum TextureTargetBinding[nzImageType_Max+1] + { + GL_TEXTURE_BINDING_1D, // nzImageType_1D + GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D_Array + GL_TEXTURE_BINDING_2D, // nzImageType_2D + GL_TEXTURE_BINDING_2D_ARRAY, // nzImageType_2D_Array + GL_TEXTURE_BINDING_3D, // nzImageType_3D + GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap + }; + + GLenum TextureTargetProxy[nzImageType_Max+1] + { + GL_PROXY_TEXTURE_1D, // nzImageType_1D + GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array + GL_PROXY_TEXTURE_2D, // nzImageType_2D + GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array + GL_PROXY_TEXTURE_3D, // nzImageType_3D + GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap + }; +} + +PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; +PFNGLATTACHSHADERPROC glAttachShader = nullptr; +PFNGLBEGINQUERYPROC glBeginQuery = nullptr; +PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation = nullptr; +PFNGLBINDBUFFERPROC glBindBuffer = nullptr; +PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr; +PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation = nullptr; +PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = nullptr; +PFNGLBINDTEXTUREPROC glBindTexture = nullptr; +PFNGLBINDVERTEXARRAYPROC glBindVertexArray = nullptr; +PFNGLBLENDFUNCPROC glBlendFunc = nullptr; +PFNGLBUFFERDATAPROC glBufferData = nullptr; +PFNGLBUFFERSUBDATAPROC glBufferSubData = nullptr; +PFNGLCLEARPROC glClear = nullptr; +PFNGLCLEARCOLORPROC glClearColor = nullptr; +PFNGLCLEARDEPTHPROC glClearDepth = nullptr; +PFNGLCLEARSTENCILPROC glClearStencil = nullptr; +PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr; +PFNGLCREATESHADERPROC glCreateShader = nullptr; +PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = nullptr; +PFNGLCOLORMASKPROC glColorMask = nullptr; +PFNGLCULLFACEPROC glCullFace = nullptr; +PFNGLCOMPILESHADERPROC glCompileShader = nullptr; +PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D = nullptr; +PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback = nullptr; +PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl = nullptr; +PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert = nullptr; +PFNGLDELETEBUFFERSPROC glDeleteBuffers = nullptr; +PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr; +PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr; +PFNGLDELETEQUERIESPROC glDeleteQueries = nullptr; +PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = nullptr; +PFNGLDELETESHADERPROC glDeleteShader = nullptr; +PFNGLDELETETEXTURESPROC glDeleteTextures = nullptr; +PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = nullptr; +PFNGLDEPTHFUNCPROC glDepthFunc = nullptr; +PFNGLDEPTHMASKPROC glDepthMask = nullptr; +PFNGLDISABLEPROC glDisable = nullptr; +PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray = nullptr; +PFNGLDRAWARRAYSPROC glDrawArrays = nullptr; +PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr; +PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr; +PFNGLDRAWELEMENTSPROC glDrawElements = nullptr; +PFNGLENDQUERYPROC glEndQuery = nullptr; +PFNGLFLUSHPROC glFlush = nullptr; +PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr; +PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture = nullptr; +PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = nullptr; +PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr; +PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = nullptr; +PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = nullptr; +PFNGLENABLEPROC glEnable = nullptr; +PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr; +PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr; +PFNGLGENBUFFERSPROC glGenBuffers = nullptr; +PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr; +PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr; +PFNGLGENQUERIESPROC glGenQueries = nullptr; +PFNGLGENTEXTURESPROC glGenTextures = nullptr; +PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr; +PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr; +PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr; +PFNGLGETERRORPROC glGetError = nullptr; +PFNGLGETINTEGERVPROC glGetIntegerv = nullptr; +PFNGLGETPROGRAMIVPROC glGetProgramiv = nullptr; +PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog = nullptr; +PFNGLGETQUERYIVPROC glGetQueryiv = nullptr; +PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv = nullptr; +PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv = nullptr; +PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog = nullptr; +PFNGLGETSHADERIVPROC glGetShaderiv = nullptr; +PFNGLGETSHADERSOURCEPROC glGetShaderSource = nullptr; +PFNGLGETSTRINGPROC glGetString = nullptr; +PFNGLGETSTRINGIPROC glGetStringi = nullptr; +PFNGLGETTEXIMAGEPROC glGetTexImage = nullptr; +PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv = nullptr; +PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr; +PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr; +PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr; +PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr; +PFNGLLINKPROGRAMPROC glLinkProgram = nullptr; +PFNGLMAPBUFFERPROC glMapBuffer = nullptr; +PFNGLMAPBUFFERRANGEPROC glMapBufferRange = nullptr; +PFNGLPIXELSTOREIPROC glPixelStorei = nullptr; +PFNGLPOLYGONMODEPROC glPolygonMode = nullptr; +PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d = nullptr; +PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = nullptr; +PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i = nullptr; +PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv = nullptr; +PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv = nullptr; +PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv = nullptr; +PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv = nullptr; +PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv = nullptr; +PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv = nullptr; +PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv = nullptr; +PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv = nullptr; +PFNGLREADPIXELSPROC glReadPixels = nullptr; +PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = nullptr; +PFNGLSCISSORPROC glScissor = nullptr; +PFNGLSHADERSOURCEPROC glShaderSource = nullptr; +PFNGLSTENCILFUNCPROC glStencilFunc = nullptr; +PFNGLSTENCILOPPROC glStencilOp = nullptr; +PFNGLTEXIMAGE1DPROC glTexImage1D = nullptr; +PFNGLTEXIMAGE2DPROC glTexImage2D = nullptr; +PFNGLTEXIMAGE3DPROC glTexImage3D = nullptr; +PFNGLTEXPARAMETERFPROC glTexParameterf = nullptr; +PFNGLTEXPARAMETERIPROC glTexParameteri = nullptr; +PFNGLTEXSTORAGE1DPROC glTexStorage1D = nullptr; +PFNGLTEXSTORAGE2DPROC glTexStorage2D = nullptr; +PFNGLTEXSTORAGE3DPROC glTexStorage3D = nullptr; +PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D = nullptr; +PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D = nullptr; +PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = nullptr; +PFNGLUNIFORM1DPROC glUniform1d = nullptr; +PFNGLUNIFORM1FPROC glUniform1f = nullptr; +PFNGLUNIFORM1IPROC glUniform1i = nullptr; +PFNGLUNIFORM2DVPROC glUniform2dv = nullptr; +PFNGLUNIFORM2FVPROC glUniform2fv = nullptr; +PFNGLUNIFORM3DVPROC glUniform3dv = nullptr; +PFNGLUNIFORM3FVPROC glUniform3fv = nullptr; +PFNGLUNIFORM4DVPROC glUniform4dv = nullptr; +PFNGLUNIFORM4FVPROC glUniform4fv = nullptr; +PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv = nullptr; +PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv = nullptr; +PFNGLUNMAPBUFFERPROC glUnmapBuffer = nullptr; +PFNGLUSEPROGRAMPROC glUseProgram = nullptr; +PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f = nullptr; +PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = nullptr; +PFNGLVIEWPORTPROC glViewport = nullptr; +#if defined(NAZARA_PLATFORM_WINDOWS) +PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; +PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; +PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; +PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = nullptr; +PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = nullptr; +#elif defined(NAZARA_PLATFORM_LINUX) +PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = nullptr; +PFNGLXSWAPINTERVALSGIPROC glXSwapInterval = nullptr; +#endif diff --git a/src/Nazara/Renderer/RenderTexture.cpp b/src/Nazara/Renderer/RenderTexture.cpp index 8d5bf552f..e7b962166 100644 --- a/src/Nazara/Renderer/RenderTexture.cpp +++ b/src/Nazara/Renderer/RenderTexture.cpp @@ -1,728 +1,728 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - struct Attachment - { - union - { - GLuint buffer; - NzTexture* texture; - }; - - bool isBuffer; - bool isUsed = false; - }; - - unsigned int attachmentIndex[nzAttachmentPoint_Max+1] = - { - 2, // nzAttachmentPoint_Color - 0, // nzAttachmentPoint_Depth - 0, // nzAttachmentPoint_DepthStencil - 1 // nzAttachmentPoint_Stencil - }; - - nzAttachmentPoint formatTypeToAttachment[nzPixelFormatType_Max+1] = - { - nzAttachmentPoint_Color, // nzPixelFormatType_Color - nzAttachmentPoint_Depth, // nzPixelFormatType_Depth - nzAttachmentPoint_DepthStencil, // nzPixelFormatType_DepthStencil - nzAttachmentPoint_Stencil // nzPixelFormatType_Stencil - }; - - GLuint lockedPrevious = 0; - nzUInt8 lockedLevel = 0; -} - -struct NzRenderTextureImpl -{ - GLuint fbo; - std::vector attachements; - std::vector drawBuffers; - NzContext* context; - bool checked = false; - bool complete = false; - bool drawBuffersUpdated = true; - unsigned int height; - unsigned int width; -}; - -NzRenderTexture::~NzRenderTexture() -{ - Destroy(); -} - -bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return false; - } - - if (attachmentPoint != nzAttachmentPoint_Color && index > 0) - { - NazaraError("Index must be 0 for non-color attachments"); - return false; - } - - unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; - if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && - m_impl->attachements[depthStencilIndex].isUsed) - { - NazaraError("Stencil target already attached by DepthStencil attachment"); - return false; - } - - if (formatTypeToAttachment[NzPixelFormat::GetType(format)] != attachmentPoint) - { - NazaraError("Pixel format type does not match attachment point type"); - return false; - } - #endif - - NzOpenGL::Format openglFormat; - if (!NzOpenGL::TranslateFormat(format, &openglFormat, NzOpenGL::FormatType_RenderBuffer)) - { - NazaraError("Failed to translate pixel format into OpenGL format"); - return false; - } - - if (!Lock()) - { - NazaraError("Failed to lock render texture"); - return false; - } - - // Détachement de l'attache précédente (Si il y a) - Detach(attachmentPoint, index); - - GLuint renderBuffer = 0; - - glGenRenderbuffers(1, &renderBuffer); - if (!renderBuffer) - { - NazaraError("Failed to create renderbuffer"); - return false; - } - - GLint previous; - glGetIntegerv(GL_RENDERBUFFER_BINDING, &previous); - - glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); - glRenderbufferStorage(GL_RENDERBUFFER, openglFormat.internalFormat, m_impl->width, m_impl->height); - - if (previous != 0) - glBindRenderbuffer(GL_RENDERBUFFER, previous); - - glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, renderBuffer); - Unlock(); - - unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; - if (m_impl->attachements.size() < minSize) - m_impl->attachements.resize(minSize); - - Attachment& attachment = m_impl->attachements[minSize-1]; - attachment.isBuffer = true; - attachment.isUsed = true; - attachment.buffer = renderBuffer; - - m_impl->checked = false; - m_impl->drawBuffersUpdated = false; - - return true; -} - -bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return false; - } - - if (attachmentPoint != nzAttachmentPoint_Color && index > 0) - { - NazaraError("Index must be 0 for non-color attachments"); - return false; - } - - unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; - if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && - m_impl->attachements[depthStencilIndex].isUsed) - { - NazaraError("Stencil target already attached by DepthStencil attachment"); - return false; - } - - if (!texture || !texture->IsValid()) - { - NazaraError("Invalid texture"); - return false; - } - - if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height) - { - NazaraError("Texture cannot be smaller than render texture"); - return false; - } - - if (texture->GetRenderTexture() != nullptr) - { - NazaraError("Texture already used by another render texture"); - return false; - } - - if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint) - { - NazaraError("Pixel format type does not match attachment point type"); - return false; - } - #endif - - if (!Lock()) - { - NazaraError("Failed to lock render texture"); - return false; - } - - // Détachement de l'attache précédente (Si il y a) - Detach(attachmentPoint, index); - - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0); - Unlock(); - - unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; - if (m_impl->attachements.size() < minSize) - m_impl->attachements.resize(minSize); - - Attachment& attachment = m_impl->attachements[minSize-1]; - attachment.isBuffer = true; - attachment.isUsed = true; - attachment.texture = texture; - - texture->AddResourceListener(this, minSize-1); - texture->SetRenderTexture(this); - - m_impl->checked = false; - m_impl->drawBuffersUpdated = false; - - return true; -} - -bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return false; - } - - if (attachmentPoint != nzAttachmentPoint_Color && index > 0) - { - NazaraError("Index must be 0 for non-color attachments"); - return false; - } - - if (attachmentPoint == nzAttachmentPoint_Stencil) - { - NazaraError("Targeting stencil-only textures is not supported"); - return false; - } - - unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; - if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && - m_impl->attachements[depthStencilIndex].isUsed) - { - NazaraError("Stencil target already attached by DepthStencil attachment"); - return false; - } - - if (!texture || !texture->IsValid()) - { - NazaraError("Invalid texture"); - return false; - } - - if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height) - { - NazaraError("Texture cannot be smaller than render texture"); - return false; - } - - unsigned int depth = (texture->GetType() == nzImageType_Cubemap) ? 6 : texture->GetDepth(); - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return false; - } - - if (texture->GetRenderTexture() != nullptr) - { - NazaraError("Texture already used by another render texture"); - return false; - } - - if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint) - { - NazaraError("Pixel format type does not match attachment point type"); - return false; - } - #endif - - if (!Lock()) - { - NazaraError("Failed to lock render texture"); - return false; - } - - // Détachement de l'attache précédente (Si il y a) - Detach(attachmentPoint, index); - - switch (texture->GetType()) - { - case nzImageType_1D: - glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_1D, texture->GetOpenGLID(), 0); - break; - - case nzImageType_1D_Array: - case nzImageType_2D_Array: - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0, z); - break; - - case nzImageType_2D: - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::TextureTarget[texture->GetType()], texture->GetOpenGLID(), 0); - break; - - case nzImageType_3D: - glFramebufferTexture3D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_3D, texture->GetOpenGLID(), 0, z); - break; - - case nzImageType_Cubemap: - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::CubemapFace[z], texture->GetOpenGLID(), 0); - break; - } - Unlock(); - - unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; - if (m_impl->attachements.size() < minSize) - m_impl->attachements.resize(minSize); - - Attachment& attachment = m_impl->attachements[minSize-1]; - attachment.isBuffer = true; - attachment.isUsed = true; - attachment.texture = texture; - - texture->AddResourceListener(this); - texture->SetRenderTexture(this); - - m_impl->checked = false; - m_impl->drawBuffersUpdated = false; - - return true; -} - -bool NzRenderTexture::Create(unsigned int width, unsigned int height, bool lock) -{ - if (!IsSupported()) - { - NazaraError("Render textures not supported"); - return false; - } - - Destroy(); - - #if NAZARA_RENDERER_SAFE - if (width == 0) - { - NazaraError("Width must be at least 1 (0)"); - return false; - } - - if (height == 0) - { - NazaraError("Height must be at least 1 (0)"); - return false; - } - - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return false; - } - #endif - - NzRenderTextureImpl* impl = new NzRenderTextureImpl; - impl->width = width; - impl->height = height; - - impl->context = NzContext::GetCurrent(); - impl->context->AddResourceListener(this); - - impl->fbo = 0; - glGenFramebuffers(1, &impl->fbo); - - if (!impl->fbo) - { - NazaraError("Failed to create framebuffer"); - delete impl; - - return false; - } - - m_impl = impl; - - if (lock && !Lock()) - { - NazaraError("Failed to lock render texture"); - delete impl; - m_impl = nullptr; - - return false; - } - - return true; -} - -void NzRenderTexture::Destroy() -{ - if (m_impl) - { - #if NAZARA_RENDERER_SAFE - if (NzContext::GetCurrent() != m_impl->context) - { - NazaraError("RenderTexture can only be used with it's creation context"); - return; - } - #endif - - m_impl->context->RemoveResourceListener(this); - - for (Attachment& attachment : m_impl->attachements) - { - if (attachment.isUsed) - { - if (attachment.isBuffer) - glDeleteRenderbuffers(1, &attachment.buffer); - else - { - attachment.texture->RemoveResourceListener(this); - attachment.texture->SetRenderTexture(nullptr); - } - } - } - - glDeleteFramebuffers(1, &m_impl->fbo); - - delete m_impl; - m_impl = nullptr; - } -} - -void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return; - } - - if (attachmentPoint != nzAttachmentPoint_Color && index > 0) - { - NazaraError("Index must be 0 for non-color attachments"); - return; - } - #endif - - unsigned int attachIndex = attachmentIndex[attachmentPoint]+index; - if (attachIndex >= m_impl->attachements.size()) - return; - - Attachment& attachement = m_impl->attachements[attachIndex]; - if (!attachement.isUsed) - return; - - if (!Lock()) - { - NazaraError("Failed to lock render texture"); - return; - } - - attachement.isUsed = false; - - if (attachement.isBuffer) - { - glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0); - glDeleteRenderbuffers(1, &attachement.buffer); - } - else - { - glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0); - attachement.texture->RemoveResourceListener(this); - attachement.texture->SetRenderTexture(nullptr); - } - - Unlock(); - - m_impl->checked = false; - m_impl->drawBuffersUpdated = false; - -} - -unsigned int NzRenderTexture::GetHeight() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return 0; - } - #endif - - return m_impl->height; -} - -NzRenderTargetParameters NzRenderTexture::GetParameters() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return NzRenderTargetParameters(); - } - #endif - - return NzRenderTargetParameters(); -} - -unsigned int NzRenderTexture::GetWidth() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return 0; - } - #endif - - return m_impl->width; -} - -bool NzRenderTexture::IsComplete() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return false; - } - #endif - - if (!m_impl->checked) - { - if (!Lock()) - { - NazaraError("Failed to lock render texture"); - return false; - } - - GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); - Unlock(); - - m_impl->complete = false; - - switch (status) - { - case GL_FRAMEBUFFER_COMPLETE: - m_impl->complete = true; - break; - - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - NazaraError("Incomplete attachment"); - break; - - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: - NazaraInternalError("Incomplete draw buffer"); - break; - - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: - NazaraInternalError("Incomplete read buffer"); - break; - - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - NazaraError("Incomplete missing attachment"); - break; - - case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: - NazaraError("Incomplete multisample"); - break; - - case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: - NazaraError("Incomplete layer targets"); - break; - - case GL_FRAMEBUFFER_UNSUPPORTED: - NazaraError("Render texture has unsupported attachments"); - break; - - default: - NazaraInternalError("Unknown error"); - } - - m_impl->checked = true; - } - - return m_impl->complete; -} - -bool NzRenderTexture::IsRenderable() const -{ - return IsComplete(); -} - -bool NzRenderTexture::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzRenderTexture::Lock() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return false; - } - - if (NzContext::GetCurrent() != m_impl->context) - { - NazaraError("RenderTexture cannot be used with this context"); - return false; - } - #endif - - if (lockedLevel++ == 0) - { - GLint previous; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previous); - - lockedPrevious = previous; - - if (lockedPrevious != m_impl->fbo) - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo); - } - - return true; -} - -void NzRenderTexture::Unlock() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Render texture not created"); - return; - } - - if (NzContext::GetCurrent() != m_impl->context) - { - NazaraError("RenderTexture cannot be used with this context"); - return; - } - - if (lockedLevel == 0) - { - NazaraWarning("Unlock called on non-locked texture"); - return; - } - #endif - - if (--lockedLevel == 0 && lockedPrevious != m_impl->fbo) // Ici, il est important qu'un FBO soit débindé si l'ancien était 0 - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, lockedPrevious); -} - -bool NzRenderTexture::HasContext() const -{ - return false; -} - -bool NzRenderTexture::IsSupported() -{ - return NzRenderer::HasCapability(nzRendererCap_RenderTexture); -} - -bool NzRenderTexture::Activate() -{ - #if NAZARA_RENDERER_SAFE - if (NzContext::GetCurrent() != m_impl->context) - { - NazaraError("RenderTexture cannot be used with this context"); - return false; - } - #endif - - if (!m_impl->drawBuffersUpdated) - { - m_impl->drawBuffers.clear(); - m_impl->drawBuffers.reserve(m_impl->attachements.size()); - for (unsigned int i = attachmentIndex[nzAttachmentPoint_Color]; i < m_impl->attachements.size(); ++i) - { - if (m_impl->attachements[i].isUsed) - m_impl->drawBuffers.push_back(GL_COLOR_ATTACHMENT0 + i - attachmentIndex[nzAttachmentPoint_Color]); - } - - m_impl->drawBuffersUpdated = true; - } - - glDrawBuffers(m_impl->drawBuffers.size(), &m_impl->drawBuffers[0]); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo); - - return true; -} - -void NzRenderTexture::Desactivate() -{ - #if NAZARA_RENDERER_SAFE - if (NzContext::GetCurrent() != m_impl->context) - { - NazaraError("RenderTexture cannot be used with this context"); - return; - } - #endif - - glFlush(); - - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -} - -void NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index) -{ - if (resource == m_impl->context) - // Notre context a été détruit, libérons la RenderTexture pour éviter un leak - Destroy(); - else - { - // Sinon, c'est une texture - - // La ressource n'est plus, du coup nous mettons à jour - Attachment& attachement = m_impl->attachements[index]; - attachement.isUsed = false; - - m_impl->checked = false; - m_impl->drawBuffersUpdated = false; - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + struct Attachment + { + union + { + GLuint buffer; + NzTexture* texture; + }; + + bool isBuffer; + bool isUsed = false; + }; + + unsigned int attachmentIndex[nzAttachmentPoint_Max+1] = + { + 2, // nzAttachmentPoint_Color + 0, // nzAttachmentPoint_Depth + 0, // nzAttachmentPoint_DepthStencil + 1 // nzAttachmentPoint_Stencil + }; + + nzAttachmentPoint formatTypeToAttachment[nzPixelFormatType_Max+1] = + { + nzAttachmentPoint_Color, // nzPixelFormatType_Color + nzAttachmentPoint_Depth, // nzPixelFormatType_Depth + nzAttachmentPoint_DepthStencil, // nzPixelFormatType_DepthStencil + nzAttachmentPoint_Stencil // nzPixelFormatType_Stencil + }; + + GLuint lockedPrevious = 0; + nzUInt8 lockedLevel = 0; +} + +struct NzRenderTextureImpl +{ + GLuint fbo; + std::vector attachements; + std::vector drawBuffers; + NzContext* context; + bool checked = false; + bool complete = false; + bool drawBuffersUpdated = true; + unsigned int height; + unsigned int width; +}; + +NzRenderTexture::~NzRenderTexture() +{ + Destroy(); +} + +bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 index, nzPixelFormat format) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return false; + } + + unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; + if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && + m_impl->attachements[depthStencilIndex].isUsed) + { + NazaraError("Stencil target already attached by DepthStencil attachment"); + return false; + } + + if (formatTypeToAttachment[NzPixelFormat::GetType(format)] != attachmentPoint) + { + NazaraError("Pixel format type does not match attachment point type"); + return false; + } + #endif + + NzOpenGL::Format openglFormat; + if (!NzOpenGL::TranslateFormat(format, &openglFormat, NzOpenGL::FormatType_RenderBuffer)) + { + NazaraError("Failed to translate pixel format into OpenGL format"); + return false; + } + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + // Détachement de l'attache précédente (Si il y a) + Detach(attachmentPoint, index); + + GLuint renderBuffer = 0; + + glGenRenderbuffers(1, &renderBuffer); + if (!renderBuffer) + { + NazaraError("Failed to create renderbuffer"); + return false; + } + + GLint previous; + glGetIntegerv(GL_RENDERBUFFER_BINDING, &previous); + + glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); + glRenderbufferStorage(GL_RENDERBUFFER, openglFormat.internalFormat, m_impl->width, m_impl->height); + + if (previous != 0) + glBindRenderbuffer(GL_RENDERBUFFER, previous); + + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, renderBuffer); + Unlock(); + + unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; + if (m_impl->attachements.size() < minSize) + m_impl->attachements.resize(minSize); + + Attachment& attachment = m_impl->attachements[minSize-1]; + attachment.isBuffer = true; + attachment.isUsed = true; + attachment.buffer = renderBuffer; + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + + return true; +} + +bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return false; + } + + unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; + if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && + m_impl->attachements[depthStencilIndex].isUsed) + { + NazaraError("Stencil target already attached by DepthStencil attachment"); + return false; + } + + if (!texture || !texture->IsValid()) + { + NazaraError("Invalid texture"); + return false; + } + + if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height) + { + NazaraError("Texture cannot be smaller than render texture"); + return false; + } + + if (texture->GetRenderTexture() != nullptr) + { + NazaraError("Texture already used by another render texture"); + return false; + } + + if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint) + { + NazaraError("Pixel format type does not match attachment point type"); + return false; + } + #endif + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + // Détachement de l'attache précédente (Si il y a) + Detach(attachmentPoint, index); + + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0); + Unlock(); + + unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; + if (m_impl->attachements.size() < minSize) + m_impl->attachements.resize(minSize); + + Attachment& attachment = m_impl->attachements[minSize-1]; + attachment.isBuffer = true; + attachment.isUsed = true; + attachment.texture = texture; + + texture->AddResourceListener(this, minSize-1); + texture->SetRenderTexture(this); + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + + return true; +} + +bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 index, NzTexture* texture, unsigned int z) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return false; + } + + if (attachmentPoint == nzAttachmentPoint_Stencil) + { + NazaraError("Targeting stencil-only textures is not supported"); + return false; + } + + unsigned int depthStencilIndex = attachmentIndex[nzAttachmentPoint_DepthStencil]; + if (attachmentPoint == nzAttachmentPoint_Stencil && m_impl->attachements.size() > depthStencilIndex && + m_impl->attachements[depthStencilIndex].isUsed) + { + NazaraError("Stencil target already attached by DepthStencil attachment"); + return false; + } + + if (!texture || !texture->IsValid()) + { + NazaraError("Invalid texture"); + return false; + } + + if (texture->GetWidth() < m_impl->width || texture->GetHeight() < m_impl->height) + { + NazaraError("Texture cannot be smaller than render texture"); + return false; + } + + unsigned int depth = (texture->GetType() == nzImageType_Cubemap) ? 6 : texture->GetDepth(); + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return false; + } + + if (texture->GetRenderTexture() != nullptr) + { + NazaraError("Texture already used by another render texture"); + return false; + } + + if (formatTypeToAttachment[NzPixelFormat::GetType(texture->GetFormat())] != attachmentPoint) + { + NazaraError("Pixel format type does not match attachment point type"); + return false; + } + #endif + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + // Détachement de l'attache précédente (Si il y a) + Detach(attachmentPoint, index); + + switch (texture->GetType()) + { + case nzImageType_1D: + glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_1D, texture->GetOpenGLID(), 0); + break; + + case nzImageType_1D_Array: + case nzImageType_2D_Array: + glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, texture->GetOpenGLID(), 0, z); + break; + + case nzImageType_2D: + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::TextureTarget[texture->GetType()], texture->GetOpenGLID(), 0); + break; + + case nzImageType_3D: + glFramebufferTexture3D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_TEXTURE_3D, texture->GetOpenGLID(), 0, z); + break; + + case nzImageType_Cubemap: + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, NzOpenGL::CubemapFace[z], texture->GetOpenGLID(), 0); + break; + } + Unlock(); + + unsigned int minSize = attachmentIndex[attachmentPoint]+index+1; + if (m_impl->attachements.size() < minSize) + m_impl->attachements.resize(minSize); + + Attachment& attachment = m_impl->attachements[minSize-1]; + attachment.isBuffer = true; + attachment.isUsed = true; + attachment.texture = texture; + + texture->AddResourceListener(this); + texture->SetRenderTexture(this); + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + + return true; +} + +bool NzRenderTexture::Create(unsigned int width, unsigned int height, bool lock) +{ + if (!IsSupported()) + { + NazaraError("Render textures not supported"); + return false; + } + + Destroy(); + + #if NAZARA_RENDERER_SAFE + if (width == 0) + { + NazaraError("Width must be at least 1 (0)"); + return false; + } + + if (height == 0) + { + NazaraError("Height must be at least 1 (0)"); + return false; + } + + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return false; + } + #endif + + NzRenderTextureImpl* impl = new NzRenderTextureImpl; + impl->width = width; + impl->height = height; + + impl->context = NzContext::GetCurrent(); + impl->context->AddResourceListener(this); + + impl->fbo = 0; + glGenFramebuffers(1, &impl->fbo); + + if (!impl->fbo) + { + NazaraError("Failed to create framebuffer"); + delete impl; + + return false; + } + + m_impl = impl; + + if (lock && !Lock()) + { + NazaraError("Failed to lock render texture"); + delete impl; + m_impl = nullptr; + + return false; + } + + return true; +} + +void NzRenderTexture::Destroy() +{ + if (m_impl) + { + #if NAZARA_RENDERER_SAFE + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture can only be used with it's creation context"); + return; + } + #endif + + m_impl->context->RemoveResourceListener(this); + + for (Attachment& attachment : m_impl->attachements) + { + if (attachment.isUsed) + { + if (attachment.isBuffer) + glDeleteRenderbuffers(1, &attachment.buffer); + else + { + attachment.texture->RemoveResourceListener(this); + attachment.texture->SetRenderTexture(nullptr); + } + } + } + + glDeleteFramebuffers(1, &m_impl->fbo); + + delete m_impl; + m_impl = nullptr; + } +} + +void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return; + } + + if (attachmentPoint != nzAttachmentPoint_Color && index > 0) + { + NazaraError("Index must be 0 for non-color attachments"); + return; + } + #endif + + unsigned int attachIndex = attachmentIndex[attachmentPoint]+index; + if (attachIndex >= m_impl->attachements.size()) + return; + + Attachment& attachement = m_impl->attachements[attachIndex]; + if (!attachement.isUsed) + return; + + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return; + } + + attachement.isUsed = false; + + if (attachement.isBuffer) + { + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0); + glDeleteRenderbuffers(1, &attachement.buffer); + } + else + { + glFramebufferTexture(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0); + attachement.texture->RemoveResourceListener(this); + attachement.texture->SetRenderTexture(nullptr); + } + + Unlock(); + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + +} + +unsigned int NzRenderTexture::GetHeight() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return 0; + } + #endif + + return m_impl->height; +} + +NzRenderTargetParameters NzRenderTexture::GetParameters() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return NzRenderTargetParameters(); + } + #endif + + return NzRenderTargetParameters(); +} + +unsigned int NzRenderTexture::GetWidth() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return 0; + } + #endif + + return m_impl->width; +} + +bool NzRenderTexture::IsComplete() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + #endif + + if (!m_impl->checked) + { + if (!Lock()) + { + NazaraError("Failed to lock render texture"); + return false; + } + + GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); + Unlock(); + + m_impl->complete = false; + + switch (status) + { + case GL_FRAMEBUFFER_COMPLETE: + m_impl->complete = true; + break; + + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + NazaraError("Incomplete attachment"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + NazaraInternalError("Incomplete draw buffer"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + NazaraInternalError("Incomplete read buffer"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + NazaraError("Incomplete missing attachment"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: + NazaraError("Incomplete multisample"); + break; + + case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: + NazaraError("Incomplete layer targets"); + break; + + case GL_FRAMEBUFFER_UNSUPPORTED: + NazaraError("Render texture has unsupported attachments"); + break; + + default: + NazaraInternalError("Unknown error"); + } + + m_impl->checked = true; + } + + return m_impl->complete; +} + +bool NzRenderTexture::IsRenderable() const +{ + return IsComplete(); +} + +bool NzRenderTexture::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzRenderTexture::Lock() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return false; + } + + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return false; + } + #endif + + if (lockedLevel++ == 0) + { + GLint previous; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previous); + + lockedPrevious = previous; + + if (lockedPrevious != m_impl->fbo) + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo); + } + + return true; +} + +void NzRenderTexture::Unlock() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Render texture not created"); + return; + } + + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return; + } + + if (lockedLevel == 0) + { + NazaraWarning("Unlock called on non-locked texture"); + return; + } + #endif + + if (--lockedLevel == 0 && lockedPrevious != m_impl->fbo) // Ici, il est important qu'un FBO soit débindé si l'ancien était 0 + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, lockedPrevious); +} + +bool NzRenderTexture::HasContext() const +{ + return false; +} + +bool NzRenderTexture::IsSupported() +{ + return NzRenderer::HasCapability(nzRendererCap_RenderTexture); +} + +bool NzRenderTexture::Activate() +{ + #if NAZARA_RENDERER_SAFE + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return false; + } + #endif + + if (!m_impl->drawBuffersUpdated) + { + m_impl->drawBuffers.clear(); + m_impl->drawBuffers.reserve(m_impl->attachements.size()); + for (unsigned int i = attachmentIndex[nzAttachmentPoint_Color]; i < m_impl->attachements.size(); ++i) + { + if (m_impl->attachements[i].isUsed) + m_impl->drawBuffers.push_back(GL_COLOR_ATTACHMENT0 + i - attachmentIndex[nzAttachmentPoint_Color]); + } + + m_impl->drawBuffersUpdated = true; + } + + glDrawBuffers(m_impl->drawBuffers.size(), &m_impl->drawBuffers[0]); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_impl->fbo); + + return true; +} + +void NzRenderTexture::Desactivate() +{ + #if NAZARA_RENDERER_SAFE + if (NzContext::GetCurrent() != m_impl->context) + { + NazaraError("RenderTexture cannot be used with this context"); + return; + } + #endif + + glFlush(); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); +} + +void NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index) +{ + if (resource == m_impl->context) + // Notre context a été détruit, libérons la RenderTexture pour éviter un leak + Destroy(); + else + { + // Sinon, c'est une texture + + // La ressource n'est plus, du coup nous mettons à jour + Attachment& attachement = m_impl->attachements[index]; + attachement.isUsed = false; + + m_impl->checked = false; + m_impl->drawBuffersUpdated = false; + } +} diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index a3fb37653..255981c0c 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -1,276 +1,276 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) -{ - Create(mode, title, style, parameters); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create render window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) -{ - Create(handle, parameters); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create render window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzRenderWindow::~NzRenderWindow() -{ - // Nécessaire si NzWindow::Destroy est appelé par son destructeur - OnWindowDestroy(); -} - -bool NzRenderWindow::CopyToImage(NzImage* image) -{ - #if NAZARA_RENDERER_SAFE - if (!m_context) - { - NazaraError("Window has not been created"); - return false; - } - - if (!image) - { - NazaraError("Image must be valid"); - return false; - } - #endif - - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return false; - } - - NzVector2ui size = GetSize(); - - if (!image->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1)) - { - NazaraError("Failed to create image"); - return false; - } - - nzUInt8* pixels = image->GetPixels(); - glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - image->FlipVertically(); - - return true; -} - -bool NzRenderWindow::CopyToTexture(NzTexture* texture) -{ - #if NAZARA_RENDERER_SAFE - if (!m_context) - { - NazaraError("Window has not been created"); - return false; - } - - if (!texture) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return false; - } - - NzVector2ui size = GetSize(); - - if (!texture->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1, true)) - { - NazaraError("Failed to create texture"); - return false; - } - - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.x, size.y); - - texture->Unlock(); - - return true; -} - -bool NzRenderWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) -{ - m_parameters = parameters; - return NzWindow::Create(mode, title, style); -} - -bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& parameters) -{ - m_parameters = parameters; - return NzWindow::Create(handle); -} - -void NzRenderWindow::Display() -{ - if (m_framerateLimit > 0) - { - int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds(); - if (remainingTime > 0) - NzThread::Sleep(remainingTime); - - m_clock.Restart(); - } - - if (m_context && m_parameters.doubleBuffered) - m_context->SwapBuffers(); -} - -void NzRenderWindow::EnableVerticalSync(bool enabled) -{ - if (m_context) - { - #if defined(NAZARA_PLATFORM_WINDOWS) - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return; - } - - if (wglSwapInterval) - wglSwapInterval(enabled ? 1 : 0); - else - #elif defined(NAZARA_PLATFORM_LINUX) - if (!m_context->SetActive(true)) - { - NazaraError("Failed to activate context"); - return; - } - - if (glXSwapInterval) - glXSwapInterval(enabled ? 1 : 0); - else - #else - #error Vertical Sync is not supported on this platform - #endif - NazaraError("Vertical Sync is not supported on this platform"); - } - else - NazaraError("No context"); -} - -unsigned int NzRenderWindow::GetHeight() const -{ - return NzWindow::GetHeight(); -} - -NzRenderTargetParameters NzRenderWindow::GetParameters() const -{ - if (m_context) - { - const NzContextParameters& parameters = m_context->GetParameters(); - return NzRenderTargetParameters(parameters.antialiasingLevel, parameters.depthBits, parameters.stencilBits); - } - else - { - NazaraError("Window not created/context not initialized"); - return NzRenderTargetParameters(); - } -} - -unsigned int NzRenderWindow::GetWidth() const -{ - return NzWindow::GetWidth(); -} - -bool NzRenderWindow::IsRenderable() const -{ - return m_impl != nullptr; // Si m_impl est valide, alors m_context l'est aussi -} - -void NzRenderWindow::SetFramerateLimit(unsigned int limit) -{ - m_framerateLimit = limit; -} - -NzContextParameters NzRenderWindow::GetContextParameters() const -{ - if (m_context) - return m_context->GetParameters(); - else - { - NazaraError("Window not created/context not initialized"); - return NzContextParameters(); - } -} - -bool NzRenderWindow::HasContext() const -{ - return true; -} - -bool NzRenderWindow::Activate() -{ - if (m_context->SetActive(true)) - { - glDrawBuffer((m_parameters.doubleBuffered) ? GL_BACK : GL_FRONT); - return true; - } - else - { - NazaraError("Failed to activate window's context"); - return false; - } -} - -bool NzRenderWindow::OnWindowCreated() -{ - m_parameters.doubleBuffered = true; - m_parameters.window = GetHandle(); - - m_context = new NzContext; - if (!m_context->Create(m_parameters)) - { - NazaraError("Failed not create context"); - delete m_context; - - return false; - } - - EnableVerticalSync(false); - - if (!SetActive(true)) // Les fenêtres s'activent à la création - NazaraWarning("Failed to activate window"); - - m_clock.Restart(); - - return true; -} - -void NzRenderWindow::OnWindowDestroy() -{ - if (m_context) - { - delete m_context; - m_context = nullptr; - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) +{ + Create(mode, title, style, parameters); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create render window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) +{ + Create(handle, parameters); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create render window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzRenderWindow::~NzRenderWindow() +{ + // Nécessaire si NzWindow::Destroy est appelé par son destructeur + OnWindowDestroy(); +} + +bool NzRenderWindow::CopyToImage(NzImage* image) +{ + #if NAZARA_RENDERER_SAFE + if (!m_context) + { + NazaraError("Window has not been created"); + return false; + } + + if (!image) + { + NazaraError("Image must be valid"); + return false; + } + #endif + + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return false; + } + + NzVector2ui size = GetSize(); + + if (!image->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1)) + { + NazaraError("Failed to create image"); + return false; + } + + nzUInt8* pixels = image->GetPixels(); + glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + image->FlipVertically(); + + return true; +} + +bool NzRenderWindow::CopyToTexture(NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_context) + { + NazaraError("Window has not been created"); + return false; + } + + if (!texture) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return false; + } + + NzVector2ui size = GetSize(); + + if (!texture->Create(nzImageType_2D, nzPixelFormat_RGBA8, size.x, size.y, 1, 1, true)) + { + NazaraError("Failed to create texture"); + return false; + } + + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.x, size.y); + + texture->Unlock(); + + return true; +} + +bool NzRenderWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) +{ + m_parameters = parameters; + return NzWindow::Create(mode, title, style); +} + +bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& parameters) +{ + m_parameters = parameters; + return NzWindow::Create(handle); +} + +void NzRenderWindow::Display() +{ + if (m_framerateLimit > 0) + { + int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds(); + if (remainingTime > 0) + NzThread::Sleep(remainingTime); + + m_clock.Restart(); + } + + if (m_context && m_parameters.doubleBuffered) + m_context->SwapBuffers(); +} + +void NzRenderWindow::EnableVerticalSync(bool enabled) +{ + if (m_context) + { + #if defined(NAZARA_PLATFORM_WINDOWS) + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return; + } + + if (wglSwapInterval) + wglSwapInterval(enabled ? 1 : 0); + else + #elif defined(NAZARA_PLATFORM_LINUX) + if (!m_context->SetActive(true)) + { + NazaraError("Failed to activate context"); + return; + } + + if (glXSwapInterval) + glXSwapInterval(enabled ? 1 : 0); + else + #else + #error Vertical Sync is not supported on this platform + #endif + NazaraError("Vertical Sync is not supported on this platform"); + } + else + NazaraError("No context"); +} + +unsigned int NzRenderWindow::GetHeight() const +{ + return NzWindow::GetHeight(); +} + +NzRenderTargetParameters NzRenderWindow::GetParameters() const +{ + if (m_context) + { + const NzContextParameters& parameters = m_context->GetParameters(); + return NzRenderTargetParameters(parameters.antialiasingLevel, parameters.depthBits, parameters.stencilBits); + } + else + { + NazaraError("Window not created/context not initialized"); + return NzRenderTargetParameters(); + } +} + +unsigned int NzRenderWindow::GetWidth() const +{ + return NzWindow::GetWidth(); +} + +bool NzRenderWindow::IsRenderable() const +{ + return m_impl != nullptr; // Si m_impl est valide, alors m_context l'est aussi +} + +void NzRenderWindow::SetFramerateLimit(unsigned int limit) +{ + m_framerateLimit = limit; +} + +NzContextParameters NzRenderWindow::GetContextParameters() const +{ + if (m_context) + return m_context->GetParameters(); + else + { + NazaraError("Window not created/context not initialized"); + return NzContextParameters(); + } +} + +bool NzRenderWindow::HasContext() const +{ + return true; +} + +bool NzRenderWindow::Activate() +{ + if (m_context->SetActive(true)) + { + glDrawBuffer((m_parameters.doubleBuffered) ? GL_BACK : GL_FRONT); + return true; + } + else + { + NazaraError("Failed to activate window's context"); + return false; + } +} + +bool NzRenderWindow::OnWindowCreated() +{ + m_parameters.doubleBuffered = true; + m_parameters.window = GetHandle(); + + m_context = new NzContext; + if (!m_context->Create(m_parameters)) + { + NazaraError("Failed not create context"); + delete m_context; + + return false; + } + + EnableVerticalSync(false); + + if (!SetActive(true)) // Les fenêtres s'activent à la création + NazaraWarning("Failed to activate window"); + + m_clock.Restart(); + + return true; +} + +void NzRenderWindow::OnWindowDestroy() +{ + if (m_context) + { + delete m_context; + m_context = nullptr; + } +} diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index a30725bbd..d31a5284f 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -1,902 +1,902 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include // Pour éviter une redéfinition de WIN32_LEAN_AND_MEAN -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - ///FIXME: Solution temporaire pour plus de facilité - enum nzMatrixCombination - { - nzMatrixCombination_ViewProj = nzMatrixType_Max+1, - nzMatrixCombination_WorldView, - nzMatrixCombination_WorldViewProj, - - nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj - }; - - NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type) - { - return new NzHardwareBuffer(parent, type); - } - - constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; - - using VAO_Key = std::tuple; - - std::map s_vaos; - NzMatrix4f s_matrix[totalMatrixCount]; - int s_matrixLocation[totalMatrixCount]; - bool s_matrixUpdated[totalMatrixCount]; - nzRendererComparison s_stencilCompare; - nzStencilOperation s_stencilFail; - nzStencilOperation s_stencilPass; - nzStencilOperation s_stencilZFail; - nzUInt32 s_stencilMask; - const NzIndexBuffer* s_indexBuffer; - NzRenderTarget* s_target; - NzShader* s_shader; - const NzVertexBuffer* s_vertexBuffer; - const NzVertexDeclaration* s_vertexDeclaration; - bool s_vaoUpdated; - bool s_capabilities[nzRendererCap_Max+1]; - bool s_stencilFuncUpdated; - bool s_stencilOpUpdated; - unsigned int s_maxAnisotropyLevel; - unsigned int s_maxRenderTarget; - unsigned int s_maxTextureUnit; - unsigned int s_stencilReference; -} - -void NzRenderer::Clear(unsigned long flags) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - if (flags) - { - GLenum mask = 0; - - if (flags & nzRendererClear_Color) - mask |= GL_COLOR_BUFFER_BIT; - - if (flags & nzRendererClear_Depth) - mask |= GL_DEPTH_BUFFER_BIT; - - if (flags & nzRendererClear_Stencil) - mask |= GL_STENCIL_BUFFER_BIT; - - glClear(mask); - } -} - -void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (!s_indexBuffer) - { - NazaraError("No index buffer"); - return; - } - #endif - - if (!EnsureStateUpdate()) - { - NazaraError("Failed to update states"); - return; - } - - if (s_indexBuffer->IsSequential()) - glDrawArrays(NzOpenGL::PrimitiveType[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount()); - else - { - nzUInt8 indexSize = s_indexBuffer->GetIndexSize(); - - GLenum type; - switch (indexSize) - { - case 1: - type = GL_UNSIGNED_BYTE; - break; - - case 2: - type = GL_UNSIGNED_SHORT; - break; - - case 4: - type = GL_UNSIGNED_INT; - break; - - default: - NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')'); - return; - } - - glDrawElements(NzOpenGL::PrimitiveType[primitive], indexCount, type, reinterpret_cast(s_indexBuffer->GetPointer()) + firstIndex*indexSize); - } -} - -void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - if (!EnsureStateUpdate()) - { - NazaraError("Failed to update states"); - return; - } - - glDrawArrays(NzOpenGL::PrimitiveType[primitive], firstVertex, vertexCount); -} - -void NzRenderer::Enable(nzRendererParameter parameter, bool enable) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - switch (parameter) - { - case nzRendererParameter_ColorWrite: - glColorMask(enable, enable, enable, enable); - break; - - case nzRendererParameter_DepthWrite: - glDepthMask(enable); - break; - - default: - if (enable) - glEnable(NzOpenGL::RendererParameter[parameter]); - else - glDisable(NzOpenGL::RendererParameter[parameter]); - - break; - } -} -/* -NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination) -{ - ///FIXME: Duplication - switch (combination) - { - case nzMatrixCombination_ViewProj: - if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) - { - s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; - s_matrixUpdated[nzMatrixCombination_ViewProj] = true; - } - break; - - case nzMatrixCombination_WorldView: - if (!s_matrixUpdated[nzMatrixCombination_WorldView]) - { - s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); - s_matrixUpdated[nzMatrixCombination_WorldView] = true; - } - break; - - case nzMatrixCombination_WorldViewProj: - if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) - { - s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; - s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; - } - break; - } - - return m_matrix[combination]; -} -*/ -NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type) -{ - return s_matrix[type]; -} - -unsigned int NzRenderer::GetMaxAnisotropyLevel() -{ - return s_maxAnisotropyLevel; -} - -unsigned int NzRenderer::GetMaxRenderTargets() -{ - return s_maxRenderTarget; -} - -unsigned int NzRenderer::GetMaxTextureUnits() -{ - return s_maxTextureUnit; -} - -NzShader* NzRenderer::GetShader() -{ - return s_shader; -} - -NzRenderTarget* NzRenderer::GetTarget() -{ - return s_target; -} - -NzRectui NzRenderer::GetViewport() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return NzRectui(); - } - #endif - - GLint params[4]; - glGetIntegerv(GL_VIEWPORT, ¶ms[0]); - - return NzRectui(params[0], params[1], params[2], params[3]); -} - -bool NzRenderer::HasCapability(nzRendererCap capability) -{ - return s_capabilities[capability]; -} - -bool NzRenderer::Initialize() -{ - if (s_moduleReferenceCouter++ != 0) - return true; // Déjà initialisé - - // Initialisation des dépendances - if (!NzUtility::Initialize()) - { - NazaraError("Failed to initialize utility module"); - return false; - } - - // Initialisation du module - if (!NzOpenGL::Initialize()) - { - NazaraError("Failed to initialize OpenGL"); - return false; - } - - NzContext::EnsureContext(); - - for (unsigned int i = 0; i < totalMatrixCount; ++i) - { - s_matrix[i].MakeIdentity(); - s_matrixLocation[i] = -1; - s_matrixUpdated[i] = false; - } - - s_indexBuffer = nullptr; - s_shader = nullptr; - s_stencilCompare = nzRendererComparison_Always; - s_stencilFail = nzStencilOperation_Keep; - s_stencilFuncUpdated = true; - s_stencilMask = 0xFFFFFFFF; - s_stencilOpUpdated = true; - s_stencilPass = nzStencilOperation_Keep; - s_stencilReference = 0; - s_stencilZFail = nzStencilOperation_Keep; - s_target = nullptr; - s_vaoUpdated = false; - s_vertexBuffer = nullptr; - s_vertexDeclaration = nullptr; - - // Récupération des capacités d'OpenGL - s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter); - s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(nzOpenGLExtension_FP64); - s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 - // MultipleRenderTargets (Techniquement natif depuis OpenGL 2.0 mais inutile sans glBindFragDataLocation) - s_capabilities[nzRendererCap_MultipleRenderTargets] = (glBindFragDataLocation != nullptr); - s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 - s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(nzOpenGLExtension_PixelBufferObject); - s_capabilities[nzRendererCap_RenderTexture] = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); - s_capabilities[nzRendererCap_Texture3D] = true; // Natif depuis OpenGL 1.2 - s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 - s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 - s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0 - - if (s_capabilities[nzRendererCap_AnisotropicFilter]) - { - GLint maxAnisotropy; - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); - - s_maxAnisotropyLevel = static_cast(maxAnisotropy); - } - else - s_maxAnisotropyLevel = 1; - - if (s_capabilities[nzRendererCap_MultipleRenderTargets]) - { - GLint maxDrawBuffers; - glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); - - GLint maxColorAttachments; - glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); - - s_maxRenderTarget = static_cast(std::min(maxColorAttachments, maxDrawBuffers)); - } - else - s_maxRenderTarget = 1; - - if (s_capabilities[nzRendererCap_TextureMulti]) - { - GLint maxTextureUnits; - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); - - GLint maxVertexAttribs; - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); - - // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) - s_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-NzOpenGL::AttributeIndex[nzElementUsage_TexCoord])); - } - else - s_maxTextureUnit = 1; - - NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); - - NazaraNotice("Initialized: Renderer module"); - - return true; -} - -bool NzRenderer::IsInitialized() -{ - return s_moduleReferenceCouter != 0; -} - -void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glBlendFunc(NzOpenGL::BlendFunc[src], NzOpenGL::BlendFunc[dest]); -} - -void NzRenderer::SetClearColor(const NzColor& color) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearColor(color.r/255.f, color.g/255.f, color.b/255.f, color.a/255.f); -} - -void NzRenderer::SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearColor(r/255.f, g/255.f, b/255.f, a/255.f); -} - -void NzRenderer::SetClearDepth(double depth) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearDepth(depth); -} - -void NzRenderer::SetClearStencil(unsigned int value) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glClearStencil(value); -} - -void NzRenderer::SetFaceCulling(nzFaceCulling cullingMode) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glCullFace(NzOpenGL::FaceCulling[cullingMode]); -} - -void NzRenderer::SetFaceFilling(nzFaceFilling fillingMode) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - glPolygonMode(GL_FRONT_AND_BACK, NzOpenGL::FaceFilling[fillingMode]); -} - -bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer) -{ - #if NAZARA_RENDERER_SAFE - if (indexBuffer && !indexBuffer->IsHardware() && !indexBuffer->IsSequential()) - { - NazaraError("Buffer must be hardware"); - return false; - } - #endif - - if (s_indexBuffer != indexBuffer) - { - s_indexBuffer = indexBuffer; - s_vaoUpdated = false; - } - - return true; -} - -void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix) -{ - s_matrix[type] = matrix; - - // Invalidation des combinaisons - switch (type) - { - case nzMatrixType_View: - case nzMatrixType_World: - s_matrixUpdated[nzMatrixCombination_WorldView] = false; - case nzMatrixType_Projection: - s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false; - s_matrixUpdated[nzMatrixCombination_ViewProj] = false; - break; - } -} - -bool NzRenderer::SetShader(NzShader* shader) -{ - if (s_shader == shader) - return true; - - if (s_shader) - s_shader->m_impl->Unbind(); - - if (shader) - { - #if NAZARA_RENDERER_SAFE - if (!shader->IsCompiled()) - { - NazaraError("Shader is not compiled"); - shader = nullptr; - - return false; - } - #endif - - if (!shader->m_impl->Bind()) - { - NazaraError("Failed to bind shader"); - shader = nullptr; - - return false; - } - - // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) - s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix"); - s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix"); - s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix"); - - s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix"); - s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix"); - s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix"); - } - - s_shader = shader; - - return true; -} - -void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc) -{ - if (compareFunc != s_stencilCompare) - { - s_stencilCompare = compareFunc; - s_stencilFuncUpdated = false; - } -} - -void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation) -{ - if (failOperation != s_stencilFail) - { - s_stencilFail = failOperation; - s_stencilOpUpdated = false; - } -} - -void NzRenderer::SetStencilMask(nzUInt32 mask) -{ - if (mask != s_stencilMask) - { - s_stencilMask = mask; - s_stencilFuncUpdated = false; - } -} - -void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation) -{ - if (passOperation != s_stencilPass) - { - s_stencilPass = passOperation; - s_stencilOpUpdated = false; - } -} - -void NzRenderer::SetStencilReferenceValue(unsigned int refValue) -{ - if (refValue != s_stencilReference) - { - s_stencilReference = refValue; - s_stencilFuncUpdated = false; - } -} - -void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation) -{ - if (zfailOperation != s_stencilZFail) - { - s_stencilZFail = zfailOperation; - s_stencilOpUpdated = false; - } -} - -bool NzRenderer::SetTarget(NzRenderTarget* target) -{ - if (s_target == target) - return true; - - if (s_target && !s_target->HasContext()) - s_target->Desactivate(); - - if (target) - { - #if NAZARA_RENDERER_SAFE - if (!target->IsRenderable()) - { - NazaraError("Target not renderable"); - return false; - } - #endif - - if (target->Activate()) - s_target = target; - else - { - NazaraError("Failed to activate target"); - s_target = nullptr; - - return false; - } - } - else - s_target = nullptr; - - return true; -} - -bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) -{ - #if NAZARA_RENDERER_SAFE - if (vertexBuffer && !vertexBuffer->IsHardware()) - { - NazaraError("Buffer must be hardware"); - return false; - } - #endif - - if (s_vertexBuffer != vertexBuffer) - { - s_vertexBuffer = vertexBuffer; - s_vaoUpdated = false; - } - - return true; -} - -bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration) -{ - if (s_vertexDeclaration != vertexDeclaration) - { - s_vertexDeclaration = vertexDeclaration; - s_vaoUpdated = false; - } - - return true; -} - -void NzRenderer::SetViewport(const NzRectui& viewport) -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - unsigned int height = s_target->GetHeight(); - - #if NAZARA_RENDERER_SAFE - if (!s_target) - { - NazaraError("Renderer has no target"); - return; - } - - unsigned int width = s_target->GetWidth(); - if (viewport.x+viewport.width > width || viewport.y+viewport.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return; - } - #endif - - glViewport(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); - glScissor(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); -} - -void NzRenderer::Uninitialize() -{ - if (--s_moduleReferenceCouter != 0) - return; // Encore utilisé - - // Libération du module - NzContext::EnsureContext(); - - // Libération des VAOs - for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it) - { - GLuint vao = static_cast(it->second); - glDeleteVertexArrays(1, &vao); - } - - NzOpenGL::Uninitialize(); - - NazaraNotice("Uninitialized: Renderer module"); - - // Libération des dépendances - NzUtility::Uninitialize(); -} - -bool NzRenderer::EnsureStateUpdate() -{ - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return false; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (!s_shader) - { - NazaraError("No shader"); - return false; - } - #endif - - // Il est plus rapide d'opérer sur l'implémentation du shader directement - NzShaderImpl* shaderImpl = s_shader->m_impl; - - if (!shaderImpl->BindTextures()) - NazaraWarning("Failed to bind textures"); - - for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) - { - if (!s_matrixUpdated[i]) - { - shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]); - s_matrixUpdated[i] = true; - } - } - - // Cas spéciaux car il faut recalculer la matrice - if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) - { - s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; - - shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]); - s_matrixUpdated[nzMatrixCombination_ViewProj] = true; - } - - if (!s_matrixUpdated[nzMatrixCombination_WorldView]) - { - s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); - - shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]); - s_matrixUpdated[nzMatrixCombination_WorldView] = true; - } - - if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) - { - s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; - - shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]); - s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; - } - - if (!s_stencilFuncUpdated) - { - glStencilFunc(NzOpenGL::RendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask); - s_stencilFuncUpdated = true; - } - - if (!s_stencilOpUpdated) - { - glStencilOp(NzOpenGL::StencilOperation[s_stencilFail], NzOpenGL::StencilOperation[s_stencilZFail], NzOpenGL::StencilOperation[s_stencilPass]); - s_stencilOpUpdated = true; - } - - if (!s_vaoUpdated) - { - #if NAZARA_RENDERER_SAFE - if (!s_vertexBuffer) - { - NazaraError("No vertex buffer"); - return false; - } - - if (!s_vertexDeclaration) - { - NazaraError("No vertex declaration"); - return false; - } - #endif - - static const bool vaoSupported = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObject); - bool update; - GLuint vao; - - // Si les VAOs sont supportés, on entoure nos appels par ceux-ci - if (vaoSupported) - { - // On recherche si un VAO existe déjà avec notre configuration - // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration - - auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration); - auto it = s_vaos.find(key); - if (it == s_vaos.end()) - { - // On créé notre VAO - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - // On l'ajoute à notre liste - s_vaos.insert(std::make_pair(key, static_cast(vao))); - - // Et on indique qu'on veut le programmer - update = true; - } - else - { - // Notre VAO existe déjà, il est donc inutile de le reprogrammer - vao = it->second; - - update = false; - } - } - else - update = true; // Fallback si les VAOs ne sont pas supportés - - if (update) - { - NzHardwareBuffer* vertexBufferImpl = static_cast(s_vertexBuffer->GetBuffer()->GetImpl()); - vertexBufferImpl->Bind(); - - const nzUInt8* buffer = reinterpret_cast(s_vertexBuffer->GetPointer()); - - unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData); - for (unsigned int i = 0; i <= nzElementUsage_Max; ++i) - { - const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast(i)); - - if (element) - { - glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); - glVertexAttribPointer(NzOpenGL::AttributeIndex[i], - NzVertexDeclaration::GetElementCount(element->type), - NzOpenGL::ElementType[element->type], - (element->type == nzElementType_Color) ? GL_TRUE : GL_FALSE, - stride, - &buffer[element->offset]); - } - else - glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); - } - - if (s_indexBuffer) - { - NzHardwareBuffer* indexBufferImpl = static_cast(s_indexBuffer->GetBuffer()->GetImpl()); - indexBufferImpl->Bind(); - } - } - - if (vaoSupported) - { - // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction - if (update) - glBindVertexArray(0); - - // Nous (re)bindons le VAO pour définir les attributs de vertice - glBindVertexArray(vao); - } - - s_vaoUpdated = true; - } - - return true; -} - -unsigned int NzRenderer::s_moduleReferenceCouter = 0; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include // Pour éviter une redéfinition de WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + ///FIXME: Solution temporaire pour plus de facilité + enum nzMatrixCombination + { + nzMatrixCombination_ViewProj = nzMatrixType_Max+1, + nzMatrixCombination_WorldView, + nzMatrixCombination_WorldViewProj, + + nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj + }; + + NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type) + { + return new NzHardwareBuffer(parent, type); + } + + constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1; + + using VAO_Key = std::tuple; + + std::map s_vaos; + NzMatrix4f s_matrix[totalMatrixCount]; + int s_matrixLocation[totalMatrixCount]; + bool s_matrixUpdated[totalMatrixCount]; + nzRendererComparison s_stencilCompare; + nzStencilOperation s_stencilFail; + nzStencilOperation s_stencilPass; + nzStencilOperation s_stencilZFail; + nzUInt32 s_stencilMask; + const NzIndexBuffer* s_indexBuffer; + NzRenderTarget* s_target; + NzShader* s_shader; + const NzVertexBuffer* s_vertexBuffer; + const NzVertexDeclaration* s_vertexDeclaration; + bool s_vaoUpdated; + bool s_capabilities[nzRendererCap_Max+1]; + bool s_stencilFuncUpdated; + bool s_stencilOpUpdated; + unsigned int s_maxAnisotropyLevel; + unsigned int s_maxRenderTarget; + unsigned int s_maxTextureUnit; + unsigned int s_stencilReference; +} + +void NzRenderer::Clear(unsigned long flags) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + if (flags) + { + GLenum mask = 0; + + if (flags & nzRendererClear_Color) + mask |= GL_COLOR_BUFFER_BIT; + + if (flags & nzRendererClear_Depth) + mask |= GL_DEPTH_BUFFER_BIT; + + if (flags & nzRendererClear_Stencil) + mask |= GL_STENCIL_BUFFER_BIT; + + glClear(mask); + } +} + +void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (!s_indexBuffer) + { + NazaraError("No index buffer"); + return; + } + #endif + + if (!EnsureStateUpdate()) + { + NazaraError("Failed to update states"); + return; + } + + if (s_indexBuffer->IsSequential()) + glDrawArrays(NzOpenGL::PrimitiveType[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount()); + else + { + nzUInt8 indexSize = s_indexBuffer->GetIndexSize(); + + GLenum type; + switch (indexSize) + { + case 1: + type = GL_UNSIGNED_BYTE; + break; + + case 2: + type = GL_UNSIGNED_SHORT; + break; + + case 4: + type = GL_UNSIGNED_INT; + break; + + default: + NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')'); + return; + } + + glDrawElements(NzOpenGL::PrimitiveType[primitive], indexCount, type, reinterpret_cast(s_indexBuffer->GetPointer()) + firstIndex*indexSize); + } +} + +void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + if (!EnsureStateUpdate()) + { + NazaraError("Failed to update states"); + return; + } + + glDrawArrays(NzOpenGL::PrimitiveType[primitive], firstVertex, vertexCount); +} + +void NzRenderer::Enable(nzRendererParameter parameter, bool enable) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + switch (parameter) + { + case nzRendererParameter_ColorWrite: + glColorMask(enable, enable, enable, enable); + break; + + case nzRendererParameter_DepthWrite: + glDepthMask(enable); + break; + + default: + if (enable) + glEnable(NzOpenGL::RendererParameter[parameter]); + else + glDisable(NzOpenGL::RendererParameter[parameter]); + + break; + } +} +/* +NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination) +{ + ///FIXME: Duplication + switch (combination) + { + case nzMatrixCombination_ViewProj: + if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) + { + s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; + s_matrixUpdated[nzMatrixCombination_ViewProj] = true; + } + break; + + case nzMatrixCombination_WorldView: + if (!s_matrixUpdated[nzMatrixCombination_WorldView]) + { + s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); + s_matrixUpdated[nzMatrixCombination_WorldView] = true; + } + break; + + case nzMatrixCombination_WorldViewProj: + if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) + { + s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; + } + break; + } + + return m_matrix[combination]; +} +*/ +NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type) +{ + return s_matrix[type]; +} + +unsigned int NzRenderer::GetMaxAnisotropyLevel() +{ + return s_maxAnisotropyLevel; +} + +unsigned int NzRenderer::GetMaxRenderTargets() +{ + return s_maxRenderTarget; +} + +unsigned int NzRenderer::GetMaxTextureUnits() +{ + return s_maxTextureUnit; +} + +NzShader* NzRenderer::GetShader() +{ + return s_shader; +} + +NzRenderTarget* NzRenderer::GetTarget() +{ + return s_target; +} + +NzRectui NzRenderer::GetViewport() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return NzRectui(); + } + #endif + + GLint params[4]; + glGetIntegerv(GL_VIEWPORT, ¶ms[0]); + + return NzRectui(params[0], params[1], params[2], params[3]); +} + +bool NzRenderer::HasCapability(nzRendererCap capability) +{ + return s_capabilities[capability]; +} + +bool NzRenderer::Initialize() +{ + if (s_moduleReferenceCouter++ != 0) + return true; // Déjà initialisé + + // Initialisation des dépendances + if (!NzUtility::Initialize()) + { + NazaraError("Failed to initialize utility module"); + return false; + } + + // Initialisation du module + if (!NzOpenGL::Initialize()) + { + NazaraError("Failed to initialize OpenGL"); + return false; + } + + NzContext::EnsureContext(); + + for (unsigned int i = 0; i < totalMatrixCount; ++i) + { + s_matrix[i].MakeIdentity(); + s_matrixLocation[i] = -1; + s_matrixUpdated[i] = false; + } + + s_indexBuffer = nullptr; + s_shader = nullptr; + s_stencilCompare = nzRendererComparison_Always; + s_stencilFail = nzStencilOperation_Keep; + s_stencilFuncUpdated = true; + s_stencilMask = 0xFFFFFFFF; + s_stencilOpUpdated = true; + s_stencilPass = nzStencilOperation_Keep; + s_stencilReference = 0; + s_stencilZFail = nzStencilOperation_Keep; + s_target = nullptr; + s_vaoUpdated = false; + s_vertexBuffer = nullptr; + s_vertexDeclaration = nullptr; + + // Récupération des capacités d'OpenGL + s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter); + s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(nzOpenGLExtension_FP64); + s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5 + // MultipleRenderTargets (Techniquement natif depuis OpenGL 2.0 mais inutile sans glBindFragDataLocation) + s_capabilities[nzRendererCap_MultipleRenderTargets] = (glBindFragDataLocation != nullptr); + s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5 + s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(nzOpenGLExtension_PixelBufferObject); + s_capabilities[nzRendererCap_RenderTexture] = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); + s_capabilities[nzRendererCap_Texture3D] = true; // Natif depuis OpenGL 1.2 + s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3 + s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3 + s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0 + + if (s_capabilities[nzRendererCap_AnisotropicFilter]) + { + GLint maxAnisotropy; + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); + + s_maxAnisotropyLevel = static_cast(maxAnisotropy); + } + else + s_maxAnisotropyLevel = 1; + + if (s_capabilities[nzRendererCap_MultipleRenderTargets]) + { + GLint maxDrawBuffers; + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); + + GLint maxColorAttachments; + glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); + + s_maxRenderTarget = static_cast(std::min(maxColorAttachments, maxDrawBuffers)); + } + else + s_maxRenderTarget = 1; + + if (s_capabilities[nzRendererCap_TextureMulti]) + { + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + + GLint maxVertexAttribs; + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); + + // Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs) + s_maxTextureUnit = static_cast(std::min(maxTextureUnits, maxVertexAttribs-NzOpenGL::AttributeIndex[nzElementUsage_TexCoord])); + } + else + s_maxTextureUnit = 1; + + NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction); + + NazaraNotice("Initialized: Renderer module"); + + return true; +} + +bool NzRenderer::IsInitialized() +{ + return s_moduleReferenceCouter != 0; +} + +void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glBlendFunc(NzOpenGL::BlendFunc[src], NzOpenGL::BlendFunc[dest]); +} + +void NzRenderer::SetClearColor(const NzColor& color) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearColor(color.r/255.f, color.g/255.f, color.b/255.f, color.a/255.f); +} + +void NzRenderer::SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearColor(r/255.f, g/255.f, b/255.f, a/255.f); +} + +void NzRenderer::SetClearDepth(double depth) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearDepth(depth); +} + +void NzRenderer::SetClearStencil(unsigned int value) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glClearStencil(value); +} + +void NzRenderer::SetFaceCulling(nzFaceCulling cullingMode) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glCullFace(NzOpenGL::FaceCulling[cullingMode]); +} + +void NzRenderer::SetFaceFilling(nzFaceFilling fillingMode) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + glPolygonMode(GL_FRONT_AND_BACK, NzOpenGL::FaceFilling[fillingMode]); +} + +bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer) +{ + #if NAZARA_RENDERER_SAFE + if (indexBuffer && !indexBuffer->IsHardware() && !indexBuffer->IsSequential()) + { + NazaraError("Buffer must be hardware"); + return false; + } + #endif + + if (s_indexBuffer != indexBuffer) + { + s_indexBuffer = indexBuffer; + s_vaoUpdated = false; + } + + return true; +} + +void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix) +{ + s_matrix[type] = matrix; + + // Invalidation des combinaisons + switch (type) + { + case nzMatrixType_View: + case nzMatrixType_World: + s_matrixUpdated[nzMatrixCombination_WorldView] = false; + case nzMatrixType_Projection: + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false; + s_matrixUpdated[nzMatrixCombination_ViewProj] = false; + break; + } +} + +bool NzRenderer::SetShader(NzShader* shader) +{ + if (s_shader == shader) + return true; + + if (s_shader) + s_shader->m_impl->Unbind(); + + if (shader) + { + #if NAZARA_RENDERER_SAFE + if (!shader->IsCompiled()) + { + NazaraError("Shader is not compiled"); + shader = nullptr; + + return false; + } + #endif + + if (!shader->m_impl->Bind()) + { + NazaraError("Failed to bind shader"); + shader = nullptr; + + return false; + } + + // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) + s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix"); + s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix"); + s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix"); + + s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix"); + s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix"); + s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix"); + } + + s_shader = shader; + + return true; +} + +void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc) +{ + if (compareFunc != s_stencilCompare) + { + s_stencilCompare = compareFunc; + s_stencilFuncUpdated = false; + } +} + +void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation) +{ + if (failOperation != s_stencilFail) + { + s_stencilFail = failOperation; + s_stencilOpUpdated = false; + } +} + +void NzRenderer::SetStencilMask(nzUInt32 mask) +{ + if (mask != s_stencilMask) + { + s_stencilMask = mask; + s_stencilFuncUpdated = false; + } +} + +void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation) +{ + if (passOperation != s_stencilPass) + { + s_stencilPass = passOperation; + s_stencilOpUpdated = false; + } +} + +void NzRenderer::SetStencilReferenceValue(unsigned int refValue) +{ + if (refValue != s_stencilReference) + { + s_stencilReference = refValue; + s_stencilFuncUpdated = false; + } +} + +void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation) +{ + if (zfailOperation != s_stencilZFail) + { + s_stencilZFail = zfailOperation; + s_stencilOpUpdated = false; + } +} + +bool NzRenderer::SetTarget(NzRenderTarget* target) +{ + if (s_target == target) + return true; + + if (s_target && !s_target->HasContext()) + s_target->Desactivate(); + + if (target) + { + #if NAZARA_RENDERER_SAFE + if (!target->IsRenderable()) + { + NazaraError("Target not renderable"); + return false; + } + #endif + + if (target->Activate()) + s_target = target; + else + { + NazaraError("Failed to activate target"); + s_target = nullptr; + + return false; + } + } + else + s_target = nullptr; + + return true; +} + +bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer) +{ + #if NAZARA_RENDERER_SAFE + if (vertexBuffer && !vertexBuffer->IsHardware()) + { + NazaraError("Buffer must be hardware"); + return false; + } + #endif + + if (s_vertexBuffer != vertexBuffer) + { + s_vertexBuffer = vertexBuffer; + s_vaoUpdated = false; + } + + return true; +} + +bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration) +{ + if (s_vertexDeclaration != vertexDeclaration) + { + s_vertexDeclaration = vertexDeclaration; + s_vaoUpdated = false; + } + + return true; +} + +void NzRenderer::SetViewport(const NzRectui& viewport) +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + unsigned int height = s_target->GetHeight(); + + #if NAZARA_RENDERER_SAFE + if (!s_target) + { + NazaraError("Renderer has no target"); + return; + } + + unsigned int width = s_target->GetWidth(); + if (viewport.x+viewport.width > width || viewport.y+viewport.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return; + } + #endif + + glViewport(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); + glScissor(viewport.x, height-viewport.height-viewport.y, viewport.width, viewport.height); +} + +void NzRenderer::Uninitialize() +{ + if (--s_moduleReferenceCouter != 0) + return; // Encore utilisé + + // Libération du module + NzContext::EnsureContext(); + + // Libération des VAOs + for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it) + { + GLuint vao = static_cast(it->second); + glDeleteVertexArrays(1, &vao); + } + + NzOpenGL::Uninitialize(); + + NazaraNotice("Uninitialized: Renderer module"); + + // Libération des dépendances + NzUtility::Uninitialize(); +} + +bool NzRenderer::EnsureStateUpdate() +{ + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return false; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (!s_shader) + { + NazaraError("No shader"); + return false; + } + #endif + + // Il est plus rapide d'opérer sur l'implémentation du shader directement + NzShaderImpl* shaderImpl = s_shader->m_impl; + + if (!shaderImpl->BindTextures()) + NazaraWarning("Failed to bind textures"); + + for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) + { + if (!s_matrixUpdated[i]) + { + shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]); + s_matrixUpdated[i] = true; + } + } + + // Cas spéciaux car il faut recalculer la matrice + if (!s_matrixUpdated[nzMatrixCombination_ViewProj]) + { + s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection]; + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]); + s_matrixUpdated[nzMatrixCombination_ViewProj] = true; + } + + if (!s_matrixUpdated[nzMatrixCombination_WorldView]) + { + s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]); + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]); + s_matrixUpdated[nzMatrixCombination_WorldView] = true; + } + + if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj]) + { + s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection]; + + shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]); + s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true; + } + + if (!s_stencilFuncUpdated) + { + glStencilFunc(NzOpenGL::RendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask); + s_stencilFuncUpdated = true; + } + + if (!s_stencilOpUpdated) + { + glStencilOp(NzOpenGL::StencilOperation[s_stencilFail], NzOpenGL::StencilOperation[s_stencilZFail], NzOpenGL::StencilOperation[s_stencilPass]); + s_stencilOpUpdated = true; + } + + if (!s_vaoUpdated) + { + #if NAZARA_RENDERER_SAFE + if (!s_vertexBuffer) + { + NazaraError("No vertex buffer"); + return false; + } + + if (!s_vertexDeclaration) + { + NazaraError("No vertex declaration"); + return false; + } + #endif + + static const bool vaoSupported = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObject); + bool update; + GLuint vao; + + // Si les VAOs sont supportés, on entoure nos appels par ceux-ci + if (vaoSupported) + { + // On recherche si un VAO existe déjà avec notre configuration + // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration + + auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration); + auto it = s_vaos.find(key); + if (it == s_vaos.end()) + { + // On créé notre VAO + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + // On l'ajoute à notre liste + s_vaos.insert(std::make_pair(key, static_cast(vao))); + + // Et on indique qu'on veut le programmer + update = true; + } + else + { + // Notre VAO existe déjà, il est donc inutile de le reprogrammer + vao = it->second; + + update = false; + } + } + else + update = true; // Fallback si les VAOs ne sont pas supportés + + if (update) + { + NzHardwareBuffer* vertexBufferImpl = static_cast(s_vertexBuffer->GetBuffer()->GetImpl()); + vertexBufferImpl->Bind(); + + const nzUInt8* buffer = reinterpret_cast(s_vertexBuffer->GetPointer()); + + unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData); + for (unsigned int i = 0; i <= nzElementUsage_Max; ++i) + { + const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast(i)); + + if (element) + { + glEnableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + glVertexAttribPointer(NzOpenGL::AttributeIndex[i], + NzVertexDeclaration::GetElementCount(element->type), + NzOpenGL::ElementType[element->type], + (element->type == nzElementType_Color) ? GL_TRUE : GL_FALSE, + stride, + &buffer[element->offset]); + } + else + glDisableVertexAttribArray(NzOpenGL::AttributeIndex[i]); + } + + if (s_indexBuffer) + { + NzHardwareBuffer* indexBufferImpl = static_cast(s_indexBuffer->GetBuffer()->GetImpl()); + indexBufferImpl->Bind(); + } + } + + if (vaoSupported) + { + // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction + if (update) + glBindVertexArray(0); + + // Nous (re)bindons le VAO pour définir les attributs de vertice + glBindVertexArray(vao); + } + + s_vaoUpdated = true; + } + + return true; +} + +unsigned int NzRenderer::s_moduleReferenceCouter = 0; diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index a6be23090..5ef569b75 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -1,627 +1,627 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -NzShader::NzShader(nzShaderLanguage language) -{ - Create(language); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create shader"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzShader::~NzShader() -{ - Destroy(); -} - -bool NzShader::Create(nzShaderLanguage language) -{ - Destroy(); - - switch (language) - { - case nzShaderLanguage_Cg: - NazaraError("Cg support is not implemented yet"); - return false; - - case nzShaderLanguage_GLSL: - m_impl = new NzGLSLShader(this); - break; - - default: - NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); - return false; - } - - if (!m_impl->Create()) - { - NazaraError("Failed to create shader"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - NotifyCreated(); - return true; -} - -bool NzShader::Compile() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - if (m_impl->Compile()) - { - m_compiled = true; - return true; - } - else - return false; -} - -void NzShader::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - } -} - -NzString NzShader::GetLog() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NzString error = "Shader not created"; - NazaraError(error); - - return error; - } - #endif - - return m_impl->GetLog(); -} - -nzShaderLanguage NzShader::GetLanguage() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NzString error = "Shader not created"; - NazaraError(error); - - return nzShaderLanguage_Unknown; - } - #endif - - return m_impl->GetLanguage(); -} - -NzString NzShader::GetSourceCode(nzShaderType type) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NzString error = "Shader not created"; - NazaraError(error); - - return error; - } - - if (!IsTypeSupported(type)) - { - NzString error = "Shader type not supported"; - NazaraError(error); - - return error; - } - - if (!m_impl->IsLoaded(type)) - { - NzString error = "Shader not loaded"; - NazaraError(error); - - return error; - } - #endif - - return m_impl->GetSourceCode(type); -} - -int NzShader::GetUniformLocation(const NzString& name) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_impl->GetUniformLocation(name); -} - -bool NzShader::HasUniform(const NzString& name) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_impl->GetUniformLocation(name) != -1; -} - -bool NzShader::IsCompiled() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_compiled; -} - -bool NzShader::IsLoaded(nzShaderType type) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!IsTypeSupported(type)) - { - NazaraError("Shader type not supported"); - return false; - } - #endif - - return m_impl->IsLoaded(type); -} - -bool NzShader::Load(nzShaderType type, const NzString& source) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!IsTypeSupported(type)) - { - NazaraError("Shader type not supported"); - return false; - } - - if (source.IsEmpty()) - { - NazaraError("Empty source code"); - return false; - } - - if (m_impl->IsLoaded(type)) - { - NazaraError("Shader already loaded"); - return false; - } - #endif - - return m_impl->Load(type, source); -} - -bool NzShader::LoadFromFile(nzShaderType type, const NzString& filePath) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (!IsTypeSupported(type)) - { - NazaraError("Shader type not supported"); - return false; - } - - if (m_impl->IsLoaded(type)) - { - NazaraError("Shader already loaded"); - return false; - } - #endif - - NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly | NzFile::Text)) - { - NazaraError("Failed to open \"" + filePath + '"'); - return false; - } - - unsigned int length = file.GetSize(); - - NzString source; - source.Resize(length); - - if (file.Read(&source[0], length) != length) - { - NazaraError("Failed to read shader file"); - return false; - } - - file.Close(); - - return m_impl->Load(type, source); -} - -bool NzShader::Lock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - #endif - - return m_impl->Lock(); -} - -bool NzShader::SendBoolean(int location, bool value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendBoolean(location, value); -} - -bool NzShader::SendDouble(int location, double value) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendDouble(location, value); -} - -bool NzShader::SendFloat(int location, float value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendFloat(location, value); -} - -bool NzShader::SendInteger(int location, int value) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendInteger(location, value); -} - -bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendMatrix(location, matrix); -} - -bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendMatrix(location, matrix); -} - -bool NzShader::SendTexture(int location, const NzTexture* texture) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendTexture(location, texture); -} - -bool NzShader::SendVector(int location, const NzVector2d& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector2f& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector3d& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector3f& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector4d& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!NzRenderer::HasCapability(nzRendererCap_FP64)) - { - NazaraError("FP64 is not supported"); - return false; - } - - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -bool NzShader::SendVector(int location, const NzVector4f& vector) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return false; - } - - if (location == -1) - { - NazaraError("Invalid location"); - return false; - } - #endif - - return m_impl->SendVector(location, vector); -} - -void NzShader::Unlock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Shader not created"); - return; - } - #endif - - return m_impl->Unlock(); -} - -bool NzShader::IsLanguageSupported(nzShaderLanguage language) -{ - switch (language) - { - case nzShaderLanguage_Cg: - return false; //FIXME: ?? - - case nzShaderLanguage_GLSL: - return true; - - default: - NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); - return false; - } -} - -bool NzShader::IsTypeSupported(nzShaderType type) -{ - switch (type) - { - case nzShaderType_Fragment: - case nzShaderType_Vertex: - return true; - - case nzShaderType_Geometry: - return false; // ?? - - default: - NazaraError("Shader type not handled (0x" + NzString::Number(type, 16) + ')'); - return false; - } -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +NzShader::NzShader(nzShaderLanguage language) +{ + Create(language); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create shader"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzShader::~NzShader() +{ + Destroy(); +} + +bool NzShader::Create(nzShaderLanguage language) +{ + Destroy(); + + switch (language) + { + case nzShaderLanguage_Cg: + NazaraError("Cg support is not implemented yet"); + return false; + + case nzShaderLanguage_GLSL: + m_impl = new NzGLSLShader(this); + break; + + default: + NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); + return false; + } + + if (!m_impl->Create()) + { + NazaraError("Failed to create shader"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + NotifyCreated(); + return true; +} + +bool NzShader::Compile() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + if (m_impl->Compile()) + { + m_compiled = true; + return true; + } + else + return false; +} + +void NzShader::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + } +} + +NzString NzShader::GetLog() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NzString error = "Shader not created"; + NazaraError(error); + + return error; + } + #endif + + return m_impl->GetLog(); +} + +nzShaderLanguage NzShader::GetLanguage() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NzString error = "Shader not created"; + NazaraError(error); + + return nzShaderLanguage_Unknown; + } + #endif + + return m_impl->GetLanguage(); +} + +NzString NzShader::GetSourceCode(nzShaderType type) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NzString error = "Shader not created"; + NazaraError(error); + + return error; + } + + if (!IsTypeSupported(type)) + { + NzString error = "Shader type not supported"; + NazaraError(error); + + return error; + } + + if (!m_impl->IsLoaded(type)) + { + NzString error = "Shader not loaded"; + NazaraError(error); + + return error; + } + #endif + + return m_impl->GetSourceCode(type); +} + +int NzShader::GetUniformLocation(const NzString& name) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->GetUniformLocation(name); +} + +bool NzShader::HasUniform(const NzString& name) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->GetUniformLocation(name) != -1; +} + +bool NzShader::IsCompiled() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_compiled; +} + +bool NzShader::IsLoaded(nzShaderType type) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (!IsTypeSupported(type)) + { + NazaraError("Shader type not supported"); + return false; + } + #endif + + return m_impl->IsLoaded(type); +} + +bool NzShader::Load(nzShaderType type, const NzString& source) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (!IsTypeSupported(type)) + { + NazaraError("Shader type not supported"); + return false; + } + + if (source.IsEmpty()) + { + NazaraError("Empty source code"); + return false; + } + + if (m_impl->IsLoaded(type)) + { + NazaraError("Shader already loaded"); + return false; + } + #endif + + return m_impl->Load(type, source); +} + +bool NzShader::LoadFromFile(nzShaderType type, const NzString& filePath) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (!IsTypeSupported(type)) + { + NazaraError("Shader type not supported"); + return false; + } + + if (m_impl->IsLoaded(type)) + { + NazaraError("Shader already loaded"); + return false; + } + #endif + + NzFile file(filePath); + if (!file.Open(NzFile::ReadOnly | NzFile::Text)) + { + NazaraError("Failed to open \"" + filePath + '"'); + return false; + } + + unsigned int length = file.GetSize(); + + NzString source; + source.Resize(length); + + if (file.Read(&source[0], length) != length) + { + NazaraError("Failed to read shader file"); + return false; + } + + file.Close(); + + return m_impl->Load(type, source); +} + +bool NzShader::Lock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + #endif + + return m_impl->Lock(); +} + +bool NzShader::SendBoolean(int location, bool value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendBoolean(location, value); +} + +bool NzShader::SendDouble(int location, double value) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendDouble(location, value); +} + +bool NzShader::SendFloat(int location, float value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendFloat(location, value); +} + +bool NzShader::SendInteger(int location, int value) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendInteger(location, value); +} + +bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendMatrix(location, matrix); +} + +bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendMatrix(location, matrix); +} + +bool NzShader::SendTexture(int location, const NzTexture* texture) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendTexture(location, texture); +} + +bool NzShader::SendVector(int location, const NzVector2d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector2f& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector3d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector3f& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector4d& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!NzRenderer::HasCapability(nzRendererCap_FP64)) + { + NazaraError("FP64 is not supported"); + return false; + } + + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +bool NzShader::SendVector(int location, const NzVector4f& vector) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return false; + } + + if (location == -1) + { + NazaraError("Invalid location"); + return false; + } + #endif + + return m_impl->SendVector(location, vector); +} + +void NzShader::Unlock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Shader not created"); + return; + } + #endif + + return m_impl->Unlock(); +} + +bool NzShader::IsLanguageSupported(nzShaderLanguage language) +{ + switch (language) + { + case nzShaderLanguage_Cg: + return false; //FIXME: ?? + + case nzShaderLanguage_GLSL: + return true; + + default: + NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); + return false; + } +} + +bool NzShader::IsTypeSupported(nzShaderType type) +{ + switch (type) + { + case nzShaderType_Fragment: + case nzShaderType_Vertex: + return true; + + case nzShaderType_Geometry: + return false; // ?? + + default: + NazaraError("Shader type not handled (0x" + NzString::Number(type, 16) + ')'); + return false; + } +} diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 792990f6d..870fda854 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -1,1556 +1,1556 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -struct NzTextureImpl -{ - GLuint id; - nzImageType type; - nzPixelFormat format; - nzUInt8 levelCount; - NzRenderTexture* renderTexture = nullptr; - bool mipmapping = false; - bool mipmapsUpdated = true; - unsigned int depth; - unsigned int height; - unsigned int width; -}; - -namespace -{ - bool CreateTexture(NzTextureImpl* impl, bool proxy) - { - NzOpenGL::Format openGLFormat; - if (!NzOpenGL::TranslateFormat(impl->format, &openGLFormat, NzOpenGL::FormatType_Texture)) - { - NazaraError("Format not supported by OpenGL"); - return false; - } - - GLenum target = (proxy) ? NzOpenGL::TextureTargetProxy[impl->type] : NzOpenGL::TextureTarget[impl->type]; - GLint previous; - glGetIntegerv(NzOpenGL::TextureTargetBinding[impl->type], &previous); - switch (impl->type) - { - case nzImageType_1D: - { - if (glTexStorage1D) - glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width); - else - { - unsigned int w = impl->width; - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - glTexImage1D(target, level, openGLFormat.internalFormat, w, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - if (w > 1U) - w >>= 1; - } - } - break; - } - - case nzImageType_1D_Array: - case nzImageType_2D: - { - if (glTexStorage2D) - glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); - else - { - unsigned int w = impl->width; - unsigned int h = impl->height; - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - glTexImage2D(target, level, openGLFormat.internalFormat, w, h, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - if (w > 1U) - w >>= 1; - - if (h > 1U) - h >>= 1; - } - } - break; - } - - case nzImageType_2D_Array: - case nzImageType_3D: - { - if (glTexStorage3D) - glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth); - else - { - unsigned int w = impl->width; - unsigned int h = impl->height; - unsigned int d = impl->depth; - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - glTexImage3D(target, level, openGLFormat.internalFormat, w, h, d, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - if (w > 1U) - w >>= 1; - - if (h > 1U) - h >>= 1; - - if (d > 1U) - d >>= 1; - } - } - break; - } - - case nzImageType_Cubemap: - { - if (glTexStorage2D) - glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); - else - { - unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique - for (nzUInt8 level = 0; level < impl->levelCount; ++level) - { - for (GLenum face : NzOpenGL::CubemapFace) - glTexImage2D(face, level, openGLFormat.internalFormat, size, size, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); - - if (size > 1U) - size >>= 1; - } - } - break; - } - } - - if (proxy) - { - GLint internalFormat = 0; - glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); - if (internalFormat == 0) - return false; - } - - return true; - } - - static unsigned short lockedLevel[nzImageType_Max+1] = {0}; - static GLuint lockedPrevious[nzImageType_Max+1] = {0}; - - void LockTexture(NzTextureImpl* impl) - { - if (lockedLevel[impl->type]++ == 0) - { - NzContext::EnsureContext(); - - GLint previous; - glGetIntegerv(NzOpenGL::TextureTargetBinding[impl->type], &previous); - - lockedPrevious[impl->type] = static_cast(previous); - - if (lockedPrevious[impl->type] != impl->id) - glBindTexture(NzOpenGL::TextureTarget[impl->type], impl->id); - } - } - - inline void SetUnpackAlignement(nzUInt8 bpp) - { - if (bpp % 8 == 0) - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - else if (bpp % 4 == 0) - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - else if (bpp % 2 == 0) - glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - else - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - } - - void UnlockTexture(NzTextureImpl* impl) - { - #ifdef NAZARA_DEBUG - if (NzContext::GetCurrent() == nullptr) - { - NazaraError("No active context"); - return; - } - #endif - - #if NAZARA_RENDERER_SAFE - if (lockedLevel[impl->type] == 0) - { - NazaraError("Unlock called on non-locked texture"); - return; - } - #endif - - if (--lockedLevel[impl->type] == 0 && lockedPrevious[impl->type] != impl->id) - glBindTexture(NzOpenGL::TextureTarget[impl->type], lockedPrevious[impl->type]); - } -} - -NzTexture::NzTexture() : -m_impl(nullptr) -{ -} - -NzTexture::NzTexture(const NzImage& image) : -m_impl(nullptr) -{ - LoadFromImage(image); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create texture"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzTexture::~NzTexture() -{ - Destroy(); -} - -bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount, bool lock) -{ - Destroy(); - - #if NAZARA_RENDERER_SAFE - if (!IsTypeSupported(type)) - { - NazaraError("Texture's type not supported"); - return false; - } - - if (!NzPixelFormat::IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - - if (!IsFormatSupported(format)) - { - NazaraError("Texture's format not supported"); - return false; - } - - if (width == 0) - { - NazaraError("Width must be at least 1 (0)"); - return false; - } - - if (height == 0) - { - NazaraError("Height must be at least 1 (0)"); - return false; - } - - if (depth == 0) - { - NazaraError("Depth must be at least 1 (0)"); - return false; - } - - switch (type) - { - case nzImageType_1D: - if (height > 1) - { - NazaraError("One dimensional texture's height must be 1"); - return false; - } - - if (depth > 1) - { - NazaraError("1D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - if (depth > 1) - { - NazaraError("2D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - break; - - case nzImageType_Cubemap: - if (depth > 1) - { - NazaraError("Cubemaps must be 1 depth"); - return false; - } - - if (width != height) - { - NazaraError("Cubemaps must have square dimensions"); - return false; - } - break; - } - #endif - - NzContext::EnsureContext(); - - if (IsMipmappingSupported()) - levelCount = std::min(levelCount, NzImage::GetMaxLevel(width, height, depth)); - else if (levelCount > 1) - { - NazaraWarning("Mipmapping not supported, reducing level count to 1"); - levelCount = 1; - } - - NzTextureImpl* impl = new NzTextureImpl; - glGenTextures(1, &impl->id); - - impl->depth = GetValidSize(depth); - impl->format = format; - impl->height = GetValidSize(height); - impl->levelCount = levelCount; - impl->type = type; - impl->width = GetValidSize(width); - - LockTexture(impl); - - // Vérification du support par la carte graphique - /*if (!CreateTexture(impl, true)) - { - NazaraError("Texture's parameters not supported by driver"); - UnlockTexture(impl); - glDeleteTextures(1, &impl->id); - delete impl; - - return false; - }*/ - - // Création de la texture - if (!CreateTexture(impl, false)) - { - NazaraError("Failed to create texture"); - UnlockTexture(impl); - glDeleteTextures(1, &impl->id); - delete impl; - - return false; - } - - m_impl = impl; - - // Paramètres par défaut - SetFilterMode(nzTextureFilter_Nearest); - SetMipmapRange(0, m_impl->levelCount); - SetWrapMode(nzTextureWrap_Repeat); - - if (m_impl->levelCount > 1U) - EnableMipmapping(true); - - if (!lock) - UnlockTexture(impl); - - NotifyCreated(); - return true; -} - -void NzTexture::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - NzContext::EnsureContext(); - - glDeleteTextures(1, &m_impl->id); - delete m_impl; - m_impl = nullptr; - } -} - -bool NzTexture::Download(NzImage* image) const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (!image) - { - NazaraError("Image must be valid"); - return false; - } - #endif - - NzOpenGL::Format format; - if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - if (!image->Create(m_impl->type, m_impl->format, m_impl->width, m_impl->height, m_impl->depth, m_impl->levelCount)) - { - NazaraError("Failed to create image"); - return false; - } - - LockTexture(m_impl); - - unsigned int width = m_impl->width; - unsigned int height = m_impl->height; - unsigned int depth = m_impl->depth; - - // Téléchargement... - for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) - { - glGetTexImage(NzOpenGL::TextureTarget[m_impl->type], level, format.dataFormat, format.dataType, image->GetPixels(level)); - - if (width > 1) - width >>= 1; - - if (height > 1) - height >>= 1; - - if (depth > 1) - depth >>= 1; - } - - UnlockTexture(m_impl); - - // Inversion de la texture pour le repère d'OpenGL - if (!image->FlipVertically()) - NazaraWarning("Failed to flip image"); - - return true; -} - -bool NzTexture::EnableMipmapping(bool enable) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (m_impl->levelCount == 1) - return true; - - if (!IsMipmappingSupported()) - { - NazaraError("Mipmapping not supported"); - return false; - } - - if (!m_impl->mipmapping && enable) - m_impl->mipmapsUpdated = false; - - m_impl->mipmapping = enable; - - return true; -} - -unsigned int NzTexture::GetAnisotropyLevel() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - if (!NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)) - return 1; - - LockTexture(m_impl); - - GLint anisotropyLevel; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropyLevel); - - UnlockTexture(m_impl); - - return anisotropyLevel; -} - -nzUInt8 NzTexture::GetBPP() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return NzPixelFormat::GetBPP(m_impl->format); -} - -unsigned int NzTexture::GetDepth() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->depth; -} - -nzTextureFilter NzTexture::GetFilterMode() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzTextureFilter_Unknown; - } - #endif - - LockTexture(m_impl); - - GLint value; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &value); - - UnlockTexture(m_impl); - - GLenum filterMode = static_cast(value); - switch (filterMode) - { - case GL_LINEAR: - case GL_LINEAR_MIPMAP_NEAREST: - return nzTextureFilter_Bilinear; - - case GL_NEAREST: - case GL_NEAREST_MIPMAP_NEAREST: - return nzTextureFilter_Nearest; - - case GL_LINEAR_MIPMAP_LINEAR: - return nzTextureFilter_Trilinear; - - default: - NazaraInternalError("OpenGL filter mode not handled (0x" + NzString::Number(filterMode, 16) + ')'); - return nzTextureFilter_Unknown; - } -} - -nzPixelFormat NzTexture::GetFormat() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzPixelFormat_Undefined; - } - #endif - - return m_impl->format; -} - -unsigned int NzTexture::GetHeight() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->height; -} - -nzImageType NzTexture::GetType() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzImageType_2D; - } - #endif - - return m_impl->type; -} - -unsigned int NzTexture::GetWidth() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->width; -} - -nzTextureWrap NzTexture::GetWrapMode() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return nzTextureWrap_Unknown; - } - #endif - - LockTexture(m_impl); - - GLint value; - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &value); - - UnlockTexture(m_impl); - - GLenum wrapMode = static_cast(value); - switch (wrapMode) - { - case GL_CLAMP_TO_EDGE: - return nzTextureWrap_Clamp; - - case GL_REPEAT: - return nzTextureWrap_Repeat; - - default: - NazaraInternalError("OpenGL wrap mode not handled (0x" + NzString::Number(wrapMode, 16) + ')'); - return nzTextureWrap_Unknown; - } -} - -bool NzTexture::IsCompressed() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return NzPixelFormat::IsCompressed(m_impl->format); -} - -bool NzTexture::IsCubemap() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return m_impl->type == nzImageType_Cubemap; -} - -bool NzTexture::IsTarget() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return m_impl->renderTexture != nullptr; -} - -bool NzTexture::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzTexture::LoadFromFile(const NzString& filePath, const NzImageParams& params) -{ - NzImage image; - if (!image.LoadFromFile(filePath, params)) - { - NazaraError("Failed to load image"); - return false; - } - - return LoadFromImage(image); -} - -bool NzTexture::LoadFromImage(const NzImage& image) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - #endif - - // Vive le Copy-On-Write - NzImage newImage(image); - - nzPixelFormat format = newImage.GetFormat(); - if (!IsFormatSupported(format)) - { - nzPixelFormat newFormat = (NzPixelFormat::HasAlpha(format)) ? nzPixelFormat_BGRA8 : nzPixelFormat_BGR8; - NazaraWarning("Format not supported, trying to convert it to " + NzPixelFormat::ToString(newFormat) + "..."); - - if (NzPixelFormat::IsConversionSupported(format, newFormat)) - { - if (newImage.Convert(newFormat)) - { - NazaraWarning("Conversion succeed"); - format = newFormat; - } - else - { - NazaraError("Conversion failed"); - return false; - } - } - else - { - NazaraError("Conversion not supported"); - return false; - } - } - - nzImageType type = newImage.GetType(); - if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), newImage.GetLevelCount(), true)) - { - NazaraError("Failed to create texture"); - return false; - } - - for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) - { - if (!Update(newImage.GetConstPixels(level), level)) - { - NazaraError("Failed to update texture"); - Destroy(); - - return false; - } - } - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) -{ - NzImage image; - if (!image.LoadFromMemory(data, size, params)) - { - NazaraError("Failed to load image"); - return false; - } - - return LoadFromImage(image); -} - -bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& params) -{ - NzImage image; - if (!image.LoadFromStream(stream, params)) - { - NazaraError("Failed to load image"); - return false; - } - - return LoadFromImage(image); -} - -bool NzTexture::Lock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - LockTexture(m_impl); - - return true; -} - -bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (anistropyLevel > 1 && !NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)) - { - NazaraError("Anisotropic filter not supported"); - return false; - } - - LockTexture(m_impl); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anistropyLevel); - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::SetFilterMode(nzTextureFilter filter) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (filter == nzTextureFilter_Trilinear && m_impl->levelCount == 1) - { - NazaraError("Trilinear filter set wihout mipmaps"); - return false; - } - #endif - - LockTexture(m_impl); - - GLenum target = NzOpenGL::TextureTarget[m_impl->type]; - switch (filter) - { - case nzTextureFilter_Bilinear: - if (m_impl->mipmapping > 1) - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - else - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - break; - - case nzTextureFilter_Nearest: - if (m_impl->mipmapping > 1) - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - else - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - break; - - case nzTextureFilter_Trilinear: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - break; - - default: - NazaraError("Texture filter not handled (0x" + NzString::Number(filter, 16) + ')'); - } - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (minLevel >= m_impl->levelCount) - { - NazaraError("Minimum level cannot be greater or equal than level count (" + NzString::Number(minLevel) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - - if (maxLevel < minLevel) - { - NazaraError("Minimum level cannot be greater than maximum level (" + NzString::Number(minLevel) + " < " + NzString::Number(maxLevel) + ')'); - return false; - } - #endif - - LockTexture(m_impl); - glTexParameteri(NzOpenGL::TextureTarget[m_impl->type], GL_TEXTURE_BASE_LEVEL, minLevel); - glTexParameteri(NzOpenGL::TextureTarget[m_impl->type], GL_TEXTURE_MAX_LEVEL, std::min(m_impl->levelCount, maxLevel)); - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::SetWrapMode(nzTextureWrap wrap) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - GLenum wrapMode; - switch (wrap) - { - case nzTextureWrap_Clamp: - wrapMode = GL_CLAMP_TO_EDGE; - break; - - case nzTextureWrap_Repeat: - wrapMode = GL_REPEAT; - break; - - default: - NazaraError("Texture wrap mode not handled (0x" + NzString::Number(wrap, 16) + ')'); - return false; - } - - LockTexture(m_impl); - - GLenum target = NzOpenGL::TextureTarget[m_impl->type]; - switch (m_impl->type) - { - // Notez l'absence de "break" ici - case nzImageType_3D: - glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode); - case nzImageType_2D: - case nzImageType_2D_Array: - case nzImageType_Cubemap: - glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode); - case nzImageType_1D: - case nzImageType_1D_Array: - glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode); - break; - - default: - break; - } - - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::Update(const NzImage& image, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - return Update(image.GetConstPixels(level), level); -} - -bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int z, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - const nzUInt8* pixels = image.GetConstPixels(level, rect.x, rect.y, z); - if (!pixels) - { - NazaraError("Failed to access image's pixels"); - return false; - } - - glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); - - bool success = Update(pixels, rect, z, level); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - return success; -} - -bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - const nzUInt8* pixels = image.GetConstPixels(level, cube.x, cube.y, cube.z); - if (!pixels) - { - NazaraError("Failed to access image's pixels"); - return false; - } - - glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image.GetHeight(level)); - - bool success = Update(pixels, cube, level); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); - - return success; -} - -bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array) - return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level); - else - return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level); -} - -bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (m_impl->renderTexture) - { - NazaraError("Texture is a target, it cannot be updated"); - return false; - } - - if (m_impl->type == nzImageType_Cubemap) - { - NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int height = std::max(m_impl->height >> level, 1U); - - #if NAZARA_RENDERER_SAFE - if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - if (z >= std::max(m_impl->depth >> level, 1U)) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(m_impl->depth) + ')'); - return false; - } - - if (level >= m_impl->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - #endif - - NzOpenGL::Format format; - if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - - // Inversion de la texture pour le repère d'OpenGL - NzImage mirrored; - mirrored.Create(m_impl->type, m_impl->format, rect.width, rect.height); - mirrored.Update(pixels); - - if (!mirrored.FlipVertically()) - NazaraWarning("Failed to flip image"); - - SetUnpackAlignement(bpp); - - LockTexture(m_impl); - switch (m_impl->type) - { - case nzImageType_1D: - glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels()); - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels()); - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels()); - break; - - case nzImageType_Cubemap: - NazaraError("Update used on a cubemap texture, please enable safe mode"); - break; - } - UnlockTexture(m_impl); - - return true; -} - -bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (m_impl->renderTexture) - { - NazaraError("Texture is a target, it cannot be updated"); - return false; - } - - if (m_impl->type == nzImageType_Cubemap) - { - NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (!cube.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int height = std::max(m_impl->height >> level, 1U); - - #if NAZARA_RENDERER_SAFE - if (cube.x+cube.width > std::max(m_impl->width >> level, 1U) || - cube.y+cube.height > height || - cube.z+cube.depth > std::max(m_impl->depth >> level, 1U)) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - - if (level >= m_impl->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - #endif - - NzOpenGL::Format format; - if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - - // Inversion de la texture pour le repère d'OpenGL - unsigned int size = cube.width*cube.height*cube.depth*bpp; - nzUInt8* mirrored = new nzUInt8[size]; - if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, cube.width, cube.height, cube.depth, pixels, mirrored)) - { - NazaraWarning("Failed to flip image"); - std::memcpy(mirrored, pixels, size); - } - - SetUnpackAlignement(bpp); - - LockTexture(m_impl); - switch (m_impl->type) - { - case nzImageType_1D: - glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored); - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored); - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored); - break; - - case nzImageType_Cubemap: - NazaraError("Update used on a cubemap texture, please enable safe mode"); - break; - } - UnlockTexture(m_impl); - - delete[] mirrored; - - return true; -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - return UpdateFace(face, image.GetConstPixels(level), NzRectui(0, 0, image.GetWidth(), image.GetHeight()), level); -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); - - bool success = UpdateFace(face, image.GetConstPixels(level), rect, level); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - return success; -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - #endif - - return UpdateFace(face, pixels, NzRectui(0, 0, m_impl->width, m_impl->height), level); -} - -bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return false; - } - - if (m_impl->renderTexture) - { - NazaraError("Texture is a target, it cannot be updated"); - return false; - } - - if (m_impl->type != nzImageType_Cubemap) - { - NazaraError("UpdateFace is designed for cubemaps, use Update instead"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int height = std::max(m_impl->height >> level, 1U); - - #if NAZARA_RENDERER_SAFE - if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - if (level >= m_impl->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); - return false; - } - #endif - - NzOpenGL::Format format; - if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) - { - NazaraError("Failed to get OpenGL format"); - return false; - } - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); - - // Inversion de la texture pour le repère d'OpenGL - unsigned int size = rect.width*rect.height*bpp; - nzUInt8* mirrored = new nzUInt8[size]; - if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, rect.width, rect.height, 1, pixels, mirrored)) - { - NazaraWarning("Failed to flip image"); - std::memcpy(mirrored, pixels, size); - } - - SetUnpackAlignement(bpp); - - LockTexture(m_impl); - glTexSubImage2D(NzOpenGL::CubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored); - UnlockTexture(m_impl); - - - return true; -} - -void NzTexture::Unlock() -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return; - } - #endif - - UnlockTexture(m_impl); -} - -unsigned int NzTexture::GetOpenGLID() const -{ - #if NAZARA_RENDERER_SAFE - if (!m_impl) - { - NazaraError("Texture must be valid"); - return 0; - } - #endif - - return m_impl->id; -} - -bool NzTexture::Prepare() const -{ - #if NAZARA_RENDERER_SAFE - if (lockedLevel[m_impl->type] > 0) - { - NazaraError("Cannot bind texture while a texture is locked"); - return false; - } - #endif - - glBindTexture(NzOpenGL::TextureTarget[m_impl->type], m_impl->id); - - if (m_impl->mipmapping && !m_impl->mipmapsUpdated) - { - glGenerateMipmap(NzOpenGL::TextureTarget[m_impl->type]); - m_impl->mipmapsUpdated = true; - } - - return true; -} - -unsigned int NzTexture::GetValidSize(unsigned int size) -{ - if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT)) - return size; - else - { - unsigned int pot = 1; - while (pot < size) - pot <<= 1; - - return pot; - } -} - -bool NzTexture::IsFormatSupported(nzPixelFormat format) -{ - switch (format) - { - // Formats de base - case nzPixelFormat_BGR8: - case nzPixelFormat_BGRA8: - case nzPixelFormat_RGB8: - case nzPixelFormat_RGBA8: - return true; - - // Packed formats supportés depuis OpenGL 1.2 - case nzPixelFormat_RGB5A1: - case nzPixelFormat_RGBA4: - return true; - - // Formats de profondeur (Supportés avec les FBOs) - case nzPixelFormat_Depth16: - case nzPixelFormat_Depth24: - case nzPixelFormat_Depth32: - case nzPixelFormat_Depth24Stencil8: - { - static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); - return supported; - } - - // Formats de stencil (Non supportés pour les textures) - case nzPixelFormat_Stencil1: - case nzPixelFormat_Stencil4: - case nzPixelFormat_Stencil8: - case nzPixelFormat_Stencil16: - return false; - - // Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..) - case nzPixelFormat_L8: - case nzPixelFormat_LA8: - return false; - - case nzPixelFormat_DXT1: - case nzPixelFormat_DXT3: - case nzPixelFormat_DXT5: - { - static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc); - return supported; - } - - case nzPixelFormat_Undefined: - break; - } - - NazaraError("Invalid pixel format"); - - return false; -} - -bool NzTexture::IsMipmappingSupported() -{ - return glGenerateMipmap != nullptr; -} - -bool NzTexture::IsTypeSupported(nzImageType type) -{ - switch (type) - { - case nzImageType_1D: - case nzImageType_2D: - case nzImageType_3D: - case nzImageType_Cubemap: - return true; // Tous supportés nativement dans OpenGL 2 - - case nzImageType_1D_Array: - case nzImageType_2D_Array: - { - static bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray); - return supported; - } - } - - NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); - return false; -} - -NzRenderTexture* NzTexture::GetRenderTexture() const -{ - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraInternalError("Texture must be valid"); - return nullptr; - } - #endif - - return m_impl->renderTexture; -} - -void NzTexture::SetRenderTexture(NzRenderTexture* renderTexture) -{ - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraInternalError("Texture must be valid"); - return; - } - #endif - - m_impl->renderTexture = renderTexture; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +struct NzTextureImpl +{ + GLuint id; + nzImageType type; + nzPixelFormat format; + nzUInt8 levelCount; + NzRenderTexture* renderTexture = nullptr; + bool mipmapping = false; + bool mipmapsUpdated = true; + unsigned int depth; + unsigned int height; + unsigned int width; +}; + +namespace +{ + bool CreateTexture(NzTextureImpl* impl, bool proxy) + { + NzOpenGL::Format openGLFormat; + if (!NzOpenGL::TranslateFormat(impl->format, &openGLFormat, NzOpenGL::FormatType_Texture)) + { + NazaraError("Format not supported by OpenGL"); + return false; + } + + GLenum target = (proxy) ? NzOpenGL::TextureTargetProxy[impl->type] : NzOpenGL::TextureTarget[impl->type]; + GLint previous; + glGetIntegerv(NzOpenGL::TextureTargetBinding[impl->type], &previous); + switch (impl->type) + { + case nzImageType_1D: + { + if (glTexStorage1D) + glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width); + else + { + unsigned int w = impl->width; + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + glTexImage1D(target, level, openGLFormat.internalFormat, w, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + if (w > 1U) + w >>= 1; + } + } + break; + } + + case nzImageType_1D_Array: + case nzImageType_2D: + { + if (glTexStorage2D) + glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); + else + { + unsigned int w = impl->width; + unsigned int h = impl->height; + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + glTexImage2D(target, level, openGLFormat.internalFormat, w, h, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + if (w > 1U) + w >>= 1; + + if (h > 1U) + h >>= 1; + } + } + break; + } + + case nzImageType_2D_Array: + case nzImageType_3D: + { + if (glTexStorage3D) + glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth); + else + { + unsigned int w = impl->width; + unsigned int h = impl->height; + unsigned int d = impl->depth; + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + glTexImage3D(target, level, openGLFormat.internalFormat, w, h, d, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + if (w > 1U) + w >>= 1; + + if (h > 1U) + h >>= 1; + + if (d > 1U) + d >>= 1; + } + } + break; + } + + case nzImageType_Cubemap: + { + if (glTexStorage2D) + glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height); + else + { + unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique + for (nzUInt8 level = 0; level < impl->levelCount; ++level) + { + for (GLenum face : NzOpenGL::CubemapFace) + glTexImage2D(face, level, openGLFormat.internalFormat, size, size, 0, openGLFormat.dataFormat, openGLFormat.dataType, nullptr); + + if (size > 1U) + size >>= 1; + } + } + break; + } + } + + if (proxy) + { + GLint internalFormat = 0; + glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); + if (internalFormat == 0) + return false; + } + + return true; + } + + static unsigned short lockedLevel[nzImageType_Max+1] = {0}; + static GLuint lockedPrevious[nzImageType_Max+1] = {0}; + + void LockTexture(NzTextureImpl* impl) + { + if (lockedLevel[impl->type]++ == 0) + { + NzContext::EnsureContext(); + + GLint previous; + glGetIntegerv(NzOpenGL::TextureTargetBinding[impl->type], &previous); + + lockedPrevious[impl->type] = static_cast(previous); + + if (lockedPrevious[impl->type] != impl->id) + glBindTexture(NzOpenGL::TextureTarget[impl->type], impl->id); + } + } + + inline void SetUnpackAlignement(nzUInt8 bpp) + { + if (bpp % 8 == 0) + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + else if (bpp % 4 == 0) + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + else if (bpp % 2 == 0) + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + else + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + } + + void UnlockTexture(NzTextureImpl* impl) + { + #ifdef NAZARA_DEBUG + if (NzContext::GetCurrent() == nullptr) + { + NazaraError("No active context"); + return; + } + #endif + + #if NAZARA_RENDERER_SAFE + if (lockedLevel[impl->type] == 0) + { + NazaraError("Unlock called on non-locked texture"); + return; + } + #endif + + if (--lockedLevel[impl->type] == 0 && lockedPrevious[impl->type] != impl->id) + glBindTexture(NzOpenGL::TextureTarget[impl->type], lockedPrevious[impl->type]); + } +} + +NzTexture::NzTexture() : +m_impl(nullptr) +{ +} + +NzTexture::NzTexture(const NzImage& image) : +m_impl(nullptr) +{ + LoadFromImage(image); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create texture"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzTexture::~NzTexture() +{ + Destroy(); +} + +bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount, bool lock) +{ + Destroy(); + + #if NAZARA_RENDERER_SAFE + if (!IsTypeSupported(type)) + { + NazaraError("Texture's type not supported"); + return false; + } + + if (!NzPixelFormat::IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + + if (!IsFormatSupported(format)) + { + NazaraError("Texture's format not supported"); + return false; + } + + if (width == 0) + { + NazaraError("Width must be at least 1 (0)"); + return false; + } + + if (height == 0) + { + NazaraError("Height must be at least 1 (0)"); + return false; + } + + if (depth == 0) + { + NazaraError("Depth must be at least 1 (0)"); + return false; + } + + switch (type) + { + case nzImageType_1D: + if (height > 1) + { + NazaraError("One dimensional texture's height must be 1"); + return false; + } + + if (depth > 1) + { + NazaraError("1D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + if (depth > 1) + { + NazaraError("2D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + break; + + case nzImageType_Cubemap: + if (depth > 1) + { + NazaraError("Cubemaps must be 1 depth"); + return false; + } + + if (width != height) + { + NazaraError("Cubemaps must have square dimensions"); + return false; + } + break; + } + #endif + + NzContext::EnsureContext(); + + if (IsMipmappingSupported()) + levelCount = std::min(levelCount, NzImage::GetMaxLevel(width, height, depth)); + else if (levelCount > 1) + { + NazaraWarning("Mipmapping not supported, reducing level count to 1"); + levelCount = 1; + } + + NzTextureImpl* impl = new NzTextureImpl; + glGenTextures(1, &impl->id); + + impl->depth = GetValidSize(depth); + impl->format = format; + impl->height = GetValidSize(height); + impl->levelCount = levelCount; + impl->type = type; + impl->width = GetValidSize(width); + + LockTexture(impl); + + // Vérification du support par la carte graphique + /*if (!CreateTexture(impl, true)) + { + NazaraError("Texture's parameters not supported by driver"); + UnlockTexture(impl); + glDeleteTextures(1, &impl->id); + delete impl; + + return false; + }*/ + + // Création de la texture + if (!CreateTexture(impl, false)) + { + NazaraError("Failed to create texture"); + UnlockTexture(impl); + glDeleteTextures(1, &impl->id); + delete impl; + + return false; + } + + m_impl = impl; + + // Paramètres par défaut + SetFilterMode(nzTextureFilter_Nearest); + SetMipmapRange(0, m_impl->levelCount); + SetWrapMode(nzTextureWrap_Repeat); + + if (m_impl->levelCount > 1U) + EnableMipmapping(true); + + if (!lock) + UnlockTexture(impl); + + NotifyCreated(); + return true; +} + +void NzTexture::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + NzContext::EnsureContext(); + + glDeleteTextures(1, &m_impl->id); + delete m_impl; + m_impl = nullptr; + } +} + +bool NzTexture::Download(NzImage* image) const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (!image) + { + NazaraError("Image must be valid"); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + if (!image->Create(m_impl->type, m_impl->format, m_impl->width, m_impl->height, m_impl->depth, m_impl->levelCount)) + { + NazaraError("Failed to create image"); + return false; + } + + LockTexture(m_impl); + + unsigned int width = m_impl->width; + unsigned int height = m_impl->height; + unsigned int depth = m_impl->depth; + + // Téléchargement... + for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) + { + glGetTexImage(NzOpenGL::TextureTarget[m_impl->type], level, format.dataFormat, format.dataType, image->GetPixels(level)); + + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + if (depth > 1) + depth >>= 1; + } + + UnlockTexture(m_impl); + + // Inversion de la texture pour le repère d'OpenGL + if (!image->FlipVertically()) + NazaraWarning("Failed to flip image"); + + return true; +} + +bool NzTexture::EnableMipmapping(bool enable) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (m_impl->levelCount == 1) + return true; + + if (!IsMipmappingSupported()) + { + NazaraError("Mipmapping not supported"); + return false; + } + + if (!m_impl->mipmapping && enable) + m_impl->mipmapsUpdated = false; + + m_impl->mipmapping = enable; + + return true; +} + +unsigned int NzTexture::GetAnisotropyLevel() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + if (!NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)) + return 1; + + LockTexture(m_impl); + + GLint anisotropyLevel; + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropyLevel); + + UnlockTexture(m_impl); + + return anisotropyLevel; +} + +nzUInt8 NzTexture::GetBPP() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return NzPixelFormat::GetBPP(m_impl->format); +} + +unsigned int NzTexture::GetDepth() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->depth; +} + +nzTextureFilter NzTexture::GetFilterMode() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzTextureFilter_Unknown; + } + #endif + + LockTexture(m_impl); + + GLint value; + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &value); + + UnlockTexture(m_impl); + + GLenum filterMode = static_cast(value); + switch (filterMode) + { + case GL_LINEAR: + case GL_LINEAR_MIPMAP_NEAREST: + return nzTextureFilter_Bilinear; + + case GL_NEAREST: + case GL_NEAREST_MIPMAP_NEAREST: + return nzTextureFilter_Nearest; + + case GL_LINEAR_MIPMAP_LINEAR: + return nzTextureFilter_Trilinear; + + default: + NazaraInternalError("OpenGL filter mode not handled (0x" + NzString::Number(filterMode, 16) + ')'); + return nzTextureFilter_Unknown; + } +} + +nzPixelFormat NzTexture::GetFormat() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzPixelFormat_Undefined; + } + #endif + + return m_impl->format; +} + +unsigned int NzTexture::GetHeight() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->height; +} + +nzImageType NzTexture::GetType() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzImageType_2D; + } + #endif + + return m_impl->type; +} + +unsigned int NzTexture::GetWidth() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->width; +} + +nzTextureWrap NzTexture::GetWrapMode() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return nzTextureWrap_Unknown; + } + #endif + + LockTexture(m_impl); + + GLint value; + glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &value); + + UnlockTexture(m_impl); + + GLenum wrapMode = static_cast(value); + switch (wrapMode) + { + case GL_CLAMP_TO_EDGE: + return nzTextureWrap_Clamp; + + case GL_REPEAT: + return nzTextureWrap_Repeat; + + default: + NazaraInternalError("OpenGL wrap mode not handled (0x" + NzString::Number(wrapMode, 16) + ')'); + return nzTextureWrap_Unknown; + } +} + +bool NzTexture::IsCompressed() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return NzPixelFormat::IsCompressed(m_impl->format); +} + +bool NzTexture::IsCubemap() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return m_impl->type == nzImageType_Cubemap; +} + +bool NzTexture::IsTarget() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return m_impl->renderTexture != nullptr; +} + +bool NzTexture::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzTexture::LoadFromFile(const NzString& filePath, const NzImageParams& params) +{ + NzImage image; + if (!image.LoadFromFile(filePath, params)) + { + NazaraError("Failed to load image"); + return false; + } + + return LoadFromImage(image); +} + +bool NzTexture::LoadFromImage(const NzImage& image) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + #endif + + // Vive le Copy-On-Write + NzImage newImage(image); + + nzPixelFormat format = newImage.GetFormat(); + if (!IsFormatSupported(format)) + { + nzPixelFormat newFormat = (NzPixelFormat::HasAlpha(format)) ? nzPixelFormat_BGRA8 : nzPixelFormat_BGR8; + NazaraWarning("Format not supported, trying to convert it to " + NzPixelFormat::ToString(newFormat) + "..."); + + if (NzPixelFormat::IsConversionSupported(format, newFormat)) + { + if (newImage.Convert(newFormat)) + { + NazaraWarning("Conversion succeed"); + format = newFormat; + } + else + { + NazaraError("Conversion failed"); + return false; + } + } + else + { + NazaraError("Conversion not supported"); + return false; + } + } + + nzImageType type = newImage.GetType(); + if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), newImage.GetLevelCount(), true)) + { + NazaraError("Failed to create texture"); + return false; + } + + for (nzUInt8 level = 0; level < m_impl->levelCount; ++level) + { + if (!Update(newImage.GetConstPixels(level), level)) + { + NazaraError("Failed to update texture"); + Destroy(); + + return false; + } + } + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) +{ + NzImage image; + if (!image.LoadFromMemory(data, size, params)) + { + NazaraError("Failed to load image"); + return false; + } + + return LoadFromImage(image); +} + +bool NzTexture::LoadFromStream(NzInputStream& stream, const NzImageParams& params) +{ + NzImage image; + if (!image.LoadFromStream(stream, params)) + { + NazaraError("Failed to load image"); + return false; + } + + return LoadFromImage(image); +} + +bool NzTexture::Lock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + LockTexture(m_impl); + + return true; +} + +bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (anistropyLevel > 1 && !NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)) + { + NazaraError("Anisotropic filter not supported"); + return false; + } + + LockTexture(m_impl); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anistropyLevel); + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::SetFilterMode(nzTextureFilter filter) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (filter == nzTextureFilter_Trilinear && m_impl->levelCount == 1) + { + NazaraError("Trilinear filter set wihout mipmaps"); + return false; + } + #endif + + LockTexture(m_impl); + + GLenum target = NzOpenGL::TextureTarget[m_impl->type]; + switch (filter) + { + case nzTextureFilter_Bilinear: + if (m_impl->mipmapping > 1) + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + else + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + break; + + case nzTextureFilter_Nearest: + if (m_impl->mipmapping > 1) + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + else + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + break; + + case nzTextureFilter_Trilinear: + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + break; + + default: + NazaraError("Texture filter not handled (0x" + NzString::Number(filter, 16) + ')'); + } + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (minLevel >= m_impl->levelCount) + { + NazaraError("Minimum level cannot be greater or equal than level count (" + NzString::Number(minLevel) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + + if (maxLevel < minLevel) + { + NazaraError("Minimum level cannot be greater than maximum level (" + NzString::Number(minLevel) + " < " + NzString::Number(maxLevel) + ')'); + return false; + } + #endif + + LockTexture(m_impl); + glTexParameteri(NzOpenGL::TextureTarget[m_impl->type], GL_TEXTURE_BASE_LEVEL, minLevel); + glTexParameteri(NzOpenGL::TextureTarget[m_impl->type], GL_TEXTURE_MAX_LEVEL, std::min(m_impl->levelCount, maxLevel)); + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::SetWrapMode(nzTextureWrap wrap) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + GLenum wrapMode; + switch (wrap) + { + case nzTextureWrap_Clamp: + wrapMode = GL_CLAMP_TO_EDGE; + break; + + case nzTextureWrap_Repeat: + wrapMode = GL_REPEAT; + break; + + default: + NazaraError("Texture wrap mode not handled (0x" + NzString::Number(wrap, 16) + ')'); + return false; + } + + LockTexture(m_impl); + + GLenum target = NzOpenGL::TextureTarget[m_impl->type]; + switch (m_impl->type) + { + // Notez l'absence de "break" ici + case nzImageType_3D: + glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode); + case nzImageType_2D: + case nzImageType_2D_Array: + case nzImageType_Cubemap: + glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode); + case nzImageType_1D: + case nzImageType_1D_Array: + glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode); + break; + + default: + break; + } + + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::Update(const NzImage& image, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + return Update(image.GetConstPixels(level), level); +} + +bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int z, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + const nzUInt8* pixels = image.GetConstPixels(level, rect.x, rect.y, z); + if (!pixels) + { + NazaraError("Failed to access image's pixels"); + return false; + } + + glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); + + bool success = Update(pixels, rect, z, level); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + return success; +} + +bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + const nzUInt8* pixels = image.GetConstPixels(level, cube.x, cube.y, cube.z); + if (!pixels) + { + NazaraError("Failed to access image's pixels"); + return false; + } + + glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image.GetHeight(level)); + + bool success = Update(pixels, cube, level); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); + + return success; +} + +bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array) + return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level); + else + return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level); +} + +bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (m_impl->renderTexture) + { + NazaraError("Texture is a target, it cannot be updated"); + return false; + } + + if (m_impl->type == nzImageType_Cubemap) + { + NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int height = std::max(m_impl->height >> level, 1U); + + #if NAZARA_RENDERER_SAFE + if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + if (z >= std::max(m_impl->depth >> level, 1U)) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(m_impl->depth) + ')'); + return false; + } + + if (level >= m_impl->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + + // Inversion de la texture pour le repère d'OpenGL + NzImage mirrored; + mirrored.Create(m_impl->type, m_impl->format, rect.width, rect.height); + mirrored.Update(pixels); + + if (!mirrored.FlipVertically()) + NazaraWarning("Failed to flip image"); + + SetUnpackAlignement(bpp); + + LockTexture(m_impl); + switch (m_impl->type) + { + case nzImageType_1D: + glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels()); + break; + + case nzImageType_Cubemap: + NazaraError("Update used on a cubemap texture, please enable safe mode"); + break; + } + UnlockTexture(m_impl); + + return true; +} + +bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (m_impl->renderTexture) + { + NazaraError("Texture is a target, it cannot be updated"); + return false; + } + + if (m_impl->type == nzImageType_Cubemap) + { + NazaraError("Update is not designed for cubemaps, use UpdateFace instead"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (!cube.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int height = std::max(m_impl->height >> level, 1U); + + #if NAZARA_RENDERER_SAFE + if (cube.x+cube.width > std::max(m_impl->width >> level, 1U) || + cube.y+cube.height > height || + cube.z+cube.depth > std::max(m_impl->depth >> level, 1U)) + { + NazaraError("Cube dimensions are out of bounds"); + return false; + } + + if (level >= m_impl->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + + // Inversion de la texture pour le repère d'OpenGL + unsigned int size = cube.width*cube.height*cube.depth*bpp; + nzUInt8* mirrored = new nzUInt8[size]; + if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, cube.width, cube.height, cube.depth, pixels, mirrored)) + { + NazaraWarning("Failed to flip image"); + std::memcpy(mirrored, pixels, size); + } + + SetUnpackAlignement(bpp); + + LockTexture(m_impl); + switch (m_impl->type) + { + case nzImageType_1D: + glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored); + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored); + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored); + break; + + case nzImageType_Cubemap: + NazaraError("Update used on a cubemap texture, please enable safe mode"); + break; + } + UnlockTexture(m_impl); + + delete[] mirrored; + + return true; +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + return UpdateFace(face, image.GetConstPixels(level), NzRectui(0, 0, image.GetWidth(), image.GetHeight()), level); +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + glPixelStorei(GL_UNPACK_ROW_LENGTH, image.GetWidth(level)); + + bool success = UpdateFace(face, image.GetConstPixels(level), rect, level); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + return success; +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + #endif + + return UpdateFace(face, pixels, NzRectui(0, 0, m_impl->width, m_impl->height), level); +} + +bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return false; + } + + if (m_impl->renderTexture) + { + NazaraError("Texture is a target, it cannot be updated"); + return false; + } + + if (m_impl->type != nzImageType_Cubemap) + { + NazaraError("UpdateFace is designed for cubemaps, use Update instead"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int height = std::max(m_impl->height >> level, 1U); + + #if NAZARA_RENDERER_SAFE + if (rect.x+rect.width > std::max(m_impl->width >> level, 1U) || rect.y+rect.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + if (level >= m_impl->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_impl->levelCount) + ')'); + return false; + } + #endif + + NzOpenGL::Format format; + if (!NzOpenGL::TranslateFormat(m_impl->format, &format, NzOpenGL::FormatType_Texture)) + { + NazaraError("Failed to get OpenGL format"); + return false; + } + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + + // Inversion de la texture pour le repère d'OpenGL + unsigned int size = rect.width*rect.height*bpp; + nzUInt8* mirrored = new nzUInt8[size]; + if (!NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_impl->format, rect.width, rect.height, 1, pixels, mirrored)) + { + NazaraWarning("Failed to flip image"); + std::memcpy(mirrored, pixels, size); + } + + SetUnpackAlignement(bpp); + + LockTexture(m_impl); + glTexSubImage2D(NzOpenGL::CubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored); + UnlockTexture(m_impl); + + + return true; +} + +void NzTexture::Unlock() +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return; + } + #endif + + UnlockTexture(m_impl); +} + +unsigned int NzTexture::GetOpenGLID() const +{ + #if NAZARA_RENDERER_SAFE + if (!m_impl) + { + NazaraError("Texture must be valid"); + return 0; + } + #endif + + return m_impl->id; +} + +bool NzTexture::Prepare() const +{ + #if NAZARA_RENDERER_SAFE + if (lockedLevel[m_impl->type] > 0) + { + NazaraError("Cannot bind texture while a texture is locked"); + return false; + } + #endif + + glBindTexture(NzOpenGL::TextureTarget[m_impl->type], m_impl->id); + + if (m_impl->mipmapping && !m_impl->mipmapsUpdated) + { + glGenerateMipmap(NzOpenGL::TextureTarget[m_impl->type]); + m_impl->mipmapsUpdated = true; + } + + return true; +} + +unsigned int NzTexture::GetValidSize(unsigned int size) +{ + if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT)) + return size; + else + { + unsigned int pot = 1; + while (pot < size) + pot <<= 1; + + return pot; + } +} + +bool NzTexture::IsFormatSupported(nzPixelFormat format) +{ + switch (format) + { + // Formats de base + case nzPixelFormat_BGR8: + case nzPixelFormat_BGRA8: + case nzPixelFormat_RGB8: + case nzPixelFormat_RGBA8: + return true; + + // Packed formats supportés depuis OpenGL 1.2 + case nzPixelFormat_RGB5A1: + case nzPixelFormat_RGBA4: + return true; + + // Formats de profondeur (Supportés avec les FBOs) + case nzPixelFormat_Depth16: + case nzPixelFormat_Depth24: + case nzPixelFormat_Depth32: + case nzPixelFormat_Depth24Stencil8: + { + static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); + return supported; + } + + // Formats de stencil (Non supportés pour les textures) + case nzPixelFormat_Stencil1: + case nzPixelFormat_Stencil4: + case nzPixelFormat_Stencil8: + case nzPixelFormat_Stencil16: + return false; + + // Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..) + case nzPixelFormat_L8: + case nzPixelFormat_LA8: + return false; + + case nzPixelFormat_DXT1: + case nzPixelFormat_DXT3: + case nzPixelFormat_DXT5: + { + static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc); + return supported; + } + + case nzPixelFormat_Undefined: + break; + } + + NazaraError("Invalid pixel format"); + + return false; +} + +bool NzTexture::IsMipmappingSupported() +{ + return glGenerateMipmap != nullptr; +} + +bool NzTexture::IsTypeSupported(nzImageType type) +{ + switch (type) + { + case nzImageType_1D: + case nzImageType_2D: + case nzImageType_3D: + case nzImageType_Cubemap: + return true; // Tous supportés nativement dans OpenGL 2 + + case nzImageType_1D_Array: + case nzImageType_2D_Array: + { + static bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray); + return supported; + } + } + + NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); + return false; +} + +NzRenderTexture* NzTexture::GetRenderTexture() const +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Texture must be valid"); + return nullptr; + } + #endif + + return m_impl->renderTexture; +} + +void NzTexture::SetRenderTexture(NzRenderTexture* renderTexture) +{ + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraInternalError("Texture must be valid"); + return; + } + #endif + + m_impl->renderTexture = renderTexture; +} diff --git a/src/Nazara/Renderer/Win32/ContextImpl.cpp b/src/Nazara/Renderer/Win32/ContextImpl.cpp index 15fd533d2..2232ca72f 100644 --- a/src/Nazara/Renderer/Win32/ContextImpl.cpp +++ b/src/Nazara/Renderer/Win32/ContextImpl.cpp @@ -1,234 +1,234 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Renderer module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila - -#include -#include -#include -#include -#include -#include -#include -#include - -NzContextImpl::NzContextImpl() -{ -} - -bool NzContextImpl::Activate() -{ - return wglMakeCurrent(m_deviceContext, m_context); -} - -bool NzContextImpl::Create(NzContextParameters& parameters) -{ - if (parameters.window) - { - m_window = static_cast(parameters.window); - m_ownsWindow = false; - } - else - { - m_window = CreateWindowA("STATIC", nullptr, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); - if (!m_window) - { - NazaraError("Failed to create window"); - return false; - } - - ShowWindow(m_window, SW_HIDE); - m_ownsWindow = true; - } - - m_deviceContext = GetDC(m_window); - if (!m_deviceContext) - { - NazaraError("Failed to get device context"); - Destroy(); - return false; - } - - int pixelFormat = 0; - if (parameters.antialiasingLevel > 0) - { - if (wglChoosePixelFormat) - { - bool valid; - UINT numFormats; - - int attributes[] = { - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_COLOR_BITS_ARB, (parameters.bitsPerPixel == 32) ? 24 : parameters.bitsPerPixel, - WGL_ALPHA_BITS_ARB, (parameters.bitsPerPixel == 32) ? 8 : 0, - WGL_DEPTH_BITS_ARB, parameters.depthBits, - WGL_STENCIL_BITS_ARB, parameters.stencilBits, - WGL_DOUBLE_BUFFER_ARB, (parameters.doubleBuffered) ? GL_TRUE : GL_FALSE, - WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, - WGL_SAMPLES_ARB, parameters.antialiasingLevel, - 0, 0 - }; - - do - { - valid = wglChoosePixelFormat(m_deviceContext, attributes, nullptr, 1, &pixelFormat, &numFormats); - } - while ((!valid || numFormats == 0) && --attributes[19] > 0); - - if (!valid) - { - NazaraWarning("Could not find a format matching requirements, disabling antialiasing..."); - pixelFormat = 0; - } - - parameters.antialiasingLevel = attributes[19]; - } - else - { - NazaraWarning("Antialiasing is not supported"); - parameters.antialiasingLevel = 0; - } - } - - PIXELFORMATDESCRIPTOR descriptor; - ZeroMemory(&descriptor, sizeof(PIXELFORMATDESCRIPTOR)); - descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR); - descriptor.nVersion = 1; - - if (pixelFormat == 0) - { - descriptor.cColorBits = parameters.bitsPerPixel; - descriptor.cDepthBits = parameters.depthBits; - descriptor.cStencilBits = parameters.stencilBits; - descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - descriptor.iPixelType = PFD_TYPE_RGBA; - - if (parameters.bitsPerPixel == 32) - descriptor.cAlphaBits = 8; - - if (parameters.doubleBuffered) - descriptor.dwFlags |= PFD_DOUBLEBUFFER; - - pixelFormat = ChoosePixelFormat(m_deviceContext, &descriptor); - if (pixelFormat == 0) - { - NazaraError("Failed to choose pixel format"); - Destroy(); - - return false; - } - } - - if (!SetPixelFormat(m_deviceContext, pixelFormat, &descriptor)) - { - NazaraError("Failed to set pixel format"); - Destroy(); - return false; - } - - // Arrivé ici, le format de pixel est choisi, nous récupérons donc les paramètres réels du futur contexte - if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0) - { - parameters.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits; - parameters.depthBits = descriptor.cDepthBits; - parameters.stencilBits = descriptor.cDepthBits; - } - else - NazaraWarning("Failed to get context's parameters"); - - HGLRC shareContext = (parameters.shared) ? static_cast(parameters.shareContext->m_impl)->m_context : nullptr; - - m_context = nullptr; - if (wglCreateContextAttribs) - { - int attributes[4*2+1]; - int* attrib = attributes; - - *attrib++ = WGL_CONTEXT_MAJOR_VERSION_ARB; - *attrib++ = parameters.majorVersion; - - *attrib++ = WGL_CONTEXT_MINOR_VERSION_ARB; - *attrib++ = parameters.minorVersion; - - if (parameters.majorVersion >= 3) - { - *attrib++ = WGL_CONTEXT_PROFILE_MASK_ARB; - *attrib++ = (parameters.compatibilityProfile) ? WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB : WGL_CONTEXT_CORE_PROFILE_BIT_ARB; - } - - if (parameters.debugMode) - { - *attrib++ = WGL_CONTEXT_FLAGS_ARB; - *attrib++ = WGL_CONTEXT_DEBUG_BIT_ARB; - - // Les contextes forward-compatible ne sont plus utilisés pour cette raison : - // http://www.opengl.org/discussion_boards/showthread.php/175052-Forward-compatible-vs-Core-profile - } - - *attrib++ = 0; - - m_context = wglCreateContextAttribs(m_deviceContext, shareContext, attributes); - } - - if (!m_context) - { - m_context = wglCreateContext(m_deviceContext); - - if (shareContext) - { - // wglShareLists n'est pas thread-safe (source: SFML) - static NzMutex mutex; - NzLockGuard lock(mutex); - - if (!wglShareLists(shareContext, m_context)) - NazaraWarning("Failed to share the context: " + NzGetLastSystemError()); - } - } - - if (!m_context) - { - NazaraError("Failed to create context"); - Destroy(); - return false; - } - - return true; -} - -void NzContextImpl::Destroy() -{ - if (m_context) - { - if (wglGetCurrentContext() == m_context) - wglMakeCurrent(nullptr, nullptr); - - wglDeleteContext(m_context); - m_context = nullptr; - } - - if (m_deviceContext) - { - ReleaseDC(m_window, m_deviceContext); - m_deviceContext = nullptr; - } - - if (m_ownsWindow) - { - DestroyWindow(m_window); - m_window = nullptr; - } -} - -void NzContextImpl::SwapBuffers() -{ - ::SwapBuffers(m_deviceContext); -} - -bool NzContextImpl::Desactivate() -{ - return wglMakeCurrent(nullptr, nullptr); -} - +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Renderer module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila + +#include +#include +#include +#include +#include +#include +#include +#include + +NzContextImpl::NzContextImpl() +{ +} + +bool NzContextImpl::Activate() +{ + return wglMakeCurrent(m_deviceContext, m_context); +} + +bool NzContextImpl::Create(NzContextParameters& parameters) +{ + if (parameters.window) + { + m_window = static_cast(parameters.window); + m_ownsWindow = false; + } + else + { + m_window = CreateWindowA("STATIC", nullptr, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); + if (!m_window) + { + NazaraError("Failed to create window"); + return false; + } + + ShowWindow(m_window, SW_HIDE); + m_ownsWindow = true; + } + + m_deviceContext = GetDC(m_window); + if (!m_deviceContext) + { + NazaraError("Failed to get device context"); + Destroy(); + return false; + } + + int pixelFormat = 0; + if (parameters.antialiasingLevel > 0) + { + if (wglChoosePixelFormat) + { + bool valid; + UINT numFormats; + + int attributes[] = { + WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, + WGL_SUPPORT_OPENGL_ARB, GL_TRUE, + WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, + WGL_COLOR_BITS_ARB, (parameters.bitsPerPixel == 32) ? 24 : parameters.bitsPerPixel, + WGL_ALPHA_BITS_ARB, (parameters.bitsPerPixel == 32) ? 8 : 0, + WGL_DEPTH_BITS_ARB, parameters.depthBits, + WGL_STENCIL_BITS_ARB, parameters.stencilBits, + WGL_DOUBLE_BUFFER_ARB, (parameters.doubleBuffered) ? GL_TRUE : GL_FALSE, + WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, + WGL_SAMPLES_ARB, parameters.antialiasingLevel, + 0, 0 + }; + + do + { + valid = wglChoosePixelFormat(m_deviceContext, attributes, nullptr, 1, &pixelFormat, &numFormats); + } + while ((!valid || numFormats == 0) && --attributes[19] > 0); + + if (!valid) + { + NazaraWarning("Could not find a format matching requirements, disabling antialiasing..."); + pixelFormat = 0; + } + + parameters.antialiasingLevel = attributes[19]; + } + else + { + NazaraWarning("Antialiasing is not supported"); + parameters.antialiasingLevel = 0; + } + } + + PIXELFORMATDESCRIPTOR descriptor; + ZeroMemory(&descriptor, sizeof(PIXELFORMATDESCRIPTOR)); + descriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR); + descriptor.nVersion = 1; + + if (pixelFormat == 0) + { + descriptor.cColorBits = parameters.bitsPerPixel; + descriptor.cDepthBits = parameters.depthBits; + descriptor.cStencilBits = parameters.stencilBits; + descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + descriptor.iPixelType = PFD_TYPE_RGBA; + + if (parameters.bitsPerPixel == 32) + descriptor.cAlphaBits = 8; + + if (parameters.doubleBuffered) + descriptor.dwFlags |= PFD_DOUBLEBUFFER; + + pixelFormat = ChoosePixelFormat(m_deviceContext, &descriptor); + if (pixelFormat == 0) + { + NazaraError("Failed to choose pixel format"); + Destroy(); + + return false; + } + } + + if (!SetPixelFormat(m_deviceContext, pixelFormat, &descriptor)) + { + NazaraError("Failed to set pixel format"); + Destroy(); + return false; + } + + // Arrivé ici, le format de pixel est choisi, nous récupérons donc les paramètres réels du futur contexte + if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0) + { + parameters.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits; + parameters.depthBits = descriptor.cDepthBits; + parameters.stencilBits = descriptor.cDepthBits; + } + else + NazaraWarning("Failed to get context's parameters"); + + HGLRC shareContext = (parameters.shared) ? static_cast(parameters.shareContext->m_impl)->m_context : nullptr; + + m_context = nullptr; + if (wglCreateContextAttribs) + { + int attributes[4*2+1]; + int* attrib = attributes; + + *attrib++ = WGL_CONTEXT_MAJOR_VERSION_ARB; + *attrib++ = parameters.majorVersion; + + *attrib++ = WGL_CONTEXT_MINOR_VERSION_ARB; + *attrib++ = parameters.minorVersion; + + if (parameters.majorVersion >= 3) + { + *attrib++ = WGL_CONTEXT_PROFILE_MASK_ARB; + *attrib++ = (parameters.compatibilityProfile) ? WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB : WGL_CONTEXT_CORE_PROFILE_BIT_ARB; + } + + if (parameters.debugMode) + { + *attrib++ = WGL_CONTEXT_FLAGS_ARB; + *attrib++ = WGL_CONTEXT_DEBUG_BIT_ARB; + + // Les contextes forward-compatible ne sont plus utilisés pour cette raison : + // http://www.opengl.org/discussion_boards/showthread.php/175052-Forward-compatible-vs-Core-profile + } + + *attrib++ = 0; + + m_context = wglCreateContextAttribs(m_deviceContext, shareContext, attributes); + } + + if (!m_context) + { + m_context = wglCreateContext(m_deviceContext); + + if (shareContext) + { + // wglShareLists n'est pas thread-safe (source: SFML) + static NzMutex mutex; + NzLockGuard lock(mutex); + + if (!wglShareLists(shareContext, m_context)) + NazaraWarning("Failed to share the context: " + NzGetLastSystemError()); + } + } + + if (!m_context) + { + NazaraError("Failed to create context"); + Destroy(); + return false; + } + + return true; +} + +void NzContextImpl::Destroy() +{ + if (m_context) + { + if (wglGetCurrentContext() == m_context) + wglMakeCurrent(nullptr, nullptr); + + wglDeleteContext(m_context); + m_context = nullptr; + } + + if (m_deviceContext) + { + ReleaseDC(m_window, m_deviceContext); + m_deviceContext = nullptr; + } + + if (m_ownsWindow) + { + DestroyWindow(m_window); + m_window = nullptr; + } +} + +void NzContextImpl::SwapBuffers() +{ + ::SwapBuffers(m_deviceContext); +} + +bool NzContextImpl::Desactivate() +{ + return wglMakeCurrent(nullptr, nullptr); +} + diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index fe9f1c0b2..d38a38e23 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -1,342 +1,342 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -struct NzAnimationImpl -{ - std::map sequenceMap; - std::vector sequences; - nzAnimationType type; - unsigned int frameCount; -}; - -bool NzAnimationParams::IsValid() const -{ - if (startFrame > endFrame) - { - NazaraError("Start frame must be lower than end frame"); - return false; - } - - return true; -} - -NzAnimation::~NzAnimation() -{ - Destroy(); -} - -bool NzAnimation::AddSequence(const NzSequence& sequence) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - unsigned int index = m_impl->sequences.size(); - - if (!sequence.name.IsEmpty()) - { - #if NAZARA_UTILITY_SAFE - auto it = m_impl->sequenceMap.find(sequence.name); - if (it != m_impl->sequenceMap.end()) - { - NazaraError("Sequence name \"" + sequence.name + "\" is already used"); - return false; - } - #endif - - m_impl->sequenceMap[sequence.name] = index; - } - - m_impl->sequences.push_back(sequence); - - return true; -} - -bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount) -{ - Destroy(); - - #if NAZARA_UTILITY_SAFE - if (type == nzAnimationType_Static) - { - NazaraError("Invalid type"); - return false; - } - - if (frameCount == 0) - { - NazaraError("Frame count must be over zero"); - return false; - } - #endif - - m_impl = new NzAnimationImpl; - m_impl->frameCount = frameCount; - m_impl->type = type; - - NotifyCreated(); - return true; -} - -void NzAnimation::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - delete m_impl; - m_impl = nullptr; - } -} - -unsigned int NzAnimation::GetFrameCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - return m_impl->frameCount; -} - -NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - auto it = m_impl->sequenceMap.find(sequenceName); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("Sequence not found"); - return nullptr; - } - - return &m_impl->sequences[it->second]; - #else - return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; - #endif -} - -NzSequence* NzAnimation::GetSequence(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); - return nullptr; - } - #endif - - return &m_impl->sequences[index]; -} - -const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - auto it = m_impl->sequenceMap.find(sequenceName); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("Sequence not found"); - return nullptr; - } - - return &m_impl->sequences[it->second]; - #else - return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; - #endif -} - -const NzSequence* NzAnimation::GetSequence(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); - return nullptr; - } - #endif - - return &m_impl->sequences[index]; -} - -unsigned int NzAnimation::GetSequenceCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return 0; - } - #endif - - return m_impl->sequences.size(); -} - -int NzAnimation::GetSequenceIndex(const NzString& sequenceName) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return -1; - } - - auto it = m_impl->sequenceMap.find(sequenceName); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("Sequence not found"); - return -1; - } - - return it->second; - #else - return m_impl->sequenceMap[sequenceName]; - #endif -} - -nzAnimationType NzAnimation::GetType() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nzAnimationType_Static; // Ce qui est une valeur invalide pour NzAnimation - } - #endif - - return m_impl->type; -} - -bool NzAnimation::HasSequence(const NzString& sequenceName) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end(); -} - -bool NzAnimation::HasSequence(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif - - return index >= m_impl->sequences.size(); -} - -bool NzAnimation::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzAnimation::LoadFromFile(const NzString& filePath, const NzAnimationParams& params) -{ - return NzAnimationLoader::LoadFromFile(this, filePath, params); -} - -bool NzAnimation::LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params) -{ - return NzAnimationLoader::LoadFromMemory(this, data, size, params); -} - -bool NzAnimation::LoadFromStream(NzInputStream& stream, const NzAnimationParams& params) -{ - return NzAnimationLoader::LoadFromStream(this, stream, params); -} - -void NzAnimation::RemoveSequence(const NzString& identifier) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } - - auto it = m_impl->sequenceMap.find(identifier); - if (it == m_impl->sequenceMap.end()) - { - NazaraError("Sequence not found"); - return; - } - - int index = it->second; - #else - int index = m_impl->sequenceMap[identifier]; - #endif - - auto it2 = m_impl->sequences.begin(); - std::advance(it2, index); - - m_impl->sequences.erase(it2); -} - -void NzAnimation::RemoveSequence(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); - return; - } - #endif - - auto it = m_impl->sequences.begin(); - std::advance(it, index); - - m_impl->sequences.erase(it); -} - -NzAnimationLoader::LoaderList NzAnimation::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +struct NzAnimationImpl +{ + std::map sequenceMap; + std::vector sequences; + nzAnimationType type; + unsigned int frameCount; +}; + +bool NzAnimationParams::IsValid() const +{ + if (startFrame > endFrame) + { + NazaraError("Start frame must be lower than end frame"); + return false; + } + + return true; +} + +NzAnimation::~NzAnimation() +{ + Destroy(); +} + +bool NzAnimation::AddSequence(const NzSequence& sequence) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + unsigned int index = m_impl->sequences.size(); + + if (!sequence.name.IsEmpty()) + { + #if NAZARA_UTILITY_SAFE + auto it = m_impl->sequenceMap.find(sequence.name); + if (it != m_impl->sequenceMap.end()) + { + NazaraError("Sequence name \"" + sequence.name + "\" is already used"); + return false; + } + #endif + + m_impl->sequenceMap[sequence.name] = index; + } + + m_impl->sequences.push_back(sequence); + + return true; +} + +bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount) +{ + Destroy(); + + #if NAZARA_UTILITY_SAFE + if (type == nzAnimationType_Static) + { + NazaraError("Invalid type"); + return false; + } + + if (frameCount == 0) + { + NazaraError("Frame count must be over zero"); + return false; + } + #endif + + m_impl = new NzAnimationImpl; + m_impl->frameCount = frameCount; + m_impl->type = type; + + NotifyCreated(); + return true; +} + +void NzAnimation::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + delete m_impl; + m_impl = nullptr; + } +} + +unsigned int NzAnimation::GetFrameCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + return m_impl->frameCount; +} + +NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + auto it = m_impl->sequenceMap.find(sequenceName); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return nullptr; + } + + return &m_impl->sequences[it->second]; + #else + return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; + #endif +} + +NzSequence* NzAnimation::GetSequence(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + if (index >= m_impl->sequences.size()) + { + NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); + return nullptr; + } + #endif + + return &m_impl->sequences[index]; +} + +const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + auto it = m_impl->sequenceMap.find(sequenceName); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return nullptr; + } + + return &m_impl->sequences[it->second]; + #else + return &m_impl->sequences[m_impl->sequenceMap[sequenceName]]; + #endif +} + +const NzSequence* NzAnimation::GetSequence(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nullptr; + } + + if (index >= m_impl->sequences.size()) + { + NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); + return nullptr; + } + #endif + + return &m_impl->sequences[index]; +} + +unsigned int NzAnimation::GetSequenceCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return 0; + } + #endif + + return m_impl->sequences.size(); +} + +int NzAnimation::GetSequenceIndex(const NzString& sequenceName) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return -1; + } + + auto it = m_impl->sequenceMap.find(sequenceName); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return -1; + } + + return it->second; + #else + return m_impl->sequenceMap[sequenceName]; + #endif +} + +nzAnimationType NzAnimation::GetType() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return nzAnimationType_Static; // Ce qui est une valeur invalide pour NzAnimation + } + #endif + + return m_impl->type; +} + +bool NzAnimation::HasSequence(const NzString& sequenceName) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end(); +} + +bool NzAnimation::HasSequence(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return false; + } + #endif + + return index >= m_impl->sequences.size(); +} + +bool NzAnimation::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzAnimation::LoadFromFile(const NzString& filePath, const NzAnimationParams& params) +{ + return NzAnimationLoader::LoadFromFile(this, filePath, params); +} + +bool NzAnimation::LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params) +{ + return NzAnimationLoader::LoadFromMemory(this, data, size, params); +} + +bool NzAnimation::LoadFromStream(NzInputStream& stream, const NzAnimationParams& params) +{ + return NzAnimationLoader::LoadFromStream(this, stream, params); +} + +void NzAnimation::RemoveSequence(const NzString& identifier) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return; + } + + auto it = m_impl->sequenceMap.find(identifier); + if (it == m_impl->sequenceMap.end()) + { + NazaraError("Sequence not found"); + return; + } + + int index = it->second; + #else + int index = m_impl->sequenceMap[identifier]; + #endif + + auto it2 = m_impl->sequences.begin(); + std::advance(it2, index); + + m_impl->sequences.erase(it2); +} + +void NzAnimation::RemoveSequence(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Animation not created"); + return; + } + + if (index >= m_impl->sequences.size()) + { + NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')'); + return; + } + #endif + + auto it = m_impl->sequences.begin(); + std::advance(it, index); + + m_impl->sequences.erase(it); +} + +NzAnimationLoader::LoaderList NzAnimation::s_loaders; diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index 4969b3129..1d3e6c9f0 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -1,339 +1,339 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - NzBufferImpl* SoftwareBufferFunction(NzBuffer* parent, nzBufferType type) - { - return new NzSoftwareBuffer(parent, type); - } -} - -NzBuffer::NzBuffer(nzBufferType type) : -m_type(type), -m_typeSize(0), -m_impl(nullptr), -m_length(0) -{ -} - -NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) : -m_type(type), -m_impl(nullptr) -{ - Create(length, typeSize, storage, usage); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create buffer"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzBuffer::~NzBuffer() -{ - Destroy(); -} - -bool NzBuffer::CopyContent(NzBuffer& buffer) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer must be valid"); - return false; - } - - if (!buffer.IsValid()) - { - NazaraError("Source buffer must be valid"); - return false; - } - - if (!buffer.GetTypeSize() != m_typeSize) - { - NazaraError("Source buffer type size does not match buffer type size"); - return false; - } - #endif - - void* ptr = buffer.Map(nzBufferAccess_ReadOnly); - if (!ptr) - { - NazaraError("Failed to map source buffer"); - return false; - } - - bool r = Fill(ptr, 0, buffer.GetLength()); - - if (!buffer.Unmap()) - NazaraWarning("Failed to unmap source buffer"); - - return r; -} - -bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) -{ - Destroy(); - - // On tente d'abord de faire un buffer hardware, si supporté - if (s_bufferFunctions[storage]) - { - NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); - if (!impl->Create(length*typeSize, usage)) - { - NazaraError("Failed to create buffer"); - delete impl; - - return false; - } - - m_impl = impl; - } - else - { - NazaraError("Buffer storage not supported"); - return false; - } - - m_length = length; - m_typeSize = typeSize; - m_storage = storage; - m_usage = usage; - - NotifyCreated(); - return true; // Si on arrive ici c'est que tout s'est bien passé. -} - -void NzBuffer::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - } -} - -bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return false; - } - - if (offset+length > m_length) - { - NazaraError("Exceeding buffer size"); - return false; - } - #endif - - return m_impl->Fill(data, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); -} - -NzBufferImpl* NzBuffer::GetImpl() const -{ - return m_impl; -} - -unsigned int NzBuffer::GetLength() const -{ - return m_length; -} - -void* NzBuffer::GetPointer() -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return nullptr; - } - #endif - - return m_impl->GetPointer(); -} - -const void* NzBuffer::GetPointer() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return nullptr; - } - #endif - - return m_impl->GetPointer(); -} - -unsigned int NzBuffer::GetSize() const -{ - return m_length*m_typeSize; -} - -nzBufferStorage NzBuffer::GetStorage() const -{ - return m_storage; -} - -nzBufferType NzBuffer::GetType() const -{ - return m_type; -} - -nzUInt8 NzBuffer::GetTypeSize() const -{ - return m_typeSize; -} - -nzBufferUsage NzBuffer::GetUsage() const -{ - return m_usage; -} - -bool NzBuffer::IsHardware() const -{ - return m_storage == nzBufferStorage_Hardware; -} - -bool NzBuffer::IsValid() const -{ - return m_impl != nullptr; -} - -void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return nullptr; - } - - if (offset+length > m_length) - { - NazaraError("Exceeding buffer size"); - return nullptr; - } - #endif - - return m_impl->Map(access, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); -} - -bool NzBuffer::SetStorage(nzBufferStorage storage) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return false; - } - #endif - - if (m_storage == storage) - return true; - - #if NAZARA_UTILITY_SAFE - if (!IsSupported(storage)) - { - NazaraError("Storage not supported"); - return false; - } - #endif - - void* ptr = m_impl->Map(nzBufferAccess_ReadOnly, 0, m_length*m_typeSize); - if (!ptr) - { - NazaraError("Failed to map buffer"); - return false; - } - - NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); - if (!impl->Create(m_length*m_typeSize, m_usage)) - { - NazaraError("Failed to create buffer"); - delete impl; - - if (!m_impl->Unmap()) - NazaraWarning("Failed to unmap buffer"); - - return false; - } - - if (!impl->Fill(ptr, 0, m_length*m_typeSize)) - { - NazaraError("Failed to fill buffer"); - impl->Destroy(); - delete impl; - - if (!m_impl->Unmap()) - NazaraWarning("Failed to unmap buffer"); - - return false; - } - - m_impl->Unmap(); - m_impl->Destroy(); - - delete m_impl; - m_impl = impl; - - m_storage = storage; - - return true; -} - -bool NzBuffer::Unmap() -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Buffer not valid"); - return false; - } - #endif - - return m_impl->Unmap(); -} - -bool NzBuffer::IsSupported(nzBufferStorage storage) -{ - return s_bufferFunctions[storage] != nullptr; -} - -void NzBuffer::SetBufferFunction(nzBufferStorage storage, BufferFunction func) -{ - s_bufferFunctions[storage] = func; -} - -bool NzBuffer::Initialize() -{ - s_bufferFunctions[nzBufferStorage_Software] = SoftwareBufferFunction; - - return true; -} - -void NzBuffer::Uninitialize() -{ - std::memset(s_bufferFunctions, 0, (nzBufferStorage_Max+1)*sizeof(NzBuffer::BufferFunction)); -} - -NzBuffer::BufferFunction NzBuffer::s_bufferFunctions[nzBufferStorage_Max+1] = {0}; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + NzBufferImpl* SoftwareBufferFunction(NzBuffer* parent, nzBufferType type) + { + return new NzSoftwareBuffer(parent, type); + } +} + +NzBuffer::NzBuffer(nzBufferType type) : +m_type(type), +m_typeSize(0), +m_impl(nullptr), +m_length(0) +{ +} + +NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) : +m_type(type), +m_impl(nullptr) +{ + Create(length, typeSize, storage, usage); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create buffer"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzBuffer::~NzBuffer() +{ + Destroy(); +} + +bool NzBuffer::CopyContent(NzBuffer& buffer) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer must be valid"); + return false; + } + + if (!buffer.IsValid()) + { + NazaraError("Source buffer must be valid"); + return false; + } + + if (!buffer.GetTypeSize() != m_typeSize) + { + NazaraError("Source buffer type size does not match buffer type size"); + return false; + } + #endif + + void* ptr = buffer.Map(nzBufferAccess_ReadOnly); + if (!ptr) + { + NazaraError("Failed to map source buffer"); + return false; + } + + bool r = Fill(ptr, 0, buffer.GetLength()); + + if (!buffer.Unmap()) + NazaraWarning("Failed to unmap source buffer"); + + return r; +} + +bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage, nzBufferUsage usage) +{ + Destroy(); + + // On tente d'abord de faire un buffer hardware, si supporté + if (s_bufferFunctions[storage]) + { + NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); + if (!impl->Create(length*typeSize, usage)) + { + NazaraError("Failed to create buffer"); + delete impl; + + return false; + } + + m_impl = impl; + } + else + { + NazaraError("Buffer storage not supported"); + return false; + } + + m_length = length; + m_typeSize = typeSize; + m_storage = storage; + m_usage = usage; + + NotifyCreated(); + return true; // Si on arrive ici c'est que tout s'est bien passé. +} + +void NzBuffer::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + } +} + +bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return false; + } + + if (offset+length > m_length) + { + NazaraError("Exceeding buffer size"); + return false; + } + #endif + + return m_impl->Fill(data, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); +} + +NzBufferImpl* NzBuffer::GetImpl() const +{ + return m_impl; +} + +unsigned int NzBuffer::GetLength() const +{ + return m_length; +} + +void* NzBuffer::GetPointer() +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + #endif + + return m_impl->GetPointer(); +} + +const void* NzBuffer::GetPointer() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + #endif + + return m_impl->GetPointer(); +} + +unsigned int NzBuffer::GetSize() const +{ + return m_length*m_typeSize; +} + +nzBufferStorage NzBuffer::GetStorage() const +{ + return m_storage; +} + +nzBufferType NzBuffer::GetType() const +{ + return m_type; +} + +nzUInt8 NzBuffer::GetTypeSize() const +{ + return m_typeSize; +} + +nzBufferUsage NzBuffer::GetUsage() const +{ + return m_usage; +} + +bool NzBuffer::IsHardware() const +{ + return m_storage == nzBufferStorage_Hardware; +} + +bool NzBuffer::IsValid() const +{ + return m_impl != nullptr; +} + +void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return nullptr; + } + + if (offset+length > m_length) + { + NazaraError("Exceeding buffer size"); + return nullptr; + } + #endif + + return m_impl->Map(access, offset*m_typeSize, ((length == 0) ? m_length-offset : length)*m_typeSize); +} + +bool NzBuffer::SetStorage(nzBufferStorage storage) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return false; + } + #endif + + if (m_storage == storage) + return true; + + #if NAZARA_UTILITY_SAFE + if (!IsSupported(storage)) + { + NazaraError("Storage not supported"); + return false; + } + #endif + + void* ptr = m_impl->Map(nzBufferAccess_ReadOnly, 0, m_length*m_typeSize); + if (!ptr) + { + NazaraError("Failed to map buffer"); + return false; + } + + NzBufferImpl* impl = s_bufferFunctions[storage](this, m_type); + if (!impl->Create(m_length*m_typeSize, m_usage)) + { + NazaraError("Failed to create buffer"); + delete impl; + + if (!m_impl->Unmap()) + NazaraWarning("Failed to unmap buffer"); + + return false; + } + + if (!impl->Fill(ptr, 0, m_length*m_typeSize)) + { + NazaraError("Failed to fill buffer"); + impl->Destroy(); + delete impl; + + if (!m_impl->Unmap()) + NazaraWarning("Failed to unmap buffer"); + + return false; + } + + m_impl->Unmap(); + m_impl->Destroy(); + + delete m_impl; + m_impl = impl; + + m_storage = storage; + + return true; +} + +bool NzBuffer::Unmap() +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Buffer not valid"); + return false; + } + #endif + + return m_impl->Unmap(); +} + +bool NzBuffer::IsSupported(nzBufferStorage storage) +{ + return s_bufferFunctions[storage] != nullptr; +} + +void NzBuffer::SetBufferFunction(nzBufferStorage storage, BufferFunction func) +{ + s_bufferFunctions[storage] = func; +} + +bool NzBuffer::Initialize() +{ + s_bufferFunctions[nzBufferStorage_Software] = SoftwareBufferFunction; + + return true; +} + +void NzBuffer::Uninitialize() +{ + std::memset(s_bufferFunctions, 0, (nzBufferStorage_Max+1)*sizeof(NzBuffer::BufferFunction)); +} + +NzBuffer::BufferFunction NzBuffer::s_bufferFunctions[nzBufferStorage_Max+1] = {0}; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 75b66ca2a..68bee7d9b 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -1,1187 +1,1187 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace -{ - inline unsigned int GetLevelSize(unsigned int size, nzUInt8 level) - { - return std::max(size >> level, 1U); - } - - inline nzUInt8* GetPixelPtr(nzUInt8* base, nzUInt8 bpp, unsigned int x, unsigned int y, unsigned int z, unsigned int width, unsigned int height) - { - return &base[(width*(height*z + y) + x)*bpp]; - } -} - -bool NzImageParams::IsValid() const -{ - return true; -} - -NzImage::NzImage() : -m_sharedImage(&emptyImage) -{ -} - -NzImage::NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) : -m_sharedImage(&emptyImage) -{ - Create(type, format, width, height, depth, levelCount); - - #ifdef NAZARA_DEBUG - if (!m_sharedImage) - { - NazaraError("Failed to create image"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzImage::NzImage(const NzImage& image) : -NzResource(image), -m_sharedImage(image.m_sharedImage) -{ - if (m_sharedImage != &emptyImage) - { - NazaraMutexLock(m_sharedImage->mutex); - m_sharedImage->refCount++; - NazaraMutexUnlock(m_sharedImage->mutex); - } -} - -NzImage::NzImage(NzImage&& image) noexcept : -m_sharedImage(image.m_sharedImage) -{ - image.m_sharedImage = &emptyImage; -} - -NzImage::~NzImage() -{ - ReleaseImage(); -} - -bool NzImage::Convert(nzPixelFormat format) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!NzPixelFormat::IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - - if (!NzPixelFormat::IsConversionSupported(m_sharedImage->format, format)) - { - NazaraError("Conversion from " + NzPixelFormat::ToString(m_sharedImage->format) + " to " + NzPixelFormat::ToString(format) + " is not supported"); - return false; - } - #endif - - if (format == m_sharedImage->format) - return true; - - nzUInt8** levels = new nzUInt8*[m_sharedImage->levelCount]; - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - - // Les images 3D et cubemaps sont stockés de la même façon - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - { - unsigned int pixelsPerFace = width*height; - nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)]; - nzUInt8* pixels = m_sharedImage->pixels[i]; - unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format); - unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format); - - for (unsigned int d = 0; d < depth; ++d) - { - if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr)) - { - NazaraError("Failed to convert image"); - - // Nettoyage de la mémoire - delete[] ptr; // Permet une optimisation de boucle (GCC) - for (unsigned int j = 0; j < i; ++j) - delete[] levels[j]; - - delete[] levels; - - return false; - } - - pixels += srcStride; - ptr += dstStride; - } - - levels[i] = ptr; - - if (width > 1) - width >>= 1; - - if (height > 1) - height >>= 1; - - if (depth > 1 && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - SharedImage* newImage = new SharedImage(1, m_sharedImage->type, format, m_sharedImage->levelCount, levels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); - - ReleaseImage(); - m_sharedImage = newImage; - - return true; -} - -bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos) -{ - #if NAZARA_UTILITY_SAFE - if (!source.IsValid()) - { - NazaraError("Source image must be valid"); - return false; - } - - if (source.GetFormat() != m_sharedImage->format) - { - NazaraError("Source image format does not match destination image format"); - return false; - } - #endif - - const nzUInt8* pixels = source.GetConstPixels(0, srcCube.x, srcCube.y, srcCube.z); - if (!pixels) - { - NazaraError("Failed to access pixels"); - return false; - } - - /* - Correctif temporaire : Update veut de la mémoire contigüe - Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour - - ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) - (Appliquer l'interface à NzTexture également) - */ - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - unsigned int dstLineStride = srcCube.width*bpp; - unsigned int dstFaceStride = dstLineStride*srcCube.height; - unsigned int srcLineStride = m_sharedImage->width*bpp; - unsigned int srcFaceStride = srcLineStride*m_sharedImage->height; - - nzUInt8* cube = new nzUInt8[dstFaceStride*srcCube.depth]; - nzUInt8* ptr = cube; - - for (unsigned int z = 0; z < srcCube.depth; ++z) - { - nzUInt8* facePixels = ptr; - for (unsigned int y = 0; y < srcCube.height; ++y) - { - std::memcpy(facePixels, pixels, dstLineStride); - - facePixels += dstLineStride; - pixels += srcLineStride; - } - - ptr += dstFaceStride; - pixels += srcFaceStride; - } - - bool success = Update(cube, NzCubeui(dstPos.x, dstPos.y, dstPos.z, srcCube.width, srcCube.height, srcCube.depth)); - - delete[] cube; - - return success; -} - -bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) -{ - ReleaseImage(); - - #if NAZARA_UTILITY_SAFE - if (!NzPixelFormat::IsValid(format)) - { - NazaraError("Invalid pixel format"); - return false; - } - - if (width == 0) - { - NazaraError("Width must be at least 1 (0)"); - return false; - } - - if (height == 0) - { - NazaraError("Height must be at least 1 (0)"); - return false; - } - - if (depth == 0) - { - NazaraError("Depth must be at least 1 (0)"); - return false; - } - - switch (type) - { - case nzImageType_1D: - if (height > 1) - { - NazaraError("1D textures must be 1 height"); - return false; - } - - if (depth > 1) - { - NazaraError("1D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_1D_Array: - case nzImageType_2D: - if (depth > 1) - { - NazaraError("2D textures must be 1 depth"); - return false; - } - break; - - case nzImageType_2D_Array: - case nzImageType_3D: - break; - - case nzImageType_Cubemap: - if (depth > 1) - { - NazaraError("Cubemaps must be 1 depth"); - return false; - } - - if (width != height) - { - NazaraError("Cubemaps must have square dimensions"); - return false; - } - break; - - default: - NazaraInternalError("Image type not handled"); - return false; - } - #endif - - levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); - - nzUInt8** levels = new nzUInt8*[levelCount]; - - unsigned int w = width; - unsigned int h = height; - unsigned int d = (type == nzImageType_Cubemap) ? 6 : depth; - - for (unsigned int i = 0; i < levelCount; ++i) - { - // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs - try - { - levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBPP(format)]; - - if (w > 1) - w >>= 1; - - if (h > 1) - h >>= 1; - - if (d > 1 && type != nzImageType_Cubemap) - d >>= 1; - } - catch (const std::exception& e) - { - NazaraError("Failed to allocate image's level " + NzString::Number(i) + " (" + NzString(e.what()) + ')'); - - // Nettoyage - delete[] levels[i]; // Permet une optimisation de boucle (GCC) - for (unsigned int j = 0; j < i; ++j) - delete[] levels[j]; - - delete[] levels; - - return false; - } - } - - m_sharedImage = new SharedImage(1, type, format, levelCount, levels, width, height, depth); - - NotifyCreated(); - return true; -} - -void NzImage::Destroy() -{ - NotifyDestroy(); - ReleaseImage(); -} - -bool NzImage::Fill(const NzColor& color) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot access pixels from compressed image"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* pixels = new nzUInt8[bpp]; - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - delete[] pixels; - - return false; - } - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - - for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) - { - nzUInt8* ptr = &m_sharedImage->pixels[level][0]; - nzUInt8* end = &m_sharedImage->pixels[level][width*height*depth*bpp]; - - while (ptr < end) - { - std::memcpy(ptr, pixels, bpp); - ptr += bpp; - } - - if (width > 1U) - width >>= 1; - - if (height > 1U) - height >>= 1; - - if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - delete[] pixels; - - return true; -} - -bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - - if (rect.x+rect.width > m_sharedImage->width || rect.y+rect.height > m_sharedImage->height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* pixels = new nzUInt8[bpp]; - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - delete[] pixels; - - return false; - } - - ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, rect.x, rect.y, z, m_sharedImage->width, m_sharedImage->height); - unsigned int srcStride = rect.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - for (unsigned int y = 0; y < rect.height; ++y) - { - nzUInt8* start = dstPixels; - nzUInt8* end = dstPixels + srcStride; - while (start < end) - { - std::memcpy(start, pixels, bpp); - start += bpp; - } - - dstPixels += dstStride; - } - - delete[] pixels; - - return true; -} - -bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!cube.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - - if (cube.x+cube.width > m_sharedImage->width || cube.y+cube.height > m_sharedImage->height || cube.z+cube.depth > m_sharedImage->depth) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* pixels = new nzUInt8[bpp]; - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - delete[] pixels; - - return false; - } - - ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height); - unsigned int srcStride = cube.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - unsigned int faceSize = dstStride * m_sharedImage->height; - for (unsigned int z = 0; z < cube.depth; ++z) - { - nzUInt8* facePixels = dstPixels; - for (unsigned int y = 0; y < cube.height; ++y) - { - nzUInt8* start = facePixels; - nzUInt8* end = facePixels + srcStride; - while (start < end) - { - std::memcpy(start, pixels, bpp); - start += bpp; - } - - facePixels += dstStride; - } - - dstPixels += faceSize; - } - - delete[] pixels; - - return true; -} - -bool NzImage::FlipHorizontally() -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot flip compressed image"); - return false; - } - #endif - - EnsureOwnership(); - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) - { - NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); - - if (width > 1U) - width >>= 1; - - if (height > 1U) - height >>= 1; - - if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - return true; -} - - -bool NzImage::FlipVertically() -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot flip compressed image"); - return false; - } - #endif - - EnsureOwnership(); - - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) - { - NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); - - if (width > 1U) - width >>= 1; - - if (height > 1U) - height >>= 1; - - if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) - depth >>= 1; - } - - return true; -} - -nzUInt8 NzImage::GetBPP() const -{ - return NzPixelFormat::GetBPP(m_sharedImage->format); -} - -const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return nullptr; - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return nullptr; - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return nullptr; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return nullptr; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return nullptr; - } - #endif - - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); -} - -unsigned int NzImage::GetDepth(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return GetLevelSize(m_sharedImage->depth, level); -} - -nzPixelFormat NzImage::GetFormat() const -{ - return m_sharedImage->format; -} - -unsigned int NzImage::GetHeight(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return GetLevelSize(m_sharedImage->height, level); -} - -nzUInt8 NzImage::GetLevelCount() const -{ - return m_sharedImage->levelCount; -} - -nzUInt8 NzImage::GetMaxLevel() const -{ - return GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); -} - -NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return NzColor(); - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot access pixels from compressed image"); - return NzColor(); - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return NzColor(); - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return NzColor(); - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return NzColor(); - } - #endif - - const nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); - - NzColor color; - if (!NzPixelFormat::Convert(m_sharedImage->format, nzPixelFormat_RGBA8, pixel, &color.r)) - NazaraError("Failed to convert image's format to RGBA8"); - - return color; -} - -nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return nullptr; - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return nullptr; - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return nullptr; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return nullptr; - } - - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return nullptr; - } - #endif - - EnsureOwnership(); - - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); -} - -unsigned int NzImage::GetSize() const -{ - unsigned int width = m_sharedImage->width; - unsigned int height = m_sharedImage->height; - unsigned int depth = m_sharedImage->depth; - - unsigned int size = 0; - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - { - size += width * height * depth; - - if (width > 1) - width >>= 1; - - if (height > 1) - height >>= 1; - - if (depth > 1) - depth >>= 1; - } - - if (m_sharedImage->type == nzImageType_Cubemap) - size *= 6; - - return size * NzPixelFormat::GetBPP(m_sharedImage->format); -} - -unsigned int NzImage::GetSize(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return (GetLevelSize(m_sharedImage->width, level)) * - (GetLevelSize(m_sharedImage->height, level)) * - ((m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)) * - NzPixelFormat::GetBPP(m_sharedImage->format); -} - -nzImageType NzImage::GetType() const -{ - return m_sharedImage->type; -} - -unsigned int NzImage::GetWidth(nzUInt8 level) const -{ - #if NAZARA_UTILITY_SAFE - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return 0; - } - #endif - - return GetLevelSize(m_sharedImage->width, level); -} - -bool NzImage::IsCompressed() const -{ - return NzPixelFormat::IsCompressed(m_sharedImage->format); -} - -bool NzImage::IsCubemap() const -{ - return m_sharedImage->type == nzImageType_Cubemap; -} - -bool NzImage::IsValid() const -{ - return m_sharedImage != &emptyImage; -} - -bool NzImage::LoadFromFile(const NzString& filePath, const NzImageParams& params) -{ - return NzImageLoader::LoadFromFile(this, filePath, params); -} - -bool NzImage::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) -{ - return NzImageLoader::LoadFromMemory(this, data, size, params); -} - -bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params) -{ - return NzImageLoader::LoadFromStream(this, stream, params); -} - -bool NzImage::SetLevelCount(nzUInt8 levelCount) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (levelCount == 0) - { - NazaraError("Level count must be positive"); - return false; - } - #endif - - levelCount = std::min(levelCount, GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth)); - - if (m_sharedImage->levelCount == levelCount) - return true; - - EnsureOwnership(); - - nzUInt8 oldLevelCount = m_sharedImage->levelCount; - nzUInt8 maxLevelCount = std::max(levelCount, oldLevelCount); - m_sharedImage->levelCount = levelCount; // Pour faire fonctionner GetSize - - nzUInt8** pixels = new nzUInt8*[levelCount]; - for (unsigned int i = 0; i < maxLevelCount; ++i) - { - if (i < oldLevelCount) - pixels[i] = m_sharedImage->pixels[i]; - else if (i < levelCount) - pixels[i] = new nzUInt8[GetSize(i)]; - else - delete[] m_sharedImage->pixels[i]; - } - - delete[] m_sharedImage->pixels; - - m_sharedImage->pixels = pixels; - - return true; -} - -bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y, unsigned int z) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (NzPixelFormat::IsCompressed(m_sharedImage->format)) - { - NazaraError("Cannot access pixels from compressed image"); - return false; - } - - if (x >= m_sharedImage->width) - { - NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); - return false; - } - - if (y >= m_sharedImage->height) - { - NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); - return false; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); - return false; - } - #endif - - nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); - - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixel)) - { - NazaraError("Failed to convert RGBA8 to image's format"); - return false; - } - - return true; -} - -bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return false; - } - #endif - - EnsureOwnership(); - - std::memcpy(m_sharedImage->pixels[level], pixels, GetSize(level)); - - return true; -} - -bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return false; - } - - if (!rect.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - #endif - - unsigned int width = GetLevelSize(m_sharedImage->width, level); - unsigned int height = GetLevelSize(m_sharedImage->height, level); - - #if NAZARA_UTILITY_SAFE - if (rect.x+rect.width > width || rect.y+rect.height > height) - { - NazaraError("Rectangle dimensions are out of bounds"); - return false; - } - - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); - if (z >= depth) - { - NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= " + NzString::Number(depth) + ')'); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, rect.x, rect.y, z, width, height); - unsigned int srcStride = rect.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - for (unsigned int y = 0; y < rect.height; ++y) - { - std::memcpy(dstPixels, pixels, srcStride); - pixels += srcStride; - dstPixels += dstStride; - } - - return true; -} - -bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) -{ - ///FIXME: Vérifier que ça fonctionne correctement - #if NAZARA_UTILITY_SAFE - if (!m_sharedImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return false; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return false; - } - #endif - - unsigned int width = GetLevelSize(m_sharedImage->width, level); - unsigned int height = GetLevelSize(m_sharedImage->height, level); - unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->height, level); - - #if NAZARA_UTILITY_SAFE - if (!cube.IsValid()) - { - NazaraError("Invalid cube"); - return false; - } - - if (cube.x+cube.width > width || cube.y+cube.height > height || cube.z+cube.depth > depth) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, cube.x, cube.y, cube.z, width, height); - unsigned int srcStride = cube.width * bpp; - unsigned int dstStride = width * bpp; - unsigned int faceSize = dstStride * height; - for (unsigned int z = 0; z < cube.depth; ++z) - { - nzUInt8* facePixels = dstPixels; - for (unsigned int y = 0; y < cube.height; ++y) - { - std::memcpy(facePixels, pixels, srcStride); - pixels += srcStride; - facePixels += dstStride; - } - - dstPixels += faceSize; - } - - return true; -} - -NzImage& NzImage::operator=(const NzImage& image) -{ - ReleaseImage(); - - m_sharedImage = image.m_sharedImage; - if (m_sharedImage != &emptyImage) - { - NazaraMutexLock(m_sharedImage->mutex); - m_sharedImage->refCount++; - NazaraMutexUnlock(m_sharedImage->mutex); - } - - return *this; -} - -NzImage& NzImage::operator=(NzImage&& image) noexcept -{ - std::swap(m_sharedImage, image.m_sharedImage); - - return *this; -} - -nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth) -{ - static const float l2 = std::log(2.f); - - unsigned int widthLevel = std::log(static_cast(width))/l2; - unsigned int heightLevel = std::log(static_cast(height))/l2; - unsigned int depthLevel = std::log(static_cast(depth))/l2; - - return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); -} - -void NzImage::EnsureOwnership() -{ - if (m_sharedImage == &emptyImage) - return; - - NazaraLock(m_sharedImage->mutex); - if (m_sharedImage->refCount > 1) - { - m_sharedImage->refCount--; - - nzUInt8** pixels = new nzUInt8*[m_sharedImage->levelCount]; - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - { - unsigned int size = GetSize(i); - pixels[i] = new nzUInt8[size]; - std::memcpy(pixels[i], m_sharedImage->pixels[i], size); - } - - m_sharedImage = new SharedImage(1, m_sharedImage->type, m_sharedImage->format, m_sharedImage->levelCount, pixels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); - } -} - -void NzImage::ReleaseImage() -{ - if (m_sharedImage == &emptyImage) - return; - - NazaraMutexLock(m_sharedImage->mutex); - bool freeSharedImage = (--m_sharedImage->refCount == 0); - NazaraMutexUnlock(m_sharedImage->mutex); - - if (freeSharedImage) - { - for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) - delete[] m_sharedImage->pixels[i]; - - delete[] m_sharedImage->pixels; - delete m_sharedImage; - } - - m_sharedImage = &emptyImage; -} - -NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); -NzImageLoader::LoaderList NzImage::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +namespace +{ + inline unsigned int GetLevelSize(unsigned int size, nzUInt8 level) + { + return std::max(size >> level, 1U); + } + + inline nzUInt8* GetPixelPtr(nzUInt8* base, nzUInt8 bpp, unsigned int x, unsigned int y, unsigned int z, unsigned int width, unsigned int height) + { + return &base[(width*(height*z + y) + x)*bpp]; + } +} + +bool NzImageParams::IsValid() const +{ + return true; +} + +NzImage::NzImage() : +m_sharedImage(&emptyImage) +{ +} + +NzImage::NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) : +m_sharedImage(&emptyImage) +{ + Create(type, format, width, height, depth, levelCount); + + #ifdef NAZARA_DEBUG + if (!m_sharedImage) + { + NazaraError("Failed to create image"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzImage::NzImage(const NzImage& image) : +NzResource(image), +m_sharedImage(image.m_sharedImage) +{ + if (m_sharedImage != &emptyImage) + { + NazaraMutexLock(m_sharedImage->mutex); + m_sharedImage->refCount++; + NazaraMutexUnlock(m_sharedImage->mutex); + } +} + +NzImage::NzImage(NzImage&& image) noexcept : +m_sharedImage(image.m_sharedImage) +{ + image.m_sharedImage = &emptyImage; +} + +NzImage::~NzImage() +{ + ReleaseImage(); +} + +bool NzImage::Convert(nzPixelFormat format) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!NzPixelFormat::IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + + if (!NzPixelFormat::IsConversionSupported(m_sharedImage->format, format)) + { + NazaraError("Conversion from " + NzPixelFormat::ToString(m_sharedImage->format) + " to " + NzPixelFormat::ToString(format) + " is not supported"); + return false; + } + #endif + + if (format == m_sharedImage->format) + return true; + + nzUInt8** levels = new nzUInt8*[m_sharedImage->levelCount]; + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + + // Les images 3D et cubemaps sont stockés de la même façon + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + { + unsigned int pixelsPerFace = width*height; + nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)]; + nzUInt8* pixels = m_sharedImage->pixels[i]; + unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format); + unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format); + + for (unsigned int d = 0; d < depth; ++d) + { + if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr)) + { + NazaraError("Failed to convert image"); + + // Nettoyage de la mémoire + delete[] ptr; // Permet une optimisation de boucle (GCC) + for (unsigned int j = 0; j < i; ++j) + delete[] levels[j]; + + delete[] levels; + + return false; + } + + pixels += srcStride; + ptr += dstStride; + } + + levels[i] = ptr; + + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + if (depth > 1 && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + SharedImage* newImage = new SharedImage(1, m_sharedImage->type, format, m_sharedImage->levelCount, levels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); + + ReleaseImage(); + m_sharedImage = newImage; + + return true; +} + +bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos) +{ + #if NAZARA_UTILITY_SAFE + if (!source.IsValid()) + { + NazaraError("Source image must be valid"); + return false; + } + + if (source.GetFormat() != m_sharedImage->format) + { + NazaraError("Source image format does not match destination image format"); + return false; + } + #endif + + const nzUInt8* pixels = source.GetConstPixels(0, srcCube.x, srcCube.y, srcCube.z); + if (!pixels) + { + NazaraError("Failed to access pixels"); + return false; + } + + /* + Correctif temporaire : Update veut de la mémoire contigüe + Il est donc nécessaire de prendre la partie de la texture que nous voulons mettre à jour + + ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) + (Appliquer l'interface à NzTexture également) + */ + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + unsigned int dstLineStride = srcCube.width*bpp; + unsigned int dstFaceStride = dstLineStride*srcCube.height; + unsigned int srcLineStride = m_sharedImage->width*bpp; + unsigned int srcFaceStride = srcLineStride*m_sharedImage->height; + + nzUInt8* cube = new nzUInt8[dstFaceStride*srcCube.depth]; + nzUInt8* ptr = cube; + + for (unsigned int z = 0; z < srcCube.depth; ++z) + { + nzUInt8* facePixels = ptr; + for (unsigned int y = 0; y < srcCube.height; ++y) + { + std::memcpy(facePixels, pixels, dstLineStride); + + facePixels += dstLineStride; + pixels += srcLineStride; + } + + ptr += dstFaceStride; + pixels += srcFaceStride; + } + + bool success = Update(cube, NzCubeui(dstPos.x, dstPos.y, dstPos.z, srcCube.width, srcCube.height, srcCube.depth)); + + delete[] cube; + + return success; +} + +bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) +{ + ReleaseImage(); + + #if NAZARA_UTILITY_SAFE + if (!NzPixelFormat::IsValid(format)) + { + NazaraError("Invalid pixel format"); + return false; + } + + if (width == 0) + { + NazaraError("Width must be at least 1 (0)"); + return false; + } + + if (height == 0) + { + NazaraError("Height must be at least 1 (0)"); + return false; + } + + if (depth == 0) + { + NazaraError("Depth must be at least 1 (0)"); + return false; + } + + switch (type) + { + case nzImageType_1D: + if (height > 1) + { + NazaraError("1D textures must be 1 height"); + return false; + } + + if (depth > 1) + { + NazaraError("1D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_1D_Array: + case nzImageType_2D: + if (depth > 1) + { + NazaraError("2D textures must be 1 depth"); + return false; + } + break; + + case nzImageType_2D_Array: + case nzImageType_3D: + break; + + case nzImageType_Cubemap: + if (depth > 1) + { + NazaraError("Cubemaps must be 1 depth"); + return false; + } + + if (width != height) + { + NazaraError("Cubemaps must have square dimensions"); + return false; + } + break; + + default: + NazaraInternalError("Image type not handled"); + return false; + } + #endif + + levelCount = std::min(levelCount, GetMaxLevel(width, height, depth)); + + nzUInt8** levels = new nzUInt8*[levelCount]; + + unsigned int w = width; + unsigned int h = height; + unsigned int d = (type == nzImageType_Cubemap) ? 6 : depth; + + for (unsigned int i = 0; i < levelCount; ++i) + { + // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs + try + { + levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBPP(format)]; + + if (w > 1) + w >>= 1; + + if (h > 1) + h >>= 1; + + if (d > 1 && type != nzImageType_Cubemap) + d >>= 1; + } + catch (const std::exception& e) + { + NazaraError("Failed to allocate image's level " + NzString::Number(i) + " (" + NzString(e.what()) + ')'); + + // Nettoyage + delete[] levels[i]; // Permet une optimisation de boucle (GCC) + for (unsigned int j = 0; j < i; ++j) + delete[] levels[j]; + + delete[] levels; + + return false; + } + } + + m_sharedImage = new SharedImage(1, type, format, levelCount, levels, width, height, depth); + + NotifyCreated(); + return true; +} + +void NzImage::Destroy() +{ + NotifyDestroy(); + ReleaseImage(); +} + +bool NzImage::Fill(const NzColor& color) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot access pixels from compressed image"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* pixels = new nzUInt8[bpp]; + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + delete[] pixels; + + return false; + } + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + + for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) + { + nzUInt8* ptr = &m_sharedImage->pixels[level][0]; + nzUInt8* end = &m_sharedImage->pixels[level][width*height*depth*bpp]; + + while (ptr < end) + { + std::memcpy(ptr, pixels, bpp); + ptr += bpp; + } + + if (width > 1U) + width >>= 1; + + if (height > 1U) + height >>= 1; + + if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + delete[] pixels; + + return true; +} + +bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + + if (rect.x+rect.width > m_sharedImage->width || rect.y+rect.height > m_sharedImage->height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* pixels = new nzUInt8[bpp]; + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + delete[] pixels; + + return false; + } + + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, rect.x, rect.y, z, m_sharedImage->width, m_sharedImage->height); + unsigned int srcStride = rect.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + for (unsigned int y = 0; y < rect.height; ++y) + { + nzUInt8* start = dstPixels; + nzUInt8* end = dstPixels + srcStride; + while (start < end) + { + std::memcpy(start, pixels, bpp); + start += bpp; + } + + dstPixels += dstStride; + } + + delete[] pixels; + + return true; +} + +bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!cube.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + + if (cube.x+cube.width > m_sharedImage->width || cube.y+cube.height > m_sharedImage->height || cube.z+cube.depth > m_sharedImage->depth) + { + NazaraError("Cube dimensions are out of bounds"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* pixels = new nzUInt8[bpp]; + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + delete[] pixels; + + return false; + } + + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height); + unsigned int srcStride = cube.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + unsigned int faceSize = dstStride * m_sharedImage->height; + for (unsigned int z = 0; z < cube.depth; ++z) + { + nzUInt8* facePixels = dstPixels; + for (unsigned int y = 0; y < cube.height; ++y) + { + nzUInt8* start = facePixels; + nzUInt8* end = facePixels + srcStride; + while (start < end) + { + std::memcpy(start, pixels, bpp); + start += bpp; + } + + facePixels += dstStride; + } + + dstPixels += faceSize; + } + + delete[] pixels; + + return true; +} + +bool NzImage::FlipHorizontally() +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot flip compressed image"); + return false; + } + #endif + + EnsureOwnership(); + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) + { + NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); + + if (width > 1U) + width >>= 1; + + if (height > 1U) + height >>= 1; + + if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + return true; +} + + +bool NzImage::FlipVertically() +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot flip compressed image"); + return false; + } + #endif + + EnsureOwnership(); + + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + for (unsigned int level = 0; level < m_sharedImage->levelCount; ++level) + { + NzPixelFormat::Flip(nzPixelFlipping_Vertically, m_sharedImage->format, width, height, depth, m_sharedImage->pixels[level], m_sharedImage->pixels[level]); + + if (width > 1U) + width >>= 1; + + if (height > 1U) + height >>= 1; + + if (depth > 1U && m_sharedImage->type != nzImageType_Cubemap) + depth >>= 1; + } + + return true; +} + +nzUInt8 NzImage::GetBPP() const +{ + return NzPixelFormat::GetBPP(m_sharedImage->format); +} + +const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return nullptr; + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return nullptr; + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return nullptr; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return nullptr; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return nullptr; + } + #endif + + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); +} + +unsigned int NzImage::GetDepth(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return GetLevelSize(m_sharedImage->depth, level); +} + +nzPixelFormat NzImage::GetFormat() const +{ + return m_sharedImage->format; +} + +unsigned int NzImage::GetHeight(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return GetLevelSize(m_sharedImage->height, level); +} + +nzUInt8 NzImage::GetLevelCount() const +{ + return m_sharedImage->levelCount; +} + +nzUInt8 NzImage::GetMaxLevel() const +{ + return GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); +} + +NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return NzColor(); + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot access pixels from compressed image"); + return NzColor(); + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return NzColor(); + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return NzColor(); + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return NzColor(); + } + #endif + + const nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + + NzColor color; + if (!NzPixelFormat::Convert(m_sharedImage->format, nzPixelFormat_RGBA8, pixel, &color.r)) + NazaraError("Failed to convert image's format to RGBA8"); + + return color; +} + +nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return nullptr; + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return nullptr; + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return nullptr; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return nullptr; + } + + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return nullptr; + } + #endif + + EnsureOwnership(); + + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); +} + +unsigned int NzImage::GetSize() const +{ + unsigned int width = m_sharedImage->width; + unsigned int height = m_sharedImage->height; + unsigned int depth = m_sharedImage->depth; + + unsigned int size = 0; + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + { + size += width * height * depth; + + if (width > 1) + width >>= 1; + + if (height > 1) + height >>= 1; + + if (depth > 1) + depth >>= 1; + } + + if (m_sharedImage->type == nzImageType_Cubemap) + size *= 6; + + return size * NzPixelFormat::GetBPP(m_sharedImage->format); +} + +unsigned int NzImage::GetSize(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return (GetLevelSize(m_sharedImage->width, level)) * + (GetLevelSize(m_sharedImage->height, level)) * + ((m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)) * + NzPixelFormat::GetBPP(m_sharedImage->format); +} + +nzImageType NzImage::GetType() const +{ + return m_sharedImage->type; +} + +unsigned int NzImage::GetWidth(nzUInt8 level) const +{ + #if NAZARA_UTILITY_SAFE + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return 0; + } + #endif + + return GetLevelSize(m_sharedImage->width, level); +} + +bool NzImage::IsCompressed() const +{ + return NzPixelFormat::IsCompressed(m_sharedImage->format); +} + +bool NzImage::IsCubemap() const +{ + return m_sharedImage->type == nzImageType_Cubemap; +} + +bool NzImage::IsValid() const +{ + return m_sharedImage != &emptyImage; +} + +bool NzImage::LoadFromFile(const NzString& filePath, const NzImageParams& params) +{ + return NzImageLoader::LoadFromFile(this, filePath, params); +} + +bool NzImage::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params) +{ + return NzImageLoader::LoadFromMemory(this, data, size, params); +} + +bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params) +{ + return NzImageLoader::LoadFromStream(this, stream, params); +} + +bool NzImage::SetLevelCount(nzUInt8 levelCount) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (levelCount == 0) + { + NazaraError("Level count must be positive"); + return false; + } + #endif + + levelCount = std::min(levelCount, GetMaxLevel(m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth)); + + if (m_sharedImage->levelCount == levelCount) + return true; + + EnsureOwnership(); + + nzUInt8 oldLevelCount = m_sharedImage->levelCount; + nzUInt8 maxLevelCount = std::max(levelCount, oldLevelCount); + m_sharedImage->levelCount = levelCount; // Pour faire fonctionner GetSize + + nzUInt8** pixels = new nzUInt8*[levelCount]; + for (unsigned int i = 0; i < maxLevelCount; ++i) + { + if (i < oldLevelCount) + pixels[i] = m_sharedImage->pixels[i]; + else if (i < levelCount) + pixels[i] = new nzUInt8[GetSize(i)]; + else + delete[] m_sharedImage->pixels[i]; + } + + delete[] m_sharedImage->pixels; + + m_sharedImage->pixels = pixels; + + return true; +} + +bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y, unsigned int z) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (NzPixelFormat::IsCompressed(m_sharedImage->format)) + { + NazaraError("Cannot access pixels from compressed image"); + return false; + } + + if (x >= m_sharedImage->width) + { + NazaraError("X value exceeds width (" + NzString::Number(x) + " >= (" + NzString::Number(m_sharedImage->width) + ')'); + return false; + } + + if (y >= m_sharedImage->height) + { + NazaraError("Y value exceeds width (" + NzString::Number(y) + " >= (" + NzString::Number(m_sharedImage->height) + ')'); + return false; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth; + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= (" + NzString::Number(depth) + ')'); + return false; + } + #endif + + nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixel)) + { + NazaraError("Failed to convert RGBA8 to image's format"); + return false; + } + + return true; +} + +bool NzImage::Update(const nzUInt8* pixels, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return false; + } + #endif + + EnsureOwnership(); + + std::memcpy(m_sharedImage->pixels[level], pixels, GetSize(level)); + + return true; +} + +bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return false; + } + + if (!rect.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + #endif + + unsigned int width = GetLevelSize(m_sharedImage->width, level); + unsigned int height = GetLevelSize(m_sharedImage->height, level); + + #if NAZARA_UTILITY_SAFE + if (rect.x+rect.width > width || rect.y+rect.height > height) + { + NazaraError("Rectangle dimensions are out of bounds"); + return false; + } + + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); + if (z >= depth) + { + NazaraError("Z value exceeds depth (" + NzString::Number(z) + " >= " + NzString::Number(depth) + ')'); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, rect.x, rect.y, z, width, height); + unsigned int srcStride = rect.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + for (unsigned int y = 0; y < rect.height; ++y) + { + std::memcpy(dstPixels, pixels, srcStride); + pixels += srcStride; + dstPixels += dstStride; + } + + return true; +} + +bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) +{ + ///FIXME: Vérifier que ça fonctionne correctement + #if NAZARA_UTILITY_SAFE + if (!m_sharedImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return false; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return false; + } + #endif + + unsigned int width = GetLevelSize(m_sharedImage->width, level); + unsigned int height = GetLevelSize(m_sharedImage->height, level); + unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->height, level); + + #if NAZARA_UTILITY_SAFE + if (!cube.IsValid()) + { + NazaraError("Invalid cube"); + return false; + } + + if (cube.x+cube.width > width || cube.y+cube.height > height || cube.z+cube.depth > depth) + { + NazaraError("Cube dimensions are out of bounds"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, cube.x, cube.y, cube.z, width, height); + unsigned int srcStride = cube.width * bpp; + unsigned int dstStride = width * bpp; + unsigned int faceSize = dstStride * height; + for (unsigned int z = 0; z < cube.depth; ++z) + { + nzUInt8* facePixels = dstPixels; + for (unsigned int y = 0; y < cube.height; ++y) + { + std::memcpy(facePixels, pixels, srcStride); + pixels += srcStride; + facePixels += dstStride; + } + + dstPixels += faceSize; + } + + return true; +} + +NzImage& NzImage::operator=(const NzImage& image) +{ + ReleaseImage(); + + m_sharedImage = image.m_sharedImage; + if (m_sharedImage != &emptyImage) + { + NazaraMutexLock(m_sharedImage->mutex); + m_sharedImage->refCount++; + NazaraMutexUnlock(m_sharedImage->mutex); + } + + return *this; +} + +NzImage& NzImage::operator=(NzImage&& image) noexcept +{ + std::swap(m_sharedImage, image.m_sharedImage); + + return *this; +} + +nzUInt8 NzImage::GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth) +{ + static const float l2 = std::log(2.f); + + unsigned int widthLevel = std::log(static_cast(width))/l2; + unsigned int heightLevel = std::log(static_cast(height))/l2; + unsigned int depthLevel = std::log(static_cast(depth))/l2; + + return std::max(std::max(std::max(widthLevel, heightLevel), depthLevel), 1U); +} + +void NzImage::EnsureOwnership() +{ + if (m_sharedImage == &emptyImage) + return; + + NazaraLock(m_sharedImage->mutex); + if (m_sharedImage->refCount > 1) + { + m_sharedImage->refCount--; + + nzUInt8** pixels = new nzUInt8*[m_sharedImage->levelCount]; + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + { + unsigned int size = GetSize(i); + pixels[i] = new nzUInt8[size]; + std::memcpy(pixels[i], m_sharedImage->pixels[i], size); + } + + m_sharedImage = new SharedImage(1, m_sharedImage->type, m_sharedImage->format, m_sharedImage->levelCount, pixels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth); + } +} + +void NzImage::ReleaseImage() +{ + if (m_sharedImage == &emptyImage) + return; + + NazaraMutexLock(m_sharedImage->mutex); + bool freeSharedImage = (--m_sharedImage->refCount == 0); + NazaraMutexUnlock(m_sharedImage->mutex); + + if (freeSharedImage) + { + for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) + delete[] m_sharedImage->pixels[i]; + + delete[] m_sharedImage->pixels; + delete m_sharedImage; + } + + m_sharedImage = &emptyImage; +} + +NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); +NzImageLoader::LoaderList NzImage::s_loaders; diff --git a/src/Nazara/Utility/Loaders/MD2/Loader.cpp b/src/Nazara/Utility/Loaders/MD2/Loader.cpp index 32042a9bc..dbe93fc39 100644 --- a/src/Nazara/Utility/Loaders/MD2/Loader.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Loader.cpp @@ -1,198 +1,198 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ - bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters) - { - NazaraUnused(parameters); - - nzUInt32 magic[2]; - if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) - return false; - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&magic[0], sizeof(nzUInt32)); - NzByteSwap(&magic[1], sizeof(nzUInt32)); - #endif - - return magic[0] == md2Ident && magic[1] == 8; - } - - bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) - { - md2_header header; - if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header)) - { - NazaraError("Failed to read header"); - return false; - } - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&header.skinwidth, sizeof(nzUInt32)); - NzByteSwap(&header.skinheight, sizeof(nzUInt32)); - NzByteSwap(&header.framesize, sizeof(nzUInt32)); - NzByteSwap(&header.num_skins, sizeof(nzUInt32)); - NzByteSwap(&header.num_vertices, sizeof(nzUInt32)); - NzByteSwap(&header.num_st, sizeof(nzUInt32)); - NzByteSwap(&header.num_tris, sizeof(nzUInt32)); - NzByteSwap(&header.num_glcmds, sizeof(nzUInt32)); - NzByteSwap(&header.num_frames, sizeof(nzUInt32)); - NzByteSwap(&header.offset_skins, sizeof(nzUInt32)); - NzByteSwap(&header.offset_st, sizeof(nzUInt32)); - NzByteSwap(&header.offset_tris, sizeof(nzUInt32)); - NzByteSwap(&header.offset_frames, sizeof(nzUInt32)); - NzByteSwap(&header.offset_glcmds, sizeof(nzUInt32)); - NzByteSwap(&header.offset_end, sizeof(nzUInt32)); - #endif - - if (stream.GetSize() < header.offset_end) - { - NazaraError("Incomplete MD2 file"); - return false; - } - - /// Création du mesh - // Animé ou statique, c'est la question - bool animated; - unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); - unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); - - if (parameters.loadAnimations && startFrame != endFrame) - animated = true; - else - animated = false; - - if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait jamais échouer - { - NazaraInternalError("Failed to create mesh"); - return false; - } - - /// Chargement des skins - if (header.num_skins > 0) - { - stream.SetCursorPos(header.offset_skins); - { - char skin[68]; - for (unsigned int i = 0; i < header.num_skins; ++i) - { - stream.Read(skin, 68*sizeof(char)); - mesh->AddSkin(skin); - } - } - } - - /// Chargement des animations - if (animated) - { - NzAnimation* animation = new NzAnimation; - if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1)) - { - // Décodage des séquences - NzString frameName; - - NzSequence sequence; - sequence.framePerSecond = 10; // Par défaut pour les animations MD2 - - char name[16], last[16]; - stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + offsetof(md2_frame, name)); - stream.Read(last, 16*sizeof(char)); - - int pos = std::strlen(last)-1; - for (unsigned int j = 0; j < 2; ++j) - { - if (!std::isdigit(last[pos])) - break; - - pos--; - } - last[pos+1] = '\0'; - - unsigned int numFrames = 0; - for (unsigned int i = startFrame; i <= endFrame; ++i) - { - stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name)); - stream.Read(name, 16*sizeof(char)); - - pos = std::strlen(name)-1; - for (unsigned int j = 0; j < 2; ++j) - { - if (!std::isdigit(name[pos])) - break; - - pos--; - } - name[pos+1] = '\0'; - - if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom - { - // Alors on enregistre la séquence - sequence.firstFrame = i-numFrames; - sequence.lastFrame = i-1; - sequence.name = last; - animation->AddSequence(sequence); - - std::strcpy(last, name); - - numFrames = 0; - } - - numFrames++; - } - - // On ajoute la dernière frame (Qui n'a pas été traitée par la boucle) - sequence.firstFrame = endFrame-numFrames; - sequence.lastFrame = endFrame; - sequence.name = last; - animation->AddSequence(sequence); - - mesh->SetAnimation(animation); - animation->SetPersistent(false); - } - else - NazaraInternalError("Failed to create animaton"); - } - - /// Chargement des submesh - // Actuellement le loader ne charge qu'un submesh - // TODO: Utiliser les commandes OpenGL pour accélérer le rendu - NzMD2Mesh* subMesh = new NzMD2Mesh(mesh); - if (!subMesh->Create(header, stream, parameters)) - { - NazaraError("Failed to create MD2 mesh"); - return false; - } - - mesh->AddSubMesh(subMesh); - - return true; - } -} - -void NzLoaders_MD2_Register() -{ - NzMD2Mesh::Initialize(); - - NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); -} - -void NzLoaders_MD2_Unregister() -{ - NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); - - NzMD2Mesh::Uninitialize(); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + bool NzLoader_MD2_Check(NzInputStream& stream, const NzMeshParams& parameters) + { + NazaraUnused(parameters); + + nzUInt32 magic[2]; + if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32)) + return false; + + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&magic[0], sizeof(nzUInt32)); + NzByteSwap(&magic[1], sizeof(nzUInt32)); + #endif + + return magic[0] == md2Ident && magic[1] == 8; + } + + bool NzLoader_MD2_Load(NzMesh* mesh, NzInputStream& stream, const NzMeshParams& parameters) + { + md2_header header; + if (stream.Read(&header, sizeof(md2_header)) != sizeof(md2_header)) + { + NazaraError("Failed to read header"); + return false; + } + + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&header.skinwidth, sizeof(nzUInt32)); + NzByteSwap(&header.skinheight, sizeof(nzUInt32)); + NzByteSwap(&header.framesize, sizeof(nzUInt32)); + NzByteSwap(&header.num_skins, sizeof(nzUInt32)); + NzByteSwap(&header.num_vertices, sizeof(nzUInt32)); + NzByteSwap(&header.num_st, sizeof(nzUInt32)); + NzByteSwap(&header.num_tris, sizeof(nzUInt32)); + NzByteSwap(&header.num_glcmds, sizeof(nzUInt32)); + NzByteSwap(&header.num_frames, sizeof(nzUInt32)); + NzByteSwap(&header.offset_skins, sizeof(nzUInt32)); + NzByteSwap(&header.offset_st, sizeof(nzUInt32)); + NzByteSwap(&header.offset_tris, sizeof(nzUInt32)); + NzByteSwap(&header.offset_frames, sizeof(nzUInt32)); + NzByteSwap(&header.offset_glcmds, sizeof(nzUInt32)); + NzByteSwap(&header.offset_end, sizeof(nzUInt32)); + #endif + + if (stream.GetSize() < header.offset_end) + { + NazaraError("Incomplete MD2 file"); + return false; + } + + /// Création du mesh + // Animé ou statique, c'est la question + bool animated; + unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); + unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); + + if (parameters.loadAnimations && startFrame != endFrame) + animated = true; + else + animated = false; + + if (!mesh->Create((animated) ? nzAnimationType_Keyframe : nzAnimationType_Static)) // Ne devrait jamais échouer + { + NazaraInternalError("Failed to create mesh"); + return false; + } + + /// Chargement des skins + if (header.num_skins > 0) + { + stream.SetCursorPos(header.offset_skins); + { + char skin[68]; + for (unsigned int i = 0; i < header.num_skins; ++i) + { + stream.Read(skin, 68*sizeof(char)); + mesh->AddSkin(skin); + } + } + } + + /// Chargement des animations + if (animated) + { + NzAnimation* animation = new NzAnimation; + if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1)) + { + // Décodage des séquences + NzString frameName; + + NzSequence sequence; + sequence.framePerSecond = 10; // Par défaut pour les animations MD2 + + char name[16], last[16]; + stream.SetCursorPos(header.offset_frames + startFrame*header.framesize + offsetof(md2_frame, name)); + stream.Read(last, 16*sizeof(char)); + + int pos = std::strlen(last)-1; + for (unsigned int j = 0; j < 2; ++j) + { + if (!std::isdigit(last[pos])) + break; + + pos--; + } + last[pos+1] = '\0'; + + unsigned int numFrames = 0; + for (unsigned int i = startFrame; i <= endFrame; ++i) + { + stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name)); + stream.Read(name, 16*sizeof(char)); + + pos = std::strlen(name)-1; + for (unsigned int j = 0; j < 2; ++j) + { + if (!std::isdigit(name[pos])) + break; + + pos--; + } + name[pos+1] = '\0'; + + if (std::strcmp(name, last) != 0) // Si les deux frames n'ont pas le même nom + { + // Alors on enregistre la séquence + sequence.firstFrame = i-numFrames; + sequence.lastFrame = i-1; + sequence.name = last; + animation->AddSequence(sequence); + + std::strcpy(last, name); + + numFrames = 0; + } + + numFrames++; + } + + // On ajoute la dernière frame (Qui n'a pas été traitée par la boucle) + sequence.firstFrame = endFrame-numFrames; + sequence.lastFrame = endFrame; + sequence.name = last; + animation->AddSequence(sequence); + + mesh->SetAnimation(animation); + animation->SetPersistent(false); + } + else + NazaraInternalError("Failed to create animaton"); + } + + /// Chargement des submesh + // Actuellement le loader ne charge qu'un submesh + // TODO: Utiliser les commandes OpenGL pour accélérer le rendu + NzMD2Mesh* subMesh = new NzMD2Mesh(mesh); + if (!subMesh->Create(header, stream, parameters)) + { + NazaraError("Failed to create MD2 mesh"); + return false; + } + + mesh->AddSubMesh(subMesh); + + return true; + } +} + +void NzLoaders_MD2_Register() +{ + NzMD2Mesh::Initialize(); + + NzMeshLoader::RegisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); +} + +void NzLoaders_MD2_Unregister() +{ + NzMeshLoader::UnregisterLoader("md2", NzLoader_MD2_Check, NzLoader_MD2_Load); + + NzMD2Mesh::Uninitialize(); +} diff --git a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp index c4c311c3c..2e74b4bea 100644 --- a/src/Nazara/Utility/Loaders/MD2/Mesh.cpp +++ b/src/Nazara/Utility/Loaders/MD2/Mesh.cpp @@ -1,292 +1,292 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -NzMD2Mesh::NzMD2Mesh(const NzMesh* parent) : -NzKeyframeMesh(parent), -m_frames(nullptr), -m_indexBuffer(nullptr), -m_vertexBuffer(nullptr) -{ -} - -NzMD2Mesh::~NzMD2Mesh() -{ - Destroy(); -} - -bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters) -{ - Destroy(); - - unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); - unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); - - m_frameCount = endFrame - startFrame + 1; - m_vertexCount = header.num_tris * 3; - - /// Chargement des vertices - std::vector texCoords(header.num_st); - std::vector triangles(header.num_tris); - - // Lecture des coordonnées de texture - stream.SetCursorPos(header.offset_st); - stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord)); - - #if defined(NAZARA_BIG_ENDIAN) - for (unsigned int i = 0; i < header.num_st; ++i) - { - NzByteSwap(&texCoords[i].u, sizeof(nzInt16)); - NzByteSwap(&texCoords[i].v, sizeof(nzInt16)); - } - #endif - - stream.SetCursorPos(header.offset_tris); - stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle)); - - #if defined(NAZARA_BIG_ENDIAN) - for (unsigned int i = 0; i < header.num_tris; ++i) - { - NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16)); - NzByteSwap(&texCoords[i].texCoords[0], sizeof(nzUInt16)); - - NzByteSwap(&triangles[i].vertices[1], sizeof(nzUInt16)); - NzByteSwap(&texCoords[i].texCoords[1], sizeof(nzUInt16)); - - NzByteSwap(&triangles[i].vertices[2], sizeof(nzUInt16)); - NzByteSwap(&texCoords[i].texCoords[2], sizeof(nzUInt16)); - } - #endif - - stream.SetCursorPos(header.offset_frames + header.framesize*startFrame); - - md2_frame frame; - frame.vertices.resize(header.num_vertices); - - // Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices - NzQuaternionf rotationQuat = NzEulerAnglesf(-90.f, 90.f, 0.f); - //NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, -90.f, 0.f)); - - unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); - - m_frames = new Frame[m_frameCount]; - for (unsigned int i = 0; i < m_frameCount; ++i) - { - stream.Read(&frame.scale, sizeof(NzVector3f)); - stream.Read(&frame.translate, sizeof(NzVector3f)); - stream.Read(&frame.name, 16*sizeof(char)); - stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex)); - - #if defined(NAZARA_BIG_ENDIAN) - NzByteSwap(&frame.scale.x, sizeof(float)); - NzByteSwap(&frame.scale.y, sizeof(float)); - NzByteSwap(&frame.scale.z, sizeof(float)); - - NzByteSwap(&frame.translate.x, sizeof(float)); - NzByteSwap(&frame.translate.y, sizeof(float)); - NzByteSwap(&frame.translate.z, sizeof(float)); - #endif - - m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice MD2 de la normale plutôt que la normale (gain d'espace) - m_frames[i].vertices = new NzVector3f[m_vertexCount]; - - NzVector3f max, min; - for (unsigned int t = 0; t < header.num_tris; ++t) - { - for (unsigned int v = 0; v < 3; ++v) - { - const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]]; - - NzVector3f vertex = rotationQuat * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z); - - // On fait en sorte d'avoir deux vertices de délimitation, définissant un rectangle dans l'espace - max.Maximize(vertex); - min.Minimize(vertex); - - // Le MD2 ne définit pas ses vertices dans le bon ordre, il nous faut donc les ajouter dans l'ordre inverse - unsigned int index = m_vertexCount - (t*3 + v) - 1; - m_frames[i].normal[index] = vert.n; - m_frames[i].vertices[index] = vertex; - } - } - - m_frames[i].aabb.SetExtends(min, max); - } - - m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant - m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic); - - nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); - if (!ptr) - { - NazaraError("Failed to map vertex buffer"); - Destroy(); - - return false; - } - - // On avance jusqu'aux dernières coordonnées de texture et on les définit dans l'ordre inverse - ptr += s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_TexCoord)->offset + stride * (m_vertexCount-1); - for (unsigned int t = 0; t < header.num_tris; ++t) - { - for (unsigned int v = 0; v < 3; ++v) - { - const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]]; - - NzVector2f* coords = reinterpret_cast(ptr); - coords->x = texC.u / static_cast(header.skinwidth); - coords->y = 1.f - texC.v / static_cast(header.skinheight); - - ptr -= stride; - } - } - - if (!m_vertexBuffer->Unmap()) - { - NazaraError("Failed to unmap buffer"); - Destroy(); - - return false; - } - - m_vertexBuffer->AddResourceReference(); - m_vertexBuffer->SetPersistent(false); - - AnimateImpl(0, 0, 0.f); - - return true; -} - -void NzMD2Mesh::Destroy() -{ - if (m_frames) - { - for (unsigned int i = 0; i < m_frameCount; ++i) - { - delete[] m_frames[i].normal; - delete[] m_frames[i].vertices; - } - - delete[] m_frames; - m_frames = nullptr; - } - - if (m_indexBuffer) - { - m_indexBuffer->RemoveResourceReference(); - m_indexBuffer = nullptr; - } - - if (m_vertexBuffer) - { - m_vertexBuffer->RemoveResourceReference(); - m_vertexBuffer = nullptr; - } -} - -const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const -{ - return m_aabb; -} - -nzAnimationType NzMD2Mesh::GetAnimationType() const -{ - if (m_frameCount > 1) - return nzAnimationType_Keyframe; - else - return nzAnimationType_Static; -} - -unsigned int NzMD2Mesh::GetFrameCount() const -{ - return m_frameCount; -} - -const NzIndexBuffer* NzMD2Mesh::GetIndexBuffer() const -{ - return nullptr; - //return m_indexBuffer; -} - -nzPrimitiveType NzMD2Mesh::GetPrimitiveType() const -{ - return nzPrimitiveType_TriangleList; -} - -const NzVertexBuffer* NzMD2Mesh::GetVertexBuffer() const -{ - return m_vertexBuffer; -} - -const NzVertexDeclaration* NzMD2Mesh::GetVertexDeclaration() const -{ - return &s_declaration; -} - -void NzMD2Mesh::Initialize() -{ - NzVertexElement elements[3]; - elements[0].offset = 0; - elements[0].type = nzElementType_Float3; - elements[0].usage = nzElementUsage_Position; - - elements[1].offset = 3*sizeof(float); - elements[1].type = nzElementType_Float3; - elements[1].usage = nzElementUsage_Normal; - - elements[2].offset = 3*sizeof(float) + 3*sizeof(float); - elements[2].type = nzElementType_Float2; - elements[2].usage = nzElementUsage_TexCoord; - - s_declaration.Create(elements, 3); -} - -void NzMD2Mesh::Uninitialize() -{ - s_declaration.Destroy(); -} - -void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) -{ - nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); - if (!ptr) - { - NazaraError("Failed to map vertex buffer"); - return; - } - - unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); - unsigned int positionOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Position)->offset; - unsigned int normalOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Normal)->offset; - - Frame* fA = &m_frames[frameA]; - Frame* fB = &m_frames[frameB]; - for (unsigned int i = 0; i < m_vertexCount; ++i) - { - NzVector3f* position = reinterpret_cast(ptr + positionOffset); - NzVector3f* normal = reinterpret_cast(ptr + normalOffset); - - *position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]); - *normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]); - - ptr += stride; - } - - if (!m_vertexBuffer->Unmap()) - NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption"); - - // Interpolation de l'AABB - NzVector3f max1 = fA->aabb.GetMaximum(); - NzVector3f min1 = fA->aabb.GetMinimum(); - m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1)); -} - -NzVertexDeclaration NzMD2Mesh::s_declaration; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +NzMD2Mesh::NzMD2Mesh(const NzMesh* parent) : +NzKeyframeMesh(parent), +m_frames(nullptr), +m_indexBuffer(nullptr), +m_vertexBuffer(nullptr) +{ +} + +NzMD2Mesh::~NzMD2Mesh() +{ + Destroy(); +} + +bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters) +{ + Destroy(); + + unsigned int startFrame = NzClamp(parameters.animation.startFrame, 0U, static_cast(header.num_frames-1)); + unsigned int endFrame = NzClamp(parameters.animation.endFrame, 0U, static_cast(header.num_frames-1)); + + m_frameCount = endFrame - startFrame + 1; + m_vertexCount = header.num_tris * 3; + + /// Chargement des vertices + std::vector texCoords(header.num_st); + std::vector triangles(header.num_tris); + + // Lecture des coordonnées de texture + stream.SetCursorPos(header.offset_st); + stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord)); + + #if defined(NAZARA_BIG_ENDIAN) + for (unsigned int i = 0; i < header.num_st; ++i) + { + NzByteSwap(&texCoords[i].u, sizeof(nzInt16)); + NzByteSwap(&texCoords[i].v, sizeof(nzInt16)); + } + #endif + + stream.SetCursorPos(header.offset_tris); + stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle)); + + #if defined(NAZARA_BIG_ENDIAN) + for (unsigned int i = 0; i < header.num_tris; ++i) + { + NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16)); + NzByteSwap(&texCoords[i].texCoords[0], sizeof(nzUInt16)); + + NzByteSwap(&triangles[i].vertices[1], sizeof(nzUInt16)); + NzByteSwap(&texCoords[i].texCoords[1], sizeof(nzUInt16)); + + NzByteSwap(&triangles[i].vertices[2], sizeof(nzUInt16)); + NzByteSwap(&texCoords[i].texCoords[2], sizeof(nzUInt16)); + } + #endif + + stream.SetCursorPos(header.offset_frames + header.framesize*startFrame); + + md2_frame frame; + frame.vertices.resize(header.num_vertices); + + // Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices + NzQuaternionf rotationQuat = NzEulerAnglesf(-90.f, 90.f, 0.f); + //NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, -90.f, 0.f)); + + unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); + + m_frames = new Frame[m_frameCount]; + for (unsigned int i = 0; i < m_frameCount; ++i) + { + stream.Read(&frame.scale, sizeof(NzVector3f)); + stream.Read(&frame.translate, sizeof(NzVector3f)); + stream.Read(&frame.name, 16*sizeof(char)); + stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex)); + + #if defined(NAZARA_BIG_ENDIAN) + NzByteSwap(&frame.scale.x, sizeof(float)); + NzByteSwap(&frame.scale.y, sizeof(float)); + NzByteSwap(&frame.scale.z, sizeof(float)); + + NzByteSwap(&frame.translate.x, sizeof(float)); + NzByteSwap(&frame.translate.y, sizeof(float)); + NzByteSwap(&frame.translate.z, sizeof(float)); + #endif + + m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice MD2 de la normale plutôt que la normale (gain d'espace) + m_frames[i].vertices = new NzVector3f[m_vertexCount]; + + NzVector3f max, min; + for (unsigned int t = 0; t < header.num_tris; ++t) + { + for (unsigned int v = 0; v < 3; ++v) + { + const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]]; + + NzVector3f vertex = rotationQuat * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z); + + // On fait en sorte d'avoir deux vertices de délimitation, définissant un rectangle dans l'espace + max.Maximize(vertex); + min.Minimize(vertex); + + // Le MD2 ne définit pas ses vertices dans le bon ordre, il nous faut donc les ajouter dans l'ordre inverse + unsigned int index = m_vertexCount - (t*3 + v) - 1; + m_frames[i].normal[index] = vert.n; + m_frames[i].vertices[index] = vertex; + } + } + + m_frames[i].aabb.SetExtends(min, max); + } + + m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant + m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic); + + nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); + if (!ptr) + { + NazaraError("Failed to map vertex buffer"); + Destroy(); + + return false; + } + + // On avance jusqu'aux dernières coordonnées de texture et on les définit dans l'ordre inverse + ptr += s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_TexCoord)->offset + stride * (m_vertexCount-1); + for (unsigned int t = 0; t < header.num_tris; ++t) + { + for (unsigned int v = 0; v < 3; ++v) + { + const md2_texCoord& texC = texCoords[triangles[t].texCoords[v]]; + + NzVector2f* coords = reinterpret_cast(ptr); + coords->x = texC.u / static_cast(header.skinwidth); + coords->y = 1.f - texC.v / static_cast(header.skinheight); + + ptr -= stride; + } + } + + if (!m_vertexBuffer->Unmap()) + { + NazaraError("Failed to unmap buffer"); + Destroy(); + + return false; + } + + m_vertexBuffer->AddResourceReference(); + m_vertexBuffer->SetPersistent(false); + + AnimateImpl(0, 0, 0.f); + + return true; +} + +void NzMD2Mesh::Destroy() +{ + if (m_frames) + { + for (unsigned int i = 0; i < m_frameCount; ++i) + { + delete[] m_frames[i].normal; + delete[] m_frames[i].vertices; + } + + delete[] m_frames; + m_frames = nullptr; + } + + if (m_indexBuffer) + { + m_indexBuffer->RemoveResourceReference(); + m_indexBuffer = nullptr; + } + + if (m_vertexBuffer) + { + m_vertexBuffer->RemoveResourceReference(); + m_vertexBuffer = nullptr; + } +} + +const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const +{ + return m_aabb; +} + +nzAnimationType NzMD2Mesh::GetAnimationType() const +{ + if (m_frameCount > 1) + return nzAnimationType_Keyframe; + else + return nzAnimationType_Static; +} + +unsigned int NzMD2Mesh::GetFrameCount() const +{ + return m_frameCount; +} + +const NzIndexBuffer* NzMD2Mesh::GetIndexBuffer() const +{ + return nullptr; + //return m_indexBuffer; +} + +nzPrimitiveType NzMD2Mesh::GetPrimitiveType() const +{ + return nzPrimitiveType_TriangleList; +} + +const NzVertexBuffer* NzMD2Mesh::GetVertexBuffer() const +{ + return m_vertexBuffer; +} + +const NzVertexDeclaration* NzMD2Mesh::GetVertexDeclaration() const +{ + return &s_declaration; +} + +void NzMD2Mesh::Initialize() +{ + NzVertexElement elements[3]; + elements[0].offset = 0; + elements[0].type = nzElementType_Float3; + elements[0].usage = nzElementUsage_Position; + + elements[1].offset = 3*sizeof(float); + elements[1].type = nzElementType_Float3; + elements[1].usage = nzElementUsage_Normal; + + elements[2].offset = 3*sizeof(float) + 3*sizeof(float); + elements[2].type = nzElementType_Float2; + elements[2].usage = nzElementUsage_TexCoord; + + s_declaration.Create(elements, 3); +} + +void NzMD2Mesh::Uninitialize() +{ + s_declaration.Destroy(); +} + +void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) +{ + nzUInt8* ptr = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_WriteOnly)); + if (!ptr) + { + NazaraError("Failed to map vertex buffer"); + return; + } + + unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData); + unsigned int positionOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Position)->offset; + unsigned int normalOffset = s_declaration.GetElement(nzElementStream_VertexData, nzElementUsage_Normal)->offset; + + Frame* fA = &m_frames[frameA]; + Frame* fB = &m_frames[frameB]; + for (unsigned int i = 0; i < m_vertexCount; ++i) + { + NzVector3f* position = reinterpret_cast(ptr + positionOffset); + NzVector3f* normal = reinterpret_cast(ptr + normalOffset); + + *position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]); + *normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]); + + ptr += stride; + } + + if (!m_vertexBuffer->Unmap()) + NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption"); + + // Interpolation de l'AABB + NzVector3f max1 = fA->aabb.GetMaximum(); + NzVector3f min1 = fA->aabb.GetMinimum(); + m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1)); +} + +NzVertexDeclaration NzMD2Mesh::s_declaration; diff --git a/src/Nazara/Utility/Loaders/PCX/Loader.cpp b/src/Nazara/Utility/Loaders/PCX/Loader.cpp index b6b5f437a..f78ce358d 100644 --- a/src/Nazara/Utility/Loaders/PCX/Loader.cpp +++ b/src/Nazara/Utility/Loaders/PCX/Loader.cpp @@ -1,346 +1,346 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -// Auteur du loader original : David Henry - -namespace -{ - struct pcx_header - { - nzUInt8 manufacturer; - nzUInt8 version; - nzUInt8 encoding; - nzUInt8 bitsPerPixel; - - nzUInt16 xmin, ymin; - nzUInt16 xmax, ymax; - nzUInt16 horzRes, vertRes; - - nzUInt8 palette[48]; - nzUInt8 reserved; - nzUInt8 numColorPlanes; - - nzUInt16 bytesPerScanLine; - nzUInt16 paletteType; - nzUInt16 horzSize, vertSize; - - nzUInt8 padding[54]; - }; - - bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - nzUInt8 manufacturer; - if (stream.Read(&manufacturer, 1) != 1) - return false; - - return manufacturer == 0x0a; - } - - bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) - { - NazaraUnused(parameters); - - pcx_header header; - if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header)) - { - NazaraError("Failed to read header"); - return false; - } - - #if defined(NAZARA_BIG_ENDIAN) - // Les fichiers PCX sont en little endian - NzByteSwap(&header.xmin, sizeof(nzUInt16)); - NzByteSwap(&header.ymin, sizeof(nzUInt16)); - NzByteSwap(&header.xmax, sizeof(nzUInt16)); - NzByteSwap(&header.ymax, sizeof(nzUInt16)); - NzByteSwap(&header.horzRes, sizeof(nzUInt16)); - NzByteSwap(&header.vertRes, sizeof(nzUInt16)); - - NzByteSwap(&header.bytesPerScanLine, sizeof(nzUInt16)); - NzByteSwap(&header.paletteType, sizeof(nzUInt16)); - NzByteSwap(&header.horzSize, sizeof(nzUInt16)); - NzByteSwap(&header.vertSize, sizeof(nzUInt16)); - #endif - - unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes; - unsigned int width = header.xmax - header.xmin+1; - unsigned int height = header.ymax - header.ymin+1; - - if (!image->Create(nzImageType_2D, nzPixelFormat_RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1)) - { - NazaraError("Failed to create image"); - return false; - } - - nzUInt8* pixels = image->GetPixels(); - - int rle_value = 0; - unsigned int rle_count = 0; - - switch (bitCount) - { - case 1: - { - for (unsigned int y = 0; y < height; ++y) - { - nzUInt8* ptr = &pixels[y * width * 3]; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - } - } - - rle_count--; - - for (int i = 7; i >= 0; --i) - { - int colorIndex = ((rle_value & (1 << i)) > 0); - - *ptr++ = header.palette[colorIndex * 3 + 0]; - *ptr++ = header.palette[colorIndex * 3 + 1]; - *ptr++ = header.palette[colorIndex * 3 + 2]; - } - } - } - break; - } - - case 4: - { - nzUInt8* colorIndex = new nzUInt8[width]; - nzUInt8* line = new nzUInt8[header.bytesPerScanLine]; - - for (unsigned int y = 0; y < height; ++y) - { - nzUInt8* ptr = &pixels[y * width * 3]; - - std::memset(colorIndex, 0, width); - - for (unsigned int c = 0; c < 4; ++c) - { - nzUInt8* pLine = line; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - delete[] colorIndex; - delete[] line; - - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - delete[] colorIndex; - delete[] line; - - return false; - } - } - } - - rle_count--; - *(pLine++) = rle_value; - } - - /* compute line's color indexes */ - for (unsigned int x = 0; x < width; ++x) - { - if (line[x / 8] & (128 >> (x % 8))) - colorIndex[x] += (1 << c); - } - } - - /* decode scan line. color index => rgb */ - for (unsigned int x = 0; x < width; ++x) - { - *ptr++ = header.palette[colorIndex[x] * 3 + 0]; - *ptr++ = header.palette[colorIndex[x] * 3 + 1]; - *ptr++ = header.palette[colorIndex[x] * 3 + 2]; - } - } - - /* release memory */ - delete[] colorIndex; - delete[] line; - break; - } - - case 8: - { - nzUInt8 palette[768]; - - /* the palette is contained in the last 769 bytes of the file */ - unsigned int curPos = stream.GetCursorPos(); - stream.SetCursorPos(stream.GetSize()-769); - nzUInt8 magic; - if (!stream.Read(&magic, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - /* first byte must be equal to 0x0c (12) */ - if (magic != 0x0c) - { - NazaraError("Colormap's first byte must be 0x0c (0x" + NzString::Number(magic, 16) + ')'); - return false; - } - - /* read palette */ - if (stream.Read(palette, 768) != 768) - { - NazaraError("Failed to read palette"); - return false; - } - - stream.SetCursorPos(curPos); - - /* read pixel data */ - for (unsigned int y = 0; y < height; ++y) - { - nzUInt8* ptr = &pixels[y * width * 3]; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - } - } - - rle_count--; - - *ptr++ = palette[rle_value * 3 + 0]; - *ptr++ = palette[rle_value * 3 + 1]; - *ptr++ = palette[rle_value * 3 + 2]; - } - } - break; - } - - case 24: - { - for (unsigned int y = 0; y < height; ++y) - { - /* for each color plane */ - for (int c = 0; c < 3; ++c) - { - nzUInt8* ptr = &pixels[y * width * 4]; - int bytes = header.bytesPerScanLine; - - /* decode line number y */ - while (bytes--) - { - if (rle_count == 0) - { - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - - if (rle_value < 0xc0) - rle_count = 1; - else - { - rle_count = rle_value - 0xc0; - if (!stream.Read(&rle_value, 1)) - { - NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); - return false; - } - } - } - - rle_count--; - ptr[c] = static_cast(rle_value); - ptr += 3; - } - } - } - break; - } - - default: - NazaraError("Failed to load " + NzString::Number(bitCount) + " bitcount pcx files"); - return false; - } - - if (parameters.loadFormat != nzPixelFormat_Undefined) - image->Convert(parameters.loadFormat); - - return true; - } -} - -void NzLoaders_PCX_Register() -{ - NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); -} - -void NzLoaders_PCX_Unregister() -{ - NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include + +// Auteur du loader original : David Henry + +namespace +{ + struct pcx_header + { + nzUInt8 manufacturer; + nzUInt8 version; + nzUInt8 encoding; + nzUInt8 bitsPerPixel; + + nzUInt16 xmin, ymin; + nzUInt16 xmax, ymax; + nzUInt16 horzRes, vertRes; + + nzUInt8 palette[48]; + nzUInt8 reserved; + nzUInt8 numColorPlanes; + + nzUInt16 bytesPerScanLine; + nzUInt16 paletteType; + nzUInt16 horzSize, vertSize; + + nzUInt8 padding[54]; + }; + + bool NzLoader_PCX_Check(NzInputStream& stream, const NzImageParams& parameters) + { + NazaraUnused(parameters); + + nzUInt8 manufacturer; + if (stream.Read(&manufacturer, 1) != 1) + return false; + + return manufacturer == 0x0a; + } + + bool NzLoader_PCX_Load(NzImage* image, NzInputStream& stream, const NzImageParams& parameters) + { + NazaraUnused(parameters); + + pcx_header header; + if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header)) + { + NazaraError("Failed to read header"); + return false; + } + + #if defined(NAZARA_BIG_ENDIAN) + // Les fichiers PCX sont en little endian + NzByteSwap(&header.xmin, sizeof(nzUInt16)); + NzByteSwap(&header.ymin, sizeof(nzUInt16)); + NzByteSwap(&header.xmax, sizeof(nzUInt16)); + NzByteSwap(&header.ymax, sizeof(nzUInt16)); + NzByteSwap(&header.horzRes, sizeof(nzUInt16)); + NzByteSwap(&header.vertRes, sizeof(nzUInt16)); + + NzByteSwap(&header.bytesPerScanLine, sizeof(nzUInt16)); + NzByteSwap(&header.paletteType, sizeof(nzUInt16)); + NzByteSwap(&header.horzSize, sizeof(nzUInt16)); + NzByteSwap(&header.vertSize, sizeof(nzUInt16)); + #endif + + unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes; + unsigned int width = header.xmax - header.xmin+1; + unsigned int height = header.ymax - header.ymin+1; + + if (!image->Create(nzImageType_2D, nzPixelFormat_RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1)) + { + NazaraError("Failed to create image"); + return false; + } + + nzUInt8* pixels = image->GetPixels(); + + int rle_value = 0; + unsigned int rle_count = 0; + + switch (bitCount) + { + case 1: + { + for (unsigned int y = 0; y < height; ++y) + { + nzUInt8* ptr = &pixels[y * width * 3]; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + } + } + + rle_count--; + + for (int i = 7; i >= 0; --i) + { + int colorIndex = ((rle_value & (1 << i)) > 0); + + *ptr++ = header.palette[colorIndex * 3 + 0]; + *ptr++ = header.palette[colorIndex * 3 + 1]; + *ptr++ = header.palette[colorIndex * 3 + 2]; + } + } + } + break; + } + + case 4: + { + nzUInt8* colorIndex = new nzUInt8[width]; + nzUInt8* line = new nzUInt8[header.bytesPerScanLine]; + + for (unsigned int y = 0; y < height; ++y) + { + nzUInt8* ptr = &pixels[y * width * 3]; + + std::memset(colorIndex, 0, width); + + for (unsigned int c = 0; c < 4; ++c) + { + nzUInt8* pLine = line; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + delete[] colorIndex; + delete[] line; + + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + delete[] colorIndex; + delete[] line; + + return false; + } + } + } + + rle_count--; + *(pLine++) = rle_value; + } + + /* compute line's color indexes */ + for (unsigned int x = 0; x < width; ++x) + { + if (line[x / 8] & (128 >> (x % 8))) + colorIndex[x] += (1 << c); + } + } + + /* decode scan line. color index => rgb */ + for (unsigned int x = 0; x < width; ++x) + { + *ptr++ = header.palette[colorIndex[x] * 3 + 0]; + *ptr++ = header.palette[colorIndex[x] * 3 + 1]; + *ptr++ = header.palette[colorIndex[x] * 3 + 2]; + } + } + + /* release memory */ + delete[] colorIndex; + delete[] line; + break; + } + + case 8: + { + nzUInt8 palette[768]; + + /* the palette is contained in the last 769 bytes of the file */ + unsigned int curPos = stream.GetCursorPos(); + stream.SetCursorPos(stream.GetSize()-769); + nzUInt8 magic; + if (!stream.Read(&magic, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + /* first byte must be equal to 0x0c (12) */ + if (magic != 0x0c) + { + NazaraError("Colormap's first byte must be 0x0c (0x" + NzString::Number(magic, 16) + ')'); + return false; + } + + /* read palette */ + if (stream.Read(palette, 768) != 768) + { + NazaraError("Failed to read palette"); + return false; + } + + stream.SetCursorPos(curPos); + + /* read pixel data */ + for (unsigned int y = 0; y < height; ++y) + { + nzUInt8* ptr = &pixels[y * width * 3]; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + } + } + + rle_count--; + + *ptr++ = palette[rle_value * 3 + 0]; + *ptr++ = palette[rle_value * 3 + 1]; + *ptr++ = palette[rle_value * 3 + 2]; + } + } + break; + } + + case 24: + { + for (unsigned int y = 0; y < height; ++y) + { + /* for each color plane */ + for (int c = 0; c < 3; ++c) + { + nzUInt8* ptr = &pixels[y * width * 4]; + int bytes = header.bytesPerScanLine; + + /* decode line number y */ + while (bytes--) + { + if (rle_count == 0) + { + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + + if (rle_value < 0xc0) + rle_count = 1; + else + { + rle_count = rle_value - 0xc0; + if (!stream.Read(&rle_value, 1)) + { + NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')'); + return false; + } + } + } + + rle_count--; + ptr[c] = static_cast(rle_value); + ptr += 3; + } + } + } + break; + } + + default: + NazaraError("Failed to load " + NzString::Number(bitCount) + " bitcount pcx files"); + return false; + } + + if (parameters.loadFormat != nzPixelFormat_Undefined) + image->Convert(parameters.loadFormat); + + return true; + } +} + +void NzLoaders_PCX_Register() +{ + NzImageLoader::RegisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); +} + +void NzLoaders_PCX_Unregister() +{ + NzImageLoader::UnregisterLoader("pcx", NzLoader_PCX_Check, NzLoader_PCX_Load); +} diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 7a8845dc7..cd1bef360 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -1,681 +1,681 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -bool NzMeshParams::IsValid() const -{ - if (!animation.IsValid()) - { - NazaraError("Invalid animation parameters"); - return false; - } - - if (!NzBuffer::IsSupported(storage)) - { - NazaraError("Storage not supported"); - return false; - } - - return true; -} - -struct NzMeshImpl -{ - std::deque skins; - std::map subMeshMap; - std::vector subMeshes; - nzAnimationType animationType; - NzAxisAlignedBox aabb; - const NzAnimation* animation = nullptr; -}; - -NzMesh::~NzMesh() -{ - Destroy(); -} - -bool NzMesh::AddSkin(const NzString& skin, bool setDefault) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - - if (skin.IsEmpty()) - { - NazaraError("Skin is empty"); - return false; - } - #endif - - if (setDefault) - m_impl->skins.push_front(skin); - else - m_impl->skins.push_back(skin); - - return true; -} - -bool NzMesh::AddSubMesh(NzSubMesh* subMesh) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - - if (!subMesh) - { - NazaraError("Invalid submesh"); - return false; - } - #endif - - subMesh->AddResourceListener(this, m_impl->subMeshes.size()); - - m_impl->aabb.SetNull(); // On invalide l'AABB - m_impl->subMeshes.push_back(subMesh); - - return true; -} - -bool NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - - if (identifier.IsEmpty()) - { - NazaraError("Identifier is empty"); - return false; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it != m_impl->subMeshMap.end()) - { - NazaraError("SubMesh identifier \"" + identifier + "\" is already used"); - return false; - } - - if (!subMesh) - { - NazaraError("Invalid submesh"); - return false; - } - #endif - - int index = m_impl->subMeshes.size(); - - subMesh->AddResourceListener(this, index); - - m_impl->aabb.SetNull(); // On invalide l'AABB - m_impl->subMeshes.push_back(subMesh); - m_impl->subMeshMap[identifier] = index; - - return true; -} - -void NzMesh::Animate(unsigned int frameA, unsigned int frameB, float interpolation) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - if (!m_impl->animation) - { - NazaraError("Mesh has no animation"); - return; - } - - unsigned int frameCount = m_impl->animation->GetFrameCount(); - if (frameA >= frameCount) - { - NazaraError("Frame A is out of range (" + NzString::Number(frameA) + " >= " + NzString::Number(frameCount) + ')'); - return; - } - - if (frameB >= frameCount) - { - NazaraError("Frame B is out of range (" + NzString::Number(frameB) + " >= " + NzString::Number(frameCount) + ')'); - return; - } - - if (interpolation < 0.f || interpolation > 1.f) - { - NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); - return; - } - #endif - - for (NzSubMesh* subMesh : m_impl->subMeshes) - subMesh->AnimateImpl(frameA, frameB, interpolation); - - m_impl->aabb.SetNull(); // On invalide l'AABB -} - -bool NzMesh::Create(nzAnimationType type) -{ - Destroy(); - - m_impl = new NzMeshImpl; - m_impl->animationType = type; - - NotifyCreated(); - - return true; -} - -void NzMesh::Destroy() -{ - if (m_impl) - { - NotifyDestroy(); - - if (m_impl->animation) - m_impl->animation->RemoveResourceListener(this); - - for (NzSubMesh* subMesh : m_impl->subMeshes) - subMesh->RemoveResourceListener(this); - - delete m_impl; - m_impl = nullptr; - } -} - -const NzAxisAlignedBox& NzMesh::GetAABB() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return NzAxisAlignedBox::Null; - } - #endif - - if (m_impl->aabb.IsNull()) - { - for (NzSubMesh* subMesh : m_impl->subMeshes) - m_impl->aabb.ExtendTo(subMesh->GetAABB()); - } - - return m_impl->aabb; -} - -const NzAnimation* NzMesh::GetAnimation() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - #endif - - return m_impl->animation; -} - -nzAnimationType NzMesh::GetAnimationType() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nzAnimationType_Static; - } - #endif - - return m_impl->animationType; -} - -unsigned int NzMesh::GetFrameCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - - if (!m_impl->animation) - { - NazaraError("Mesh has no animation"); - return 0; - } - #endif - - return m_impl->animation->GetFrameCount(); -} - -NzString NzMesh::GetSkin(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return NzString(); - } - - if (index >= m_impl->skins.size()) - { - NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); - return NzString(); - } - #endif - - return m_impl->skins[index]; -} - -unsigned int NzMesh::GetSkinCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - #endif - - return m_impl->skins.size(); -} - -NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return nullptr; - } - - return m_impl->subMeshes[it->second]; - #else - return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; - #endif -} - -NzSubMesh* NzMesh::GetSubMesh(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - if (index >= m_impl->subMeshes.size()) - { - NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); - return nullptr; - } - #endif - - return m_impl->subMeshes[index]; -} - -const NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return nullptr; - } - - return m_impl->subMeshes[it->second]; - #else - return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; - #endif -} - -const NzSubMesh* NzMesh::GetSubMesh(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return nullptr; - } - - if (index >= m_impl->subMeshes.size()) - { - NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); - return nullptr; - } - #endif - - return m_impl->subMeshes[index]; -} - -unsigned int NzMesh::GetSubMeshCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - #endif - - return m_impl->subMeshes.size(); -} - -int NzMesh::GetSubMeshIndex(const NzString& identifier) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return -1; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return -1; - } - - return it->second; - #else - return m_impl->subMeshMap[identifier]; - #endif -} - -unsigned int NzMesh::GetVertexCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return 0; - } - #endif - - unsigned int vertexCount = 0; - for (NzSubMesh* subMesh : m_impl->subMeshes) - vertexCount += subMesh->GetVertexCount(); - - return vertexCount; -} - -void NzMesh::InvalidateAABB() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - #endif - - m_impl->aabb.SetNull(); -} - -bool NzMesh::HasAnimation() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->animation != nullptr; -} - -bool NzMesh::HasSkin(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->skins.size() > index; -} - -bool NzMesh::HasSubMesh(const NzString& identifier) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end(); -} - -bool NzMesh::HasSubMesh(unsigned int index) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return index < m_impl->subMeshes.size(); -} - -bool NzMesh::IsAnimable() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - #endif - - return m_impl->animationType != nzAnimationType_Static; -} - -bool NzMesh::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzMesh::LoadFromFile(const NzString& filePath, const NzMeshParams& params) -{ - return NzMeshLoader::LoadFromFile(this, filePath, params); -} - -bool NzMesh::LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params) -{ - return NzMeshLoader::LoadFromMemory(this, data, size, params); -} - -bool NzMesh::LoadFromStream(NzInputStream& stream, const NzMeshParams& params) -{ - return NzMeshLoader::LoadFromStream(this, stream, params); -} - -void NzMesh::RemoveSkin(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - if (m_impl->skins.size() <= index) - { - NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); - return; - } - #endif - - // On accède à l'itérateur correspondant à l'entrée #index - auto it = m_impl->skins.begin(); - std::advance(it, index); - - m_impl->skins.erase(it); -} - -void NzMesh::RemoveSubMesh(const NzString& identifier) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - auto it = m_impl->subMeshMap.find(identifier); - if (it == m_impl->subMeshMap.end()) - { - NazaraError("SubMesh not found"); - return; - } - - unsigned int index = it->second; - #else - unsigned int index = m_impl->subMeshMap[identifier]; - #endif - - // On déplace l'itérateur du début d'une distance de x - auto it2 = m_impl->subMeshes.begin(); - std::advance(it, index); - - // On libère la ressource - (*it2)->RemoveResourceListener(this); - m_impl->subMeshes.erase(it2); - - m_impl->aabb.SetNull(); // On invalide l'AABB -} - -void NzMesh::RemoveSubMesh(unsigned int index) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return; - } - - if (index >= m_impl->subMeshes.size()) - { - NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); - return; - } - #endif - - // On déplace l'itérateur du début de x - auto it = m_impl->subMeshes.begin(); - std::advance(it, index); - - // On libère la ressource - (*it)->RemoveResourceListener(this); - m_impl->subMeshes.erase(it); - - m_impl->aabb.SetNull(); // On invalide l'AABB -} - -bool NzMesh::SetAnimation(const NzAnimation* animation) -{ - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Mesh not created"); - return false; - } - - if (m_impl->animationType == nzAnimationType_Static) - { - NazaraError("Static meshes cannot have animation"); - return false; - } - #endif - - if (animation == m_impl->animation) - return true; - - if (m_impl->animation) - m_impl->animation->RemoveResourceListener(this); - - if (animation) - { - #if NAZARA_UTILITY_SAFE - if (animation->GetType() != m_impl->animationType) - { - NazaraError("Animation's type must match mesh animation type"); - return false; - } - #endif - - animation->AddResourceListener(this); - } - - m_impl->animation = animation; - - return true; -} - -void NzMesh::OnResourceCreated(const NzResource* resource, int index) -{ - NazaraUnused(index); - - if (resource == m_impl->animation) - { - #if NAZARA_UTILITY_SAFE - if (m_impl->animation->GetType() != m_impl->animationType) - { - NazaraError("Animation's type must match mesh animation type"); - - m_impl->animation->RemoveResourceListener(this); - m_impl->animation = nullptr; - } - #endif - } -} - -void NzMesh::OnResourceReleased(const NzResource* resource, int index) -{ - if (resource == m_impl->animation) - SetAnimation(nullptr); - else - RemoveSubMesh(index); -} - -NzMeshLoader::LoaderList NzMesh::s_loaders; +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool NzMeshParams::IsValid() const +{ + if (!animation.IsValid()) + { + NazaraError("Invalid animation parameters"); + return false; + } + + if (!NzBuffer::IsSupported(storage)) + { + NazaraError("Storage not supported"); + return false; + } + + return true; +} + +struct NzMeshImpl +{ + std::deque skins; + std::map subMeshMap; + std::vector subMeshes; + nzAnimationType animationType; + NzAxisAlignedBox aabb; + const NzAnimation* animation = nullptr; +}; + +NzMesh::~NzMesh() +{ + Destroy(); +} + +bool NzMesh::AddSkin(const NzString& skin, bool setDefault) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (skin.IsEmpty()) + { + NazaraError("Skin is empty"); + return false; + } + #endif + + if (setDefault) + m_impl->skins.push_front(skin); + else + m_impl->skins.push_back(skin); + + return true; +} + +bool NzMesh::AddSubMesh(NzSubMesh* subMesh) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (!subMesh) + { + NazaraError("Invalid submesh"); + return false; + } + #endif + + subMesh->AddResourceListener(this, m_impl->subMeshes.size()); + + m_impl->aabb.SetNull(); // On invalide l'AABB + m_impl->subMeshes.push_back(subMesh); + + return true; +} + +bool NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (identifier.IsEmpty()) + { + NazaraError("Identifier is empty"); + return false; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it != m_impl->subMeshMap.end()) + { + NazaraError("SubMesh identifier \"" + identifier + "\" is already used"); + return false; + } + + if (!subMesh) + { + NazaraError("Invalid submesh"); + return false; + } + #endif + + int index = m_impl->subMeshes.size(); + + subMesh->AddResourceListener(this, index); + + m_impl->aabb.SetNull(); // On invalide l'AABB + m_impl->subMeshes.push_back(subMesh); + m_impl->subMeshMap[identifier] = index; + + return true; +} + +void NzMesh::Animate(unsigned int frameA, unsigned int frameB, float interpolation) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + if (!m_impl->animation) + { + NazaraError("Mesh has no animation"); + return; + } + + unsigned int frameCount = m_impl->animation->GetFrameCount(); + if (frameA >= frameCount) + { + NazaraError("Frame A is out of range (" + NzString::Number(frameA) + " >= " + NzString::Number(frameCount) + ')'); + return; + } + + if (frameB >= frameCount) + { + NazaraError("Frame B is out of range (" + NzString::Number(frameB) + " >= " + NzString::Number(frameCount) + ')'); + return; + } + + if (interpolation < 0.f || interpolation > 1.f) + { + NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); + return; + } + #endif + + for (NzSubMesh* subMesh : m_impl->subMeshes) + subMesh->AnimateImpl(frameA, frameB, interpolation); + + m_impl->aabb.SetNull(); // On invalide l'AABB +} + +bool NzMesh::Create(nzAnimationType type) +{ + Destroy(); + + m_impl = new NzMeshImpl; + m_impl->animationType = type; + + NotifyCreated(); + + return true; +} + +void NzMesh::Destroy() +{ + if (m_impl) + { + NotifyDestroy(); + + if (m_impl->animation) + m_impl->animation->RemoveResourceListener(this); + + for (NzSubMesh* subMesh : m_impl->subMeshes) + subMesh->RemoveResourceListener(this); + + delete m_impl; + m_impl = nullptr; + } +} + +const NzAxisAlignedBox& NzMesh::GetAABB() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return NzAxisAlignedBox::Null; + } + #endif + + if (m_impl->aabb.IsNull()) + { + for (NzSubMesh* subMesh : m_impl->subMeshes) + m_impl->aabb.ExtendTo(subMesh->GetAABB()); + } + + return m_impl->aabb; +} + +const NzAnimation* NzMesh::GetAnimation() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + #endif + + return m_impl->animation; +} + +nzAnimationType NzMesh::GetAnimationType() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nzAnimationType_Static; + } + #endif + + return m_impl->animationType; +} + +unsigned int NzMesh::GetFrameCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + + if (!m_impl->animation) + { + NazaraError("Mesh has no animation"); + return 0; + } + #endif + + return m_impl->animation->GetFrameCount(); +} + +NzString NzMesh::GetSkin(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return NzString(); + } + + if (index >= m_impl->skins.size()) + { + NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); + return NzString(); + } + #endif + + return m_impl->skins[index]; +} + +unsigned int NzMesh::GetSkinCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + #endif + + return m_impl->skins.size(); +} + +NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return nullptr; + } + + return m_impl->subMeshes[it->second]; + #else + return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; + #endif +} + +NzSubMesh* NzMesh::GetSubMesh(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + if (index >= m_impl->subMeshes.size()) + { + NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); + return nullptr; + } + #endif + + return m_impl->subMeshes[index]; +} + +const NzSubMesh* NzMesh::GetSubMesh(const NzString& identifier) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return nullptr; + } + + return m_impl->subMeshes[it->second]; + #else + return m_impl->subMeshes[m_impl->subMeshMap[identifier]]; + #endif +} + +const NzSubMesh* NzMesh::GetSubMesh(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return nullptr; + } + + if (index >= m_impl->subMeshes.size()) + { + NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); + return nullptr; + } + #endif + + return m_impl->subMeshes[index]; +} + +unsigned int NzMesh::GetSubMeshCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + #endif + + return m_impl->subMeshes.size(); +} + +int NzMesh::GetSubMeshIndex(const NzString& identifier) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return -1; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return -1; + } + + return it->second; + #else + return m_impl->subMeshMap[identifier]; + #endif +} + +unsigned int NzMesh::GetVertexCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return 0; + } + #endif + + unsigned int vertexCount = 0; + for (NzSubMesh* subMesh : m_impl->subMeshes) + vertexCount += subMesh->GetVertexCount(); + + return vertexCount; +} + +void NzMesh::InvalidateAABB() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + #endif + + m_impl->aabb.SetNull(); +} + +bool NzMesh::HasAnimation() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->animation != nullptr; +} + +bool NzMesh::HasSkin(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->skins.size() > index; +} + +bool NzMesh::HasSubMesh(const NzString& identifier) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end(); +} + +bool NzMesh::HasSubMesh(unsigned int index) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return index < m_impl->subMeshes.size(); +} + +bool NzMesh::IsAnimable() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + #endif + + return m_impl->animationType != nzAnimationType_Static; +} + +bool NzMesh::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzMesh::LoadFromFile(const NzString& filePath, const NzMeshParams& params) +{ + return NzMeshLoader::LoadFromFile(this, filePath, params); +} + +bool NzMesh::LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params) +{ + return NzMeshLoader::LoadFromMemory(this, data, size, params); +} + +bool NzMesh::LoadFromStream(NzInputStream& stream, const NzMeshParams& params) +{ + return NzMeshLoader::LoadFromStream(this, stream, params); +} + +void NzMesh::RemoveSkin(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + if (m_impl->skins.size() <= index) + { + NazaraError("Skin index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->skins.size()) + ')'); + return; + } + #endif + + // On accède à l'itérateur correspondant à l'entrée #index + auto it = m_impl->skins.begin(); + std::advance(it, index); + + m_impl->skins.erase(it); +} + +void NzMesh::RemoveSubMesh(const NzString& identifier) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + auto it = m_impl->subMeshMap.find(identifier); + if (it == m_impl->subMeshMap.end()) + { + NazaraError("SubMesh not found"); + return; + } + + unsigned int index = it->second; + #else + unsigned int index = m_impl->subMeshMap[identifier]; + #endif + + // On déplace l'itérateur du début d'une distance de x + auto it2 = m_impl->subMeshes.begin(); + std::advance(it, index); + + // On libère la ressource + (*it2)->RemoveResourceListener(this); + m_impl->subMeshes.erase(it2); + + m_impl->aabb.SetNull(); // On invalide l'AABB +} + +void NzMesh::RemoveSubMesh(unsigned int index) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return; + } + + if (index >= m_impl->subMeshes.size()) + { + NazaraError("SubMesh index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->subMeshes.size()) + ')'); + return; + } + #endif + + // On déplace l'itérateur du début de x + auto it = m_impl->subMeshes.begin(); + std::advance(it, index); + + // On libère la ressource + (*it)->RemoveResourceListener(this); + m_impl->subMeshes.erase(it); + + m_impl->aabb.SetNull(); // On invalide l'AABB +} + +bool NzMesh::SetAnimation(const NzAnimation* animation) +{ + #if NAZARA_UTILITY_SAFE + if (!m_impl) + { + NazaraError("Mesh not created"); + return false; + } + + if (m_impl->animationType == nzAnimationType_Static) + { + NazaraError("Static meshes cannot have animation"); + return false; + } + #endif + + if (animation == m_impl->animation) + return true; + + if (m_impl->animation) + m_impl->animation->RemoveResourceListener(this); + + if (animation) + { + #if NAZARA_UTILITY_SAFE + if (animation->GetType() != m_impl->animationType) + { + NazaraError("Animation's type must match mesh animation type"); + return false; + } + #endif + + animation->AddResourceListener(this); + } + + m_impl->animation = animation; + + return true; +} + +void NzMesh::OnResourceCreated(const NzResource* resource, int index) +{ + NazaraUnused(index); + + if (resource == m_impl->animation) + { + #if NAZARA_UTILITY_SAFE + if (m_impl->animation->GetType() != m_impl->animationType) + { + NazaraError("Animation's type must match mesh animation type"); + + m_impl->animation->RemoveResourceListener(this); + m_impl->animation = nullptr; + } + #endif + } +} + +void NzMesh::OnResourceReleased(const NzResource* resource, int index) +{ + if (resource == m_impl->animation) + SetAnimation(nullptr); + else + RemoveSubMesh(index); +} + +NzMeshLoader::LoaderList NzMesh::s_loaders; diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index bf1fe2b6b..d3d470dd7 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -1,199 +1,199 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -NzStaticMesh::NzStaticMesh(const NzMesh* parent) : -NzSubMesh(parent) -{ -} - -NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) : -NzSubMesh(parent) -{ - #ifdef NAZARA_DEBUG - if (!Create(vertexDeclaration, vertexBuffer, indexBuffer)) - { - NazaraError("Failed to create mesh"); - throw std::runtime_error("Constructor failed"); - } - #else - Create(vertexDeclaration, vertexBuffer, indexBuffer); - #endif -} - -NzStaticMesh::~NzStaticMesh() -{ - Destroy(); -} - -bool NzStaticMesh::Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) -{ - Destroy(); - - #if NAZARA_UTILITY_SAFE - if (!vertexDeclaration) - { - NazaraError("Invalid vertex declaration"); - return false; - } - - if (!vertexBuffer) - { - NazaraError("Invalid vertex buffer"); - return false; - } - #endif - - if (indexBuffer) - indexBuffer->AddResourceListener(this); - - m_indexBuffer = indexBuffer; - - m_vertexBuffer = vertexBuffer; - m_vertexBuffer->AddResourceListener(this); - - m_vertexDeclaration = vertexDeclaration; - m_vertexDeclaration->AddResourceListener(this); - - return true; -} - -void NzStaticMesh::Destroy() -{ - m_aabb.SetNull(); - - if (m_indexBuffer) - { - m_indexBuffer->RemoveResourceListener(this); - m_indexBuffer = nullptr; - } - - if (m_vertexBuffer) - { - m_vertexBuffer->RemoveResourceListener(this); - m_vertexBuffer = nullptr; - } - - if (m_vertexDeclaration) - { - m_vertexDeclaration->RemoveResourceListener(this); - m_vertexDeclaration = nullptr; - } -} - -bool NzStaticMesh::GenerateAABB() -{ - if (!m_aabb.IsNull()) - return true; - - const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position); - if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3 - { - // On lock le buffer pour itérer sur toutes les positions et composer notre AABB - nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_ReadOnly)); - if (!buffer) - { - NazaraWarning("Failed to lock vertex buffer"); - return false; - } - - buffer += position->offset; - unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData); - unsigned int vertexCount = m_vertexBuffer->GetVertexCount(); - for (unsigned int i = 0; i < vertexCount; ++i) - { - m_aabb.ExtendTo(*reinterpret_cast(buffer)); - - buffer += stride; - } - - if (!m_vertexBuffer->Unmap()) - NazaraWarning("Failed to unmap vertex buffer"); - } - - return true; -} - -const NzAxisAlignedBox& NzStaticMesh::GetAABB() const -{ - return m_aabb; -} - -nzAnimationType NzStaticMesh::GetAnimationType() const -{ - return nzAnimationType_Static; -} - -unsigned int NzStaticMesh::GetFrameCount() const -{ - return 1; -} - -const NzIndexBuffer* NzStaticMesh::GetIndexBuffer() const -{ - return m_indexBuffer; -} - -nzPrimitiveType NzStaticMesh::GetPrimitiveType() const -{ - return m_primitiveType; -} - -const NzVertexBuffer* NzStaticMesh::GetVertexBuffer() const -{ - return m_vertexBuffer; -} - -const NzVertexDeclaration* NzStaticMesh::GetVertexDeclaration() const -{ - return m_vertexDeclaration; -} - -bool NzStaticMesh::IsAnimated() const -{ - return false; -} - -bool NzStaticMesh::IsValid() const -{ - return m_vertexBuffer != nullptr && m_vertexDeclaration != nullptr; -} - -void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb) -{ - m_aabb = aabb; -} - -void NzStaticMesh::SetPrimitiveType(nzPrimitiveType primitiveType) -{ - m_primitiveType = primitiveType; -} - -void NzStaticMesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) -{ - NazaraUnused(frameA); - NazaraUnused(frameB); - NazaraUnused(interpolation); - - // Le safe mode est censé nous protéger de cet appel - NazaraError("Static mesh have no animation, please enable safe mode"); -} - -void NzStaticMesh::OnResourceReleased(const NzResource* resource, int index) -{ - NazaraUnused(index); - - if (resource == m_indexBuffer) - m_indexBuffer = nullptr; - else if (resource == m_vertexBuffer) - m_vertexBuffer = nullptr; - else if (resource == m_vertexDeclaration) - m_vertexDeclaration = nullptr; - else - NazaraInternalError("Not listening to " + NzString::Pointer(resource)); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +NzStaticMesh::NzStaticMesh(const NzMesh* parent) : +NzSubMesh(parent) +{ +} + +NzStaticMesh::NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) : +NzSubMesh(parent) +{ + #ifdef NAZARA_DEBUG + if (!Create(vertexDeclaration, vertexBuffer, indexBuffer)) + { + NazaraError("Failed to create mesh"); + throw std::runtime_error("Constructor failed"); + } + #else + Create(vertexDeclaration, vertexBuffer, indexBuffer); + #endif +} + +NzStaticMesh::~NzStaticMesh() +{ + Destroy(); +} + +bool NzStaticMesh::Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer) +{ + Destroy(); + + #if NAZARA_UTILITY_SAFE + if (!vertexDeclaration) + { + NazaraError("Invalid vertex declaration"); + return false; + } + + if (!vertexBuffer) + { + NazaraError("Invalid vertex buffer"); + return false; + } + #endif + + if (indexBuffer) + indexBuffer->AddResourceListener(this); + + m_indexBuffer = indexBuffer; + + m_vertexBuffer = vertexBuffer; + m_vertexBuffer->AddResourceListener(this); + + m_vertexDeclaration = vertexDeclaration; + m_vertexDeclaration->AddResourceListener(this); + + return true; +} + +void NzStaticMesh::Destroy() +{ + m_aabb.SetNull(); + + if (m_indexBuffer) + { + m_indexBuffer->RemoveResourceListener(this); + m_indexBuffer = nullptr; + } + + if (m_vertexBuffer) + { + m_vertexBuffer->RemoveResourceListener(this); + m_vertexBuffer = nullptr; + } + + if (m_vertexDeclaration) + { + m_vertexDeclaration->RemoveResourceListener(this); + m_vertexDeclaration = nullptr; + } +} + +bool NzStaticMesh::GenerateAABB() +{ + if (!m_aabb.IsNull()) + return true; + + const NzVertexElement* position = m_vertexDeclaration->GetElement(nzElementStream_VertexData, nzElementUsage_Position); + if (position && position->type == nzElementType_Float3) // Si nous avons des positions du type Vec3 + { + // On lock le buffer pour itérer sur toutes les positions et composer notre AABB + nzUInt8* buffer = reinterpret_cast(m_vertexBuffer->Map(nzBufferAccess_ReadOnly)); + if (!buffer) + { + NazaraWarning("Failed to lock vertex buffer"); + return false; + } + + buffer += position->offset; + unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData); + unsigned int vertexCount = m_vertexBuffer->GetVertexCount(); + for (unsigned int i = 0; i < vertexCount; ++i) + { + m_aabb.ExtendTo(*reinterpret_cast(buffer)); + + buffer += stride; + } + + if (!m_vertexBuffer->Unmap()) + NazaraWarning("Failed to unmap vertex buffer"); + } + + return true; +} + +const NzAxisAlignedBox& NzStaticMesh::GetAABB() const +{ + return m_aabb; +} + +nzAnimationType NzStaticMesh::GetAnimationType() const +{ + return nzAnimationType_Static; +} + +unsigned int NzStaticMesh::GetFrameCount() const +{ + return 1; +} + +const NzIndexBuffer* NzStaticMesh::GetIndexBuffer() const +{ + return m_indexBuffer; +} + +nzPrimitiveType NzStaticMesh::GetPrimitiveType() const +{ + return m_primitiveType; +} + +const NzVertexBuffer* NzStaticMesh::GetVertexBuffer() const +{ + return m_vertexBuffer; +} + +const NzVertexDeclaration* NzStaticMesh::GetVertexDeclaration() const +{ + return m_vertexDeclaration; +} + +bool NzStaticMesh::IsAnimated() const +{ + return false; +} + +bool NzStaticMesh::IsValid() const +{ + return m_vertexBuffer != nullptr && m_vertexDeclaration != nullptr; +} + +void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb) +{ + m_aabb = aabb; +} + +void NzStaticMesh::SetPrimitiveType(nzPrimitiveType primitiveType) +{ + m_primitiveType = primitiveType; +} + +void NzStaticMesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) +{ + NazaraUnused(frameA); + NazaraUnused(frameB); + NazaraUnused(interpolation); + + // Le safe mode est censé nous protéger de cet appel + NazaraError("Static mesh have no animation, please enable safe mode"); +} + +void NzStaticMesh::OnResourceReleased(const NzResource* resource, int index) +{ + NazaraUnused(index); + + if (resource == m_indexBuffer) + m_indexBuffer = nullptr; + else if (resource == m_vertexBuffer) + m_vertexBuffer = nullptr; + else if (resource == m_vertexDeclaration) + m_vertexDeclaration = nullptr; + else + NazaraInternalError("Not listening to " + NzString::Pointer(resource)); +} diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index 6c66a8f67..e4d24b0ec 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -1,372 +1,372 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_VERTEXDECLARATION -#include -#else -#include -#endif - -#include - -namespace -{ - const unsigned int elementCount[] = - { - 4, // nzElementType_Color - 1, // nzElementType_Double1 - 2, // nzElementType_Double2 - 3, // nzElementType_Double3 - 4, // nzElementType_Double4 - 1, // nzElementType_Float1 - 2, // nzElementType_Float2 - 3, // nzElementType_Float3 - 4 // nzElementType_Float4 - }; - - const unsigned int elementSize[] = - { - 4*sizeof(nzUInt8), // nzElementType_Color - 1*sizeof(double), // nzElementType_Double1 - 2*sizeof(double), // nzElementType_Double2 - 3*sizeof(double), // nzElementType_Double3 - 4*sizeof(double), // nzElementType_Double4 - 1*sizeof(float), // nzElementType_Float1 - 2*sizeof(float), // nzElementType_Float2 - 3*sizeof(float), // nzElementType_Float3 - 4*sizeof(float) // nzElementType_Float4 - }; - - bool VertexElementCompare(const NzVertexElement& elementA, const NzVertexElement& elementB) - { - // Nous classons d'abord par stream - if (elementA.stream == elementB.stream) - { - // Ensuite par usage - if (elementA.usage == elementB.usage) - // Et finalement par usageIndex - return elementA.usageIndex < elementB.usageIndex; - else - return elementA.usage < elementB.usage; - } - else - return elementA.stream < elementB.stream; - } -} - -struct NzVertexDeclarationImpl -{ - std::vector elements; - int elementPos[nzElementStream_Max+1][nzElementUsage_Max+1]; - int streamPos[nzElementStream_Max+1]; - unsigned int stride[nzElementStream_Max+1] = {0}; - - unsigned short refCount = 1; - NazaraMutex(mutex) -}; - -NzVertexDeclaration::NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount) -{ - #ifdef NAZARA_DEBUG - if (!Create(elements, elementCount)) - { - NazaraError("Failed to create declaration"); - throw std::runtime_error("Constructor failed"); - } - #else - Create(elements, elementCount); - #endif -} - -NzVertexDeclaration::NzVertexDeclaration(const NzVertexDeclaration& declaration) : -NzResource(), -m_sharedImpl(declaration.m_sharedImpl) -{ - if (m_sharedImpl) - { - NazaraMutexLock(m_sharedImpl->mutex); - m_sharedImpl->refCount++; - NazaraMutexUnlock(m_sharedImpl->mutex); - } -} - -NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept : -m_sharedImpl(declaration.m_sharedImpl) -{ - declaration.m_sharedImpl = nullptr; -} - -NzVertexDeclaration::~NzVertexDeclaration() -{ - Destroy(); -} - -bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int elementCount) -{ - Destroy(); - - #if NAZARA_UTILITY_SAFE - if (!elements || elementCount == 0) - { - NazaraError("No element"); - return false; - } - #endif - - NzVertexDeclarationImpl* impl = new NzVertexDeclarationImpl; - std::memset(&impl->elementPos, -1, (nzElementStream_Max+1)*(nzElementUsage_Max+1)*sizeof(int)); - std::memset(&impl->streamPos, -1, (nzElementStream_Max+1)*sizeof(int)); - - // On copie et trie les éléments - impl->elements.resize(elementCount); - std::memcpy(&impl->elements[0], elements, elementCount*sizeof(NzVertexElement)); - std::sort(impl->elements.begin(), impl->elements.end(), VertexElementCompare); - - for (unsigned int i = 0; i < elementCount; ++i) - { - NzVertexElement& current = impl->elements[i]; - #if NAZARA_UTILITY_SAFE - // Notre tableau étant trié, s'il y a collision, les deux éléments identiques se suivent... - if (i > 0) - { - NzVertexElement& previous = impl->elements[i-1]; // On accède à l'élément précédent - if (previous.usage == current.usage && previous.usageIndex == current.usageIndex && previous.stream == current.stream) - { - // Les deux éléments sont identiques là où ils ne devraient pas, nous avons une collision... - NazaraError("Element usage 0x" + NzString::Number(current.usage, 16) + " collision with usage index " + NzString::Number(current.usageIndex) + " on stream 0x" + NzString::Number(current.stream, 16)); - delete impl; - - return false; - } - } - #endif - - if (current.usageIndex == 0) - impl->elementPos[current.stream][current.usage] = i; - - if (impl->streamPos[current.stream] == -1) - impl->streamPos[current.stream] = i; // Premier élément du stream (via le triage) - - impl->stride[current.stream] += elementSize[current.type]; - } - - #if NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 - for (unsigned int& stride : impl->stride) - stride = ((static_cast(stride)-1)/32+1)*32; - #endif - - m_sharedImpl = impl; - - NotifyCreated(); - return true; -} - -void NzVertexDeclaration::Destroy() -{ - if (!m_sharedImpl) - return; - - NotifyDestroy(); - - NazaraMutexLock(m_sharedImpl->mutex); - bool freeSharedImpl = (--m_sharedImpl->refCount == 0); - NazaraMutexUnlock(m_sharedImpl->mutex); - - if (freeSharedImpl) - delete m_sharedImpl; - - m_sharedImpl = nullptr; -} - -const NzVertexElement* NzVertexDeclaration::GetElement(unsigned int i) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return nullptr; - } - - if (i >= m_sharedImpl->elements.size()) - { - NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_sharedImpl->elements.size()) + ')'); - return nullptr; - } - #endif - - return &m_sharedImpl->elements[i]; -} - -const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, unsigned int i) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return nullptr; - } - - int streamPos = m_sharedImpl->streamPos[stream]; - if (streamPos == -1) - { - NazaraError("Declaration has no stream 0x" + NzString::Number(stream, 16)); - return nullptr; - } - - unsigned int upperLimit = GetElementCount(stream); - if (i >= upperLimit) - { - NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(upperLimit) + ')'); - return nullptr; - } - #endif - - return &m_sharedImpl->elements[m_sharedImpl->streamPos[stream]+i]; -} - -const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return nullptr; - } - #endif - - int elementPos = m_sharedImpl->elementPos[stream][usage]; - if (elementPos == -1) - return nullptr; - - elementPos += usageIndex; - if (static_cast(elementPos) >= m_sharedImpl->elements.size()) - return nullptr; - - NzVertexElement& element = m_sharedImpl->elements[elementPos]; - if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) - return nullptr; - - return &element; -} - -unsigned int NzVertexDeclaration::GetElementCount() const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return 0; - } - #endif - - return m_sharedImpl->elements.size(); -} - -unsigned int NzVertexDeclaration::GetElementCount(nzElementStream stream) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return 0; - } - #endif - - int streamPos = m_sharedImpl->streamPos[stream]; - if (streamPos == -1) - return 0; - - unsigned int upperLimit = 0; - if (stream == nzElementStream_Max) - upperLimit = m_sharedImpl->elements.size(); - else - { - for (unsigned int upperStream = stream+1; upperStream <= nzElementStream_Max; ++upperStream) - { - if (m_sharedImpl->streamPos[upperStream] != -1) - { - upperLimit = m_sharedImpl->streamPos[upperStream]; - break; - } - else if (upperStream == nzElementStream_Max) // Dernier stream, toujours pas de limite - upperLimit = m_sharedImpl->elements.size(); - } - } - - return upperLimit-streamPos; -} - -unsigned int NzVertexDeclaration::GetStride(nzElementStream stream) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return 0; - } - #endif - - return m_sharedImpl->stride[stream]; -} - -bool NzVertexDeclaration::HasStream(nzElementStream stream) const -{ - #if NAZARA_UTILITY_SAFE - if (!m_sharedImpl) - { - NazaraError("Declaration not created"); - return false; - } - #endif - - return m_sharedImpl->streamPos[stream] != -1; -} - -bool NzVertexDeclaration::IsValid() const -{ - return m_sharedImpl != nullptr; -} - -NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration) -{ - Destroy(); - - m_sharedImpl = declaration.m_sharedImpl; - if (m_sharedImpl) - { - NazaraMutexLock(m_sharedImpl->mutex); - m_sharedImpl->refCount++; - NazaraMutexUnlock(m_sharedImpl->mutex); - } - - return *this; -} - -NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) noexcept -{ - Destroy(); - - m_sharedImpl = declaration.m_sharedImpl; - declaration.m_sharedImpl = nullptr; - - return *this; -} - -unsigned int NzVertexDeclaration::GetElementCount(nzElementType type) -{ - return elementCount[type]; -} - -unsigned int NzVertexDeclaration::GetElementSize(nzElementType type) -{ - return elementSize[type]; -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_VERTEXDECLARATION +#include +#else +#include +#endif + +#include + +namespace +{ + const unsigned int elementCount[] = + { + 4, // nzElementType_Color + 1, // nzElementType_Double1 + 2, // nzElementType_Double2 + 3, // nzElementType_Double3 + 4, // nzElementType_Double4 + 1, // nzElementType_Float1 + 2, // nzElementType_Float2 + 3, // nzElementType_Float3 + 4 // nzElementType_Float4 + }; + + const unsigned int elementSize[] = + { + 4*sizeof(nzUInt8), // nzElementType_Color + 1*sizeof(double), // nzElementType_Double1 + 2*sizeof(double), // nzElementType_Double2 + 3*sizeof(double), // nzElementType_Double3 + 4*sizeof(double), // nzElementType_Double4 + 1*sizeof(float), // nzElementType_Float1 + 2*sizeof(float), // nzElementType_Float2 + 3*sizeof(float), // nzElementType_Float3 + 4*sizeof(float) // nzElementType_Float4 + }; + + bool VertexElementCompare(const NzVertexElement& elementA, const NzVertexElement& elementB) + { + // Nous classons d'abord par stream + if (elementA.stream == elementB.stream) + { + // Ensuite par usage + if (elementA.usage == elementB.usage) + // Et finalement par usageIndex + return elementA.usageIndex < elementB.usageIndex; + else + return elementA.usage < elementB.usage; + } + else + return elementA.stream < elementB.stream; + } +} + +struct NzVertexDeclarationImpl +{ + std::vector elements; + int elementPos[nzElementStream_Max+1][nzElementUsage_Max+1]; + int streamPos[nzElementStream_Max+1]; + unsigned int stride[nzElementStream_Max+1] = {0}; + + unsigned short refCount = 1; + NazaraMutex(mutex) +}; + +NzVertexDeclaration::NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount) +{ + #ifdef NAZARA_DEBUG + if (!Create(elements, elementCount)) + { + NazaraError("Failed to create declaration"); + throw std::runtime_error("Constructor failed"); + } + #else + Create(elements, elementCount); + #endif +} + +NzVertexDeclaration::NzVertexDeclaration(const NzVertexDeclaration& declaration) : +NzResource(), +m_sharedImpl(declaration.m_sharedImpl) +{ + if (m_sharedImpl) + { + NazaraMutexLock(m_sharedImpl->mutex); + m_sharedImpl->refCount++; + NazaraMutexUnlock(m_sharedImpl->mutex); + } +} + +NzVertexDeclaration::NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept : +m_sharedImpl(declaration.m_sharedImpl) +{ + declaration.m_sharedImpl = nullptr; +} + +NzVertexDeclaration::~NzVertexDeclaration() +{ + Destroy(); +} + +bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int elementCount) +{ + Destroy(); + + #if NAZARA_UTILITY_SAFE + if (!elements || elementCount == 0) + { + NazaraError("No element"); + return false; + } + #endif + + NzVertexDeclarationImpl* impl = new NzVertexDeclarationImpl; + std::memset(&impl->elementPos, -1, (nzElementStream_Max+1)*(nzElementUsage_Max+1)*sizeof(int)); + std::memset(&impl->streamPos, -1, (nzElementStream_Max+1)*sizeof(int)); + + // On copie et trie les éléments + impl->elements.resize(elementCount); + std::memcpy(&impl->elements[0], elements, elementCount*sizeof(NzVertexElement)); + std::sort(impl->elements.begin(), impl->elements.end(), VertexElementCompare); + + for (unsigned int i = 0; i < elementCount; ++i) + { + NzVertexElement& current = impl->elements[i]; + #if NAZARA_UTILITY_SAFE + // Notre tableau étant trié, s'il y a collision, les deux éléments identiques se suivent... + if (i > 0) + { + NzVertexElement& previous = impl->elements[i-1]; // On accède à l'élément précédent + if (previous.usage == current.usage && previous.usageIndex == current.usageIndex && previous.stream == current.stream) + { + // Les deux éléments sont identiques là où ils ne devraient pas, nous avons une collision... + NazaraError("Element usage 0x" + NzString::Number(current.usage, 16) + " collision with usage index " + NzString::Number(current.usageIndex) + " on stream 0x" + NzString::Number(current.stream, 16)); + delete impl; + + return false; + } + } + #endif + + if (current.usageIndex == 0) + impl->elementPos[current.stream][current.usage] = i; + + if (impl->streamPos[current.stream] == -1) + impl->streamPos[current.stream] = i; // Premier élément du stream (via le triage) + + impl->stride[current.stream] += elementSize[current.type]; + } + + #if NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 + for (unsigned int& stride : impl->stride) + stride = ((static_cast(stride)-1)/32+1)*32; + #endif + + m_sharedImpl = impl; + + NotifyCreated(); + return true; +} + +void NzVertexDeclaration::Destroy() +{ + if (!m_sharedImpl) + return; + + NotifyDestroy(); + + NazaraMutexLock(m_sharedImpl->mutex); + bool freeSharedImpl = (--m_sharedImpl->refCount == 0); + NazaraMutexUnlock(m_sharedImpl->mutex); + + if (freeSharedImpl) + delete m_sharedImpl; + + m_sharedImpl = nullptr; +} + +const NzVertexElement* NzVertexDeclaration::GetElement(unsigned int i) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return nullptr; + } + + if (i >= m_sharedImpl->elements.size()) + { + NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_sharedImpl->elements.size()) + ')'); + return nullptr; + } + #endif + + return &m_sharedImpl->elements[i]; +} + +const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, unsigned int i) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return nullptr; + } + + int streamPos = m_sharedImpl->streamPos[stream]; + if (streamPos == -1) + { + NazaraError("Declaration has no stream 0x" + NzString::Number(stream, 16)); + return nullptr; + } + + unsigned int upperLimit = GetElementCount(stream); + if (i >= upperLimit) + { + NazaraError("Element index out of range (" + NzString::Number(i) + " >= " + NzString::Number(upperLimit) + ')'); + return nullptr; + } + #endif + + return &m_sharedImpl->elements[m_sharedImpl->streamPos[stream]+i]; +} + +const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return nullptr; + } + #endif + + int elementPos = m_sharedImpl->elementPos[stream][usage]; + if (elementPos == -1) + return nullptr; + + elementPos += usageIndex; + if (static_cast(elementPos) >= m_sharedImpl->elements.size()) + return nullptr; + + NzVertexElement& element = m_sharedImpl->elements[elementPos]; + if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) + return nullptr; + + return &element; +} + +unsigned int NzVertexDeclaration::GetElementCount() const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return 0; + } + #endif + + return m_sharedImpl->elements.size(); +} + +unsigned int NzVertexDeclaration::GetElementCount(nzElementStream stream) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return 0; + } + #endif + + int streamPos = m_sharedImpl->streamPos[stream]; + if (streamPos == -1) + return 0; + + unsigned int upperLimit = 0; + if (stream == nzElementStream_Max) + upperLimit = m_sharedImpl->elements.size(); + else + { + for (unsigned int upperStream = stream+1; upperStream <= nzElementStream_Max; ++upperStream) + { + if (m_sharedImpl->streamPos[upperStream] != -1) + { + upperLimit = m_sharedImpl->streamPos[upperStream]; + break; + } + else if (upperStream == nzElementStream_Max) // Dernier stream, toujours pas de limite + upperLimit = m_sharedImpl->elements.size(); + } + } + + return upperLimit-streamPos; +} + +unsigned int NzVertexDeclaration::GetStride(nzElementStream stream) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return 0; + } + #endif + + return m_sharedImpl->stride[stream]; +} + +bool NzVertexDeclaration::HasStream(nzElementStream stream) const +{ + #if NAZARA_UTILITY_SAFE + if (!m_sharedImpl) + { + NazaraError("Declaration not created"); + return false; + } + #endif + + return m_sharedImpl->streamPos[stream] != -1; +} + +bool NzVertexDeclaration::IsValid() const +{ + return m_sharedImpl != nullptr; +} + +NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration) +{ + Destroy(); + + m_sharedImpl = declaration.m_sharedImpl; + if (m_sharedImpl) + { + NazaraMutexLock(m_sharedImpl->mutex); + m_sharedImpl->refCount++; + NazaraMutexUnlock(m_sharedImpl->mutex); + } + + return *this; +} + +NzVertexDeclaration& NzVertexDeclaration::operator=(NzVertexDeclaration&& declaration) noexcept +{ + Destroy(); + + m_sharedImpl = declaration.m_sharedImpl; + declaration.m_sharedImpl = nullptr; + + return *this; +} + +unsigned int NzVertexDeclaration::GetElementCount(nzElementType type) +{ + return elementCount[type]; +} + +unsigned int NzVertexDeclaration::GetElementSize(nzElementType type) +{ + return elementSize[type]; +} diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index acfecb9e5..f70eab837 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -1,534 +1,534 @@ -// Copyright (C) 2012 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) - #include - #include - #include -#elif defined(NAZARA_PLATFORM_LINUX) - #include - #include - #include -#else - #error Lack of implementation: Window -#endif - -#include - -namespace -{ - NzWindow* fullscreenWindow = nullptr; -} - -NzWindow::NzWindow() : -#if NAZARA_UTILITY_THREADED_WINDOW -m_impl(nullptr), -m_eventListener(true), -m_waitForEvent(false) -#else -m_impl(nullptr) -#endif -{ -} - -NzWindow::NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style) : -#if NAZARA_UTILITY_THREADED_WINDOW -m_impl(nullptr), -m_eventListener(true), -m_waitForEvent(false) -#else -m_impl(nullptr) -#endif -{ - Create(mode, title, style); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzWindow::NzWindow(NzWindowHandle handle) : -#if NAZARA_UTILITY_THREADED_WINDOW -m_impl(nullptr), -m_eventListener(true), -m_waitForEvent(false) -#else -m_impl(nullptr) -#endif -{ - Create(handle); - - #ifdef NAZARA_DEBUG - if (!m_impl) - { - NazaraError("Failed to create window"); - throw std::runtime_error("Constructor failed"); - } - #endif -} - -NzWindow::~NzWindow() -{ - Destroy(); -} - -bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) -{ - // Si la fenêtre est déjà ouverte, nous conservons sa position - bool opened = IsOpen(); - NzVector2i position; - if (opened) - position = m_impl->GetPosition(); - - Destroy(); - - // Inspiré du code de la SFML par Laurent Gomila - if (style & nzWindowStyle_Fullscreen) - { - if (fullscreenWindow) - { - NazaraError("Window (" + NzString::Pointer(fullscreenWindow) + ") already in fullscreen mode"); - style &= ~nzWindowStyle_Fullscreen; - } - else - { - if (!mode.IsFullscreenValid()) - { - NazaraWarning("Video mode is not fullscreen valid"); - mode = NzVideoMode::GetFullscreenModes()[0]; - } - - fullscreenWindow = this; - } - } - else if (style & nzWindowStyle_Closable || style & nzWindowStyle_Resizable) - style |= nzWindowStyle_Titlebar; - - m_impl = new NzWindowImpl(this); - if (!m_impl->Create(mode, title, style)) - { - NazaraError("Failed to create window implementation"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - m_ownsWindow = true; - - if (!OnWindowCreated()) - { - NazaraError("Failed to initialize window extension"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - // Paramètres par défaut - m_impl->EnableKeyRepeat(true); - m_impl->EnableSmoothScrolling(false); - m_impl->SetCursor(nzWindowCursor_Default); - m_impl->SetMaximumSize(-1, -1); - m_impl->SetMinimumSize(-1, -1); - m_impl->SetVisible(true); - - if (opened) - m_impl->SetPosition(position.x, position.y); - - return true; -} - -bool NzWindow::Create(NzWindowHandle handle) -{ - Destroy(); - - m_impl = new NzWindowImpl(this); - if (!m_impl->Create(handle)) - { - NazaraError("Unable to create window implementation"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - m_ownsWindow = false; - - if (!OnWindowCreated()) - { - NazaraError("Failed to initialize window's derivate"); - delete m_impl; - m_impl = nullptr; - - return false; - } - - return true; -} - -void NzWindow::Destroy() -{ - if (m_impl) - { - OnWindowDestroy(); - - m_impl->Destroy(); - delete m_impl; - m_impl = nullptr; - - if (fullscreenWindow == this) - fullscreenWindow = nullptr; - } -} - -void NzWindow::EnableKeyRepeat(bool enable) -{ - if (m_impl) - m_impl->EnableKeyRepeat(enable); -} - -void NzWindow::EnableSmoothScrolling(bool enable) -{ - if (m_impl) - m_impl->EnableSmoothScrolling(enable); -} - -NzWindowHandle NzWindow::GetHandle() const -{ - if (m_impl) - return m_impl->GetHandle(); - else - return static_cast(0); -} - -unsigned int NzWindow::GetHeight() const -{ - if (m_impl) - return m_impl->GetHeight(); - else - return 0; -} - -NzVector2i NzWindow::GetPosition() const -{ - if (m_impl) - return m_impl->GetPosition(); - else - return NzVector2i(0); -} - -NzVector2ui NzWindow::GetSize() const -{ - if (m_impl) - return m_impl->GetSize(); - else - return NzVector2ui(0U); -} - -NzString NzWindow::GetTitle() const -{ - if (m_impl) - return m_impl->GetTitle(); - else - return NzString(); -} - -unsigned int NzWindow::GetWidth() const -{ - if (m_impl) - return m_impl->GetWidth(); - else - return 0; -} - -bool NzWindow::HasFocus() const -{ - if (m_impl) - return m_impl->HasFocus(); - else - return false; -} - -bool NzWindow::IsOpen() const -{ - return m_impl != nullptr; -} - -bool NzWindow::IsMinimized() const -{ - if (m_impl) - return m_impl->IsMinimized(); - else - return false; -} - -bool NzWindow::IsValid() const -{ - return m_impl != nullptr; -} - -bool NzWindow::IsVisible() const -{ - if (m_impl) - return m_impl->IsVisible(); - else - return false; -} - -bool NzWindow::PollEvent(NzEvent* event) -{ - if (!m_impl) - return false; - - #if NAZARA_UTILITY_THREADED_WINDOW - NzLockGuard lock(m_eventMutex); - #else - m_impl->ProcessEvents(false); - #endif - - if (!m_events.empty()) - { - if (event) - *event = m_events.front(); - - m_events.pop(); - - return true; - } - - return false; -} - -void NzWindow::SetCursor(nzWindowCursor cursor) -{ - if (m_impl) - m_impl->SetCursor(cursor); -} - -void NzWindow::SetCursor(const NzCursor& cursor) -{ - #if NAZARA_UTILITY_SAFE - if (!cursor.IsValid()) - { - NazaraError("Cursor is not valid"); - return; - } - #endif - - if (m_impl) - m_impl->SetCursor(cursor); -} - -void NzWindow::SetEventListener(bool listener) -{ - if (!m_impl) - return; - - #if NAZARA_UTILITY_THREADED_WINDOW - m_impl->SetEventListener(listener); - if (!listener) - { - // On vide la pile des évènements - NzLockGuard lock(m_eventMutex); - while (!m_events.empty()) - m_events.pop(); - } - #else - if (m_ownsWindow) - { - // Inutile de transmettre l'ordre dans ce cas-là - if (!listener) - NazaraError("A non-threaded window needs to listen to events"); - } - else - m_impl->SetEventListener(listener); - #endif -} - -void NzWindow::SetFocus() -{ - if (m_impl) - m_impl->SetFocus(); -} - -void NzWindow::SetIcon(const NzIcon& icon) -{ - #if NAZARA_UTILITY_SAFE - if (!icon.IsValid()) - { - NazaraError("Icon is not valid"); - return; - } - #endif - - if (m_impl) - m_impl->SetIcon(icon); -} - -void NzWindow::SetMaximumSize(const NzVector2i& maxSize) -{ - if (m_impl) - m_impl->SetMaximumSize(maxSize.x, maxSize.y); -} - -void NzWindow::SetMaximumSize(int width, int height) -{ - if (m_impl) - m_impl->SetMaximumSize(width, height); -} - -void NzWindow::SetMinimumSize(const NzVector2i& minSize) -{ - if (m_impl) - m_impl->SetMinimumSize(minSize.x, minSize.y); -} - -void NzWindow::SetMinimumSize(int width, int height) -{ - if (m_impl) - m_impl->SetMinimumSize(width, height); -} - -void NzWindow::SetPosition(const NzVector2i& position) -{ - if (m_impl) - m_impl->SetPosition(position.x, position.y); -} - -void NzWindow::SetPosition(int x, int y) -{ - if (m_impl) - m_impl->SetPosition(x, y); -} - -void NzWindow::SetSize(const NzVector2i& size) -{ - if (m_impl) - m_impl->SetSize(size.x, size.y); -} - -void NzWindow::SetSize(unsigned int width, unsigned int height) -{ - if (m_impl) - m_impl->SetSize(width, height); -} - -void NzWindow::SetStayOnTop(bool stayOnTop) -{ - if (m_impl) - m_impl->SetStayOnTop(stayOnTop); -} - -void NzWindow::SetTitle(const NzString& title) -{ - if (m_impl) - m_impl->SetTitle(title); -} - -void NzWindow::SetVisible(bool visible) -{ - if (m_impl) - m_impl->SetVisible(visible); -} - -bool NzWindow::WaitEvent(NzEvent* event) -{ - if (!m_impl) - return false; - - #if NAZARA_UTILITY_THREADED_WINDOW - NzLockGuard lock(m_eventMutex); - - if (m_events.empty()) - { - m_waitForEvent = true; - m_eventConditionMutex.Lock(); - m_eventMutex.Unlock(); - m_eventCondition.Wait(&m_eventConditionMutex); - m_eventMutex.Lock(); - m_eventConditionMutex.Unlock(); - m_waitForEvent = false; - } - - if (!m_events.empty()) - { - if (event) - *event = m_events.front(); - - m_events.pop(); - - return true; - } - - return false; - #else - while (m_events.empty()) - m_impl->ProcessEvents(true); - - if (event) - *event = m_events.front(); - - m_events.pop(); - - return true; - #endif -} - -bool NzWindow::OnWindowCreated() -{ - return true; -} - -void NzWindow::OnWindowDestroy() -{ -} - -void NzWindow::IgnoreNextMouseEvent(int mouseX, int mouseY) const -{ - if (m_impl) - m_impl->IgnoreNextMouseEvent(mouseX, mouseY); -} - -void NzWindow::PushEvent(const NzEvent& event) -{ - #if NAZARA_UTILITY_THREADED_WINDOW - m_eventMutex.Lock(); - #endif - - m_events.push(event); - - #if NAZARA_UTILITY_THREADED_WINDOW - m_eventMutex.Unlock(); - - if (m_waitForEvent) - { - m_eventConditionMutex.Lock(); - m_eventCondition.Signal(); - m_eventConditionMutex.Unlock(); - } - #endif -} - -bool NzWindow::Initialize() -{ - return NzWindowImpl::Initialize(); -} - -void NzWindow::Uninitialize() -{ - NzWindowImpl::Uninitialize(); -} +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include +#include + +#if defined(NAZARA_PLATFORM_WINDOWS) + #include + #include + #include +#elif defined(NAZARA_PLATFORM_LINUX) + #include + #include + #include +#else + #error Lack of implementation: Window +#endif + +#include + +namespace +{ + NzWindow* fullscreenWindow = nullptr; +} + +NzWindow::NzWindow() : +#if NAZARA_UTILITY_THREADED_WINDOW +m_impl(nullptr), +m_eventListener(true), +m_waitForEvent(false) +#else +m_impl(nullptr) +#endif +{ +} + +NzWindow::NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style) : +#if NAZARA_UTILITY_THREADED_WINDOW +m_impl(nullptr), +m_eventListener(true), +m_waitForEvent(false) +#else +m_impl(nullptr) +#endif +{ + Create(mode, title, style); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzWindow::NzWindow(NzWindowHandle handle) : +#if NAZARA_UTILITY_THREADED_WINDOW +m_impl(nullptr), +m_eventListener(true), +m_waitForEvent(false) +#else +m_impl(nullptr) +#endif +{ + Create(handle); + + #ifdef NAZARA_DEBUG + if (!m_impl) + { + NazaraError("Failed to create window"); + throw std::runtime_error("Constructor failed"); + } + #endif +} + +NzWindow::~NzWindow() +{ + Destroy(); +} + +bool NzWindow::Create(NzVideoMode mode, const NzString& title, nzUInt32 style) +{ + // Si la fenêtre est déjà ouverte, nous conservons sa position + bool opened = IsOpen(); + NzVector2i position; + if (opened) + position = m_impl->GetPosition(); + + Destroy(); + + // Inspiré du code de la SFML par Laurent Gomila + if (style & nzWindowStyle_Fullscreen) + { + if (fullscreenWindow) + { + NazaraError("Window (" + NzString::Pointer(fullscreenWindow) + ") already in fullscreen mode"); + style &= ~nzWindowStyle_Fullscreen; + } + else + { + if (!mode.IsFullscreenValid()) + { + NazaraWarning("Video mode is not fullscreen valid"); + mode = NzVideoMode::GetFullscreenModes()[0]; + } + + fullscreenWindow = this; + } + } + else if (style & nzWindowStyle_Closable || style & nzWindowStyle_Resizable) + style |= nzWindowStyle_Titlebar; + + m_impl = new NzWindowImpl(this); + if (!m_impl->Create(mode, title, style)) + { + NazaraError("Failed to create window implementation"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + m_ownsWindow = true; + + if (!OnWindowCreated()) + { + NazaraError("Failed to initialize window extension"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + // Paramètres par défaut + m_impl->EnableKeyRepeat(true); + m_impl->EnableSmoothScrolling(false); + m_impl->SetCursor(nzWindowCursor_Default); + m_impl->SetMaximumSize(-1, -1); + m_impl->SetMinimumSize(-1, -1); + m_impl->SetVisible(true); + + if (opened) + m_impl->SetPosition(position.x, position.y); + + return true; +} + +bool NzWindow::Create(NzWindowHandle handle) +{ + Destroy(); + + m_impl = new NzWindowImpl(this); + if (!m_impl->Create(handle)) + { + NazaraError("Unable to create window implementation"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + m_ownsWindow = false; + + if (!OnWindowCreated()) + { + NazaraError("Failed to initialize window's derivate"); + delete m_impl; + m_impl = nullptr; + + return false; + } + + return true; +} + +void NzWindow::Destroy() +{ + if (m_impl) + { + OnWindowDestroy(); + + m_impl->Destroy(); + delete m_impl; + m_impl = nullptr; + + if (fullscreenWindow == this) + fullscreenWindow = nullptr; + } +} + +void NzWindow::EnableKeyRepeat(bool enable) +{ + if (m_impl) + m_impl->EnableKeyRepeat(enable); +} + +void NzWindow::EnableSmoothScrolling(bool enable) +{ + if (m_impl) + m_impl->EnableSmoothScrolling(enable); +} + +NzWindowHandle NzWindow::GetHandle() const +{ + if (m_impl) + return m_impl->GetHandle(); + else + return static_cast(0); +} + +unsigned int NzWindow::GetHeight() const +{ + if (m_impl) + return m_impl->GetHeight(); + else + return 0; +} + +NzVector2i NzWindow::GetPosition() const +{ + if (m_impl) + return m_impl->GetPosition(); + else + return NzVector2i(0); +} + +NzVector2ui NzWindow::GetSize() const +{ + if (m_impl) + return m_impl->GetSize(); + else + return NzVector2ui(0U); +} + +NzString NzWindow::GetTitle() const +{ + if (m_impl) + return m_impl->GetTitle(); + else + return NzString(); +} + +unsigned int NzWindow::GetWidth() const +{ + if (m_impl) + return m_impl->GetWidth(); + else + return 0; +} + +bool NzWindow::HasFocus() const +{ + if (m_impl) + return m_impl->HasFocus(); + else + return false; +} + +bool NzWindow::IsOpen() const +{ + return m_impl != nullptr; +} + +bool NzWindow::IsMinimized() const +{ + if (m_impl) + return m_impl->IsMinimized(); + else + return false; +} + +bool NzWindow::IsValid() const +{ + return m_impl != nullptr; +} + +bool NzWindow::IsVisible() const +{ + if (m_impl) + return m_impl->IsVisible(); + else + return false; +} + +bool NzWindow::PollEvent(NzEvent* event) +{ + if (!m_impl) + return false; + + #if NAZARA_UTILITY_THREADED_WINDOW + NzLockGuard lock(m_eventMutex); + #else + m_impl->ProcessEvents(false); + #endif + + if (!m_events.empty()) + { + if (event) + *event = m_events.front(); + + m_events.pop(); + + return true; + } + + return false; +} + +void NzWindow::SetCursor(nzWindowCursor cursor) +{ + if (m_impl) + m_impl->SetCursor(cursor); +} + +void NzWindow::SetCursor(const NzCursor& cursor) +{ + #if NAZARA_UTILITY_SAFE + if (!cursor.IsValid()) + { + NazaraError("Cursor is not valid"); + return; + } + #endif + + if (m_impl) + m_impl->SetCursor(cursor); +} + +void NzWindow::SetEventListener(bool listener) +{ + if (!m_impl) + return; + + #if NAZARA_UTILITY_THREADED_WINDOW + m_impl->SetEventListener(listener); + if (!listener) + { + // On vide la pile des évènements + NzLockGuard lock(m_eventMutex); + while (!m_events.empty()) + m_events.pop(); + } + #else + if (m_ownsWindow) + { + // Inutile de transmettre l'ordre dans ce cas-là + if (!listener) + NazaraError("A non-threaded window needs to listen to events"); + } + else + m_impl->SetEventListener(listener); + #endif +} + +void NzWindow::SetFocus() +{ + if (m_impl) + m_impl->SetFocus(); +} + +void NzWindow::SetIcon(const NzIcon& icon) +{ + #if NAZARA_UTILITY_SAFE + if (!icon.IsValid()) + { + NazaraError("Icon is not valid"); + return; + } + #endif + + if (m_impl) + m_impl->SetIcon(icon); +} + +void NzWindow::SetMaximumSize(const NzVector2i& maxSize) +{ + if (m_impl) + m_impl->SetMaximumSize(maxSize.x, maxSize.y); +} + +void NzWindow::SetMaximumSize(int width, int height) +{ + if (m_impl) + m_impl->SetMaximumSize(width, height); +} + +void NzWindow::SetMinimumSize(const NzVector2i& minSize) +{ + if (m_impl) + m_impl->SetMinimumSize(minSize.x, minSize.y); +} + +void NzWindow::SetMinimumSize(int width, int height) +{ + if (m_impl) + m_impl->SetMinimumSize(width, height); +} + +void NzWindow::SetPosition(const NzVector2i& position) +{ + if (m_impl) + m_impl->SetPosition(position.x, position.y); +} + +void NzWindow::SetPosition(int x, int y) +{ + if (m_impl) + m_impl->SetPosition(x, y); +} + +void NzWindow::SetSize(const NzVector2i& size) +{ + if (m_impl) + m_impl->SetSize(size.x, size.y); +} + +void NzWindow::SetSize(unsigned int width, unsigned int height) +{ + if (m_impl) + m_impl->SetSize(width, height); +} + +void NzWindow::SetStayOnTop(bool stayOnTop) +{ + if (m_impl) + m_impl->SetStayOnTop(stayOnTop); +} + +void NzWindow::SetTitle(const NzString& title) +{ + if (m_impl) + m_impl->SetTitle(title); +} + +void NzWindow::SetVisible(bool visible) +{ + if (m_impl) + m_impl->SetVisible(visible); +} + +bool NzWindow::WaitEvent(NzEvent* event) +{ + if (!m_impl) + return false; + + #if NAZARA_UTILITY_THREADED_WINDOW + NzLockGuard lock(m_eventMutex); + + if (m_events.empty()) + { + m_waitForEvent = true; + m_eventConditionMutex.Lock(); + m_eventMutex.Unlock(); + m_eventCondition.Wait(&m_eventConditionMutex); + m_eventMutex.Lock(); + m_eventConditionMutex.Unlock(); + m_waitForEvent = false; + } + + if (!m_events.empty()) + { + if (event) + *event = m_events.front(); + + m_events.pop(); + + return true; + } + + return false; + #else + while (m_events.empty()) + m_impl->ProcessEvents(true); + + if (event) + *event = m_events.front(); + + m_events.pop(); + + return true; + #endif +} + +bool NzWindow::OnWindowCreated() +{ + return true; +} + +void NzWindow::OnWindowDestroy() +{ +} + +void NzWindow::IgnoreNextMouseEvent(int mouseX, int mouseY) const +{ + if (m_impl) + m_impl->IgnoreNextMouseEvent(mouseX, mouseY); +} + +void NzWindow::PushEvent(const NzEvent& event) +{ + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventMutex.Lock(); + #endif + + m_events.push(event); + + #if NAZARA_UTILITY_THREADED_WINDOW + m_eventMutex.Unlock(); + + if (m_waitForEvent) + { + m_eventConditionMutex.Lock(); + m_eventCondition.Signal(); + m_eventConditionMutex.Unlock(); + } + #endif +} + +bool NzWindow::Initialize() +{ + return NzWindowImpl::Initialize(); +} + +void NzWindow::Uninitialize() +{ + NzWindowImpl::Uninitialize(); +} From bdb7703ab21af796b343652808650865b8ed5f58 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Sep 2012 19:10:35 +0200 Subject: [PATCH 20/31] Improved OS detection macros Former-commit-id: 6f89791cfde43a813dc1250bd82ba9f54afb7786 --- include/Nazara/Prerequesites.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Prerequesites.hpp b/include/Nazara/Prerequesites.hpp index af3ec7707..f397ca247 100644 --- a/include/Nazara/Prerequesites.hpp +++ b/include/Nazara/Prerequesites.hpp @@ -101,7 +101,7 @@ #define _WIN32_WINNT NAZARA_WINNT #endif #endif -#elif defined(linux) || defined(__linux) +#elif defined(__linux__) || defined(linux) || defined(__linux) #if !defined(NAZARA_STATIC) && defined(NAZARA_COMPILER_GCC) #define NAZARA_API __attribute__((visibility ("default"))) #else @@ -109,11 +109,11 @@ #endif #define NAZARA_PLATFORM_LINUX #define NAZARA_PLATFORM_POSIX -/*#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh) +/*#elif defined(__APPLE__) || defined(macintosh) || defined(Macintosh) #define NAZARA_API #define NAZARA_PLATFORM_MACOS #define NAZARA_PLATFORM_POSIX -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#elif defined(__FreeBSD__) #define NAZARA_API #define NAZARA_PLATFORM_FREEBSD #define NAZARA_PLATFORM_POSIX*/ From 49ac00f28dae4d673b69f33a1c3d50217a30eff2 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 23 Sep 2012 18:07:31 +0200 Subject: [PATCH 21/31] Fixed error message Former-commit-id: f07c8fe20e7e11d49da8c114cdf518bf04484855 --- src/Nazara/Utility/Mesh.cpp | 1 - src/Nazara/Utility/SubMesh.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index cd1bef360..adcf25d71 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -181,7 +181,6 @@ bool NzMesh::Create(nzAnimationType type) m_impl->animationType = type; NotifyCreated(); - return true; } diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index fb382d97a..557bdf435 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -30,7 +30,7 @@ void NzSubMesh::Animate(unsigned int frameA, unsigned int frameB, float interpol #if NAZARA_UTILITY_SAFE if (!m_parent->HasAnimation()) { - NazaraError("SubMesh has no animation"); + NazaraError("Parent mesh has no animation"); return; } From 8d057fb3b131cc489669ef40b28e4e52187ed867 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 30 Sep 2012 23:11:00 +0200 Subject: [PATCH 22/31] Renamed GetBPP to GetBytesPerPixel Also added GetBitsPerPixel Former-commit-id: 9cc1df58133c538b1dc74215a9022d13dfd9d7f6 --- include/Nazara/Renderer/Texture.hpp | 2 +- include/Nazara/Utility/Image.hpp | 2 +- include/Nazara/Utility/PixelFormat.hpp | 3 +- include/Nazara/Utility/PixelFormat.inl | 82 +++++++++++++++----------- src/Nazara/Renderer/Texture.cpp | 10 ++-- src/Nazara/Utility/Image.cpp | 36 +++++------ 6 files changed, 73 insertions(+), 62 deletions(-) diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index 9a849146e..111063113 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -34,7 +34,7 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable bool EnableMipmapping(bool enable); unsigned int GetAnisotropyLevel() const; - nzUInt8 GetBPP() const; + nzUInt8 GetBytesPerPixel() const; unsigned int GetDepth() const; nzTextureFilter GetFilterMode() const; nzPixelFormat GetFormat() const; diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index d58ff1736..5c7411496 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -66,7 +66,7 @@ class NAZARA_API NzImage : public NzResource bool FlipHorizontally(); bool FlipVertically(); - nzUInt8 GetBPP() const; + nzUInt8 GetBytesPerPixel() const; const nzUInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0) const; unsigned int GetDepth(nzUInt8 level = 0) const; nzPixelFormat GetFormat() const; diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 7d46d82ef..e155bd9a1 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -27,7 +27,8 @@ class NzPixelFormat static bool Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst); - static nzUInt8 GetBPP(nzPixelFormat format); + static nzUInt8 GetBitsPerPixel(nzPixelFormat format); + static nzUInt8 GetBytesPerPixel(nzPixelFormat format); static nzPixelFormatType GetType(nzPixelFormat format); static bool HasAlpha(nzPixelFormat format); diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index b48af518c..d3fdc5d30 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -10,7 +10,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor { if (srcFormat == dstFormat) { - std::memcpy(dst, src, GetBPP(srcFormat)); + std::memcpy(dst, src, GetBytesPerPixel(srcFormat)); return true; } @@ -35,7 +35,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor return false; } - if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBPP(srcFormat), reinterpret_cast(dst))) + if (!func(reinterpret_cast(src), reinterpret_cast(src) + GetBytesPerPixel(srcFormat), reinterpret_cast(dst))) { NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed"); return false; @@ -93,7 +93,7 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, } #endif - nzUInt8 bpp = GetBPP(format); + nzUInt8 bpp = GetBytesPerPixel(format); unsigned int lineStride = width*bpp; switch (flipping) { @@ -164,93 +164,91 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format, return true; } -inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) +inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format) { switch (format) { case nzPixelFormat_BGR8: - return 3; + return 24; case nzPixelFormat_BGRA8: - return 4; + return 32; case nzPixelFormat_DXT1: - return 1; + return 8; case nzPixelFormat_DXT3: - return 2; + return 16; case nzPixelFormat_DXT5: - return 2; + return 16; case nzPixelFormat_L8: - return 1; + return 8; case nzPixelFormat_LA8: - return 2; + return 16; /* case nzPixelFormat_RGB16F: - return 6; + return 48; case nzPixelFormat_RGB16I: - return 6; + return 48; case nzPixelFormat_RGB32F: - return 12; + return 96; case nzPixelFormat_RGB32I: - return 12; + return 96; case nzPixelFormat_RGBA16F: - return 8; + return 64; case nzPixelFormat_RGBA16I: - return 8; + return 64; case nzPixelFormat_RGBA32F: - return 16; + return 128; case nzPixelFormat_RGBA32I: - return 16; + return 128; */ case nzPixelFormat_RGBA4: - return 2; + return 16; case nzPixelFormat_RGB5A1: - return 2; + return 16; case nzPixelFormat_RGB8: - return 3; + return 24; case nzPixelFormat_RGBA8: - return 4; + return 32; case nzPixelFormat_Depth16: - return 2; + return 16; case nzPixelFormat_Depth24: - return 3; + return 24; case nzPixelFormat_Depth24Stencil8: - return 4; + return 32; case nzPixelFormat_Depth32: - return 4; + return 32; case nzPixelFormat_Stencil1: - NazaraWarning("This format uses less than one byte per pixel"); - return 0; - - case nzPixelFormat_Stencil4: - NazaraWarning("This format uses less than one byte per pixel"); - return 0; - - case nzPixelFormat_Stencil8: return 1; - case nzPixelFormat_Stencil16: + case nzPixelFormat_Stencil4: return 2; + case nzPixelFormat_Stencil8: + return 8; + + case nzPixelFormat_Stencil16: + return 16; + case nzPixelFormat_Undefined: break; } @@ -259,6 +257,18 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format) return 0; } +inline nzUInt8 NzPixelFormat::GetBytesPerPixel(nzPixelFormat format) +{ + nzUInt8 bytesPerPixel = GetBitsPerPixel(format)/8; + + #if NAZARA_UTILITY_SAFE + if (bytesPerPixel == 0) + NazaraWarning("This format is invalid or uses less than one byte per pixel"); + #endif + + return bytesPerPixel; +} + inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format) { switch (format) diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index 870fda854..786faa070 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -485,7 +485,7 @@ unsigned int NzTexture::GetAnisotropyLevel() const return anisotropyLevel; } -nzUInt8 NzTexture::GetBPP() const +nzUInt8 NzTexture::GetBytesPerPixel() const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -495,7 +495,7 @@ nzUInt8 NzTexture::GetBPP() const } #endif - return NzPixelFormat::GetBPP(m_impl->format); + return NzPixelFormat::GetBytesPerPixel(m_impl->format); } unsigned int NzTexture::GetDepth() const @@ -1113,7 +1113,7 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int return false; } - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format); // Inversion de la texture pour le repère d'OpenGL NzImage mirrored; @@ -1210,7 +1210,7 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 leve return false; } - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format); // Inversion de la texture pour le repère d'OpenGL unsigned int size = cube.width*cube.height*cube.depth*bpp; @@ -1365,7 +1365,7 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe return false; } - nzUInt8 bpp = NzPixelFormat::GetBPP(m_impl->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format); // Inversion de la texture pour le repère d'OpenGL unsigned int size = rect.width*rect.height*bpp; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 68bee7d9b..021f4211d 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -105,10 +105,10 @@ bool NzImage::Convert(nzPixelFormat format) for (unsigned int i = 0; i < m_sharedImage->levelCount; ++i) { unsigned int pixelsPerFace = width*height; - nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)]; + nzUInt8* ptr = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBytesPerPixel(format)]; nzUInt8* pixels = m_sharedImage->pixels[i]; - unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format); - unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format); + unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); + unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBytesPerPixel(format); for (unsigned int d = 0; d < depth; ++d) { @@ -180,7 +180,7 @@ bool NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto ///FIXME: Trouver une interface pour gérer ce genre de problème (Façon OpenGL?) (Appliquer l'interface à NzTexture également) */ - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); unsigned int dstLineStride = srcCube.width*bpp; unsigned int dstFaceStride = dstLineStride*srcCube.height; unsigned int srcLineStride = m_sharedImage->width*bpp; @@ -302,7 +302,7 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, // Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs try { - levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBPP(format)]; + levels[i] = new nzUInt8[w * h * d * NzPixelFormat::GetBytesPerPixel(format)]; if (w > 1) w >>= 1; @@ -358,7 +358,7 @@ bool NzImage::Fill(const NzColor& color) EnsureOwnership(); - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); nzUInt8* pixels = new nzUInt8[bpp]; if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) { @@ -429,7 +429,7 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) EnsureOwnership(); - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); nzUInt8* pixels = new nzUInt8[bpp]; if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) { @@ -485,7 +485,7 @@ bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) EnsureOwnership(); - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); nzUInt8* pixels = new nzUInt8[bpp]; if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixels)) { @@ -601,9 +601,9 @@ bool NzImage::FlipVertically() return true; } -nzUInt8 NzImage::GetBPP() const +nzUInt8 NzImage::GetBytesPerPixel() const { - return NzPixelFormat::GetBPP(m_sharedImage->format); + return NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); } const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned int z, nzUInt8 level) const @@ -641,7 +641,7 @@ const nzUInt8* NzImage::GetConstPixels(unsigned int x, unsigned int y, unsigned } #endif - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); } unsigned int NzImage::GetDepth(nzUInt8 level) const @@ -720,7 +720,7 @@ NzColor NzImage::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) c } #endif - const nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + const nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); NzColor color; if (!NzPixelFormat::Convert(m_sharedImage->format, nzPixelFormat_RGBA8, pixel, &color.r)) @@ -767,7 +767,7 @@ nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUI EnsureOwnership(); - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); } unsigned int NzImage::GetSize() const @@ -794,7 +794,7 @@ unsigned int NzImage::GetSize() const if (m_sharedImage->type == nzImageType_Cubemap) size *= 6; - return size * NzPixelFormat::GetBPP(m_sharedImage->format); + return size * NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); } unsigned int NzImage::GetSize(nzUInt8 level) const @@ -810,7 +810,7 @@ unsigned int NzImage::GetSize(nzUInt8 level) const return (GetLevelSize(m_sharedImage->width, level)) * (GetLevelSize(m_sharedImage->height, level)) * ((m_sharedImage->type == nzImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)) * - NzPixelFormat::GetBPP(m_sharedImage->format); + NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); } nzImageType NzImage::GetType() const @@ -941,7 +941,7 @@ bool NzImage::SetPixelColor(const NzColor& color, unsigned int x, unsigned int y } #endif - nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBPP(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + nzUInt8* pixel = GetPixelPtr(m_sharedImage->pixels[0], NzPixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, pixel)) { @@ -1029,7 +1029,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z EnsureOwnership(); - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, rect.x, rect.y, z, width, height); unsigned int srcStride = rect.width * bpp; unsigned int dstStride = m_sharedImage->width * bpp; @@ -1086,7 +1086,7 @@ bool NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level) EnsureOwnership(); - nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format); + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, cube.x, cube.y, cube.z, width, height); unsigned int srcStride = cube.width * bpp; unsigned int dstStride = width * bpp; From aaca9349fdcb358b055acfbb19662d0ab1f98184 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 30 Sep 2012 23:11:43 +0200 Subject: [PATCH 23/31] Fixed Matrix4 equality comparison Former-commit-id: cb1e21196c2053138a8d70bc09d39ecbf7b83ba8 --- include/Nazara/Math/Matrix4.hpp | 6 +++++- include/Nazara/Math/Matrix4.inl | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index a8b2cd5cc..51bdaf0ce 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -22,7 +22,8 @@ template class NzVector2; template class NzVector3; template class NzVector4; -template class NzMatrix4 +template +class NzMatrix4 { public: NzMatrix4(); @@ -104,6 +105,9 @@ template class NzMatrix4 NzMatrix4& operator*=(const NzMatrix4& matrix); NzMatrix4& operator*=(T scalar); + bool operator==(const NzMatrix4& mat) const; + bool operator!=(const NzMatrix4& mat) const; + static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); static NzMatrix4 Identity(); diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 5dbad7f42..3d6d30f7c 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -724,6 +724,28 @@ NzMatrix4& NzMatrix4::operator*=(T scalar) return *this; } +template +bool NzMatrix4::operator==(const NzMatrix4& mat) const +{ + if (!m_sharedMatrix) + return mat.m_sharedMatrix == nullptr; + + if (!mat.m_sharedMatrix) + return false; + + for (unsigned int i = 0; i < 16; ++i) + if (!NzNumberEquals((&m_sharedMatrix->m11)[i])) + return false; + + return true; +} + +template +bool NzMatrix4::operator!=(const NzMatrix4& mat) const +{ + return !operator==(mat); +} + template NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) { From 07e949404c5317f15aa587185eb342c3226fc9e7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 1 Oct 2012 00:57:32 +0200 Subject: [PATCH 24/31] Added NzStream and stream options Former-commit-id: d2c69b12f34fffff4d412111e7af7cc4dbb638a8 --- include/Nazara/Core/Enums.hpp | 7 ++++++ include/Nazara/Core/File.hpp | 1 - include/Nazara/Core/InputStream.hpp | 6 ++--- include/Nazara/Core/Stream.hpp | 28 +++++++++++++++++++++++ src/Nazara/Core/File.cpp | 35 +++++++---------------------- src/Nazara/Core/InputStream.cpp | 3 +++ src/Nazara/Core/Stream.cpp | 18 +++++++++++++++ 7 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 include/Nazara/Core/Stream.hpp create mode 100644 src/Nazara/Core/Stream.cpp diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 9dcd77593..b3bb1bb2e 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -27,4 +27,11 @@ enum nzErrorType nzErrorType_Max = nzErrorType_Warning }; +enum nzStreamOptionFlags +{ + nzStreamOption_None = 0x0, + + nzStreamOption_Text = 0x1 +}; + #endif // NAZARA_ENUMS_CORE_HPP diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 1f36f99f6..bcab9c24f 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -72,7 +72,6 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable NzString GetFileName() const; time_t GetLastAccessTime() const; time_t GetLastWriteTime() const; - NzString GetLine(unsigned int lineSize = 0) override; nzUInt64 GetSize() const; bool IsOpen() const; diff --git a/include/Nazara/Core/InputStream.hpp b/include/Nazara/Core/InputStream.hpp index cc2507314..4c99311ff 100644 --- a/include/Nazara/Core/InputStream.hpp +++ b/include/Nazara/Core/InputStream.hpp @@ -8,23 +8,21 @@ #define NAZARA_INPUTSTREAM_HPP #include +#include class NzString; -class NzInputStream +class NAZARA_API NzInputStream : public NzStream { public: virtual ~NzInputStream(); virtual bool EndOfStream() const = 0; - virtual nzUInt64 GetCursorPos() const = 0; virtual NzString GetLine(unsigned int lineSize = 0); virtual nzUInt64 GetSize() const = 0; virtual std::size_t Read(void* buffer, std::size_t size) = 0; - - virtual bool SetCursorPos(nzUInt64 offset) = 0; }; #endif // NAZARA_INPUTSTREAM_HPP diff --git a/include/Nazara/Core/Stream.hpp b/include/Nazara/Core/Stream.hpp new file mode 100644 index 000000000..ef67c337b --- /dev/null +++ b/include/Nazara/Core/Stream.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_STREAM_HPP +#define NAZARA_STREAM_HPP + +#include +#include + +class NAZARA_API NzStream +{ + public: + virtual ~NzStream(); + + virtual nzUInt64 GetCursorPos() const = 0; + unsigned int GetStreamOptions() const; + + virtual bool SetCursorPos(nzUInt64 offset) = 0; + void SetStreamOptions(unsigned int options); + + protected: + unsigned int m_streamOptions; +}; + +#endif // NAZARA_STREAM_HPP diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 5a2148569..0325444b8 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -193,31 +193,6 @@ time_t NzFile::GetLastWriteTime() const return GetLastWriteTime(m_filePath); } -NzString NzFile::GetLine(unsigned int lineSize) -{ - NazaraLock(m_mutex) - - #if NAZARA_CORE_SAFE - if (!IsOpen()) - { - NazaraError("File not opened"); - return NzString(); - } - - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) - { - NazaraError("File not opened with read access"); - return NzString(); - } - #endif - - NzString line = NzInputStream::GetLine(lineSize); - if (m_openMode & Text && !m_impl->EndOfFile() && line.EndsWith('\r')) - line.Resize(-1); - - return line; -} - nzUInt64 NzFile::GetSize() const { NazaraLock(m_mutex) @@ -272,7 +247,7 @@ std::size_t NzFile::Read(void* buffer, std::size_t typeSize, unsigned int count) if (byteRead == 0) return 0; - if (buffer && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness() && typeSize != 1) + if (buffer && typeSize != 1 && m_endianness != nzEndianness_Unknown && m_endianness != NzGetPlatformEndianness()) { unsigned int typeCount = byteRead/typeSize; for (unsigned int i = 0; i < typeCount; ++i) @@ -323,6 +298,9 @@ bool NzFile::Open(unsigned long openMode) return false; } + if (m_openMode & Text) + m_streamOptions &= nzStreamOption_Text; + return true; } @@ -410,6 +388,9 @@ bool NzFile::SetOpenMode(unsigned int openMode) delete m_impl; m_impl = impl; + + if (m_openMode & Text) + m_streamOptions &= nzStreamOption_Text; } m_openMode = openMode; @@ -423,7 +404,7 @@ bool NzFile::Write(const NzString& string) NzString temp(string); - if (m_openMode & Text) + if (m_streamOptions & nzStreamOption_Text) { #if defined(NAZARA_PLATFORM_WINDOWS) temp.Replace("\n", "\r\n"); diff --git a/src/Nazara/Core/InputStream.cpp b/src/Nazara/Core/InputStream.cpp index 76e4d46ea..7049a080e 100644 --- a/src/Nazara/Core/InputStream.cpp +++ b/src/Nazara/Core/InputStream.cpp @@ -45,5 +45,8 @@ NzString NzInputStream::GetLine(unsigned int lineSize) } } + if (m_streamOptions & nzStreamOption_Text && !EndOfStream() && line.EndsWith('\r')) + line.Resize(-1); + return line; } diff --git a/src/Nazara/Core/Stream.cpp b/src/Nazara/Core/Stream.cpp new file mode 100644 index 000000000..37cb56e2f --- /dev/null +++ b/src/Nazara/Core/Stream.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2012 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +NzStream::~NzStream() = default; + +unsigned int NzStream::GetStreamOptions() const +{ + return m_streamOptions; +} + +void NzStream::SetStreamOptions(unsigned int options) +{ + m_streamOptions = options; +} From 516bf7b3b9e0b90e6967f5dd06fd3d625db8cdc3 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 09:22:59 +0200 Subject: [PATCH 25/31] Fixed NzStream options Former-commit-id: 1479dd2bbed9587af7b9b7c165192709478f30e1 --- include/Nazara/Core/Stream.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Core/Stream.hpp b/include/Nazara/Core/Stream.hpp index ef67c337b..79e9f88a7 100644 --- a/include/Nazara/Core/Stream.hpp +++ b/include/Nazara/Core/Stream.hpp @@ -13,6 +13,7 @@ class NAZARA_API NzStream { public: + NzStream() = default; virtual ~NzStream(); virtual nzUInt64 GetCursorPos() const = 0; @@ -22,7 +23,7 @@ class NAZARA_API NzStream void SetStreamOptions(unsigned int options); protected: - unsigned int m_streamOptions; + unsigned int m_streamOptions = 0; }; #endif // NAZARA_STREAM_HPP From b219b19710a6124527771f3908087061a5999208 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 09:23:39 +0200 Subject: [PATCH 26/31] Fixed Tuple.inl including Utility debug headers Former-commit-id: 259b43f54669c6b58e04ee16719df73b441b72dd --- include/Nazara/Core/Tuple.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Core/Tuple.inl b/include/Nazara/Core/Tuple.inl index b4d4e801c..ed786e34c 100644 --- a/include/Nazara/Core/Tuple.inl +++ b/include/Nazara/Core/Tuple.inl @@ -6,7 +6,7 @@ // Merci à Ryan "FullMetal Alchemist" Lahfa // Merci aussi à Freedom de siteduzero.com -#include +#include template struct NzTupleUnpack @@ -34,4 +34,4 @@ void NzUnpackTuple(F func, const std::tuple& t) NzTupleUnpack()(func, t); } -#include +#include From 7bab3d94435d59b80957b91187373fc8f759f4fd Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 09:32:55 +0200 Subject: [PATCH 27/31] Cleaned code Former-commit-id: 65b235b0c8326e060ec7032bb2a153e22518a25a --- include/Nazara/Math/Basic.hpp | 4 -- include/Nazara/Math/Basic.inl | 46 ++++----------------- include/Nazara/Prerequesites.hpp | 8 ++-- include/Nazara/Renderer/Context.hpp | 2 +- src/Nazara/Audio/Loaders/sndfile/Loader.cpp | 6 +-- src/Nazara/Core/Win32/FileImpl.cpp | 12 +++--- src/Nazara/Renderer/Context.cpp | 35 +++++++--------- src/Nazara/Renderer/Renderer.cpp | 19 +++++---- src/Nazara/Utility/Buffer.cpp | 3 +- 9 files changed, 48 insertions(+), 87 deletions(-) diff --git a/include/Nazara/Math/Basic.hpp b/include/Nazara/Math/Basic.hpp index 572afa5e3..47d344c7b 100644 --- a/include/Nazara/Math/Basic.hpp +++ b/include/Nazara/Math/Basic.hpp @@ -24,12 +24,8 @@ template T NzDegrees(T degrees); template T NzDegreeToRadian(T degrees); inline unsigned int NzGetNumberLength(signed char number); inline unsigned int NzGetNumberLength(unsigned char number); -inline unsigned int NzGetNumberLength(short number); -inline unsigned int NzGetNumberLength(unsigned short number); inline unsigned int NzGetNumberLength(int number); inline unsigned int NzGetNumberLength(unsigned int number); -inline unsigned int NzGetNumberLength(long number); -inline unsigned int NzGetNumberLength(unsigned long number); inline unsigned int NzGetNumberLength(long long number); inline unsigned int NzGetNumberLength(unsigned long long number); inline unsigned int NzGetNumberLength(float number, nzUInt8 precision = NAZARA_CORE_REAL_PRECISION); diff --git a/include/Nazara/Math/Basic.inl b/include/Nazara/Math/Basic.inl index 875ca00f8..457920a5a 100644 --- a/include/Nazara/Math/Basic.inl +++ b/include/Nazara/Math/Basic.inl @@ -52,9 +52,6 @@ T NzDegreeToRadian(T degrees) unsigned int NzGetNumberLength(signed char number) { - if (number == 0) - return 1; - // Le standard définit le char comme étant codé sur un octet static_assert(sizeof(number) == 1, "Signed char must be one byte-sized"); @@ -62,15 +59,18 @@ unsigned int NzGetNumberLength(signed char number) return 3; else if (number >= 10) return 2; - else + else if (number >= 0) return 1; + else if (number > -10) + return 2; + else if (number > -100) + return 3; + else + return 4; } unsigned int NzGetNumberLength(unsigned char number) { - if (number == 0) - return 1; - // Le standard définit le char comme étant codé sur un octet static_assert(sizeof(number) == 1, "Signed char must be one byte-sized"); @@ -82,22 +82,6 @@ unsigned int NzGetNumberLength(unsigned char number) return 1; } -unsigned int NzGetNumberLength(short number) -{ - if (number == 0) - return 1; - - return static_cast(std::log10(std::abs(number)))+(number < 0 ? 2 : 1); -} - -unsigned int NzGetNumberLength(unsigned short number) -{ - if (number == 0) - return 1; - - return static_cast(std::log10(number))+1; -} - unsigned int NzGetNumberLength(int number) { if (number == 0) @@ -114,22 +98,6 @@ unsigned int NzGetNumberLength(unsigned int number) return static_cast(std::log10(number))+1; } -unsigned int NzGetNumberLength(long number) -{ - if (number == 0) - return 1; - - return static_cast(std::log10(std::abs(number)))+(number < 0 ? 2 : 1); -} - -unsigned int NzGetNumberLength(unsigned long number) -{ - if (number == 0) - return 1; - - return static_cast(std::log10(number))+1; -} - unsigned int NzGetNumberLength(long long number) { if (number == 0) diff --git a/include/Nazara/Prerequesites.hpp b/include/Nazara/Prerequesites.hpp index f397ca247..facdf9b50 100644 --- a/include/Nazara/Prerequesites.hpp +++ b/include/Nazara/Prerequesites.hpp @@ -63,6 +63,8 @@ #define NazaraUnused(a) (void) a #if defined(_WIN32) || defined(__WIN32__) + #define NAZARA_PLATFORM_WINDOWS + #if !defined(NAZARA_STATIC) #ifdef NAZARA_BUILD #define NAZARA_API __declspec(dllexport) @@ -72,7 +74,6 @@ #else #define NAZARA_API #endif - #define NAZARA_PLATFORM_WINDOWS // Des defines pour le header Windows #if defined(NAZARA_BUILD) // Pour ne pas entrer en conflit avec les defines de l'application ou d'une autre bibliothèque @@ -102,13 +103,14 @@ #endif #endif #elif defined(__linux__) || defined(linux) || defined(__linux) + #define NAZARA_PLATFORM_LINUX + #define NAZARA_PLATFORM_POSIX + #if !defined(NAZARA_STATIC) && defined(NAZARA_COMPILER_GCC) #define NAZARA_API __attribute__((visibility ("default"))) #else #define NAZARA_API #endif - #define NAZARA_PLATFORM_LINUX - #define NAZARA_PLATFORM_POSIX /*#elif defined(__APPLE__) || defined(macintosh) || defined(Macintosh) #define NAZARA_API #define NAZARA_PLATFORM_MACOS diff --git a/include/Nazara/Renderer/Context.hpp b/include/Nazara/Renderer/Context.hpp index cd368ac94..14d3263e3 100644 --- a/include/Nazara/Renderer/Context.hpp +++ b/include/Nazara/Renderer/Context.hpp @@ -39,7 +39,7 @@ class NAZARA_API NzContext : public NzResource private: NzContextParameters m_parameters; - NzContextImpl* m_impl; + NzContextImpl* m_impl = nullptr; static NzContext* s_reference; }; diff --git a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp index 3e0c73c51..35a4b42d8 100644 --- a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp +++ b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp @@ -17,19 +17,19 @@ namespace { sf_count_t GetSize(void* user_data) { - NzInputStream* stream = reinterpret_cast(user_data); + NzInputStream* stream = static_cast(user_data); return stream->GetSize(); } sf_count_t Read(void* ptr, sf_count_t count, void* user_data) { - NzInputStream* stream = reinterpret_cast(user_data); + NzInputStream* stream = static_cast(user_data); return stream->Read(ptr, count); } sf_count_t Seek(sf_count_t offset, int whence, void* user_data) { - NzInputStream* stream = reinterpret_cast(user_data); + NzInputStream* stream = static_cast(user_data); switch (whence) { case SEEK_CUR: diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index 56ad64855..bf927a6f0 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme Leclercq +// Copyright (C) 2012 Jérôme Leclercq // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -113,11 +113,11 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size) m_endOfFileUpdated = true; return read; - ///FIXME: D'après la documenation, read vaut 0 si ReadFile atteint la fin du fichier - /// D'après les tests, ce n'est pas le cas, la taille lue est inférieure à la taille en argument, mais pas nulle - /// Peut-être ais-je mal compris la documentation - /// Le correctif (dans le cas où la doc serait vraie) est commenté en début de fonction et après ce commentaire - /// Il est cependant plus lourd, et ne fonctionne pas avec le comportement observé de la fonction + ///FIXME: D'après la documentation, read vaut 0 si ReadFile atteint la fin du fichier + /// D'après les tests, ce n'est pas le cas, la taille lue est inférieure à la taille en argument, mais pas nulle + /// Peut-être ais-je mal compris la documentation + /// Le correctif (dans le cas où la doc serait vraie) est commenté en début de fonction et après ce commentaire + /// Il est cependant plus lourd, et ne fonctionne pas avec le comportement observé de la fonction /* if (read == 0) { diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index 813bf66ef..fc38cfb5f 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -37,27 +37,27 @@ namespace ss << "\n-Source: "; switch (source) { - case GL_DEBUG_SOURCE_API_ARB: + case GL_DEBUG_SOURCE_API: ss << "OpenGL"; break; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: ss << "Operating system"; break; - case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: + case GL_DEBUG_SOURCE_SHADER_COMPILER: ss << "Shader compiler"; break; - case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: + case GL_DEBUG_SOURCE_THIRD_PARTY: ss << "Shader compiler"; break; - case GL_DEBUG_SOURCE_APPLICATION_ARB: + case GL_DEBUG_SOURCE_APPLICATION: ss << "Application"; break; - case GL_DEBUG_SOURCE_OTHER_ARB: + case GL_DEBUG_SOURCE_OTHER: ss << "Other"; break; @@ -71,27 +71,27 @@ namespace ss << "-Type: "; switch (type) { - case GL_DEBUG_TYPE_ERROR_ARB: + case GL_DEBUG_TYPE_ERROR: ss << "Error"; break; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: ss << "Deprecated behavior"; break; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: ss << "Undefined behavior"; break; - case GL_DEBUG_TYPE_PORTABILITY_ARB: + case GL_DEBUG_TYPE_PORTABILITY: ss << "Portability"; break; - case GL_DEBUG_TYPE_PERFORMANCE_ARB: + case GL_DEBUG_TYPE_PERFORMANCE: ss << "Performance"; break; - case GL_DEBUG_TYPE_OTHER_ARB: + case GL_DEBUG_TYPE_OTHER: ss << "Other"; break; @@ -105,15 +105,15 @@ namespace ss << "-Severity: "; switch (severity) { - case GL_DEBUG_SEVERITY_HIGH_ARB: + case GL_DEBUG_SEVERITY_HIGH: ss << "High"; break; - case GL_DEBUG_SEVERITY_MEDIUM_ARB: + case GL_DEBUG_SEVERITY_MEDIUM: ss << "Medium"; break; - case GL_DEBUG_SEVERITY_LOW_ARB: + case GL_DEBUG_SEVERITY_LOW: ss << "Low"; break; @@ -130,11 +130,6 @@ namespace } } -NzContext::NzContext() : -m_impl(nullptr) -{ -} - NzContext::~NzContext() { Destroy(); diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index d31a5284f..a1c280493 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -616,8 +616,13 @@ bool NzRenderer::SetTarget(NzRenderTarget* target) if (s_target == target) return true; - if (s_target && !s_target->HasContext()) - s_target->Desactivate(); + if (s_target) + { + if (!s_target->HasContext()) + s_target->Desactivate(); + + s_target = nullptr; + } if (target) { @@ -629,18 +634,14 @@ bool NzRenderer::SetTarget(NzRenderTarget* target) } #endif - if (target->Activate()) - s_target = target; - else + if (!target->Activate()) { NazaraError("Failed to activate target"); - s_target = nullptr; - return false; } + + s_target = target; } - else - s_target = nullptr; return true; } diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index 1d3e6c9f0..728d4be45 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -292,10 +292,9 @@ bool NzBuffer::SetStorage(nzBufferStorage storage) m_impl->Unmap(); m_impl->Destroy(); - delete m_impl; - m_impl = impl; + m_impl = impl; m_storage = storage; return true; From 10fc3868652e4e503ae76102df9ca5b739d6b6bc Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 09:33:54 +0200 Subject: [PATCH 28/31] Added VertexDeclaration::HasElement Former-commit-id: 30dccfba56bba0e56c08da79c3fde3bdf94119cb --- include/Nazara/Utility/VertexDeclaration.hpp | 5 +++ src/Nazara/Utility/VertexDeclaration.cpp | 45 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 0bb4f7f18..f4db3bae2 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -2,6 +2,8 @@ // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp +#pragma once + #ifndef NAZARA_VERTEXDECLARATION_HPP #define NAZARA_VERTEXDECLARATION_HPP @@ -39,6 +41,9 @@ class NAZARA_API NzVertexDeclaration : public NzResource unsigned int GetElementCount(nzElementStream stream) const; unsigned int GetStride(nzElementStream stream) const; + bool HasElement(unsigned int i) const; + bool HasElement(nzElementStream stream, unsigned int i) const; + bool HasElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const; bool HasStream(nzElementStream stream) const; bool IsValid() const; diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index e4d24b0ec..6b5ec7e2f 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -244,16 +244,34 @@ const NzVertexElement* NzVertexDeclaration::GetElement(nzElementStream stream, n #endif int elementPos = m_sharedImpl->elementPos[stream][usage]; + + #if NAZARA_UTILITY_SAFE if (elementPos == -1) + { + NazaraError("Element not found"); return nullptr; + } + #endif elementPos += usageIndex; + + #if NAZARA_UTILITY_SAFE if (static_cast(elementPos) >= m_sharedImpl->elements.size()) + { + NazaraError("Element not found"); return nullptr; + } + #endif NzVertexElement& element = m_sharedImpl->elements[elementPos]; + + #if NAZARA_UTILITY_SAFE if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) + { + NazaraError("Element not found"); return nullptr; + } + #endif return &element; } @@ -318,6 +336,33 @@ unsigned int NzVertexDeclaration::GetStride(nzElementStream stream) const return m_sharedImpl->stride[stream]; } +bool NzVertexDeclaration::HasElement(unsigned int i) const +{ + return i < m_sharedImpl->elements.size(); +} + +bool NzVertexDeclaration::HasElement(nzElementStream stream, unsigned int i) const +{ + return i < GetElementCount(stream); +} + +bool NzVertexDeclaration::HasElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex) const +{ + int elementPos = m_sharedImpl->elementPos[stream][usage]; + if (elementPos == -1) + return false; + + elementPos += usageIndex; + if (static_cast(elementPos) >= m_sharedImpl->elements.size()) + return false; + + NzVertexElement& element = m_sharedImpl->elements[elementPos]; + if (element.stream != stream || element.usage != usage || element.usageIndex != usageIndex) + return false; + + return true; +} + bool NzVertexDeclaration::HasStream(nzElementStream stream) const { #if NAZARA_UTILITY_SAFE From 41bfaf694124b9039e006e3a6ec0280730d1117e Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 09:34:29 +0200 Subject: [PATCH 29/31] Fixed String::Simplified() Former-commit-id: 6193b710728d0ff1ab0387428d65f0ce5bebd115 --- src/Nazara/Core/String.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index 339e19976..7e5e26cc4 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -3318,6 +3318,9 @@ NzString NzString::Reversed() const NzString NzString::Simplified(nzUInt32 flags) const { + if (m_sharedString->size == 0) + return NzString(); + char* str = new char[m_sharedString->size+1]; char* p = str; From defbb0f1a698c20ec40789730e7ac7cf41f2963a Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 09:36:56 +0200 Subject: [PATCH 30/31] Updated examples It is now possible to pause the animation in AnimatedMesh demo with the P key Former-commit-id: 98d1b5196007dd524e2257157d6e7fd3171fb070 --- examples/AnimatedMesh/main.cpp | 7 ++++++- examples/DopplerEffect/main.cpp | 13 +++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/AnimatedMesh/main.cpp b/examples/AnimatedMesh/main.cpp index f90cbd866..ab14bb62a 100644 --- a/examples/AnimatedMesh/main.cpp +++ b/examples/AnimatedMesh/main.cpp @@ -247,6 +247,7 @@ int main() // Quelques variables bool camMode = true; + bool paused = false; bool thirdPerson = false; bool windowOpen = true; @@ -338,6 +339,8 @@ int main() } else if (event.key.code == NzKeyboard::Escape) windowOpen = false; + else if (event.key.code == NzKeyboard::P) + paused = !paused; break; @@ -433,7 +436,9 @@ int main() drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos); // Animation - AnimateModel(drfreak, elapsedTime); + if (!paused) + AnimateModel(drfreak, elapsedTime); + updateClock.Restart(); } diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp index ef4bcf936..5176a8330 100644 --- a/examples/DopplerEffect/main.cpp +++ b/examples/DopplerEffect/main.cpp @@ -1,12 +1,13 @@ #include #include #include // Thread::Sleep +#include #include #include int main() { - // NzKeyboard ne nécessite pas l'initialisation d'Utility + // NzKeyboard ne nécessite pas l'initialisation du module Utilitaire NzInitializer audio; if (!audio) { @@ -32,11 +33,11 @@ int main() // On fait en sorte de répéter le son sound.EnableLooping(true); - // La source du son se situe en (50, 0, 5) - sound.SetPosition(50, 0, 5); + // La source du son se situe vers la gauche (Et un peu en avant) + sound.SetPosition(NzVector3f::Left()*50.f + NzVector3f::Forward()*5.); - // Et possède une vitesse de -10 par seconde sur l'axe X - sound.SetVelocity(-10, 0, 0); + // Et possède une vitesse de 10 par seconde vers la droite + sound.SetVelocity(NzVector3f::Left()*-10.f); // On joue le son sound.Play(); @@ -58,7 +59,7 @@ int main() std::cout << "Sound position: " << pos << std::endl; // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap - if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) + if (pos.x > NzVector3f::Left().x*-50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape)) sound.Stop(); // On arrête le son (Stoppant également la boucle) clock.Restart(); From 34c1479a30f02270d557e872a5c3c35da306a4ae Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 4 Oct 2012 23:32:24 +0200 Subject: [PATCH 31/31] Renamed "one-library" build option to "united" Former-commit-id: 0578d236b4e209f1e9b35ae4302c040322e15ee8 --- build/scripts/module/audio.lua | 4 ++-- build/scripts/module/core.lua | 2 +- build/scripts/module/noise.lua | 4 ++-- build/scripts/module/renderer.lua | 4 ++-- build/scripts/module/utility.lua | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build/scripts/module/audio.lua b/build/scripts/module/audio.lua index c46087c86..07281d45f 100644 --- a/build/scripts/module/audio.lua +++ b/build/scripts/module/audio.lua @@ -1,4 +1,4 @@ -if (not _OPTIONS["one-library"]) then +if (not _OPTIONS["united"]) then project "NazaraAudio" end @@ -19,7 +19,7 @@ else -- Link posix ? end -if (_OPTIONS["one-library"]) then +if (_OPTIONS["united"]) then excludes "../src/Nazara/Audio/Debug/Leaks.cpp" else configuration "DebugStatic" diff --git a/build/scripts/module/core.lua b/build/scripts/module/core.lua index df08604da..049d27ded 100644 --- a/build/scripts/module/core.lua +++ b/build/scripts/module/core.lua @@ -1,4 +1,4 @@ -if (not _OPTIONS["one-library"]) then +if (not _OPTIONS["united"]) then project "NazaraCore" end diff --git a/build/scripts/module/noise.lua b/build/scripts/module/noise.lua index 9fb0b9f71..5a969041b 100644 --- a/build/scripts/module/noise.lua +++ b/build/scripts/module/noise.lua @@ -1,4 +1,4 @@ -if (not _OPTIONS["one-library"]) then +if (not _OPTIONS["united"]) then project "NazaraNoise" end @@ -16,7 +16,7 @@ else excludes { "../src/Nazara/Noise/Win32/*.hpp", "../src/Nazara/Noise/Win32/*.cpp" } end -if (_OPTIONS["one-library"]) then +if (_OPTIONS["united"]) then excludes "../src/Nazara/Noise/Debug/Leaks.cpp" else configuration "DebugStatic" diff --git a/build/scripts/module/renderer.lua b/build/scripts/module/renderer.lua index 09a1b260e..83eeecd57 100644 --- a/build/scripts/module/renderer.lua +++ b/build/scripts/module/renderer.lua @@ -1,4 +1,4 @@ -if (not _OPTIONS["one-library"]) then +if (not _OPTIONS["united"]) then project "NazaraRenderer" end @@ -21,7 +21,7 @@ else excludes { "../src/Nazara/Renderer/Win32/*.hpp", "../src/Nazara/Renderer/Win32/*.cpp" } end -if (_OPTIONS["one-library"]) then +if (_OPTIONS["united"]) then excludes "../src/Nazara/Renderer/Debug/Leaks.cpp" else configuration "DebugStatic" diff --git a/build/scripts/module/utility.lua b/build/scripts/module/utility.lua index 097ed0915..87ca1167e 100644 --- a/build/scripts/module/utility.lua +++ b/build/scripts/module/utility.lua @@ -1,4 +1,4 @@ -if (not _OPTIONS["one-library"]) then +if (not _OPTIONS["united"]) then project "NazaraUtility" end @@ -20,7 +20,7 @@ else excludes { "../src/Nazara/Utility/Win32/*.hpp", "../src/Nazara/Utility/Win32/*.cpp" } end -if (_OPTIONS["one-library"]) then +if (_OPTIONS["united"]) then excludes "../src/Nazara/Utility/Debug/Leaks.cpp" else configuration "DebugStatic"