Add new Renderer architecture (far from complete)
Former-commit-id: 52226793d7a087dfe0523315d3303934daffee49 [formerly 9de1c04df6b371f861a2eee8bba38902ee5041cd] [formerly ecd3099df5498722f6390447f40bd3907b8e40c4 [formerly 3076df585565fc9759ab3e718270f2e5ef620840]] Former-commit-id: 92d52f967d0b088d1271afef26069e08cacd6b0f [formerly 5fe27e2ead104278951c772c2121a7b677f88d4d] Former-commit-id: fb6c2456d8edd3ec022d5d953f79fecdd4f2b8f4
This commit is contained in:
parent
d7a10031d7
commit
bdedd05032
|
|
@ -0,0 +1,50 @@
|
|||
TOOL.Name = "VulkanRenderer"
|
||||
|
||||
TOOL.ClientOnly = true
|
||||
|
||||
TOOL.Kind = "Library"
|
||||
TOOL.TargetDirectory = "../lib"
|
||||
|
||||
TOOL.Defines = {
|
||||
"NAZARA_BUILD",
|
||||
"NAZARA_VULKANRENDERER_BUILD"
|
||||
}
|
||||
|
||||
TOOL.Includes = {
|
||||
"../include",
|
||||
"../src/",
|
||||
"../extlibs/include"
|
||||
}
|
||||
|
||||
TOOL.Files = {
|
||||
"../include/Nazara/VulkanRenderer/**.hpp",
|
||||
"../include/Nazara/VulkanRenderer/**.inl",
|
||||
"../src/Nazara/VulkanRenderer/**.hpp",
|
||||
"../src/Nazara/VulkanRenderer/**.inl",
|
||||
"../src/Nazara/VulkanRenderer/**.cpp"
|
||||
}
|
||||
|
||||
TOOL.Libraries = {
|
||||
"NazaraCore",
|
||||
"NazaraRenderer",
|
||||
"NazaraUtility"
|
||||
}
|
||||
|
||||
TOOL.OsDefines.Linux = {
|
||||
-- "VK_USE_PLATFORM_MIR_KHR",
|
||||
"VK_USE_PLATFORM_XCB_KHR"
|
||||
-- "VK_USE_PLATFORM_XLIB_KHR",
|
||||
-- "VK_USE_PLATFORM_WAYLAND_KHR"
|
||||
}
|
||||
|
||||
TOOL.OsDefines.BSD = TOOL.OsDefines.Linux
|
||||
TOOL.OsDefines.Solaris = TOOL.OsDefines.Linux
|
||||
|
||||
TOOL.OsDefines.Windows = {
|
||||
"VK_USE_PLATFORM_WIN32_KHR"
|
||||
}
|
||||
|
||||
TOOL.OsFiles.Windows = {
|
||||
"../src/Nazara/VulkanRenderer/Win32/**.hpp",
|
||||
"../src/Nazara/VulkanRenderer/Win32/**.cpp"
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
// Copyright (C) 2015 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
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Context;
|
||||
|
||||
using ContextConstRef = ObjectRef<const Context>;
|
||||
using ContextLibrary = ObjectLibrary<Context>;
|
||||
using ContextRef = ObjectRef<Context>;
|
||||
|
||||
class ContextImpl;
|
||||
|
||||
class NAZARA_RENDERER_API Context : public RefCounted
|
||||
{
|
||||
friend ContextImpl;
|
||||
friend ContextLibrary;
|
||||
friend class OpenGL;
|
||||
|
||||
public:
|
||||
Context() = default;
|
||||
Context(const Context&) = delete;
|
||||
Context(Context&&) = delete;
|
||||
~Context();
|
||||
|
||||
bool Create(const ContextParameters& parameters = ContextParameters());
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
const ContextParameters& GetParameters() const;
|
||||
|
||||
bool IsActive() const;
|
||||
|
||||
bool SetActive(bool active) const;
|
||||
void SwapBuffers();
|
||||
|
||||
Context& operator=(const Context&) = delete;
|
||||
Context& operator=(Context&&) = delete;
|
||||
|
||||
static bool EnsureContext();
|
||||
|
||||
static const Context* GetCurrent();
|
||||
static const Context* GetReference();
|
||||
static const Context* GetThreadContext();
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnContextDestroy, const Context* /*context*/);
|
||||
NazaraSignal(OnContextRelease, const Context* /*context*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
ContextParameters m_parameters;
|
||||
ContextImpl* m_impl = nullptr;
|
||||
|
||||
static std::unique_ptr<Context> s_reference;
|
||||
static std::vector<std::unique_ptr<Context>> s_contexts;
|
||||
static ContextLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CONTEXT_HPP
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
// Copyright (C) 2015 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_CONTEXTPARAMETERS_HPP
|
||||
#define NAZARA_CONTEXTPARAMETERS_HPP
|
||||
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderTargetParameters.hpp>
|
||||
#include <Nazara/Utility/VideoMode.hpp>
|
||||
#include <Nazara/Utility/WindowHandle.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Context;
|
||||
|
||||
struct NAZARA_RENDERER_API ContextParameters
|
||||
{
|
||||
ContextParameters(const RenderTargetParameters& parameters = RenderTargetParameters()) :
|
||||
antialiasingLevel(parameters.antialiasingLevel),
|
||||
bitsPerPixel(VideoMode::GetDesktopMode().bitsPerPixel),
|
||||
depthBits(parameters.depthBits),
|
||||
majorVersion(defaultMajorVersion),
|
||||
minorVersion(defaultMinorVersion),
|
||||
stencilBits(parameters.stencilBits),
|
||||
shareContext(defaultShareContext),
|
||||
window(0),
|
||||
compatibilityProfile(defaultCompatibilityProfile),
|
||||
debugMode(defaultDebugMode),
|
||||
doubleBuffered(defaultDoubleBuffered),
|
||||
shared(defaultShared)
|
||||
{
|
||||
}
|
||||
|
||||
UInt8 antialiasingLevel;
|
||||
UInt8 bitsPerPixel;
|
||||
UInt8 depthBits;
|
||||
UInt8 majorVersion;
|
||||
UInt8 minorVersion;
|
||||
UInt8 stencilBits;
|
||||
const Context* shareContext;
|
||||
WindowHandle window;
|
||||
bool compatibilityProfile;
|
||||
bool debugMode;
|
||||
bool doubleBuffered;
|
||||
bool shared;
|
||||
|
||||
static UInt8 defaultMajorVersion;
|
||||
static UInt8 defaultMinorVersion;
|
||||
static const Context* defaultShareContext;
|
||||
static bool defaultCompatibilityProfile;
|
||||
static bool defaultDebugMode;
|
||||
static bool defaultDoubleBuffered;
|
||||
static bool defaultShared;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CONTEXTPARAMETERS_HPP
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (C) 2015 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_DEBUGDRAWER_HPP
|
||||
#define NAZARA_DEBUGDRAWER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/OrientedBox.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Skeleton;
|
||||
|
||||
class NAZARA_RENDERER_API DebugDrawer
|
||||
{
|
||||
public:
|
||||
static void Draw(const BoundingVolumef& volume);
|
||||
static void Draw(const Boxf& box);
|
||||
static void Draw(const Boxi& box);
|
||||
static void Draw(const Boxui& box);
|
||||
static void Draw(const Frustumf& frustum);
|
||||
static void Draw(const OrientedBoxf& orientedBox);
|
||||
static void Draw(const Skeleton* skeleton);
|
||||
static void Draw(const Vector3f& position, float size = 0.1f);
|
||||
static void DrawAxes(const Vector3f& position = Vector3f::Zero(), float size = 1.f);
|
||||
static void DrawBinormals(const StaticMesh* subMesh);
|
||||
static void DrawCone(const Vector3f& origin, const Quaternionf& rotation, float angle, float length);
|
||||
static void DrawLine(const Vector3f& p1, const Vector3f& p2);
|
||||
static void DrawPoints(const Vector3f* ptr, unsigned int pointCount);
|
||||
static void DrawNormals(const StaticMesh* subMesh);
|
||||
static void DrawTangents(const StaticMesh* subMesh);
|
||||
|
||||
static void EnableDepthBuffer(bool depthBuffer);
|
||||
|
||||
static float GetLineWidth();
|
||||
static float GetPointSize();
|
||||
static Color GetPrimaryColor();
|
||||
static Color GetSecondaryColor();
|
||||
|
||||
static bool Initialize();
|
||||
static bool IsDepthBufferEnabled();
|
||||
|
||||
static void SetLineWidth(float width);
|
||||
static void SetPointSize(float size);
|
||||
static void SetPrimaryColor(const Color& color);
|
||||
static void SetSecondaryColor(const Color& color);
|
||||
|
||||
static void Uninitialize();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DEBUG_DRAWER_HPP
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// Copyright (C) 2016 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
|
||||
|
||||
|
|
@ -9,114 +9,29 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
enum AttachmentPoint
|
||||
enum RenderAPI
|
||||
{
|
||||
AttachmentPoint_Color,
|
||||
AttachmentPoint_Depth,
|
||||
AttachmentPoint_DepthStencil,
|
||||
AttachmentPoint_Stencil,
|
||||
RenderAPI_Direct3D, ///< Microsoft Render API, only works on MS platforms
|
||||
RenderAPI_Mantle, ///< AMD Render API, Vulkan predecessor, only works on AMD GPUs
|
||||
RenderAPI_Metal, ///< Apple Render API, only works on OS X platforms
|
||||
RenderAPI_OpenGL, ///< Khronos Render API, works on Web/Desktop/Mobile and some consoles
|
||||
RenderAPI_Vulkan, ///< New Khronos Render API, made to replace OpenGL, works on desktop (Windows/Linux) and mobile (Android)
|
||||
|
||||
AttachmentPoint_Max = AttachmentPoint_Stencil
|
||||
RenderAPI_Other, ///< RenderAPI not corresponding to an entry of the enum, or result of a failed query
|
||||
|
||||
RenderAPI_Max = RenderAPI_Other
|
||||
};
|
||||
|
||||
enum GpuQueryCondition
|
||||
enum RenderDeviceType
|
||||
{
|
||||
GpuQueryCondition_Region_NoWait,
|
||||
GpuQueryCondition_Region_Wait,
|
||||
GpuQueryCondition_NoWait,
|
||||
GpuQueryCondition_Wait,
|
||||
RenderDeviceType_Integrated, ///< Hardware-accelerated chipset integrated to a CPU (ex: Intel Graphics HD 4000)
|
||||
RenderDeviceType_Dedicated, ///< Hardware-accelerated GPU (ex: AMD R9 390)
|
||||
RenderDeviceType_Software, ///< Software-renderer
|
||||
RenderDeviceType_Virtual, ///< Proxy renderer relaying instructions to another unknown device
|
||||
|
||||
GpuQueryCondition_Max = GpuQueryCondition_Wait
|
||||
};
|
||||
RenderDeviceType_Unknown, ///< Device type not corresponding to an entry of the enum, or result of a failed query
|
||||
|
||||
enum GpuQueryMode
|
||||
{
|
||||
GpuQueryMode_AnySamplesPassed,
|
||||
GpuQueryMode_AnySamplesPassedConservative,
|
||||
GpuQueryMode_PrimitiveGenerated,
|
||||
GpuQueryMode_SamplesPassed,
|
||||
GpuQueryMode_TimeElapsed,
|
||||
GpuQueryMode_TransformFeedbackPrimitivesWritten,
|
||||
|
||||
GpuQueryMode_Max = GpuQueryMode_TransformFeedbackPrimitivesWritten
|
||||
};
|
||||
|
||||
enum MatrixType
|
||||
{
|
||||
// Matrices de base
|
||||
MatrixType_Projection,
|
||||
MatrixType_View,
|
||||
MatrixType_World,
|
||||
|
||||
// Matrices combinées
|
||||
MatrixType_ViewProj,
|
||||
MatrixType_WorldView,
|
||||
MatrixType_WorldViewProj,
|
||||
|
||||
// Matrice inversées
|
||||
MatrixType_InvProjection,
|
||||
MatrixType_InvView,
|
||||
MatrixType_InvViewProj,
|
||||
MatrixType_InvWorld,
|
||||
MatrixType_InvWorldView,
|
||||
MatrixType_InvWorldViewProj,
|
||||
|
||||
MatrixType_Max = MatrixType_InvWorldViewProj
|
||||
};
|
||||
|
||||
enum PixelBufferType
|
||||
{
|
||||
PixelBufferType_Pack,
|
||||
PixelBufferType_Unpack,
|
||||
|
||||
PixelBufferType_Max = PixelBufferType_Unpack
|
||||
};
|
||||
|
||||
enum RendererCap
|
||||
{
|
||||
RendererCap_AnisotropicFilter,
|
||||
RendererCap_FP64,
|
||||
RendererCap_Instancing,
|
||||
|
||||
RendererCap_Max = RendererCap_Instancing
|
||||
};
|
||||
|
||||
enum RendererBufferFlags
|
||||
{
|
||||
RendererBuffer_Color = 0x1,
|
||||
RendererBuffer_Depth = 0x2,
|
||||
RendererBuffer_Stencil = 0x4,
|
||||
|
||||
RendererBuffer_Max = RendererBuffer_Stencil*2-1
|
||||
};
|
||||
|
||||
enum ShaderUniform
|
||||
{
|
||||
ShaderUniform_InvProjMatrix,
|
||||
ShaderUniform_InvTargetSize,
|
||||
ShaderUniform_InvViewMatrix,
|
||||
ShaderUniform_InvViewProjMatrix,
|
||||
ShaderUniform_InvWorldMatrix,
|
||||
ShaderUniform_InvWorldViewMatrix,
|
||||
ShaderUniform_InvWorldViewProjMatrix,
|
||||
ShaderUniform_ProjMatrix,
|
||||
ShaderUniform_TargetSize,
|
||||
ShaderUniform_ViewMatrix,
|
||||
ShaderUniform_ViewProjMatrix,
|
||||
ShaderUniform_WorldMatrix,
|
||||
ShaderUniform_WorldViewMatrix,
|
||||
ShaderUniform_WorldViewProjMatrix,
|
||||
|
||||
ShaderUniform_Max = ShaderUniform_WorldViewProjMatrix
|
||||
};
|
||||
|
||||
enum ShaderStageType
|
||||
{
|
||||
ShaderStageType_Fragment,
|
||||
ShaderStageType_Geometry,
|
||||
ShaderStageType_Vertex,
|
||||
|
||||
ShaderStageType_Max = ShaderStageType_Vertex
|
||||
RenderDeviceType_Max = RenderDeviceType_Unknown
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright (C) 2015 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_GPUQUERY_HPP
|
||||
#define NAZARA_GPUQUERY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_RENDERER_API GpuQuery
|
||||
{
|
||||
public:
|
||||
GpuQuery();
|
||||
GpuQuery(const GpuQuery&) = delete;
|
||||
GpuQuery(GpuQuery&&) = delete; ///TODO
|
||||
~GpuQuery();
|
||||
|
||||
void Begin(GpuQueryMode mode);
|
||||
void End();
|
||||
|
||||
unsigned int GetResult() const;
|
||||
|
||||
bool IsResultAvailable() const;
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
GpuQuery& operator=(const GpuQuery&) = delete;
|
||||
GpuQuery& operator=(GpuQuery&&) = delete; ///TODO
|
||||
|
||||
static bool IsModeSupported(GpuQueryMode mode);
|
||||
static bool IsSupported();
|
||||
|
||||
private:
|
||||
GpuQueryMode m_mode;
|
||||
unsigned int m_id;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_GPUQUERY_HPP
|
||||
|
|
@ -1,346 +0,0 @@
|
|||
// Copyright (C) 2015 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
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
// Inclusion des headers OpenGL
|
||||
#include <GL3/glcorearb.h>
|
||||
#include <GL3/glext.h>
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#include <GL3/wglext.h>
|
||||
#elif defined(NAZARA_PLATFORM_GLX)
|
||||
namespace GLX
|
||||
{
|
||||
#include <GL/glx.h> // Defined in a namespace to avoid conflict
|
||||
}
|
||||
#include <GL3/glxext.h>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum OpenGLExtension
|
||||
{
|
||||
OpenGLExtension_AnisotropicFilter,
|
||||
OpenGLExtension_DebugOutput,
|
||||
OpenGLExtension_FP64,
|
||||
OpenGLExtension_GetProgramBinary,
|
||||
OpenGLExtension_SeparateShaderObjects,
|
||||
OpenGLExtension_Shader_ImageLoadStore,
|
||||
OpenGLExtension_TextureCompression_s3tc,
|
||||
OpenGLExtension_TextureStorage,
|
||||
|
||||
OpenGLExtension_Max = OpenGLExtension_TextureStorage
|
||||
};
|
||||
|
||||
class Context;
|
||||
class RenderTarget;
|
||||
|
||||
using OpenGLFunc = void (*)();
|
||||
|
||||
class NAZARA_RENDERER_API OpenGL
|
||||
{
|
||||
friend Context;
|
||||
|
||||
public:
|
||||
enum FormatType
|
||||
{
|
||||
FormatType_RenderBuffer,
|
||||
// FormatType_MultisampleTexture,
|
||||
FormatType_Texture
|
||||
};
|
||||
|
||||
struct Format
|
||||
{
|
||||
GLenum dataFormat;
|
||||
GLenum dataType;
|
||||
GLint internalFormat;
|
||||
GLint swizzle[4];
|
||||
};
|
||||
|
||||
OpenGL() = delete;
|
||||
~OpenGL() = delete;
|
||||
|
||||
static void ApplyStates(const RenderStates& states);
|
||||
|
||||
static void BindBuffer(BufferType type, GLuint id);
|
||||
static void BindProgram(GLuint id);
|
||||
static void BindSampler(GLuint unit, GLuint id);
|
||||
static void BindScissorBox(const Recti& scissorBox);
|
||||
static void BindTexture(ImageType type, GLuint id);
|
||||
static void BindTexture(unsigned int textureUnit, ImageType type, GLuint id);
|
||||
static void BindTextureUnit(unsigned int textureUnit);
|
||||
static void BindViewport(const Recti& viewport);
|
||||
|
||||
static void DeleteBuffer(BufferType type, GLuint id);
|
||||
static void DeleteFrameBuffer(const Context* context, GLuint id);
|
||||
static void DeleteProgram(GLuint id);
|
||||
static void DeleteSampler(GLuint id);
|
||||
static void DeleteTexture(GLuint id);
|
||||
static void DeleteVertexArray(const Context* context, GLuint id);
|
||||
|
||||
static GLuint GetCurrentBuffer(BufferType type);
|
||||
static GLuint GetCurrentProgram();
|
||||
static Recti GetCurrentScissorBox();
|
||||
static const RenderTarget* GetCurrentTarget();
|
||||
static GLuint GetCurrentTexture();
|
||||
static GLuint GetCurrentTexture(unsigned int textureUnit);
|
||||
static unsigned int GetCurrentTextureUnit();
|
||||
static Recti GetCurrentViewport();
|
||||
|
||||
static OpenGLFunc GetEntry(const String& entryPoint);
|
||||
static unsigned int GetGLSLVersion();
|
||||
static String GetRendererName();
|
||||
static String GetVendorName();
|
||||
static unsigned int GetVersion();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
static bool IsSupported(OpenGLExtension extension);
|
||||
static bool IsSupported(const String& string);
|
||||
|
||||
static void SetBuffer(BufferType type, GLuint id);
|
||||
static void SetProgram(GLuint id);
|
||||
static void SetScissorBox(const Recti& scissorBox);
|
||||
static void SetTarget(const RenderTarget* renderTarget);
|
||||
static void SetTexture(GLuint id);
|
||||
static void SetTexture(unsigned int textureUnit, GLuint id);
|
||||
static void SetTextureUnit(unsigned int textureUnit);
|
||||
static void SetViewport(const Recti& viewport);
|
||||
|
||||
static bool TranslateFormat(PixelFormatType pixelFormat, Format* format, FormatType target);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
static GLenum Attachment[AttachmentPoint_Max+1];
|
||||
static GLenum BlendFunc[BlendFunc_Max+1];
|
||||
static GLenum BufferLock[BufferAccess_Max+1];
|
||||
static GLenum BufferLockRange[BufferAccess_Max+1];
|
||||
static GLenum BufferTarget[BufferType_Max+1];
|
||||
static GLenum BufferTargetBinding[BufferType_Max+1];
|
||||
static GLenum BufferUsage[BufferUsage_Max+1];
|
||||
static GLenum ComponentType[ComponentType_Max+1];
|
||||
static GLenum CubemapFace[6]; // Un cube possède six faces et ça n'est pas près de changer
|
||||
static GLenum FaceFilling[FaceFilling_Max+1];
|
||||
static GLenum FaceSide[FaceSide_Max+1];
|
||||
static GLenum PrimitiveMode[PrimitiveMode_Max+1];
|
||||
static GLenum QueryCondition[GpuQueryCondition_Max+1];
|
||||
static GLenum QueryMode[GpuQueryMode_Max+1];
|
||||
static GLenum RendererComparison[RendererComparison_Max+1];
|
||||
static GLenum RendererParameter[RendererParameter_Max+1];
|
||||
static GLenum SamplerWrapMode[SamplerWrap_Max+1];
|
||||
static GLenum ShaderStage[ShaderStageType_Max+1];
|
||||
static GLenum StencilOperation[StencilOperation_Max+1];
|
||||
static GLenum TextureTarget[ImageType_Max+1];
|
||||
static GLenum TextureTargetBinding[ImageType_Max+1];
|
||||
static GLenum TextureTargetProxy[ImageType_Max+1];
|
||||
static UInt8 VertexComponentIndex[VertexComponent_Max+1];
|
||||
|
||||
private:
|
||||
static void OnContextChanged(const Context* newContext);
|
||||
static void OnContextDestruction(const Context* context);
|
||||
};
|
||||
|
||||
NAZARA_RENDERER_API extern PFNGLACTIVETEXTUREPROC glActiveTexture;
|
||||
NAZARA_RENDERER_API extern PFNGLATTACHSHADERPROC glAttachShader;
|
||||
NAZARA_RENDERER_API extern PFNGLBEGINCONDITIONALRENDERPROC glBeginConditionalRender;
|
||||
NAZARA_RENDERER_API extern PFNGLBEGINQUERYPROC glBeginQuery;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDBUFFERPROC glBindBuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDFRAGDATALOCATIONPROC glBindFragDataLocation;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDSAMPLERPROC glBindSampler;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDTEXTUREPROC glBindTexture;
|
||||
NAZARA_RENDERER_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
|
||||
NAZARA_RENDERER_API extern PFNGLBLENDFUNCPROC glBlendFunc;
|
||||
NAZARA_RENDERER_API extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
|
||||
NAZARA_RENDERER_API extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLBUFFERDATAPROC glBufferData;
|
||||
NAZARA_RENDERER_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData;
|
||||
NAZARA_RENDERER_API extern PFNGLCLEARPROC glClear;
|
||||
NAZARA_RENDERER_API extern PFNGLCLEARCOLORPROC glClearColor;
|
||||
NAZARA_RENDERER_API extern PFNGLCLEARDEPTHPROC glClearDepth;
|
||||
NAZARA_RENDERER_API extern PFNGLCLEARSTENCILPROC glClearStencil;
|
||||
NAZARA_RENDERER_API extern PFNGLCREATEPROGRAMPROC glCreateProgram;
|
||||
NAZARA_RENDERER_API extern PFNGLCREATESHADERPROC glCreateShader;
|
||||
NAZARA_RENDERER_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
|
||||
NAZARA_RENDERER_API extern PFNGLCOLORMASKPROC glColorMask;
|
||||
NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glCompressedTexSubImage1D;
|
||||
NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glCompressedTexSubImage2D;
|
||||
NAZARA_RENDERER_API extern PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glCompressedTexSubImage3D;
|
||||
NAZARA_RENDERER_API extern PFNGLCULLFACEPROC glCullFace;
|
||||
NAZARA_RENDERER_API extern PFNGLCOMPILESHADERPROC glCompileShader;
|
||||
NAZARA_RENDERER_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D;
|
||||
NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGECALLBACKPROC glDebugMessageCallback;
|
||||
NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGECONTROLPROC glDebugMessageControl;
|
||||
NAZARA_RENDERER_API extern PFNGLDEBUGMESSAGEINSERTPROC glDebugMessageInsert;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETEQUERIESPROC glDeleteQueries;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETESAMPLERSPROC glDeleteSamplers;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETESHADERPROC glDeleteShader;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETETEXTURESPROC glDeleteTextures;
|
||||
NAZARA_RENDERER_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
|
||||
NAZARA_RENDERER_API extern PFNGLDEPTHFUNCPROC glDepthFunc;
|
||||
NAZARA_RENDERER_API extern PFNGLDEPTHMASKPROC glDepthMask;
|
||||
NAZARA_RENDERER_API extern PFNGLDISABLEPROC glDisable;
|
||||
NAZARA_RENDERER_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWARRAYSPROC glDrawArrays;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWBUFFERPROC glDrawBuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWELEMENTSPROC glDrawElements;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced;
|
||||
NAZARA_RENDERER_API extern PFNGLDRAWTEXTURENVPROC glDrawTexture;
|
||||
NAZARA_RENDERER_API extern PFNGLENABLEPROC glEnable;
|
||||
NAZARA_RENDERER_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
|
||||
NAZARA_RENDERER_API extern PFNGLENDCONDITIONALRENDERPROC glEndConditionalRender;
|
||||
NAZARA_RENDERER_API extern PFNGLENDQUERYPROC glEndQuery;
|
||||
NAZARA_RENDERER_API extern PFNGLFLUSHPROC glFlush;
|
||||
NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture;
|
||||
NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
|
||||
NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
|
||||
NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
|
||||
NAZARA_RENDERER_API extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
|
||||
NAZARA_RENDERER_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
|
||||
NAZARA_RENDERER_API extern PFNGLGENBUFFERSPROC glGenBuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLGENQUERIESPROC glGenQueries;
|
||||
NAZARA_RENDERER_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
|
||||
NAZARA_RENDERER_API extern PFNGLGENSAMPLERSPROC glGenSamplers;
|
||||
NAZARA_RENDERER_API extern PFNGLGENTEXTURESPROC glGenTextures;
|
||||
NAZARA_RENDERER_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
|
||||
NAZARA_RENDERER_API extern PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform;
|
||||
NAZARA_RENDERER_API extern PFNGLGETBOOLEANVPROC glGetBooleanv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog;
|
||||
NAZARA_RENDERER_API extern PFNGLGETERRORPROC glGetError;
|
||||
NAZARA_RENDERER_API extern PFNGLGETFLOATVPROC glGetFloatv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETINTEGERVPROC glGetIntegerv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETPROGRAMBINARYPROC glGetProgramBinary;
|
||||
NAZARA_RENDERER_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
||||
NAZARA_RENDERER_API extern PFNGLGETQUERYIVPROC glGetQueryiv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
|
||||
NAZARA_RENDERER_API extern PFNGLGETSHADERIVPROC glGetShaderiv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource;
|
||||
NAZARA_RENDERER_API extern PFNGLGETSTRINGPROC glGetString;
|
||||
NAZARA_RENDERER_API extern PFNGLGETSTRINGIPROC glGetStringi;
|
||||
NAZARA_RENDERER_API extern PFNGLGETTEXIMAGEPROC glGetTexImage;
|
||||
NAZARA_RENDERER_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv;
|
||||
NAZARA_RENDERER_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
||||
NAZARA_RENDERER_API extern PFNGLINVALIDATEBUFFERDATAPROC glInvalidateBufferData;
|
||||
NAZARA_RENDERER_API extern PFNGLISENABLEDPROC glIsEnabled;
|
||||
NAZARA_RENDERER_API extern PFNGLLINEWIDTHPROC glLineWidth;
|
||||
NAZARA_RENDERER_API extern PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||
NAZARA_RENDERER_API extern PFNGLMAPBUFFERPROC glMapBuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange;
|
||||
NAZARA_RENDERER_API extern PFNGLPIXELSTOREIPROC glPixelStorei;
|
||||
NAZARA_RENDERER_API extern PFNGLPOINTSIZEPROC glPointSize;
|
||||
NAZARA_RENDERER_API extern PFNGLPOLYGONMODEPROC glPolygonMode;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMBINARYPROC glProgramBinary;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMPARAMETERIPROC glProgramParameteri;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1DVPROC glProgramUniform1dv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1FVPROC glProgramUniform1fv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM1IVPROC glProgramUniform1iv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM2IVPROC glProgramUniform2iv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM3IVPROC glProgramUniform3iv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORM4IVPROC glProgramUniform4iv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv;
|
||||
NAZARA_RENDERER_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv;
|
||||
NAZARA_RENDERER_API extern PFNGLREADPIXELSPROC glReadPixels;
|
||||
NAZARA_RENDERER_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
|
||||
NAZARA_RENDERER_API extern PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf;
|
||||
NAZARA_RENDERER_API extern PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri;
|
||||
NAZARA_RENDERER_API extern PFNGLSCISSORPROC glScissor;
|
||||
NAZARA_RENDERER_API extern PFNGLSHADERSOURCEPROC glShaderSource;
|
||||
NAZARA_RENDERER_API extern PFNGLSTENCILFUNCPROC glStencilFunc;
|
||||
NAZARA_RENDERER_API extern PFNGLSTENCILFUNCSEPARATEPROC glStencilFuncSeparate;
|
||||
NAZARA_RENDERER_API extern PFNGLSTENCILOPPROC glStencilOp;
|
||||
NAZARA_RENDERER_API extern PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXIMAGE1DPROC glTexImage1D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXIMAGE2DPROC glTexImage2D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXIMAGE3DPROC glTexImage3D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXPARAMETERFPROC glTexParameterf;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXPARAMETERIPROC glTexParameteri;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D;
|
||||
NAZARA_RENDERER_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM1DPROC glUniform1d;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM1FPROC glUniform1f;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM1IPROC glUniform1i;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM1DVPROC glUniform1dv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM1FVPROC glUniform1fv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM1IVPROC glUniform1iv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM2DVPROC glUniform2dv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM2FVPROC glUniform2fv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM2IVPROC glUniform2iv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM3DVPROC glUniform3dv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM3FVPROC glUniform3fv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM3IVPROC glUniform3iv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM4DVPROC glUniform4dv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM4FVPROC glUniform4fv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORM4IVPROC glUniform4iv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
|
||||
NAZARA_RENDERER_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer;
|
||||
NAZARA_RENDERER_API extern PFNGLUSEPROGRAMPROC glUseProgram;
|
||||
NAZARA_RENDERER_API extern PFNGLVALIDATEPROGRAMPROC glValidateProgram;
|
||||
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f;
|
||||
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor;
|
||||
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
|
||||
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer;
|
||||
NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer;
|
||||
NAZARA_RENDERER_API extern PFNGLVIEWPORTPROC glViewport;
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
NAZARA_RENDERER_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat;
|
||||
NAZARA_RENDERER_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs;
|
||||
NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB;
|
||||
NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT;
|
||||
NAZARA_RENDERER_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval;
|
||||
#elif defined(NAZARA_PLATFORM_GLX)
|
||||
NAZARA_RENDERER_API extern GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs;
|
||||
NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
|
||||
NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA;
|
||||
NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERER_OPENGL
|
||||
|
||||
#endif // NAZARA_OPENGL_HPP
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
// Copyright (C) 2015 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_RENDERBUFFER_HPP
|
||||
#define NAZARA_RENDERBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RenderBuffer;
|
||||
|
||||
using RenderBufferConstRef = ObjectRef<const RenderBuffer>;
|
||||
using RenderBufferLibrary = ObjectLibrary<RenderBuffer>;
|
||||
using RenderBufferRef = ObjectRef<RenderBuffer>;
|
||||
|
||||
class NAZARA_RENDERER_API RenderBuffer : public RefCounted
|
||||
{
|
||||
friend RenderBufferLibrary;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
RenderBuffer();
|
||||
RenderBuffer(const RenderBuffer&) = delete;
|
||||
RenderBuffer(RenderBuffer&&) = delete;
|
||||
~RenderBuffer();
|
||||
|
||||
bool Create(PixelFormatType format, unsigned int width, unsigned int height);
|
||||
void Destroy();
|
||||
|
||||
unsigned int GetHeight() const;
|
||||
PixelFormatType GetFormat() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
RenderBuffer& operator=(const RenderBuffer&) = delete;
|
||||
RenderBuffer& operator=(RenderBuffer&&) = delete;
|
||||
|
||||
template<typename... Args> static RenderBufferRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnRenderBufferDestroy, const RenderBuffer* /*renderBuffer*/);
|
||||
NazaraSignal(OnRenderBufferRelease, const RenderBuffer* /*renderBuffer*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
PixelFormatType m_pixelFormat;
|
||||
unsigned int m_height;
|
||||
unsigned int m_id;
|
||||
unsigned int m_width;
|
||||
|
||||
static RenderBufferLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/RenderBuffer.inl>
|
||||
|
||||
#endif // NAZARA_RENDERBUFFER_HPP
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2015 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 <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
RenderBufferRef RenderBuffer::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<RenderBuffer> object(new RenderBuffer(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2016 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_RENDERDEVICE_HPP
|
||||
#define NAZARA_RENDERDEVICE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderDevice
|
||||
{
|
||||
RenderDeviceType type;
|
||||
String name;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERER_HPP
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2016 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_RENDERPIPELINE_HPP
|
||||
#define NAZARA_RENDERPIPELINE_HPP
|
||||
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderPipelineInfo : RenderStates
|
||||
{
|
||||
ShaderConstRef shader;
|
||||
};
|
||||
|
||||
class RenderPipeline
|
||||
{
|
||||
public:
|
||||
inline RenderPipeline();
|
||||
inline ~RenderPipeline();
|
||||
|
||||
inline bool Create(const RenderPipelineInfo& pipelineInfo);
|
||||
inline void Destroy();
|
||||
|
||||
inline const RenderPipelineInfo& GetInfo() const;
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
private:
|
||||
RenderPipelineInfo m_pipelineInfo;
|
||||
bool m_valid;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/RenderPipeline.inl>
|
||||
|
||||
#endif // NAZARA_RENDERPIPELINE_HPP
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
// Copyright (C) 2016 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 <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RenderPipeline::RenderPipeline() :
|
||||
m_valid(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline RenderPipeline::~RenderPipeline()
|
||||
{
|
||||
}
|
||||
|
||||
inline bool RenderPipeline::Create(const RenderPipelineInfo& pipelineInfo)
|
||||
{
|
||||
NazaraAssert(pipelineInfo.shader, "Invalid shader");
|
||||
|
||||
m_pipelineInfo = pipelineInfo;
|
||||
m_valid = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void RenderPipeline::Destroy()
|
||||
{
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
inline const RenderPipelineInfo& RenderPipeline::GetInfo() const
|
||||
{
|
||||
NazaraAssert(m_valid, "Invalid pipeline info");
|
||||
|
||||
return m_pipelineInfo;
|
||||
}
|
||||
|
||||
inline bool RenderPipeline::IsValid() const
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
// Copyright (C) 2015 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_RENDERSTATES_HPP
|
||||
#define NAZARA_RENDERSTATES_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderStates
|
||||
{
|
||||
BlendFunc dstBlend = BlendFunc_Zero;
|
||||
BlendFunc srcBlend = BlendFunc_One;
|
||||
FaceFilling faceFilling = FaceFilling_Fill;
|
||||
FaceSide cullingSide = FaceSide_Back;
|
||||
RendererComparison depthFunc = RendererComparison_Less;
|
||||
|
||||
struct
|
||||
{
|
||||
RendererComparison back = RendererComparison_Always;
|
||||
RendererComparison front = RendererComparison_Always;
|
||||
} stencilCompare;
|
||||
|
||||
struct
|
||||
{
|
||||
UInt32 back = 0xFFFFFFFF;
|
||||
UInt32 front = 0xFFFFFFFF;
|
||||
} stencilCompareMask;
|
||||
|
||||
struct
|
||||
{
|
||||
StencilOperation back = StencilOperation_Keep;
|
||||
StencilOperation front = StencilOperation_Keep;
|
||||
} stencilDepthFail;
|
||||
|
||||
struct
|
||||
{
|
||||
StencilOperation back = StencilOperation_Keep;
|
||||
StencilOperation front = StencilOperation_Keep;
|
||||
} stencilFail;
|
||||
|
||||
struct
|
||||
{
|
||||
StencilOperation back = StencilOperation_Keep;
|
||||
StencilOperation front = StencilOperation_Keep;
|
||||
} stencilPass;
|
||||
|
||||
struct
|
||||
{
|
||||
UInt32 back = 0U;
|
||||
UInt32 front = 0U;
|
||||
} stencilReference;
|
||||
|
||||
struct
|
||||
{
|
||||
UInt32 back = 0xFFFFFFFF;
|
||||
UInt32 front = 0xFFFFFFFF;
|
||||
} stencilWriteMask;
|
||||
|
||||
bool blending = false;
|
||||
bool colorWrite = true;
|
||||
bool depthBuffer = false;
|
||||
bool depthWrite = true;
|
||||
bool faceCulling = false;
|
||||
bool scissorTest = false;
|
||||
bool stencilTest = false;
|
||||
|
||||
float lineWidth = 1.f;
|
||||
float pointSize = 1.f;
|
||||
};
|
||||
|
||||
inline bool operator==(const RenderStates& lhs, const RenderStates& rhs);
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/RenderStates.inl>
|
||||
|
||||
#endif // NAZARA_RENDERSTATES_HPP
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <functional>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool operator==(const RenderStates& lhs, const RenderStates& rhs)
|
||||
{
|
||||
#define NazaraRenderStateMember(field) if (lhs.field != rhs.field) return false
|
||||
#define NazaraRenderStateBoolMember NazaraRenderStateMember
|
||||
#define NazaraRenderStateFloatMember(field, maxDiff) if (!NumberEquals(lhs.field, rhs.field, maxDiff)) return false
|
||||
|
||||
NazaraRenderStateBoolMember(blending);
|
||||
NazaraRenderStateBoolMember(colorWrite);
|
||||
NazaraRenderStateBoolMember(depthBuffer);
|
||||
NazaraRenderStateBoolMember(faceCulling);
|
||||
NazaraRenderStateBoolMember(scissorTest);
|
||||
NazaraRenderStateBoolMember(stencilTest);
|
||||
|
||||
if (lhs.depthBuffer)
|
||||
NazaraRenderStateBoolMember(depthWrite);
|
||||
|
||||
NazaraRenderStateMember(faceFilling);
|
||||
|
||||
if (lhs.blending) //< Remember, at this time we know lhs.blending == rhs.blending
|
||||
{
|
||||
NazaraRenderStateMember(dstBlend);
|
||||
NazaraRenderStateMember(srcBlend);
|
||||
}
|
||||
|
||||
if (lhs.depthBuffer)
|
||||
NazaraRenderStateMember(depthFunc);
|
||||
|
||||
if (lhs.faceCulling)
|
||||
NazaraRenderStateMember(cullingSide);
|
||||
|
||||
if (lhs.stencilTest)
|
||||
{
|
||||
NazaraRenderStateMember(stencilCompare.back);
|
||||
NazaraRenderStateMember(stencilCompare.front);
|
||||
NazaraRenderStateMember(stencilCompareMask.back);
|
||||
NazaraRenderStateMember(stencilCompareMask.front);
|
||||
NazaraRenderStateMember(stencilDepthFail.back);
|
||||
NazaraRenderStateMember(stencilDepthFail.front);
|
||||
NazaraRenderStateMember(stencilFail.back);
|
||||
NazaraRenderStateMember(stencilFail.front);
|
||||
NazaraRenderStateMember(stencilPass.back);
|
||||
NazaraRenderStateMember(stencilPass.front);
|
||||
NazaraRenderStateMember(stencilReference.back);
|
||||
NazaraRenderStateMember(stencilReference.front);
|
||||
NazaraRenderStateMember(stencilWriteMask.back);
|
||||
NazaraRenderStateMember(stencilWriteMask.front);
|
||||
}
|
||||
|
||||
NazaraRenderStateFloatMember(lineWidth, 0.001f);
|
||||
NazaraRenderStateFloatMember(pointSize, 0.001f);
|
||||
|
||||
#undef NazaraRenderStateMember
|
||||
#undef NazaraRenderStateBoolMember
|
||||
#undef NazaraRenderStateFloatMember
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Nz::RenderStates>
|
||||
{
|
||||
size_t operator()(const Nz::RenderStates& pipelineInfo) const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
|
||||
Nz::UInt8 parameterHash = 0;
|
||||
Nz::UInt8 parameterIndex = 0;
|
||||
|
||||
#define NazaraRenderStateBool(member) parameterHash |= ((pipelineInfo.member) ? 1U : 0U) << (parameterIndex++)
|
||||
#define NazaraRenderStateBoolDep(dependency, member) parameterHash |= ((pipelineInfo.dependency && pipelineInfo.member) ? 1U : 0U) << (parameterIndex++)
|
||||
#define NazaraRenderStateEnum(member) Nz::HashCombine(seed, static_cast<Nz::UInt8>(pipelineInfo.member))
|
||||
#define NazaraRenderStateFloat(member, maxDiff) Nz::HashCombine(seed, std::floor(pipelineInfo.member / maxDiff) * maxDiff)
|
||||
|
||||
NazaraRenderStateBool(blending);
|
||||
NazaraRenderStateBool(colorWrite);
|
||||
NazaraRenderStateBool(depthBuffer);
|
||||
NazaraRenderStateBool(faceCulling);
|
||||
NazaraRenderStateBool(scissorTest);
|
||||
NazaraRenderStateBool(stencilTest);
|
||||
|
||||
NazaraRenderStateBoolDep(depthBuffer, depthWrite);
|
||||
|
||||
NazaraRenderStateEnum(faceFilling);
|
||||
|
||||
if (pipelineInfo.blending) //< Remember, at this time we know lhs.blending == rhs.blending
|
||||
{
|
||||
NazaraRenderStateEnum(dstBlend);
|
||||
NazaraRenderStateEnum(srcBlend);
|
||||
}
|
||||
|
||||
if (pipelineInfo.depthBuffer)
|
||||
NazaraRenderStateEnum(depthFunc);
|
||||
|
||||
if (pipelineInfo.faceCulling)
|
||||
NazaraRenderStateEnum(cullingSide);
|
||||
|
||||
if (pipelineInfo.stencilTest)
|
||||
{
|
||||
NazaraRenderStateEnum(stencilCompare.back);
|
||||
NazaraRenderStateEnum(stencilCompare.front);
|
||||
NazaraRenderStateEnum(stencilCompareMask.back);
|
||||
NazaraRenderStateEnum(stencilCompareMask.front);
|
||||
NazaraRenderStateEnum(stencilDepthFail.back);
|
||||
NazaraRenderStateEnum(stencilDepthFail.front);
|
||||
NazaraRenderStateEnum(stencilFail.back);
|
||||
NazaraRenderStateEnum(stencilFail.front);
|
||||
NazaraRenderStateEnum(stencilPass.back);
|
||||
NazaraRenderStateEnum(stencilPass.front);
|
||||
NazaraRenderStateEnum(stencilReference.back);
|
||||
NazaraRenderStateEnum(stencilReference.front);
|
||||
NazaraRenderStateEnum(stencilWriteMask.back);
|
||||
NazaraRenderStateEnum(stencilWriteMask.front);
|
||||
}
|
||||
|
||||
NazaraRenderStateFloat(lineWidth, 0.001f);
|
||||
NazaraRenderStateFloat(pointSize, 0.001f);
|
||||
|
||||
#undef NazaraRenderStateBool
|
||||
#undef NazaraRenderStateBoolDep
|
||||
#undef NazaraRenderStateEnum
|
||||
#undef NazaraRenderStateFloat
|
||||
|
||||
Nz::HashCombine(seed, parameterHash);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderTargetParameters.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Renderer;
|
||||
|
||||
class NAZARA_RENDERER_API RenderTarget
|
||||
{
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
RenderTarget() = default;
|
||||
RenderTarget(const RenderTarget&) = delete;
|
||||
RenderTarget(RenderTarget&&) = delete; ///TOOD?
|
||||
virtual ~RenderTarget();
|
||||
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
virtual RenderTargetParameters 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;
|
||||
|
||||
RenderTarget& operator=(const RenderTarget&) = delete;
|
||||
RenderTarget& operator=(RenderTarget&&) = delete; ///TOOD?
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnRenderTargetParametersChange, const RenderTarget* /*renderTarget*/);
|
||||
NazaraSignal(OnRenderTargetRelease, const RenderTarget* /*renderTarget*/);
|
||||
NazaraSignal(OnRenderTargetSizeChange, const RenderTarget* /*renderTarget*/);
|
||||
|
||||
protected:
|
||||
virtual bool Activate() const = 0;
|
||||
virtual void Desactivate() const;
|
||||
virtual void EnsureTargetUpdated() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERTARGET_HPP
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (C) 2015 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_RENDERTARGETPARAMETERS_HPP
|
||||
#define NAZARA_RENDERTARGETPARAMETERS_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RenderTargetParameters
|
||||
{
|
||||
RenderTargetParameters(UInt8 antialiasing = 0, UInt8 depth = 24, UInt8 stencil = 0) :
|
||||
antialiasingLevel(antialiasing),
|
||||
depthBits(depth),
|
||||
stencilBits(stencil)
|
||||
{
|
||||
}
|
||||
|
||||
UInt8 antialiasingLevel;
|
||||
UInt8 depthBits;
|
||||
UInt8 stencilBits;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERTARGETPARAMETERS_HPP
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
|
||||
///TODO: Faire fonctionner les RenderTexture indépendamment du contexte (un FBO par instance et par contexte l'utilisant)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
class Context;
|
||||
class RenderBuffer;
|
||||
class Texture;
|
||||
|
||||
struct RenderTextureImpl;
|
||||
|
||||
class NAZARA_RENDERER_API RenderTexture : public RenderTarget
|
||||
{
|
||||
public:
|
||||
inline RenderTexture();
|
||||
RenderTexture(const RenderTexture&) = delete;
|
||||
RenderTexture(RenderTexture&&) = delete; ///TODO?
|
||||
inline ~RenderTexture();
|
||||
|
||||
bool AttachBuffer(AttachmentPoint attachmentPoint, UInt8 index, RenderBuffer* buffer);
|
||||
bool AttachBuffer(AttachmentPoint attachmentPoint, UInt8 index, PixelFormatType format, unsigned int width, unsigned int height);
|
||||
bool AttachTexture(AttachmentPoint attachmentPoint, UInt8 index, Texture* texture, unsigned int z = 0);
|
||||
|
||||
bool Create(bool lock = false);
|
||||
void Destroy();
|
||||
|
||||
void Detach(AttachmentPoint attachmentPoint, UInt8 index);
|
||||
|
||||
unsigned int GetHeight() const override;
|
||||
RenderTargetParameters GetParameters() const override;
|
||||
Vector2ui GetSize() const;
|
||||
unsigned int GetWidth() const override;
|
||||
|
||||
bool IsComplete() const;
|
||||
bool IsRenderable() const override;
|
||||
inline bool IsValid() const;
|
||||
|
||||
bool Lock() const;
|
||||
|
||||
inline void SetColorTarget(UInt8 target) const;
|
||||
void SetColorTargets(const UInt8* targets, unsigned int targetCount) const;
|
||||
void SetColorTargets(const std::initializer_list<UInt8>& targets) const;
|
||||
|
||||
void Unlock() const;
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
bool HasContext() const override;
|
||||
|
||||
RenderTexture& operator=(const RenderTexture&) = delete;
|
||||
RenderTexture& operator=(RenderTexture&&) = delete; ///TODO?
|
||||
|
||||
static inline void Blit(RenderTexture* src, RenderTexture* dst, UInt32 buffers = RendererBuffer_Color | RendererBuffer_Depth | RendererBuffer_Stencil, bool bilinearFilter = false);
|
||||
static void Blit(RenderTexture* src, Rectui srcRect, RenderTexture* dst, Rectui dstRect, UInt32 buffers = RendererBuffer_Color | RendererBuffer_Depth | RendererBuffer_Stencil, bool bilinearFilter = false);
|
||||
|
||||
protected:
|
||||
bool Activate() const override;
|
||||
void Desactivate() const override;
|
||||
void EnsureTargetUpdated() const override;
|
||||
|
||||
private:
|
||||
inline void InvalidateDrawBuffers() const;
|
||||
inline void InvalidateSize() const;
|
||||
inline void InvalidateTargets() const;
|
||||
void OnContextDestroy(const Context* context);
|
||||
void OnRenderBufferDestroy(const RenderBuffer* renderBuffer, unsigned int attachmentIndex);
|
||||
void OnTextureDestroy(const Texture* texture, unsigned int attachmentIndex);
|
||||
void UpdateDrawBuffers() const;
|
||||
void UpdateSize() const;
|
||||
void UpdateTargets() const;
|
||||
|
||||
RenderTextureImpl* m_impl;
|
||||
mutable bool m_checked ;
|
||||
mutable bool m_drawBuffersUpdated;
|
||||
mutable bool m_sizeUpdated;
|
||||
mutable bool m_targetsUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/RenderTexture.inl>
|
||||
|
||||
#endif // NAZARA_RENDERTEXTURE_HPP
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Core/Error.hpp>
|
||||
#include <cstring>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RenderTexture::RenderTexture() :
|
||||
m_impl(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline RenderTexture::~RenderTexture()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline bool RenderTexture::IsValid() const
|
||||
{
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
inline void RenderTexture::SetColorTarget(UInt8 target) const
|
||||
{
|
||||
SetColorTargets(&target, 1);
|
||||
}
|
||||
|
||||
inline void RenderTexture::Blit(RenderTexture* src, RenderTexture* dst, UInt32 buffers, bool bilinearFilter)
|
||||
{
|
||||
Blit(src, src->GetSize(), dst, dst->GetSize(), buffers, bilinearFilter);
|
||||
}
|
||||
|
||||
inline void RenderTexture::InvalidateDrawBuffers() const
|
||||
{
|
||||
m_drawBuffersUpdated = false;
|
||||
}
|
||||
|
||||
inline void RenderTexture::InvalidateSize() const
|
||||
{
|
||||
m_sizeUpdated = false;
|
||||
|
||||
OnRenderTargetSizeChange(this);
|
||||
}
|
||||
|
||||
inline void RenderTexture::InvalidateTargets() const
|
||||
{
|
||||
m_checked = false;
|
||||
m_drawBuffersUpdated = false;
|
||||
m_targetsUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -13,9 +13,6 @@
|
|||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractImage;
|
||||
class Context;
|
||||
class Texture;
|
||||
struct ContextParameters;
|
||||
|
||||
class NAZARA_RENDERER_API RenderWindow : public RenderTarget, public Window
|
||||
{
|
||||
public:
|
||||
RenderWindow() = default;
|
||||
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
||||
RenderWindow(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
||||
RenderWindow(const RenderWindow&) = delete;
|
||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
||||
virtual ~RenderWindow();
|
||||
|
||||
bool CopyToImage(AbstractImage* image, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
||||
bool CopyToImage(AbstractImage* image, const Rectui& rect, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
||||
|
||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
||||
bool Create(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
||||
|
||||
void Display();
|
||||
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
unsigned int GetHeight() const override;
|
||||
RenderTargetParameters GetParameters() const override;
|
||||
unsigned int GetWidth() const override;
|
||||
|
||||
bool IsRenderable() const override;
|
||||
bool IsValid() const;
|
||||
|
||||
void SetFramerateLimit(unsigned int limit);
|
||||
|
||||
// Fonctions OpenGL
|
||||
ContextParameters GetContextParameters() const;
|
||||
bool HasContext() const override;
|
||||
|
||||
RenderWindow& operator=(const RenderWindow&) = delete;
|
||||
RenderWindow& operator=(RenderWindow&&) = delete; ///TODO
|
||||
|
||||
protected:
|
||||
bool Activate() const override;
|
||||
void EnsureTargetUpdated() const override;
|
||||
bool OnWindowCreated() override;
|
||||
void OnWindowDestroy() override;
|
||||
void OnWindowResized() override;
|
||||
|
||||
private:
|
||||
mutable std::vector<UInt8> m_buffer;
|
||||
Clock m_clock;
|
||||
ContextParameters m_parameters;
|
||||
mutable Context* m_context = nullptr;
|
||||
unsigned int m_framerateLimit = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERWINDOW_HPP
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractImage;
|
||||
class Context;
|
||||
class Texture;
|
||||
struct ContextParameters;
|
||||
|
||||
class NAZARA_RENDERER_API RenderWindow : public RenderTarget, public Window
|
||||
{
|
||||
public:
|
||||
RenderWindow() = default;
|
||||
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
||||
RenderWindow(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
||||
RenderWindow(const RenderWindow&) = delete;
|
||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
||||
virtual ~RenderWindow();
|
||||
|
||||
bool CopyToImage(AbstractImage* image, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
||||
bool CopyToImage(AbstractImage* image, const Rectui& rect, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
||||
|
||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
||||
bool Create(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
||||
|
||||
void Display();
|
||||
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
unsigned int GetHeight() const override;
|
||||
RenderTargetParameters GetParameters() const override;
|
||||
unsigned int GetWidth() const override;
|
||||
|
||||
bool IsRenderable() const override;
|
||||
bool IsValid() const;
|
||||
|
||||
void SetFramerateLimit(unsigned int limit);
|
||||
|
||||
// Fonctions OpenGL
|
||||
ContextParameters GetContextParameters() const;
|
||||
bool HasContext() const override;
|
||||
|
||||
RenderWindow& operator=(const RenderWindow&) = delete;
|
||||
RenderWindow& operator=(RenderWindow&&) = delete; ///TODO
|
||||
|
||||
protected:
|
||||
bool Activate() const override;
|
||||
void EnsureTargetUpdated() const override;
|
||||
bool OnWindowCreated() override;
|
||||
void OnWindowDestroy() override;
|
||||
void OnWindowResized() override;
|
||||
|
||||
private:
|
||||
mutable std::vector<UInt8> m_buffer;
|
||||
Clock m_clock;
|
||||
ContextParameters m_parameters;
|
||||
mutable Context* m_context = nullptr;
|
||||
unsigned int m_framerateLimit = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERWINDOW_HPP
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// Copyright (C) 2016 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
|
||||
|
||||
|
|
@ -8,120 +8,33 @@
|
|||
#define NAZARA_RENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/GpuQuery.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Color;
|
||||
class Context;
|
||||
class IndexBuffer;
|
||||
class RenderTarget;
|
||||
class Shader;
|
||||
class Texture;
|
||||
class VertexBuffer;
|
||||
|
||||
class NAZARA_RENDERER_API Renderer
|
||||
{
|
||||
friend Texture;
|
||||
|
||||
public:
|
||||
using DrawCall = void (*)(PrimitiveMode, unsigned int, unsigned int);
|
||||
using DrawCallInstanced = void (*)(unsigned int, PrimitiveMode, unsigned int, unsigned int);
|
||||
|
||||
Renderer() = delete;
|
||||
~Renderer() = delete;
|
||||
|
||||
static void BeginCondition(const GpuQuery& query, GpuQueryCondition condition);
|
||||
|
||||
static void Clear(UInt32 flags = RendererBuffer_Color | RendererBuffer_Depth);
|
||||
|
||||
static void DrawFullscreenQuad();
|
||||
static void DrawIndexedPrimitives(PrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount);
|
||||
static void DrawIndexedPrimitivesInstanced(unsigned int instanceCount, PrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount);
|
||||
static void DrawPrimitives(PrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount);
|
||||
static void DrawPrimitivesInstanced(unsigned int instanceCount, PrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount);
|
||||
|
||||
static void Enable(RendererParameter parameter, bool enable);
|
||||
|
||||
static void EndCondition();
|
||||
|
||||
static void Flush();
|
||||
|
||||
static RendererComparison GetDepthFunc();
|
||||
static VertexBuffer* GetInstanceBuffer();
|
||||
static float GetLineWidth();
|
||||
static Matrix4f GetMatrix(MatrixType type);
|
||||
static UInt8 GetMaxAnisotropyLevel();
|
||||
static unsigned int GetMaxColorAttachments();
|
||||
static unsigned int GetMaxRenderTargets();
|
||||
static unsigned int GetMaxTextureSize();
|
||||
static unsigned int GetMaxTextureUnits();
|
||||
static unsigned int GetMaxVertexAttribs();
|
||||
static float GetPointSize();
|
||||
static const RenderStates& GetRenderStates();
|
||||
static Recti GetScissorRect();
|
||||
static const Shader* GetShader();
|
||||
static const RenderTarget* GetTarget();
|
||||
static Recti GetViewport();
|
||||
|
||||
static bool HasCapability(RendererCap capability);
|
||||
|
||||
static inline RendererImpl* GetRendererImpl();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsComponentTypeSupported(ComponentType type);
|
||||
static bool IsEnabled(RendererParameter parameter);
|
||||
static bool IsInitialized();
|
||||
|
||||
static void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend);
|
||||
static void SetClearColor(const Color& color);
|
||||
static void SetClearColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a = 255);
|
||||
static void SetClearDepth(double depth);
|
||||
static void SetClearStencil(unsigned int value);
|
||||
static void SetDepthFunc(RendererComparison compareFunc);
|
||||
static void SetFaceCulling(FaceSide faceSide);
|
||||
static void SetFaceFilling(FaceFilling fillingMode);
|
||||
static void SetIndexBuffer(const IndexBuffer* indexBuffer);
|
||||
static void SetLineWidth(float size);
|
||||
static void SetMatrix(MatrixType type, const Matrix4f& matrix);
|
||||
static void SetPointSize(float size);
|
||||
static void SetRenderStates(const RenderStates& states);
|
||||
static void SetScissorRect(const Recti& rect);
|
||||
static void SetShader(const Shader* shader);
|
||||
static void SetStencilCompareFunction(RendererComparison compareFunc, FaceSide faceSide = FaceSide_FrontAndBack);
|
||||
static void SetStencilFailOperation(StencilOperation failOperation, FaceSide faceSide = FaceSide_FrontAndBack);
|
||||
static void SetStencilMask(UInt32 mask, FaceSide faceSide = FaceSide_FrontAndBack);
|
||||
static void SetStencilPassOperation(StencilOperation passOperation, FaceSide faceSide = FaceSide_FrontAndBack);
|
||||
static void SetStencilReferenceValue(unsigned int refValue, FaceSide faceSide = FaceSide_FrontAndBack);
|
||||
static void SetStencilZFailOperation(StencilOperation zfailOperation, FaceSide faceSide = FaceSide_FrontAndBack);
|
||||
static bool SetTarget(const RenderTarget* target);
|
||||
static void SetTexture(UInt8 unit, const Texture* texture);
|
||||
static void SetTextureSampler(UInt8 textureUnit, const TextureSampler& sampler);
|
||||
static void SetVertexBuffer(const VertexBuffer* vertexBuffer);
|
||||
static void SetViewport(const Recti& viewport);
|
||||
static inline bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static void EnableInstancing(bool instancing);
|
||||
static bool EnsureStateUpdate();
|
||||
static void OnContextRelease(const Context* context);
|
||||
static void OnIndexBufferRelease(const IndexBuffer* indexBuffer);
|
||||
static void OnShaderReleased(const Shader* shader);
|
||||
static void OnTextureReleased(const Texture* texture);
|
||||
static void OnVertexBufferRelease(const VertexBuffer* vertexBuffer);
|
||||
static void OnVertexDeclarationRelease(const VertexDeclaration* vertexDeclaration);
|
||||
static void UpdateMatrix(MatrixType type);
|
||||
|
||||
static DynLib s_rendererLib;
|
||||
static std::unique_ptr<RendererImpl> s_rendererImpl;
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/Renderer.inl>
|
||||
|
||||
#endif // NAZARA_RENDERER_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2016 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 <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RendererImpl* Renderer::GetRendererImpl()
|
||||
{
|
||||
return s_rendererImpl.get();
|
||||
}
|
||||
|
||||
inline bool Renderer::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCounter != 0;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2015 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_RENDERER_RENDERERIMPL_HPP
|
||||
#define NAZARA_RENDERER_RENDERERIMPL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RendererImpl;
|
||||
|
||||
using CreateRendererImplFunc = RendererImpl*(*)();
|
||||
|
||||
class NAZARA_RENDERER_API RendererImpl
|
||||
{
|
||||
public:
|
||||
RendererImpl() = default;
|
||||
virtual ~RendererImpl();
|
||||
|
||||
virtual bool IsBetterThan(const RendererImpl* other) const = 0;
|
||||
|
||||
virtual RenderAPI QueryAPI() const = 0;
|
||||
virtual String QueryAPIString() const = 0;
|
||||
virtual UInt32 QueryAPIVersion() const = 0;
|
||||
|
||||
virtual std::vector<RenderDevice> QueryRenderDevices() const = 0;
|
||||
|
||||
virtual bool Prepare(const ParameterList& parameters) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERER_RENDERERIMPL_HPP
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
// Copyright (C) 2015 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_SHADER_HPP
|
||||
#define NAZARA_SHADER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Shader;
|
||||
class ShaderStage;
|
||||
|
||||
using ShaderConstRef = ObjectRef<const Shader>;
|
||||
using ShaderLibrary = ObjectLibrary<Shader>;
|
||||
using ShaderRef = ObjectRef<Shader>;
|
||||
|
||||
class NAZARA_RENDERER_API Shader : public RefCounted
|
||||
{
|
||||
friend ShaderLibrary;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader(Shader&&) = delete;
|
||||
~Shader();
|
||||
|
||||
void AttachStage(ShaderStageType stage, const ShaderStage& shaderStage);
|
||||
bool AttachStageFromFile(ShaderStageType stage, const String& filePath);
|
||||
bool AttachStageFromSource(ShaderStageType stage, const char* source, unsigned int length);
|
||||
bool AttachStageFromSource(ShaderStageType stage, const String& source);
|
||||
|
||||
void Bind() const;
|
||||
|
||||
bool Create();
|
||||
void Destroy();
|
||||
|
||||
ByteArray GetBinary() const;
|
||||
String GetLog() const;
|
||||
String GetSourceCode(ShaderStageType stage) const;
|
||||
int GetUniformLocation(const String& name) const;
|
||||
int GetUniformLocation(ShaderUniform shaderUniform) const;
|
||||
|
||||
bool HasStage(ShaderStageType stage) const;
|
||||
|
||||
bool IsBinaryRetrievable() const;
|
||||
bool IsLinked() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool Link();
|
||||
|
||||
bool LoadFromBinary(const void* buffer, unsigned int size);
|
||||
bool LoadFromBinary(const ByteArray& byteArray);
|
||||
|
||||
void SendBoolean(int location, bool value) const;
|
||||
void SendColor(int location, const Color& color) const;
|
||||
void SendDouble(int location, double value) const;
|
||||
void SendDoubleArray(int location, const double* values, unsigned int count) const;
|
||||
void SendFloat(int location, float value) const;
|
||||
void SendFloatArray(int location, const float* values, unsigned int count) const;
|
||||
void SendInteger(int location, int value) const;
|
||||
void SendIntegerArray(int location, const int* values, unsigned int count) const;
|
||||
void SendMatrix(int location, const Matrix4d& matrix) const;
|
||||
void SendMatrix(int location, const Matrix4f& matrix) const;
|
||||
void SendVector(int location, const Vector2d& vector) const;
|
||||
void SendVector(int location, const Vector2f& vector) const;
|
||||
void SendVector(int location, const Vector2i& vector) const;
|
||||
void SendVector(int location, const Vector3d& vector) const;
|
||||
void SendVector(int location, const Vector3f& vector) const;
|
||||
void SendVector(int location, const Vector3i& vector) const;
|
||||
void SendVector(int location, const Vector4d& vector) const;
|
||||
void SendVector(int location, const Vector4f& vector) const;
|
||||
void SendVector(int location, const Vector4i& vector) const;
|
||||
void SendVectorArray(int location, const Vector2d* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector2f* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector2i* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector3d* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector3f* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector3i* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector4d* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector4f* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector4i* vectors, unsigned int count) const;
|
||||
|
||||
bool Validate() const;
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
Shader& operator=(Shader&&) = delete;
|
||||
|
||||
static bool IsStageSupported(ShaderStageType stage);
|
||||
template<typename... Args> static ShaderRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnShaderDestroy, const Shader* /*shader*/);
|
||||
NazaraSignal(OnShaderRelease, const Shader* /*shader*/);
|
||||
NazaraSignal(OnShaderUniformInvalidated, const Shader* /*shader*/);
|
||||
|
||||
private:
|
||||
bool PostLinkage();
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::vector<unsigned int> m_attachedShaders[ShaderStageType_Max+1];
|
||||
bool m_linked;
|
||||
int m_uniformLocations[ShaderUniform_Max+1];
|
||||
unsigned int m_program;
|
||||
|
||||
static ShaderLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/Shader.inl>
|
||||
|
||||
#endif // NAZARA_SHADER_HPP
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2015 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 <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
ShaderRef Shader::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<Shader> object(new Shader(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright (C) 2015 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_SHADERSTAGE_HPP
|
||||
#define NAZARA_SHADERSTAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_RENDERER_API ShaderStage
|
||||
{
|
||||
public:
|
||||
ShaderStage();
|
||||
ShaderStage(ShaderStageType stage);
|
||||
ShaderStage(const ShaderStage&) = delete;
|
||||
ShaderStage(ShaderStage&& stage);
|
||||
~ShaderStage();
|
||||
|
||||
bool Compile();
|
||||
|
||||
bool Create(ShaderStageType stage);
|
||||
void Destroy();
|
||||
|
||||
String GetLog() const;
|
||||
String GetSource() const;
|
||||
|
||||
bool IsCompiled() const;
|
||||
bool IsValid() const;
|
||||
|
||||
void SetSource(const char* source, unsigned int length);
|
||||
void SetSource(const String& source);
|
||||
bool SetSourceFromFile(const String& filePath);
|
||||
|
||||
ShaderStage& operator=(const ShaderStage&) = delete;
|
||||
ShaderStage& operator=(ShaderStage&& shader);
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
static bool IsSupported(ShaderStageType stage);
|
||||
|
||||
private:
|
||||
ShaderStageType m_stage;
|
||||
bool m_compiled;
|
||||
unsigned int m_id;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SHADERSTAGE_HPP
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/CubemapParams.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Texture;
|
||||
|
||||
using TextureConstRef = ObjectRef<const Texture>;
|
||||
using TextureLibrary = ObjectLibrary<Texture>;
|
||||
using TextureManager = ResourceManager<Texture, ImageParams>;
|
||||
using TextureRef = ObjectRef<Texture>;
|
||||
|
||||
struct TextureImpl;
|
||||
|
||||
class NAZARA_RENDERER_API Texture : public AbstractImage, public RefCounted, public Resource
|
||||
{
|
||||
friend TextureLibrary;
|
||||
friend TextureManager;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
Texture() = default;
|
||||
Texture(ImageType type, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||
explicit Texture(const Image& image);
|
||||
Texture(const Texture&) = delete;
|
||||
Texture(Texture&&) = delete;
|
||||
~Texture();
|
||||
|
||||
bool Create(ImageType type, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||
void Destroy();
|
||||
|
||||
bool Download(Image* image) const;
|
||||
|
||||
bool EnableMipmapping(bool enable);
|
||||
|
||||
void EnsureMipmapsUpdate() const;
|
||||
|
||||
unsigned int GetDepth(UInt8 level = 0) const;
|
||||
PixelFormatType GetFormat() const;
|
||||
unsigned int GetHeight(UInt8 level = 0) const;
|
||||
UInt8 GetLevelCount() const;
|
||||
UInt8 GetMaxLevel() const;
|
||||
std::size_t GetMemoryUsage() const;
|
||||
std::size_t GetMemoryUsage(UInt8 level) const;
|
||||
Vector3ui GetSize(UInt8 level = 0) const;
|
||||
ImageType GetType() const;
|
||||
unsigned int GetWidth(UInt8 level = 0) const;
|
||||
|
||||
bool HasMipmaps() const;
|
||||
|
||||
void InvalidateMipmaps();
|
||||
bool IsValid() const;
|
||||
|
||||
// Load
|
||||
bool LoadFromFile(const String& filePath, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
bool LoadFromImage(const Image& image, bool generateMipmaps = true);
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
|
||||
// LoadArray
|
||||
bool LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
|
||||
// LoadCubemap
|
||||
bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
||||
bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
|
||||
// LoadFace
|
||||
bool LoadFaceFromFile(CubemapFace face, const String& filePath, const ImageParams& params = ImageParams());
|
||||
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
|
||||
|
||||
// Save
|
||||
bool SaveToFile(const String& filePath, const ImageParams& params = ImageParams());
|
||||
bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
|
||||
|
||||
bool SetMipmapRange(UInt8 minLevel, UInt8 maxLevel);
|
||||
|
||||
bool Update(const Image& image, UInt8 level = 0);
|
||||
bool Update(const Image& image, const Boxui& box, UInt8 level = 0);
|
||||
bool Update(const Image& image, const Rectui& rect, unsigned int z = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
Texture& operator=(const Texture&) = delete;
|
||||
Texture& operator=(Texture&&) = delete;
|
||||
|
||||
static bool IsFormatSupported(PixelFormatType format);
|
||||
static bool IsMipmappingSupported();
|
||||
static bool IsTypeSupported(ImageType type);
|
||||
template<typename... Args> static TextureRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnTextureDestroy, const Texture* /*texture*/);
|
||||
NazaraSignal(OnTextureRelease, const Texture* /*texture*/);
|
||||
|
||||
private:
|
||||
bool CreateTexture(bool proxy);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
TextureImpl* m_impl = nullptr;
|
||||
|
||||
static TextureLibrary::LibraryMap s_library;
|
||||
static TextureManager::ManagerMap s_managerMap;
|
||||
static TextureManager::ManagerParams s_managerParameters;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/Texture.inl>
|
||||
|
||||
#endif // NAZARA_TEXTURE_HPP
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2015 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 <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
TextureRef Texture::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<Texture> object(new Texture(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
}
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright (C) 2015 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_TEXTURESAMPLER_HPP
|
||||
#define NAZARA_TEXTURESAMPLER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Texture;
|
||||
|
||||
class NAZARA_RENDERER_API TextureSampler
|
||||
{
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
TextureSampler();
|
||||
TextureSampler(const TextureSampler& sampler) = default;
|
||||
|
||||
UInt8 GetAnisotropicLevel() const;
|
||||
SamplerFilter GetFilterMode() const;
|
||||
SamplerWrap GetWrapMode() const;
|
||||
|
||||
void SetAnisotropyLevel(UInt8 anisotropyLevel);
|
||||
void SetFilterMode(SamplerFilter filterMode);
|
||||
void SetWrapMode(SamplerWrap wrapMode);
|
||||
|
||||
TextureSampler& operator=(const TextureSampler& sampler) = default;
|
||||
|
||||
static UInt8 GetDefaultAnisotropicLevel();
|
||||
static SamplerFilter GetDefaultFilterMode();
|
||||
static SamplerWrap GetDefaultWrapMode();
|
||||
|
||||
static void SetDefaultAnisotropyLevel(UInt8 anisotropyLevel);
|
||||
static void SetDefaultFilterMode(SamplerFilter filterMode);
|
||||
static void SetDefaultWrapMode(SamplerWrap wrapMode);
|
||||
|
||||
private:
|
||||
void Apply(const Texture* texture) const;
|
||||
void Bind(unsigned int unit) const;
|
||||
unsigned int GetOpenGLID() const;
|
||||
void UpdateSamplerId() const;
|
||||
bool UseMipmaps(bool mipmaps);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
SamplerFilter m_filterMode;
|
||||
SamplerWrap m_wrapMode;
|
||||
UInt8 m_anisotropicLevel;
|
||||
bool m_mipmaps;
|
||||
mutable unsigned int m_samplerId;
|
||||
|
||||
static SamplerFilter s_defaultFilterMode;
|
||||
static SamplerWrap s_defaultWrapMode;
|
||||
static UInt8 s_defaultAnisotropyLevel;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_TEXTURESAMPLER_HPP
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright (C) 2015 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_UBERSHADER_HPP
|
||||
#define NAZARA_UBERSHADER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class UberShader;
|
||||
|
||||
using UberShaderConstRef = ObjectRef<const UberShader>;
|
||||
using UberShaderLibrary = ObjectLibrary<UberShader>;
|
||||
using UberShaderRef = ObjectRef<UberShader>;
|
||||
|
||||
class NAZARA_RENDERER_API UberShader : public RefCounted
|
||||
{
|
||||
friend UberShaderLibrary;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
UberShader() = default;
|
||||
UberShader(const UberShader&) = delete;
|
||||
UberShader(UberShader&&) = delete;
|
||||
virtual ~UberShader();
|
||||
|
||||
virtual UberShaderInstance* Get(const ParameterList& parameters) const = 0;
|
||||
|
||||
UberShader& operator=(const UberShader&) = delete;
|
||||
UberShader& operator=(UberShader&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnUberShaderRelease, const UberShader* /*uberShader*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static UberShaderLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_UBERSHADER_HPP
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (C) 2015 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_UBERSHADERINSTANCE_HPP
|
||||
#define NAZARA_UBERSHADERINSTANCE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_RENDERER_API UberShaderInstance
|
||||
{
|
||||
public:
|
||||
UberShaderInstance(const Shader* shader);
|
||||
virtual ~UberShaderInstance();
|
||||
|
||||
virtual bool Activate() const = 0;
|
||||
|
||||
const Shader* GetShader() const;
|
||||
|
||||
protected:
|
||||
ShaderConstRef m_shader;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_UBERSHADERINSTANCE_HPP
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2015 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_UBERSHADERINSTANCEPREPROCESSOR_HPP
|
||||
#define NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_RENDERER_API UberShaderInstancePreprocessor : public UberShaderInstance
|
||||
{
|
||||
public:
|
||||
UberShaderInstancePreprocessor(const Shader* shader);
|
||||
virtual ~UberShaderInstancePreprocessor();
|
||||
|
||||
bool Activate() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (C) 2015 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_UBERSHADERPREPROCESSOR_HPP
|
||||
#define NAZARA_UBERSHADERPREPROCESSOR_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class UberShaderPreprocessor;
|
||||
|
||||
using UberShaderPreprocessorConstRef = ObjectRef<const UberShaderPreprocessor>;
|
||||
using UberShaderPreprocessorRef = ObjectRef<UberShaderPreprocessor>;
|
||||
|
||||
class NAZARA_RENDERER_API UberShaderPreprocessor : public UberShader
|
||||
{
|
||||
public:
|
||||
UberShaderPreprocessor() = default;
|
||||
~UberShaderPreprocessor();
|
||||
|
||||
UberShaderInstance* Get(const ParameterList& parameters) const;
|
||||
|
||||
void SetShader(ShaderStageType stage, const String& source, const String& shaderFlags, const String& requiredFlags = String());
|
||||
bool SetShaderFromFile(ShaderStageType stage, const String& filePath, const String& shaderFlags, const String& requiredFlags = String());
|
||||
|
||||
static bool IsSupported();
|
||||
template<typename... Args> static UberShaderPreprocessorRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnUberShaderPreprocessorRelease, const UberShaderPreprocessor* /*uberShaderPreprocessor*/);
|
||||
|
||||
private:
|
||||
struct CachedShader
|
||||
{
|
||||
mutable std::unordered_map<UInt32, ShaderStage> cache;
|
||||
std::unordered_map<String, UInt32> flags;
|
||||
UInt32 requiredFlags;
|
||||
String source;
|
||||
bool present = false;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<UInt32, UberShaderInstancePreprocessor> m_cache;
|
||||
std::unordered_map<String, UInt32> m_flags;
|
||||
CachedShader m_shaders[ShaderStageType_Max+1];
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/UberShaderPreprocessor.inl>
|
||||
|
||||
#endif // NAZARA_UBERSHADERPREPROCESSOR_HPP
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2015 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 <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
UberShaderPreprocessorRef UberShaderPreprocessor::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<UberShaderPreprocessor> object(new UberShaderPreprocessor(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
// This file was automatically generated on 20 Jul 2016 at 13:49:17
|
||||
|
||||
/*
|
||||
Nazara Engine - Vulkan
|
||||
|
||||
Copyright (C) 2015 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_GLOBAL_VULKAN_HPP
|
||||
#define NAZARA_GLOBAL_VULKAN_HPP
|
||||
|
||||
#include <Nazara/Vulkan/Config.hpp>
|
||||
#include <Nazara/Vulkan/RenderTarget.hpp>
|
||||
#include <Nazara/Vulkan/RenderWindow.hpp>
|
||||
#include <Nazara/Vulkan/VkBuffer.hpp>
|
||||
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
|
||||
#include <Nazara/Vulkan/VkCommandPool.hpp>
|
||||
#include <Nazara/Vulkan/VkDescriptorPool.hpp>
|
||||
#include <Nazara/Vulkan/VkDescriptorSet.hpp>
|
||||
#include <Nazara/Vulkan/VkDescriptorSetLayout.hpp>
|
||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
||||
#include <Nazara/Vulkan/VkDeviceMemory.hpp>
|
||||
#include <Nazara/Vulkan/VkDeviceObject.hpp>
|
||||
#include <Nazara/Vulkan/VkFramebuffer.hpp>
|
||||
#include <Nazara/Vulkan/VkImageView.hpp>
|
||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
||||
#include <Nazara/Vulkan/VkLoader.hpp>
|
||||
#include <Nazara/Vulkan/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/Vulkan/VkPipeline.hpp>
|
||||
#include <Nazara/Vulkan/VkPipelineCache.hpp>
|
||||
#include <Nazara/Vulkan/VkPipelineLayout.hpp>
|
||||
#include <Nazara/Vulkan/VkQueue.hpp>
|
||||
#include <Nazara/Vulkan/VkRenderPass.hpp>
|
||||
#include <Nazara/Vulkan/VkSemaphore.hpp>
|
||||
#include <Nazara/Vulkan/VkShaderModule.hpp>
|
||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
||||
#include <Nazara/Vulkan/VkSwapchain.hpp>
|
||||
#include <Nazara/Vulkan/Vulkan.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_VULKAN_HPP
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// This file was automatically generated on 17 Aug 2016 at 14:07:55
|
||||
|
||||
/*
|
||||
Nazara Engine - Vulkan
|
||||
|
||||
Copyright (C) 2015 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_GLOBAL_VULKANRENDERER_HPP
|
||||
#define NAZARA_GLOBAL_VULKANRENDERER_HPP
|
||||
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/RenderTarget.hpp>
|
||||
#include <Nazara/VulkanRenderer/RenderWindow.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSet.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSetLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkFramebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkImageView.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPipelineCache.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPipelineLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkQueue.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkRenderPass.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkShaderModule.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.hpp>
|
||||
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_VULKANRENDERER_HPP
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Nazara Engine - Vulkan
|
||||
|
||||
Copyright (C) 2015 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_VULKANRENDERER_HPP
|
||||
#define NAZARA_CONFIG_VULKANRENDERER_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
#define NAZARA_VULKANRENDERER_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_VULKANRENDERER_SAFE 1
|
||||
|
||||
/// Chaque modification d'un paramètre ci-dessous implique une modification (souvent mineure) du code
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/VulkanRenderer/ConfigCheck.hpp>
|
||||
|
||||
#if !defined(NAZARA_STATIC)
|
||||
#ifdef NAZARA_VULKANRENDERER_BUILD
|
||||
#define NAZARA_VULKANRENDERER_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_VULKANRENDERER_API NAZARA_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define NAZARA_VULKANRENDERER_API
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_MODULENAME_HPP
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_CHECK_VULKANE_HPP
|
||||
#define NAZARA_CONFIG_CHECK_VULKANE_HPP
|
||||
|
||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define CheckType(name, type, err) static_assert(std::is_ ##type <decltype(name)>::value, #type err)
|
||||
#define CheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_VULKANRENDERER_MANAGE_MEMORY
|
||||
#undef NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#define NAZARA_MODULENAME_MANAGE_MEMORY 0
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_CHECK_VULKANRENDERER_HPP
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#include <Nazara/Core/Debug/NewRedefinition.hpp>
|
||||
#endif
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (C) 201 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERTARGET_HPP
|
||||
#define NAZARA_RENDERTARGET_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkFrameBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkRenderPass.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Renderer;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API RenderTarget
|
||||
{
|
||||
friend Renderer;
|
||||
|
||||
public:
|
||||
RenderTarget() = default;
|
||||
RenderTarget(const RenderTarget&) = delete;
|
||||
RenderTarget(RenderTarget&&) = delete; ///TOOD?
|
||||
virtual ~RenderTarget();
|
||||
|
||||
virtual bool Acquire(UInt32* imageIndex) const = 0;
|
||||
|
||||
virtual void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) = 0;
|
||||
virtual void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) = 0;
|
||||
|
||||
virtual const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const = 0;
|
||||
virtual UInt32 GetFramebufferCount() const = 0;
|
||||
|
||||
const Vk::RenderPass& GetRenderPass() const { return m_renderPass; }
|
||||
|
||||
const Vk::Semaphore& GetRenderSemaphore() const { return m_imageReadySemaphore; }
|
||||
|
||||
virtual void Present(UInt32 imageIndex) = 0;
|
||||
|
||||
RenderTarget& operator=(const RenderTarget&) = delete;
|
||||
RenderTarget& operator=(RenderTarget&&) = delete; ///TOOD?
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnRenderTargetRelease, const RenderTarget* /*renderTarget*/);
|
||||
NazaraSignal(OnRenderTargetSizeChange, const RenderTarget* /*renderTarget*/);
|
||||
|
||||
protected:
|
||||
Vk::RenderPass m_renderPass;
|
||||
Vk::Semaphore m_imageReadySemaphore;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERTARGET_HPP
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERWINDOW_HPP
|
||||
#define NAZARA_RENDERWINDOW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/RenderTarget.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkFramebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API RenderWindow : public RenderTarget, public Window
|
||||
{
|
||||
public:
|
||||
RenderWindow();
|
||||
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
||||
RenderWindow(WindowHandle handle);
|
||||
RenderWindow(const RenderWindow&) = delete;
|
||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
||||
virtual ~RenderWindow();
|
||||
|
||||
bool Acquire(UInt32* index) const override;
|
||||
|
||||
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||
|
||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
||||
bool Create(WindowHandle handle);
|
||||
|
||||
const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
|
||||
UInt32 GetFramebufferCount() const;
|
||||
const Vk::DeviceHandle& GetDevice() const;
|
||||
UInt32 GetPresentableFamilyQueue() const;
|
||||
const Vk::Surface& GetSurface() const;
|
||||
const Vk::Swapchain& GetSwapchain() const;
|
||||
|
||||
void Present(UInt32 imageIndex) override;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void SetDepthStencilFormats(std::vector<PixelFormatType> pixelFormat);
|
||||
void SetPhysicalDevice(VkPhysicalDevice device);
|
||||
|
||||
RenderWindow& operator=(const RenderWindow&) = delete;
|
||||
RenderWindow& operator=(RenderWindow&&) = delete; ///TODO
|
||||
|
||||
private:
|
||||
bool OnWindowCreated() override;
|
||||
void OnWindowDestroy() override;
|
||||
void OnWindowResized() override;
|
||||
|
||||
bool SetupDepthBuffer();
|
||||
bool SetupRenderPass();
|
||||
bool SetupSwapchain();
|
||||
|
||||
Clock m_clock;
|
||||
VkColorSpaceKHR m_colorSpace;
|
||||
VkFormat m_colorFormat;
|
||||
VkFormat m_depthStencilFormat;
|
||||
VkPhysicalDevice m_forcedPhysicalDevice;
|
||||
std::vector<PixelFormatType> m_wantedDepthStencilFormats;
|
||||
std::vector<Vk::Framebuffer> m_frameBuffers;
|
||||
Vk::DeviceHandle m_device;
|
||||
Vk::DeviceMemory m_depthBufferMemory;
|
||||
Vk::Image m_depthBuffer;
|
||||
Vk::ImageView m_depthBufferView;
|
||||
Vk::Queue m_presentQueue;
|
||||
Vk::Surface m_surface;
|
||||
Vk::Swapchain m_swapchain;
|
||||
UInt32 m_presentableFamilyQueue;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERWINDOW_HPP
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Buffer : public DeviceObject<Buffer, VkBuffer, VkBufferCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Buffer() = default;
|
||||
Buffer(const Buffer&) = delete;
|
||||
Buffer(Buffer&&) = default;
|
||||
~Buffer() = default;
|
||||
|
||||
bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
Buffer& operator=(const Buffer&) = delete;
|
||||
Buffer& operator=(Buffer&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkBuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKBUFFER_HPP
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Buffer::BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkBindBufferMemory(*m_device, m_handle, memory, offset);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to bind buffer memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Buffer::Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkBufferCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkBufferCreateFlags flags;
|
||||
size, // VkDeviceSize size;
|
||||
usage, // VkBufferUsageFlags usage;
|
||||
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
|
||||
0, // uint32_t queueFamilyIndexCount;
|
||||
nullptr // const uint32_t* pQueueFamilyIndices;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Buffer::GetMemoryRequirements() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid buffer");
|
||||
|
||||
VkMemoryRequirements memoryRequirements;
|
||||
m_device->vkGetBufferMemoryRequirements(*m_device, m_handle, &memoryRequirements);
|
||||
|
||||
return memoryRequirements;
|
||||
}
|
||||
|
||||
inline VkResult Buffer::CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle)
|
||||
{
|
||||
return device->vkCreateBuffer(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Buffer::DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyBuffer(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class CommandBuffer
|
||||
{
|
||||
friend CommandPool;
|
||||
|
||||
public:
|
||||
inline CommandBuffer();
|
||||
CommandBuffer(const CommandBuffer&) = delete;
|
||||
inline CommandBuffer(CommandBuffer&& commandBuffer);
|
||||
inline ~CommandBuffer();
|
||||
|
||||
inline bool Begin(const VkCommandBufferBeginInfo& info);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
||||
|
||||
inline void BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
inline void BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets);
|
||||
inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets);
|
||||
inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets);
|
||||
inline void BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType);
|
||||
inline void BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline);
|
||||
inline void BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset);
|
||||
inline void BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset);
|
||||
|
||||
inline void ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect);
|
||||
inline void ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects);
|
||||
|
||||
inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range);
|
||||
inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
||||
|
||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range);
|
||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0);
|
||||
|
||||
inline bool End();
|
||||
|
||||
inline void EndRenderPass();
|
||||
|
||||
inline void Free();
|
||||
|
||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier);
|
||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier, const VkBufferMemoryBarrier& bufferMemoryBarrier, const VkImageMemoryBarrier& imageMemoryBarrier);
|
||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers);
|
||||
|
||||
inline void SetScissor(const Recti& scissorRegion);
|
||||
inline void SetScissor(const VkRect2D& scissorRegion);
|
||||
inline void SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors);
|
||||
inline void SetViewport(const Rectf& viewport, float minDepth, float maxDepth);
|
||||
inline void SetViewport(const VkViewport& viewport);
|
||||
inline void SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports);
|
||||
|
||||
inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
|
||||
inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
|
||||
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
|
||||
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
CommandBuffer& operator=(const CommandBuffer&) = delete;
|
||||
CommandBuffer& operator=(CommandBuffer&& commandBuffer);
|
||||
|
||||
inline operator VkCommandBuffer() const;
|
||||
|
||||
private:
|
||||
inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle);
|
||||
|
||||
CommandPoolHandle m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkCommandBuffer m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP
|
||||
|
|
@ -0,0 +1,419 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline CommandBuffer::CommandBuffer() :
|
||||
m_pool(),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline CommandBuffer::CommandBuffer(CommandPool& pool, VkCommandBuffer handle) :
|
||||
m_pool(&pool),
|
||||
m_handle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) :
|
||||
m_pool(std::move(commandBuffer.m_pool)),
|
||||
m_allocator(commandBuffer.m_allocator),
|
||||
m_handle(commandBuffer.m_handle),
|
||||
m_lastErrorCode(commandBuffer.m_lastErrorCode)
|
||||
{
|
||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline CommandBuffer::~CommandBuffer()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(const VkCommandBufferBeginInfo& info)
|
||||
{
|
||||
m_lastErrorCode = m_pool->GetDevice()->vkBeginCommandBuffer(m_handle, &info);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to begin command buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags)
|
||||
{
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
nullptr
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo)
|
||||
{
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&inheritanceInfo
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics)
|
||||
{
|
||||
NazaraAssert(flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, "Continue bit is required to ignore renderPass, subpass and framebuffer");
|
||||
|
||||
VkCommandBufferInheritanceInfo inheritanceInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
|
||||
nullptr,
|
||||
renderPass,
|
||||
subpass,
|
||||
framebuffer,
|
||||
VkBool32((occlusionQueryEnable) ? VK_TRUE : VK_FALSE),
|
||||
queryFlags,
|
||||
pipelineStatistics
|
||||
};
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&inheritanceInfo
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics)
|
||||
{
|
||||
NazaraAssert(flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, "Continue bit is required to ignore renderPass, subpass and framebuffer");
|
||||
|
||||
VkCommandBufferInheritanceInfo inheritanceInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
|
||||
nullptr,
|
||||
VK_NULL_HANDLE,
|
||||
0,
|
||||
VK_NULL_HANDLE,
|
||||
VkBool32((occlusionQueryEnable) ? VK_TRUE : VK_FALSE),
|
||||
queryFlags,
|
||||
pipelineStatistics
|
||||
};
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&inheritanceInfo
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBeginRenderPass(m_handle, &beginInfo, contents);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets)
|
||||
{
|
||||
return BindDescriptorSets(pipelineBindPoint, layout, firstSet, 1U, &descriptorSets);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets)
|
||||
{
|
||||
return BindDescriptorSets(pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, 0U, nullptr);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindDescriptorSets(m_handle, pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, dynamicOffsetCount, dynamicOffsets);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindIndexBuffer(m_handle, buffer, offset, indexType);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindPipeline(m_handle, pipelineBindPoint, pipeline);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset)
|
||||
{
|
||||
return BindVertexBuffers(binding, 1, &buffer, &offset);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindVertexBuffers(m_handle, firstBinding, bindingCount, buffer, offset);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect)
|
||||
{
|
||||
return ClearAttachments(1U, &attachment, 1U, &rect);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdClearAttachments(m_handle, attachmentCount, attachments, rectCount, rects);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range)
|
||||
{
|
||||
return ClearColorImage(image, imageLayout, color, 1U, &range);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdClearColorImage(m_handle, image, imageLayout, &color, rangeCount, ranges);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range)
|
||||
{
|
||||
return ClearDepthStencilImage(image, imageLayout, depthStencil, 1U, &range);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange * ranges)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdClearDepthStencilImage(m_handle, image, imageLayout, &depthStencil, rangeCount, ranges);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, Int32 vertexOffset, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDrawIndexed(m_handle, indexCount, instanceCount, firstVertex, vertexOffset, firstInstance);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::End()
|
||||
{
|
||||
m_lastErrorCode = m_pool->GetDevice()->vkEndCommandBuffer(m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to end command buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void CommandBuffer::EndRenderPass()
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdEndRenderPass(m_handle);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
m_pool->GetDevice()->vkFreeCommandBuffers(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier)
|
||||
{
|
||||
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 0, nullptr, 0, nullptr, 1, &imageMemoryBarrier);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier, const VkBufferMemoryBarrier& bufferMemoryBarrier, const VkImageMemoryBarrier& imageMemoryBarrier)
|
||||
{
|
||||
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 1, &memoryBarrier, 1, &bufferMemoryBarrier, 1, &imageMemoryBarrier);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdPipelineBarrier(m_handle, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, memoryBarriers, bufferMemoryBarrierCount, bufferMemoryBarriers, imageMemoryBarrierCount, imageMemoryBarriers);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetScissor(const Recti& scissorRegion)
|
||||
{
|
||||
VkRect2D rect = {
|
||||
{scissorRegion.x, scissorRegion.y}, // VkOffset2D offset
|
||||
{UInt32(scissorRegion.width), UInt32(scissorRegion.height)} // VkExtent2D extent
|
||||
};
|
||||
|
||||
SetScissor(rect);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetScissor(const VkRect2D& scissorRegion)
|
||||
{
|
||||
return SetScissor(0, 1, &scissorRegion);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdSetScissor(m_handle, firstScissor, scissorCount, scissors);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
|
||||
{
|
||||
return SetImageLayout(image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, oldImageLayout, newImageLayout);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange)
|
||||
{
|
||||
return SetImageLayout(image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, oldImageLayout, newImageLayout, subresourceRange);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
|
||||
{
|
||||
VkImageSubresourceRange imageRange = {
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
|
||||
0, // uint32_t baseMipLevel
|
||||
1, // uint32_t levelCount
|
||||
0, // uint32_t baseArrayLayer
|
||||
1 // uint32_t layerCount
|
||||
};
|
||||
|
||||
return SetImageLayout(image, srcStageMask, dstStageMask, oldImageLayout, newImageLayout, imageRange);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange)
|
||||
{
|
||||
VkAccessFlags srcAccessMask;
|
||||
switch (oldImageLayout)
|
||||
{
|
||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_PREINITIALIZED:
|
||||
srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_GENERAL:
|
||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
|
||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
||||
default:
|
||||
srcAccessMask = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
VkAccessFlags dstAccessMask;
|
||||
switch (newImageLayout)
|
||||
{
|
||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
|
||||
if (oldImageLayout != VK_IMAGE_LAYOUT_UNDEFINED)
|
||||
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
|
||||
dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
|
||||
dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
||||
if (srcAccessMask == 0)
|
||||
srcAccessMask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
|
||||
dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
|
||||
dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
|
||||
srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
|
||||
dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_GENERAL:
|
||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
|
||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
||||
default:
|
||||
dstAccessMask = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
VkImageMemoryBarrier imageBarrier = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType
|
||||
nullptr, // const void* pNext
|
||||
srcAccessMask, // VkAccessFlags srcAccessMask
|
||||
dstAccessMask, // VkAccessFlags dstAccessMask
|
||||
oldImageLayout, // VkImageLayout oldLayout
|
||||
newImageLayout, // VkImageLayout newLayout
|
||||
VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex
|
||||
VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex
|
||||
image, // VkImage image
|
||||
subresourceRange // VkImageSubresourceRange subresourceRange
|
||||
};
|
||||
|
||||
return PipelineBarrier(srcStageMask, dstStageMask, 0, imageBarrier);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetViewport(const Rectf& viewport, float minDepth, float maxDepth)
|
||||
{
|
||||
VkViewport rect = {
|
||||
viewport.x, // float x;
|
||||
viewport.y, // float y;
|
||||
viewport.width, // float width;
|
||||
viewport.height, // float height;
|
||||
minDepth, // float minDepth;
|
||||
maxDepth // float maxDepth;
|
||||
};
|
||||
|
||||
SetViewport(rect);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetViewport(const VkViewport& viewport)
|
||||
{
|
||||
return SetViewport(0, 1, &viewport);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdSetViewport(m_handle, firstViewport, viewportCount, viewports);
|
||||
}
|
||||
|
||||
inline VkResult CommandBuffer::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline CommandBuffer& CommandBuffer::operator=(CommandBuffer&& commandBuffer)
|
||||
{
|
||||
m_allocator = commandBuffer.m_allocator;
|
||||
m_handle = commandBuffer.m_handle;
|
||||
m_lastErrorCode = commandBuffer.m_lastErrorCode;
|
||||
m_pool = std::move(commandBuffer.m_pool);
|
||||
m_handle = commandBuffer.m_handle;
|
||||
|
||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline CommandBuffer::operator VkCommandBuffer() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class CommandBuffer;
|
||||
class CommandPool;
|
||||
|
||||
using CommandPoolHandle = ObjectHandle<CommandPool>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API CommandPool : public DeviceObject<CommandPool, VkCommandPool, VkCommandPoolCreateInfo>, public HandledObject<CommandPool>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
CommandPool() = default;
|
||||
CommandPool(const CommandPool&) = delete;
|
||||
CommandPool(CommandPool&&) = default;
|
||||
~CommandPool() = default;
|
||||
|
||||
CommandBuffer AllocateCommandBuffer(VkCommandBufferLevel level);
|
||||
std::vector<CommandBuffer> AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline bool Reset(VkCommandPoolResetFlags flags);
|
||||
|
||||
CommandPool& operator=(const CommandPool&) = delete;
|
||||
CommandPool& operator=(CommandPool&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool CommandPool::Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkCommandPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
queueFamilyIndex
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool CommandPool::Reset(VkCommandPoolResetFlags flags)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkResetCommandPool(*m_device, m_handle, flags);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkResult CommandPool::CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle)
|
||||
{
|
||||
return device->vkCreateCommandPool(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void CommandPool::DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyCommandPool(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorPool;
|
||||
class DescriptorSet;
|
||||
|
||||
using DescriptorPoolHandle = ObjectHandle<DescriptorPool>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API DescriptorPool : public DeviceObject<DescriptorPool, VkDescriptorPool, VkDescriptorPoolCreateInfo>, public HandledObject<DescriptorPool>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DescriptorPool() = default;
|
||||
DescriptorPool(const DescriptorPool&) = delete;
|
||||
DescriptorPool(DescriptorPool&&) = default;
|
||||
~DescriptorPool() = default;
|
||||
|
||||
DescriptorSet AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts);
|
||||
std::vector<DescriptorSet> AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
DescriptorPool& operator=(const DescriptorPool&) = delete;
|
||||
DescriptorPool& operator=(DescriptorPool&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkDescriptorPoolCreateFlags flags;
|
||||
maxSets, // uint32_t maxSets;
|
||||
1U, // uint32_t poolSizeCount;
|
||||
&poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkDescriptorPoolCreateFlags flags;
|
||||
maxSets, // uint32_t maxSets;
|
||||
poolSizeCount, // uint32_t poolSizeCount;
|
||||
poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorPool::CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle)
|
||||
{
|
||||
return device->vkCreateDescriptorPool(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DescriptorPool::DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyDescriptorPool(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorSet
|
||||
{
|
||||
friend DescriptorPool;
|
||||
|
||||
public:
|
||||
inline DescriptorSet();
|
||||
DescriptorSet(const DescriptorSet&) = delete;
|
||||
inline DescriptorSet(DescriptorSet&& descriptorSet);
|
||||
inline ~DescriptorSet();
|
||||
|
||||
inline void Free();
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline void WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
|
||||
inline void WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo);
|
||||
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
|
||||
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo);
|
||||
inline void WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
|
||||
inline void WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
|
||||
|
||||
DescriptorSet& operator=(const DescriptorSet&) = delete;
|
||||
DescriptorSet& operator=(DescriptorSet&& descriptorSet);
|
||||
|
||||
inline operator VkDescriptorSet() const;
|
||||
|
||||
private:
|
||||
inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle);
|
||||
|
||||
DescriptorPoolHandle m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDescriptorSet m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSet.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSet.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline DescriptorSet::DescriptorSet() :
|
||||
m_pool(),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline DescriptorSet::DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle) :
|
||||
m_pool(&pool),
|
||||
m_handle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) :
|
||||
m_pool(std::move(descriptorSet.m_pool)),
|
||||
m_allocator(descriptorSet.m_allocator),
|
||||
m_handle(descriptorSet.m_handle),
|
||||
m_lastErrorCode(descriptorSet.m_lastErrorCode)
|
||||
{
|
||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline DescriptorSet::~DescriptorSet()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline void DescriptorSet::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSet::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
|
||||
{
|
||||
return WriteUniformDescriptor(binding, 0U, buffer, offset, range);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo)
|
||||
{
|
||||
return WriteUniformDescriptors(binding, 0U, 1U, &bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
|
||||
{
|
||||
VkDescriptorBufferInfo bufferInfo =
|
||||
{
|
||||
buffer, // VkBuffer buffer;
|
||||
offset, // VkDeviceSize offset;
|
||||
range // VkDeviceSize range;
|
||||
};
|
||||
|
||||
return WriteUniformDescriptor(binding, arrayElement, bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo)
|
||||
{
|
||||
return WriteUniformDescriptors(binding, arrayElement, 1U, &bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
|
||||
{
|
||||
return WriteUniformDescriptors(binding, 0U, descriptorCount, bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
|
||||
{
|
||||
VkWriteDescriptorSet writeDescriptorSet =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
m_handle, // VkDescriptorSet dstSet;
|
||||
binding, // uint32_t dstBinding;
|
||||
arrayElement, // uint32_t dstArrayElement;
|
||||
descriptorCount, // uint32_t descriptorCount;
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
|
||||
nullptr, // const VkDescriptorImageInfo* pImageInfo;
|
||||
bufferInfo, // const VkDescriptorBufferInfo* pBufferInfo;
|
||||
nullptr // const VkBufferView* pTexelBufferView;
|
||||
};
|
||||
|
||||
return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr);
|
||||
}
|
||||
|
||||
inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet)
|
||||
{
|
||||
m_allocator = descriptorSet.m_allocator;
|
||||
m_handle = descriptorSet.m_handle;
|
||||
m_lastErrorCode = descriptorSet.m_lastErrorCode;
|
||||
m_pool = std::move(descriptorSet.m_pool);
|
||||
m_handle = descriptorSet.m_handle;
|
||||
|
||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DescriptorSet::operator VkDescriptorSet() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorSetLayout : public DeviceObject<DescriptorSetLayout, VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DescriptorSetLayout() = default;
|
||||
DescriptorSetLayout(const DescriptorSetLayout&) = delete;
|
||||
DescriptorSetLayout(DescriptorSetLayout&&) = default;
|
||||
~DescriptorSetLayout() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
DescriptorSetLayout& operator=(const DescriptorSetLayout&) = delete;
|
||||
DescriptorSetLayout& operator=(DescriptorSetLayout&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSetLayout.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSetLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, 1U, &binding, flags, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorSetLayoutCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkDescriptorSetLayoutCreateFlags flags;
|
||||
bindingCount, // uint32_t bindingCount;
|
||||
binding // const VkDescriptorSetLayoutBinding* pBindings;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSetLayout::CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle)
|
||||
{
|
||||
return device->vkCreateDescriptorSetLayout(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DescriptorSetLayout::DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyDescriptorSetLayout(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Device;
|
||||
class Queue;
|
||||
class Instance;
|
||||
|
||||
using DeviceHandle = ObjectHandle<Device>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API Device : public HandledObject<Device>
|
||||
{
|
||||
public:
|
||||
struct QueueFamilyInfo;
|
||||
struct QueueInfo;
|
||||
using QueueList = std::vector<QueueInfo>;
|
||||
|
||||
inline Device(Instance& instance);
|
||||
Device(const Device&) = delete;
|
||||
Device(Device&&) = delete;
|
||||
inline ~Device();
|
||||
|
||||
bool Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline const std::vector<QueueFamilyInfo>& GetEnabledQueues() const;
|
||||
inline const QueueList& GetEnabledQueues(UInt32 familyQueue) const;
|
||||
|
||||
inline Queue GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex);
|
||||
inline Instance& GetInstance();
|
||||
inline const Instance& GetInstance() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
inline VkPhysicalDevice GetPhysicalDevice() const;
|
||||
|
||||
inline bool IsExtensionLoaded(const String& extensionName);
|
||||
inline bool IsLayerLoaded(const String& layerName);
|
||||
|
||||
inline bool WaitForIdle();
|
||||
|
||||
Device& operator=(const Device&) = delete;
|
||||
Device& operator=(Device&&) = delete;
|
||||
|
||||
inline operator VkDevice();
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) PFN_##func func
|
||||
|
||||
// Vulkan core
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAllocateCommandBuffers);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAllocateDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAllocateMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkBeginCommandBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkBindBufferMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkBindImageMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBeginQuery);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBeginRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindIndexBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindPipeline);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindVertexBuffers);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBlitImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdClearAttachments);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdClearColorImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdClearDepthStencilImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyBufferToImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyImageToBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyQueryPoolResults);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDispatch);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDispatchIndirect);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDraw);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDrawIndexed);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDrawIndexedIndirect);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDrawIndirect);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdEndQuery);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdEndRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdExecuteCommands);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdFillBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdNextSubpass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdPipelineBarrier);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdPushConstants);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdResetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdResetQueryPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdResolveImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetBlendConstants);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetDepthBias);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetDepthBounds);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetLineWidth);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetScissor);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetStencilCompareMask);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetStencilReference);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetStencilWriteMask);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetViewport);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdUpdateBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdWaitEvents);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdWriteTimestamp);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateBufferView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateCommandPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateComputePipelines);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateFramebuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateGraphicsPipelines);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateImageView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreatePipelineCache);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreatePipelineLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSampler);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSemaphore);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateShaderModule);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyBufferView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyCommandPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDevice);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyFramebuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyImageView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyPipeline);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyPipelineCache);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyPipelineLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySampler);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySemaphore);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyShaderModule);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDeviceWaitIdle);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkEndCommandBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFreeCommandBuffers);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFreeDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFreeMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFlushMappedMemoryRanges);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetBufferMemoryRequirements);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetDeviceMemoryCommitment);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetDeviceQueue);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetEventStatus);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetFenceStatus);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetImageMemoryRequirements);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetImageSubresourceLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetRenderAreaGranularity);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkInvalidateMappedMemoryRanges);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkMapMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkMergePipelineCaches);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueSubmit);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueWaitIdle);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetCommandBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetCommandPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetFences);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkSetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkUnmapMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkUpdateDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkWaitForFences);
|
||||
|
||||
// VK_KHR_display_swapchain
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSharedSwapchainsKHR);
|
||||
|
||||
// VK_KHR_surface
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR);
|
||||
|
||||
// VK_KHR_swapchain
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAcquireNextImageKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSwapchainKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySwapchainKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetSwapchainImagesKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueuePresentKHR);
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_DEVICE_FUNCTION
|
||||
|
||||
struct QueueInfo
|
||||
{
|
||||
QueueFamilyInfo* familyInfo;
|
||||
VkQueue queue;
|
||||
float priority;
|
||||
};
|
||||
|
||||
struct QueueFamilyInfo
|
||||
{
|
||||
QueueList queues;
|
||||
VkExtent3D minImageTransferGranularity;
|
||||
VkQueueFlags flags;
|
||||
UInt32 familyIndex;
|
||||
UInt32 timestampValidBits;
|
||||
};
|
||||
|
||||
private:
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
Instance& m_instance;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDevice m_device;
|
||||
VkPhysicalDevice m_physicalDevice;
|
||||
VkResult m_lastErrorCode;
|
||||
std::unordered_set<String> m_loadedExtensions;
|
||||
std::unordered_set<String> m_loadedLayers;
|
||||
std::vector<QueueFamilyInfo> m_enabledQueuesInfos;
|
||||
std::vector<const QueueList*> m_queuesByFamily;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDevice.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkQueue.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Device::Device(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_device(VK_NULL_HANDLE),
|
||||
m_physicalDevice(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Device::~Device()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void Device::Destroy()
|
||||
{
|
||||
if (m_device != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDeviceWaitIdle(m_device);
|
||||
vkDestroyDevice(m_device, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
|
||||
m_device = VK_NULL_HANDLE;
|
||||
m_physicalDevice = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const
|
||||
{
|
||||
return m_enabledQueuesInfos;
|
||||
}
|
||||
|
||||
inline const Device::QueueList& Device::GetEnabledQueues(UInt32 familyQueue) const
|
||||
{
|
||||
NazaraAssert(familyQueue < m_enabledQueuesInfos.size(), "Invalid family queue");
|
||||
|
||||
return *m_queuesByFamily[familyQueue];
|
||||
}
|
||||
|
||||
inline Queue Device::GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex)
|
||||
{
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
|
||||
|
||||
return Queue(CreateHandle(), queue);
|
||||
}
|
||||
|
||||
inline Instance& Device::GetInstance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
inline const Instance& Device::GetInstance() const
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
inline VkResult Device::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline VkPhysicalDevice Device::GetPhysicalDevice() const
|
||||
{
|
||||
return m_physicalDevice;
|
||||
}
|
||||
|
||||
inline bool Device::IsExtensionLoaded(const String& extensionName)
|
||||
{
|
||||
return m_loadedExtensions.count(extensionName) > 0;
|
||||
}
|
||||
|
||||
inline bool Device::IsLayerLoaded(const String& layerName)
|
||||
{
|
||||
return m_loadedLayers.count(layerName) > 0;
|
||||
}
|
||||
|
||||
inline bool Device::WaitForIdle()
|
||||
{
|
||||
m_lastErrorCode = vkDeviceWaitIdle(m_device);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to wait for device idle");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Device::operator VkDevice()
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Device::GetProcAddr(const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = m_instance.GetDeviceProcAddr(m_device, name);
|
||||
if (!func)
|
||||
NazaraError("Failed to get " + String(name) + " address");
|
||||
|
||||
return func;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DeviceMemory : public DeviceObject<DeviceMemory, VkDeviceMemory, VkMemoryAllocateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DeviceMemory();
|
||||
DeviceMemory(const DeviceMemory&) = delete;
|
||||
DeviceMemory(DeviceMemory&& memory);
|
||||
~DeviceMemory() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline void* GetMappedPointer();
|
||||
|
||||
inline bool Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags = 0);
|
||||
|
||||
inline void Unmap();
|
||||
|
||||
DeviceMemory& operator=(const DeviceMemory&) = delete;
|
||||
DeviceMemory& operator=(DeviceMemory&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
void* m_mappedPtr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline DeviceMemory::DeviceMemory() :
|
||||
m_mappedPtr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceMemory::DeviceMemory(DeviceMemory&& memory) :
|
||||
DeviceObject(std::move(memory))
|
||||
{
|
||||
m_mappedPtr = memory.m_mappedPtr;
|
||||
memory.m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMemoryAllocateInfo allocInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
size, // VkDeviceSize allocationSize;
|
||||
memoryType // uint32_t memoryTypeIndex;
|
||||
};
|
||||
|
||||
return Create(device, allocInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device->GetPhysicalDevice());
|
||||
|
||||
UInt32 typeMask = 1;
|
||||
for (UInt32 i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
|
||||
{
|
||||
if (typeBits & typeMask)
|
||||
{
|
||||
if ((deviceInfo.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
||||
return Create(device, size, i, allocator);
|
||||
}
|
||||
|
||||
typeMask <<= 1;
|
||||
}
|
||||
|
||||
NazaraError("Failed to find a memory type suitable for typeBits: " + String::Number(typeBits) + " and properties: 0x" + String::Number(properties, 16));
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void* DeviceMemory::GetMappedPointer()
|
||||
{
|
||||
return m_mappedPtr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &m_mappedPtr);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to map device memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void DeviceMemory::Unmap()
|
||||
{
|
||||
NazaraAssert(m_mappedPtr != nullptr, "Memory is not mapped");
|
||||
|
||||
m_device->vkUnmapMemory(*m_device, m_handle);
|
||||
m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline VkResult DeviceMemory::CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle)
|
||||
{
|
||||
return device->vkAllocateMemory(*device, allocInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DeviceMemory::DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkFreeMemory(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
class DeviceObject
|
||||
{
|
||||
public:
|
||||
inline DeviceObject();
|
||||
DeviceObject(const DeviceObject&) = delete;
|
||||
DeviceObject(DeviceObject&&);
|
||||
inline ~DeviceObject();
|
||||
|
||||
inline bool Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
DeviceObject& operator=(const DeviceObject&) = delete;
|
||||
DeviceObject& operator=(DeviceObject&&) = delete;
|
||||
|
||||
inline operator VkType() const;
|
||||
|
||||
protected:
|
||||
DeviceHandle m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkType m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject() :
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject(DeviceObject&& object) :
|
||||
m_device(std::move(object.m_device)),
|
||||
m_allocator(object.m_allocator),
|
||||
m_handle(object.m_handle),
|
||||
m_lastErrorCode(object.m_lastErrorCode)
|
||||
{
|
||||
object.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::~DeviceObject()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline bool DeviceObject<C, VkType, CreateInfo>::Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_device = device;
|
||||
m_lastErrorCode = C::CreateHelper(m_device, &createInfo, allocator, &m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to create Vulkan object");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the allocator to access them when needed
|
||||
if (allocator)
|
||||
m_allocator = *allocator;
|
||||
else
|
||||
m_allocator.pfnAllocation = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline void DeviceObject<C, VkType, CreateInfo>::Destroy()
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
C::DestroyHelper(m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline bool DeviceObject<C, VkType, CreateInfo>::IsValid() const
|
||||
{
|
||||
return m_handle != VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline const DeviceHandle& DeviceObject<C, VkType, CreateInfo>::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline VkResult DeviceObject<C, VkType, CreateInfo>::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::operator VkType() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
#include "VkDeviceObject.hpp"
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Framebuffer : public DeviceObject<Framebuffer, VkFramebuffer, VkFramebufferCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Framebuffer() = default;
|
||||
Framebuffer(const Framebuffer&) = delete;
|
||||
Framebuffer(Framebuffer&&) = default;
|
||||
~Framebuffer() = default;
|
||||
|
||||
Framebuffer& operator=(const Framebuffer&) = delete;
|
||||
Framebuffer& operator=(Framebuffer&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkFramebuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkFramebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult Framebuffer::CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle)
|
||||
{
|
||||
return device->vkCreateFramebuffer(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Framebuffer::DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyFramebuffer(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKIMAGE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKIMAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Image : public DeviceObject<Image, VkImage, VkImageCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Image() = default;
|
||||
Image(const Image&) = delete;
|
||||
Image(Image&&) = default;
|
||||
~Image() = default;
|
||||
|
||||
bool BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
Image& operator=(const Image&) = delete;
|
||||
Image& operator=(Image&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImage.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKIMAGE_HPP
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Image::BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkBindImageMemory(*m_device, m_handle, memory, offset);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to bind buffer memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Image::GetMemoryRequirements() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid image");
|
||||
|
||||
VkMemoryRequirements memoryRequirements;
|
||||
m_device->vkGetImageMemoryRequirements(*m_device, m_handle, &memoryRequirements);
|
||||
|
||||
return memoryRequirements;
|
||||
}
|
||||
|
||||
inline VkResult Image::CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle)
|
||||
{
|
||||
return device->vkCreateImage(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Image::DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyImage(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class ImageView : public DeviceObject<ImageView, VkImageView, VkImageViewCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
ImageView() = default;
|
||||
ImageView(const ImageView&) = delete;
|
||||
ImageView(ImageView&&) = default;
|
||||
~ImageView() = default;
|
||||
|
||||
ImageView& operator=(const ImageView&) = delete;
|
||||
ImageView& operator=(ImageView&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImageView.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImageView.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult ImageView::CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle)
|
||||
{
|
||||
return device->vkCreateImageView(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void ImageView::DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyImageView(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKINSTANCE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKINSTANCE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API Instance
|
||||
{
|
||||
public:
|
||||
inline Instance();
|
||||
Instance(const Instance&) = delete;
|
||||
Instance(Instance&&) = delete;
|
||||
inline ~Instance();
|
||||
|
||||
bool Create(const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const String& appName, UInt32 appVersion, const String& engineName, UInt32 engineVersion, const std::vector<const char*>& layers, const std::vector<const char*>& extensions, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
bool EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* physicalDevices);
|
||||
|
||||
inline PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name);
|
||||
|
||||
inline VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures(VkPhysicalDevice device);
|
||||
inline VkFormatProperties GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format);
|
||||
inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties);
|
||||
inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device);
|
||||
inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device);
|
||||
bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties);
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool IsExtensionLoaded(const String& extensionName);
|
||||
inline bool IsLayerLoaded(const String& layerName);
|
||||
|
||||
Instance& operator=(const Instance&) = delete;
|
||||
Instance& operator=(Instance&&) = delete;
|
||||
|
||||
inline operator VkInstance();
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) PFN_##func func
|
||||
|
||||
// Vulkan core
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDevice);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroyInstance);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDeviceProcAddr);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties);
|
||||
|
||||
// VK_KHR_display
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDisplayModeKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDisplayModePropertiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDisplayPlaneCapabilitiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDisplayPlaneSupportedDisplaysKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPropertiesKHR);
|
||||
|
||||
// VK_KHR_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroySurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR);
|
||||
|
||||
// VK_EXT_debug_report
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDebugReportCallbackEXT);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroyDebugReportCallbackEXT);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDebugReportMessageEXT);
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
// VK_KHR_android_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateAndroidSurfaceKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
// VK_KHR_mir_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateMirSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceMirPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
// VK_KHR_xcb_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateXcbSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceXcbPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
// VK_KHR_xlib_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateXlibSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceXlibPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
// VK_KHR_wayland_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateWaylandSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
// VK_KHR_win32_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateWin32SurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceWin32PresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_INSTANCE_FUNCTION
|
||||
|
||||
private:
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkInstance m_instance;
|
||||
VkResult m_lastErrorCode;
|
||||
std::unordered_set<String> m_loadedExtensions;
|
||||
std::unordered_set<String> m_loadedLayers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkInstance.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKINSTANCE_HPP
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Instance::Instance() :
|
||||
m_instance(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline Instance::~Instance()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline bool Instance::Create(const String& appName, UInt32 appVersion, const String& engineName, UInt32 engineVersion, const std::vector<const char*>& layers, const std::vector<const char*>& extensions, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkApplicationInfo appInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
nullptr,
|
||||
appName.GetConstBuffer(),
|
||||
appVersion,
|
||||
engineName.GetConstBuffer(),
|
||||
engineVersion
|
||||
};
|
||||
|
||||
VkInstanceCreateInfo instanceInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
nullptr,
|
||||
0,
|
||||
&appInfo,
|
||||
static_cast<UInt32>(layers.size()),
|
||||
(!layers.empty()) ? layers.data() : nullptr,
|
||||
static_cast<UInt32>(extensions.size()),
|
||||
(!extensions.empty()) ? extensions.data() : nullptr
|
||||
};
|
||||
|
||||
return Create(instanceInfo, allocator);
|
||||
}
|
||||
|
||||
inline void Instance::Destroy()
|
||||
{
|
||||
if (m_instance)
|
||||
{
|
||||
vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Instance::GetDeviceProcAddr(VkDevice device, const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = vkGetDeviceProcAddr(device, name);
|
||||
if (!func)
|
||||
NazaraError("Failed to get " + String(name) + " address");
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
inline VkResult Instance::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Instance::IsExtensionLoaded(const String& extensionName)
|
||||
{
|
||||
return m_loadedExtensions.count(extensionName) > 0;
|
||||
}
|
||||
|
||||
inline bool Instance::IsLayerLoaded(const String& layerName)
|
||||
{
|
||||
return m_loadedLayers.count(layerName) > 0;
|
||||
}
|
||||
|
||||
inline Instance::operator VkInstance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
inline VkPhysicalDeviceFeatures Instance::GetPhysicalDeviceFeatures(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceFeatures features;
|
||||
vkGetPhysicalDeviceFeatures(device, &features);
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
inline VkFormatProperties Instance::GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format)
|
||||
{
|
||||
VkFormatProperties formatProperties;
|
||||
vkGetPhysicalDeviceFormatProperties(device, format, &formatProperties);
|
||||
|
||||
return formatProperties;
|
||||
}
|
||||
|
||||
inline bool Instance::GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties)
|
||||
{
|
||||
m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to get physical device image format properties");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkPhysicalDeviceMemoryProperties Instance::GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties);
|
||||
|
||||
return memoryProperties;
|
||||
}
|
||||
|
||||
inline VkPhysicalDeviceProperties Instance::GetPhysicalDeviceProperties(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceProperties properties;
|
||||
vkGetPhysicalDeviceProperties(device, &properties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
|
||||
if (!func)
|
||||
NazaraError("Failed to get " + String(name) + " address");
|
||||
|
||||
return func;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKLOADER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKLOADER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API Loader
|
||||
{
|
||||
public:
|
||||
Loader() = delete;
|
||||
~Loader() = delete;
|
||||
|
||||
static bool EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* properties, const char* layerName = nullptr);
|
||||
static bool EnumerateInstanceLayerProperties(std::vector<VkLayerProperties>* properties);
|
||||
|
||||
static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(func) static PFN_##func func
|
||||
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkCreateInstance);
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkEnumerateInstanceExtensionProperties);
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkEnumerateInstanceLayerProperties);
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkGetInstanceProcAddr);
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_GLOBAL_FUNCTION
|
||||
|
||||
private:
|
||||
static DynLib s_vulkanLib;
|
||||
static VkResult s_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkLoader.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKLOADER_HPP
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline PFN_vkVoidFunction Loader::GetInstanceProcAddr(VkInstance instance, const char* name)
|
||||
{
|
||||
return vkGetInstanceProcAddr(instance, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
struct PhysicalDevice
|
||||
{
|
||||
VkPhysicalDevice device;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
std::vector<VkQueueFamilyProperties> queues;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPIPELINE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPIPELINE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Pipeline
|
||||
{
|
||||
public:
|
||||
inline Pipeline();
|
||||
Pipeline(const Pipeline&) = delete;
|
||||
Pipeline(Pipeline&&);
|
||||
inline ~Pipeline();
|
||||
|
||||
inline bool CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
Pipeline& operator=(const Pipeline&) = delete;
|
||||
Pipeline& operator=(Pipeline&&) = delete;
|
||||
|
||||
inline operator VkPipeline() const;
|
||||
|
||||
protected:
|
||||
inline bool Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator);
|
||||
|
||||
DeviceHandle m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkPipeline m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipeline.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPIPELINE_HPP
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Pipeline::Pipeline() :
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Pipeline::Pipeline(Pipeline&& object) :
|
||||
m_device(std::move(object.m_device)),
|
||||
m_allocator(object.m_allocator),
|
||||
m_handle(object.m_handle),
|
||||
m_lastErrorCode(object.m_lastErrorCode)
|
||||
{
|
||||
object.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline Pipeline::~Pipeline()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline bool Pipeline::CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
}
|
||||
|
||||
inline bool Pipeline::CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
}
|
||||
|
||||
inline void Pipeline::Destroy()
|
||||
{
|
||||
if (m_handle != VK_NULL_HANDLE)
|
||||
{
|
||||
m_device->vkDestroyPipeline(*m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
inline const DeviceHandle& Pipeline::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline VkResult Pipeline::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline Pipeline::operator VkPipeline() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
inline bool Pipeline::Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_device = device;
|
||||
m_lastErrorCode = result;
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to create Vulkan object");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the allocator to access them when needed
|
||||
if (allocator)
|
||||
m_allocator = *allocator;
|
||||
else
|
||||
m_allocator.pfnAllocation = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class PipelineCache : public DeviceObject<PipelineCache, VkPipelineCache, VkPipelineCacheCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
PipelineCache() = default;
|
||||
PipelineCache(const PipelineCache&) = delete;
|
||||
PipelineCache(PipelineCache&&) = default;
|
||||
~PipelineCache() = default;
|
||||
|
||||
PipelineCache& operator=(const PipelineCache&) = delete;
|
||||
PipelineCache& operator=(PipelineCache&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipelineCache.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipelineCache.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult PipelineCache::CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle)
|
||||
{
|
||||
return device->vkCreatePipelineCache(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void PipelineCache::DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyPipelineCache(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class PipelineLayout : public DeviceObject<PipelineLayout, VkPipelineLayout, VkPipelineLayoutCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
PipelineLayout() = default;
|
||||
PipelineLayout(const PipelineLayout&) = delete;
|
||||
PipelineLayout(PipelineLayout&&) = default;
|
||||
~PipelineLayout() = default;
|
||||
|
||||
PipelineLayout& operator=(const PipelineLayout&) = delete;
|
||||
PipelineLayout& operator=(PipelineLayout&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipelineLayout.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipelineLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult PipelineLayout::CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle)
|
||||
{
|
||||
return device->vkCreatePipelineLayout(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void PipelineLayout::DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyPipelineLayout(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKQUEUE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Queue
|
||||
{
|
||||
public:
|
||||
inline Queue();
|
||||
inline Queue(const DeviceHandle& device, VkQueue queue);
|
||||
inline Queue(const Queue& queue);
|
||||
inline Queue(Queue&& queue);
|
||||
inline ~Queue() = default;
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool Present(const VkPresentInfoKHR& presentInfo) const;
|
||||
inline bool Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE) const;
|
||||
|
||||
inline bool Submit(const VkSubmitInfo& submit, VkFence fence = VK_NULL_HANDLE) const;
|
||||
inline bool Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence = VK_NULL_HANDLE) const;
|
||||
|
||||
inline bool WaitIdle() const;
|
||||
|
||||
Queue& operator=(const Queue& queue) = delete;
|
||||
inline Queue& operator=(Queue&&);
|
||||
|
||||
inline operator VkQueue();
|
||||
|
||||
protected:
|
||||
DeviceHandle m_device;
|
||||
VkQueue m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkQueue.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKQUEUE_HPP
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkQueue.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Queue::Queue() :
|
||||
Queue(DeviceHandle(), VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(const DeviceHandle& device, VkQueue queue) :
|
||||
m_device(device),
|
||||
m_handle(queue),
|
||||
m_lastErrorCode(VkResult::VK_SUCCESS)
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(const Queue& queue) :
|
||||
m_device(queue.m_device),
|
||||
m_handle(queue.m_handle),
|
||||
m_lastErrorCode(queue.m_lastErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(Queue&& queue) :
|
||||
m_device(queue.m_device),
|
||||
m_handle(queue.m_handle),
|
||||
m_lastErrorCode(queue.m_lastErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
inline const DeviceHandle& Queue::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline VkResult Queue::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Queue::Present(const VkPresentInfoKHR& presentInfo) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueuePresentKHR(m_handle, &presentInfo);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Queue::Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore) const
|
||||
{
|
||||
VkPresentInfoKHR presentInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||
nullptr,
|
||||
(waitSemaphore) ? 1U : 0U,
|
||||
&waitSemaphore,
|
||||
1U,
|
||||
&swapchain,
|
||||
&imageIndex,
|
||||
nullptr
|
||||
};
|
||||
|
||||
return Present(presentInfo);
|
||||
}
|
||||
|
||||
inline bool Queue::Submit(const VkSubmitInfo& submit, VkFence fence) const
|
||||
{
|
||||
return Submit(1, &submit, fence);
|
||||
}
|
||||
|
||||
inline bool Queue::Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueueSubmit(m_handle, submitCount, submits, fence);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Queue::WaitIdle() const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueueWaitIdle(m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Queue& Queue::operator=(Queue&& queue)
|
||||
{
|
||||
m_device = std::move(queue.m_device);
|
||||
m_handle = queue.m_handle;
|
||||
m_lastErrorCode = queue.m_lastErrorCode;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Queue::operator VkQueue()
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKRENDERPASS_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKRENDERPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class RenderPass : public DeviceObject<RenderPass, VkRenderPass, VkRenderPassCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
RenderPass() = default;
|
||||
RenderPass(const RenderPass&) = delete;
|
||||
RenderPass(RenderPass&&) = default;
|
||||
~RenderPass() = default;
|
||||
|
||||
RenderPass& operator=(const RenderPass&) = delete;
|
||||
RenderPass& operator=(RenderPass&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkRenderPass.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKRENDERPASS_HPP
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkRenderPass.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult RenderPass::CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle)
|
||||
{
|
||||
return device->vkCreateRenderPass(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void RenderPass::DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyRenderPass(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Semaphore : public DeviceObject<Semaphore, VkSemaphore, VkSemaphoreCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Semaphore() = default;
|
||||
Semaphore(const Semaphore&) = delete;
|
||||
Semaphore(Semaphore&&) = default;
|
||||
~Semaphore() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
Semaphore& operator=(const Semaphore&) = delete;
|
||||
Semaphore& operator=(Semaphore&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Semaphore::Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkSemaphoreCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||
nullptr,
|
||||
flags
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult Semaphore::CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
||||
{
|
||||
return device->vkCreateSemaphore(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Semaphore::DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroySemaphore(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class ShaderModule : public DeviceObject<ShaderModule, VkShaderModule, VkShaderModuleCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
ShaderModule() = default;
|
||||
ShaderModule(const ShaderModule&) = delete;
|
||||
ShaderModule(ShaderModule&&) = default;
|
||||
~ShaderModule() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
ShaderModule& operator=(const ShaderModule&) = delete;
|
||||
ShaderModule& operator=(ShaderModule&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkShaderModule.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkShaderModule.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool ShaderModule::Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkShaderModuleCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
size,
|
||||
code
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult ShaderModule::CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle)
|
||||
{
|
||||
return device->vkCreateShaderModule(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void ShaderModule::DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyShaderModule(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSURFACE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSURFACE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Instance;
|
||||
|
||||
class Surface
|
||||
{
|
||||
public:
|
||||
inline Surface(Instance& instance);
|
||||
Surface(const Surface&) = delete;
|
||||
Surface(Surface&& surface);
|
||||
inline ~Surface();
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
// VK_KHR_android_surface
|
||||
inline bool Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
// VK_KHR_mir_surface
|
||||
inline bool Create(const VkMirSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
// VK_KHR_xcb_surface
|
||||
inline bool Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
// VK_KHR_xlib_surface
|
||||
inline bool Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
// VK_KHR_wayland_surface
|
||||
inline bool Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
// VK_KHR_win32_surface
|
||||
inline bool Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
inline void Destroy();
|
||||
|
||||
bool GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const;
|
||||
bool GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const;
|
||||
bool GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const;
|
||||
bool GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const;
|
||||
|
||||
inline bool IsSupported() const;
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
Surface& operator=(const Surface&) = delete;
|
||||
Surface& operator=(Surface&&) = delete;
|
||||
|
||||
inline operator VkSurfaceKHR() const;
|
||||
|
||||
private:
|
||||
inline bool Create(const VkAllocationCallbacks* allocator);
|
||||
|
||||
Instance& m_instance;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkSurfaceKHR m_surface;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSurface.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSURFACE_HPP
|
||||
|
|
@ -0,0 +1,314 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Surface::Surface(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_surface(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Surface::Surface(Surface&& surface) :
|
||||
m_instance(surface.m_instance),
|
||||
m_allocator(surface.m_allocator),
|
||||
m_surface(surface.m_surface),
|
||||
m_lastErrorCode(surface.m_lastErrorCode)
|
||||
{
|
||||
surface.m_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline Surface::~Surface()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
inline bool Surface::Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateAndroidSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkAndroidSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
inline bool Surface::Create(const VkMirSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateMirSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMirSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
connection,
|
||||
surface
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
inline bool Surface::Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateXcbSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkXcbSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
connection,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
inline bool Surface::Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateXlibSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkXlibSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
display,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
inline bool Surface::Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateWaylandSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkWaylandSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
display,
|
||||
surface
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
inline bool Surface::Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateWin32SurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkWin32SurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
instance,
|
||||
handle
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void Surface::Destroy()
|
||||
{
|
||||
if (m_surface != VK_NULL_HANDLE)
|
||||
{
|
||||
m_instance.vkDestroySurfaceKHR(m_instance, m_surface, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
inline VkResult Surface::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Surface::GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query surface capabilities");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const
|
||||
{
|
||||
// First, query format count
|
||||
UInt32 surfaceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0)
|
||||
{
|
||||
NazaraError("Failed to query format count");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now we can get the list of the available physical device
|
||||
surfaceFormats->resize(surfaceCount);
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query formats");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const
|
||||
{
|
||||
// First, query present modes count
|
||||
UInt32 presentModeCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, nullptr);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || presentModeCount == 0)
|
||||
{
|
||||
NazaraError("Failed to query present mode count");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now we can get the list of the available physical device
|
||||
presentModes->resize(presentModeCount);
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query present modes");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const
|
||||
{
|
||||
VkBool32 presentationSupported = VK_FALSE;
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query surface capabilities");
|
||||
return false;
|
||||
}
|
||||
|
||||
*supported = (presentationSupported == VK_TRUE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::IsSupported() const
|
||||
{
|
||||
if (!m_instance.IsExtensionLoaded("VK_KHR_surface"))
|
||||
return false;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_android_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_mir_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_xcb_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_xlib_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_wayland_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_win32_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline Surface::operator VkSurfaceKHR() const
|
||||
{
|
||||
return m_surface;
|
||||
}
|
||||
|
||||
inline bool Surface::Create(const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to create Vulkan surface");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the allocator to access them when needed
|
||||
if (allocator)
|
||||
m_allocator = *allocator;
|
||||
else
|
||||
m_allocator.pfnAllocation = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkImageView.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Swapchain : public DeviceObject<Swapchain, VkSwapchainKHR, VkSwapchainCreateInfoKHR>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
struct Buffer;
|
||||
|
||||
Swapchain() = default;
|
||||
Swapchain(const Swapchain&) = delete;
|
||||
Swapchain(Swapchain&&) = default;
|
||||
~Swapchain() = default;
|
||||
|
||||
inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const;
|
||||
|
||||
inline bool Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline const Buffer& GetBuffer(UInt32 index) const;
|
||||
inline const std::vector<Buffer>& GetBuffers() const;
|
||||
inline UInt32 GetBufferCount() const;
|
||||
|
||||
inline bool IsSupported() const;
|
||||
|
||||
Swapchain& operator=(const Swapchain&) = delete;
|
||||
Swapchain& operator=(Swapchain&&) = delete;
|
||||
|
||||
struct Buffer
|
||||
{
|
||||
VkImage image;
|
||||
ImageView view;
|
||||
};
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
std::vector<Buffer> m_buffers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Swapchain::AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkAcquireNextImageKHR(*m_device, m_handle, timeout, semaphore, fence, imageIndex);
|
||||
switch (m_lastErrorCode)
|
||||
{
|
||||
case VkResult::VK_SUBOPTIMAL_KHR:
|
||||
case VkResult::VK_SUCCESS:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool Swapchain::Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (!DeviceObject::Create(device, createInfo, allocator))
|
||||
return false;
|
||||
|
||||
UInt32 imageCount = 0;
|
||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, nullptr);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || imageCount == 0)
|
||||
{
|
||||
NazaraError("Failed to query swapchain image count");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<VkImage> images(imageCount);
|
||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, images.data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query swapchain images");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_buffers.resize(imageCount);
|
||||
for (UInt32 i = 0; i < imageCount; ++i)
|
||||
{
|
||||
m_buffers[i].image = images[i];
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
0, // VkImageViewCreateFlags flags;
|
||||
m_buffers[i].image, // VkImage image;
|
||||
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
|
||||
createInfo.imageFormat, // VkFormat format;
|
||||
{ // VkComponentMapping components;
|
||||
VK_COMPONENT_SWIZZLE_R, // VkComponentSwizzle .r;
|
||||
VK_COMPONENT_SWIZZLE_G, // VkComponentSwizzle .g;
|
||||
VK_COMPONENT_SWIZZLE_B, // VkComponentSwizzle .b;
|
||||
VK_COMPONENT_SWIZZLE_A // VkComponentSwizzle .a;
|
||||
},
|
||||
{ // VkImageSubresourceRange subresourceRange;
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags .aspectMask;
|
||||
0, // uint32_t .baseMipLevel;
|
||||
1, // uint32_t .levelCount;
|
||||
0, // uint32_t .baseArrayLayer;
|
||||
1 // uint32_t .layerCount;
|
||||
}
|
||||
};
|
||||
|
||||
if (!m_buffers[i].view.Create(m_device, imageViewCreateInfo))
|
||||
{
|
||||
NazaraError("Failed to create image view for image #" + String::Number(i));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const Swapchain::Buffer& Swapchain::GetBuffer(UInt32 index) const
|
||||
{
|
||||
return m_buffers[index];
|
||||
}
|
||||
|
||||
inline const std::vector<Swapchain::Buffer>& Swapchain::GetBuffers() const
|
||||
{
|
||||
return m_buffers;
|
||||
}
|
||||
|
||||
inline UInt32 Swapchain::GetBufferCount() const
|
||||
{
|
||||
return static_cast<UInt32>(m_buffers.size());
|
||||
}
|
||||
|
||||
inline bool Swapchain::IsSupported() const
|
||||
{
|
||||
if (!m_device->IsExtensionLoaded("VK_KHR_swapchain"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkResult Swapchain::CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
||||
{
|
||||
return device->vkCreateSwapchainKHR(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Swapchain::DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroySwapchainKHR(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKAN_HPP
|
||||
#define NAZARA_VULKAN_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API Vulkan
|
||||
{
|
||||
public:
|
||||
Vulkan() = delete;
|
||||
~Vulkan() = delete;
|
||||
|
||||
static Vk::DeviceHandle CreateDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
|
||||
static Vk::Instance& GetInstance();
|
||||
|
||||
static const std::vector<Vk::PhysicalDevice>& GetPhysicalDevices();
|
||||
static const Vk::PhysicalDevice& GetPhysicalDeviceInfo(VkPhysicalDevice physDevice);
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static Vk::DeviceHandle SelectDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
|
||||
static void SetParameters(const ParameterList& parameters);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static std::list<Vk::Device> s_devices;
|
||||
static std::vector<Vk::PhysicalDevice> s_physDevices;
|
||||
static Vk::Instance s_instance;
|
||||
static ParameterList s_initializationParameters;
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKAN_HPP
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 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_VULKANRENDERER_HPP
|
||||
#define NAZARA_VULKANRENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API VulkanRenderer : public RendererImpl
|
||||
{
|
||||
public:
|
||||
VulkanRenderer() = default;
|
||||
~VulkanRenderer() = default;
|
||||
|
||||
bool IsBetterThan(const RendererImpl* other) const override;
|
||||
|
||||
RenderAPI QueryAPI() const override;
|
||||
String QueryAPIString() const override;
|
||||
UInt32 QueryAPIVersion() const override;
|
||||
std::vector<RenderDevice> QueryRenderDevices() const override;
|
||||
|
||||
bool Prepare(const ParameterList& parameters) override;
|
||||
|
||||
static constexpr UInt32 APIVersion = VK_API_VERSION_1_0;
|
||||
|
||||
private:
|
||||
Vk::Instance m_instance;
|
||||
std::vector<Vk::PhysicalDevice> m_physDevices;
|
||||
UInt32 m_apiVersion;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_HPP
|
||||
|
|
@ -1,376 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#include <Nazara/Renderer/Win32/ContextImpl.hpp>
|
||||
#elif defined(NAZARA_PLATFORM_GLX)
|
||||
#include <Nazara/Renderer/GLX/ContextImpl.hpp>
|
||||
#define CALLBACK
|
||||
#else
|
||||
#error Lack of implementation: Context
|
||||
#endif
|
||||
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace
|
||||
{
|
||||
thread_local const Context* s_currentContext = nullptr;
|
||||
thread_local const Context* s_threadContext = nullptr;
|
||||
|
||||
void CALLBACK DebugCallback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, const void* userParam)
|
||||
{
|
||||
NazaraUnused(length);
|
||||
|
||||
StringStream ss;
|
||||
ss << "OpenGL debug message (ID: 0x" << String::Number(id, 16) << "):\n";
|
||||
ss << "Sent by context: " << userParam;
|
||||
ss << "\n-Source: ";
|
||||
switch (source)
|
||||
{
|
||||
case GL_DEBUG_SOURCE_API:
|
||||
ss << "OpenGL API";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
||||
ss << "Operating system";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
||||
ss << "Shader compiler";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
||||
ss << "Third party";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_APPLICATION:
|
||||
ss << "Application";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SOURCE_OTHER:
|
||||
ss << "Other";
|
||||
break;
|
||||
|
||||
default:
|
||||
// Peut être rajouté par une extension
|
||||
ss << "Unknown";
|
||||
break;
|
||||
}
|
||||
ss << '\n';
|
||||
|
||||
ss << "-Type: ";
|
||||
switch (type)
|
||||
{
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
ss << "Error";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
ss << "Deprecated behavior";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
ss << "Undefined behavior";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
ss << "Portability";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
ss << "Performance";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_TYPE_OTHER:
|
||||
ss << "Other";
|
||||
break;
|
||||
|
||||
default:
|
||||
// Peut être rajouté par une extension
|
||||
ss << "Unknown";
|
||||
break;
|
||||
}
|
||||
ss << '\n';
|
||||
|
||||
ss << "-Severity: ";
|
||||
switch (severity)
|
||||
{
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
ss << "High";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
ss << "Medium";
|
||||
break;
|
||||
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
ss << "Low";
|
||||
break;
|
||||
|
||||
default:
|
||||
// Peut être rajouté par une extension
|
||||
ss << "Unknown";
|
||||
break;
|
||||
}
|
||||
ss << '\n';
|
||||
|
||||
ss << "Message: " << message << '\n';
|
||||
|
||||
NazaraNotice(ss);
|
||||
}
|
||||
}
|
||||
|
||||
Context::~Context()
|
||||
{
|
||||
OnContextRelease(this);
|
||||
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool Context::Create(const ContextParameters& parameters)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_parameters = parameters;
|
||||
if (m_parameters.shared && !m_parameters.shareContext)
|
||||
m_parameters.shareContext = s_reference.get();
|
||||
|
||||
std::unique_ptr<ContextImpl> impl(new ContextImpl);
|
||||
if (!impl->Create(m_parameters))
|
||||
{
|
||||
NazaraError("Failed to create context implementation");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl = impl.release();
|
||||
|
||||
CallOnExit onExit([this] () { Destroy(); });
|
||||
|
||||
if (!SetActive(true))
|
||||
{
|
||||
NazaraError("Failed to activate context");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_parameters.antialiasingLevel > 0)
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
|
||||
if (m_parameters.debugMode && OpenGL::IsSupported(OpenGLExtension_DebugOutput))
|
||||
{
|
||||
glDebugMessageCallback(&DebugCallback, this);
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
#endif
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::Destroy()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
OnContextDestroy(this);
|
||||
|
||||
OpenGL::OnContextDestruction(this);
|
||||
SetActive(false);
|
||||
|
||||
m_impl->Destroy();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Context::EnableVerticalSync(bool enabled)
|
||||
{
|
||||
#ifdef NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("No context has been created");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_impl->EnableVerticalSync(enabled);
|
||||
}
|
||||
|
||||
const ContextParameters& Context::GetParameters() const
|
||||
{
|
||||
#ifdef NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
NazaraError("No context has been created");
|
||||
#endif
|
||||
|
||||
return m_parameters;
|
||||
}
|
||||
|
||||
bool Context::IsActive() const
|
||||
{
|
||||
#ifdef NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("No context has been created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return s_currentContext == this;
|
||||
}
|
||||
|
||||
bool Context::SetActive(bool active) const
|
||||
{
|
||||
#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 ((s_currentContext == this) == active)
|
||||
return true;
|
||||
|
||||
if (active)
|
||||
{
|
||||
if (!m_impl->Activate())
|
||||
return false;
|
||||
|
||||
s_currentContext = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ContextImpl::Desactivate())
|
||||
return false;
|
||||
|
||||
s_currentContext = nullptr;
|
||||
}
|
||||
|
||||
OpenGL::OnContextChanged(s_currentContext);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::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 Context::EnsureContext()
|
||||
{
|
||||
if (!s_currentContext)
|
||||
{
|
||||
if (!s_threadContext)
|
||||
{
|
||||
std::unique_ptr<Context> context(new Context);
|
||||
if (!context->Create())
|
||||
{
|
||||
NazaraError("Failed to create context");
|
||||
return false;
|
||||
}
|
||||
|
||||
s_threadContext = context.get();
|
||||
|
||||
s_contexts.emplace_back(std::move(context));
|
||||
}
|
||||
|
||||
if (!s_threadContext->SetActive(true))
|
||||
{
|
||||
NazaraError("Failed to active thread context");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const Context* Context::GetCurrent()
|
||||
{
|
||||
return s_currentContext;
|
||||
}
|
||||
|
||||
const Context* Context::GetReference()
|
||||
{
|
||||
return s_reference.get();
|
||||
}
|
||||
|
||||
const Context* Context::GetThreadContext()
|
||||
{
|
||||
EnsureContext();
|
||||
|
||||
return s_threadContext;
|
||||
}
|
||||
|
||||
bool Context::Initialize()
|
||||
{
|
||||
if (!ContextLibrary::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise library");
|
||||
return false;
|
||||
}
|
||||
|
||||
ContextParameters parameters;
|
||||
parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même
|
||||
|
||||
std::unique_ptr<Context> reference(new Context);
|
||||
if (!reference->Create(parameters))
|
||||
{
|
||||
NazaraError("Failed to create reference context");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Le contexte de référence doit rester désactivé pour le partage
|
||||
if (!reference->SetActive(false))
|
||||
{
|
||||
NazaraError("Failed to desactive reference context");
|
||||
return false;
|
||||
}
|
||||
|
||||
s_reference = std::move(reference);
|
||||
|
||||
// Le contexte de référence est partagé par défaut avec les autres contextes
|
||||
ContextParameters::defaultShareContext = s_reference.get();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::Uninitialize()
|
||||
{
|
||||
ContextLibrary::Uninitialize();
|
||||
s_contexts.clear(); // On supprime tous les contextes créés
|
||||
s_reference.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<Context> Context::s_reference;
|
||||
std::vector<std::unique_ptr<Context>> Context::s_contexts;
|
||||
ContextLibrary::LibraryMap Context::s_library;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
// Version majeure d'OpenGL, initialisé par OpenGL::Initialize()
|
||||
UInt8 ContextParameters::defaultMajorVersion;
|
||||
|
||||
// Version majeure d'OpenGL, initialisé par OpenGL::Initialize()
|
||||
UInt8 ContextParameters::defaultMinorVersion;
|
||||
|
||||
// Contexte de partage par défaut, initialisé par OpenGL::Initialize()
|
||||
const Context* ContextParameters::defaultShareContext = nullptr;
|
||||
|
||||
// Si possible, garder la compatibilité avec les fonctionnalités dépréciées
|
||||
bool ContextParameters::defaultCompatibilityProfile = false;
|
||||
|
||||
// Mode debug d'OpenGL par défaut
|
||||
#if NAZARA_RENDERER_OPENGL_DEBUG || defined(NAZARA_DEBUG)
|
||||
bool ContextParameters::defaultDebugMode = true;
|
||||
#else
|
||||
bool ContextParameters::defaultDebugMode = false;
|
||||
#endif
|
||||
|
||||
// Active le double-buffering sur les contextes
|
||||
bool ContextParameters::defaultDoubleBuffered = false;
|
||||
|
||||
// Active le partage des ressources entre contextes (Via le defaultShareContext)
|
||||
bool ContextParameters::defaultShared = true;
|
||||
}
|
||||
|
|
@ -1,741 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/DebugDrawer.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
///TODO: Améliorer
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static Shader* s_shader = nullptr;
|
||||
static Color s_primaryColor;
|
||||
static Color s_secondaryColor;
|
||||
static RenderStates s_renderStates;
|
||||
static VertexBuffer s_vertexBuffer;
|
||||
static bool s_initialized = false;
|
||||
static int s_colorLocation = -1;
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const BoundingVolumef& volume)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!volume.IsFinite())
|
||||
return;
|
||||
|
||||
Color oldPrimaryColor = s_primaryColor;
|
||||
|
||||
Draw(volume.aabb);
|
||||
|
||||
s_primaryColor = s_secondaryColor;
|
||||
Draw(volume.obb);
|
||||
|
||||
s_primaryColor = oldPrimaryColor;
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const Boxi& box)
|
||||
{
|
||||
Draw(Boxf(box));
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const Boxf& box)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24);
|
||||
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
|
||||
|
||||
Vector3f max, min;
|
||||
max = box.GetMaximum();
|
||||
min = box.GetMinimum();
|
||||
|
||||
vertex->position.Set(min.x, min.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, min.y, min.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(min.x, min.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(min.x, max.y, min.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(min.x, min.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(min.x, min.y, max.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(max.x, max.y, max.z);
|
||||
vertex++;
|
||||
vertex->position.Set(min.x, max.y, max.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(max.x, max.y, max.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, min.y, max.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(max.x, max.y, max.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, max.y, min.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(min.x, min.y, max.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, min.y, max.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(min.x, min.y, max.z);
|
||||
vertex++;
|
||||
vertex->position.Set(min.x, max.y, max.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(min.x, max.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, max.y, min.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(min.x, max.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(min.x, max.y, max.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(max.x, min.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, max.y, min.z);
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(max.x, min.y, min.z);
|
||||
vertex++;
|
||||
vertex->position.Set(max.x, min.y, max.z);
|
||||
vertex++;
|
||||
|
||||
mapper.Unmap();
|
||||
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, 24);
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const Boxui& box)
|
||||
{
|
||||
Draw(Boxf(box));
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const Frustumf& frustum)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24);
|
||||
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearRightBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarLeftBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarRightTop));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarRightTop));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarRightBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarRightTop));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearRightTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarRightBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftTop));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearRightTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftTop));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearRightBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearRightTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_NearRightBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(frustum.GetCorner(BoxCorner_FarRightBottom));
|
||||
vertex++;
|
||||
|
||||
mapper.Unmap();
|
||||
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, 24);
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const OrientedBoxf& orientedBox)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24);
|
||||
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearRightBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarLeftBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarRightTop));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarRightTop));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarRightBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarRightTop));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearRightTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarRightBottom));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarLeftBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftTop));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearRightTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftTop));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarLeftTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearRightBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearRightTop));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearRightBottom));
|
||||
vertex++;
|
||||
vertex->position.Set(orientedBox.GetCorner(BoxCorner_FarRightBottom));
|
||||
vertex++;
|
||||
|
||||
mapper.Unmap();
|
||||
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, 24);
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const Skeleton* skeleton)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int jointCount = skeleton->GetJointCount();
|
||||
if (s_vertexBuffer.GetVertexCount() < jointCount*2)
|
||||
{
|
||||
NazaraError("Debug buffer not large enougth to draw object");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, jointCount*2);
|
||||
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
|
||||
|
||||
unsigned int vertexCount = 0;
|
||||
for (unsigned int i = 0; i < jointCount; ++i)
|
||||
{
|
||||
const Node* joint = skeleton->GetJoint(i);
|
||||
const Node* parent = joint->GetParent();
|
||||
if (parent)
|
||||
{
|
||||
vertex->position = joint->GetPosition();
|
||||
vertex++;
|
||||
|
||||
vertex->position = parent->GetPosition();
|
||||
vertex++;
|
||||
|
||||
vertexCount += 2;
|
||||
}
|
||||
}
|
||||
|
||||
mapper.Unmap();
|
||||
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, vertexCount);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_secondaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_PointList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugDrawer::Draw(const Vector3f& position, float size)
|
||||
{
|
||||
Draw(Boxf(position.x - size*0.5f, position.y - size*0.5f, position.z - size*0.5f, size, size, size));
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawAxes(const Vector3f& position, float size)
|
||||
{
|
||||
Color oldPrimaryColor = s_primaryColor;
|
||||
s_primaryColor = Color::Red;
|
||||
DrawLine(position, position + Vector3f::UnitX() * 3.f * size / 4.f);
|
||||
s_primaryColor = Color::Green;
|
||||
DrawLine(position, position + Vector3f::UnitY() * 3.f * size / 4.f);
|
||||
s_primaryColor = Color::Blue;
|
||||
DrawLine(position, position + Vector3f::UnitZ() * 3.f * size / 4.f);
|
||||
|
||||
s_primaryColor = Color::Red;
|
||||
DrawCone(position + Vector3f::UnitX() * size, EulerAnglesf(0.f, 90.f, 0.f), 15, size / 4.f);
|
||||
s_primaryColor = Color::Green;
|
||||
DrawCone(position + Vector3f::UnitY() * size, EulerAnglesf(-90.f, 0.f, 0.f), 15, size / 4.f);
|
||||
s_primaryColor = Color::Blue;
|
||||
DrawCone(position + Vector3f::UnitZ() * size, EulerAnglesf(0.f, 0.f, 0.f), 15, size / 4.f);
|
||||
s_primaryColor = oldPrimaryColor;
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawBinormals(const StaticMesh* subMesh)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int normalCount = subMesh->GetVertexCount();
|
||||
unsigned int vertexCount = normalCount*2;
|
||||
if (s_vertexBuffer.GetVertexCount() < vertexCount)
|
||||
{
|
||||
NazaraError("Debug buffer not large enougth to draw object");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly);
|
||||
BufferMapper<VertexBuffer> outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount);
|
||||
|
||||
MeshVertex* inputVertex = static_cast<MeshVertex*>(inputMapper.GetPointer());
|
||||
VertexStruct_XYZ* outputVertex = static_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
|
||||
|
||||
for (unsigned int i = 0; i < normalCount; ++i)
|
||||
{
|
||||
outputVertex->position = inputVertex->position;
|
||||
outputVertex++;
|
||||
|
||||
outputVertex->position = inputVertex->position + Vector3f::CrossProduct(inputVertex->normal, inputVertex->tangent)*0.01f;
|
||||
outputVertex++;
|
||||
|
||||
inputVertex++;
|
||||
}
|
||||
|
||||
inputMapper.Unmap();
|
||||
outputMapper.Unmap();
|
||||
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawCone(const Vector3f& origin, const Quaternionf& rotation, float angle, float length)
|
||||
{
|
||||
if (!Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
Matrix4f transformMatrix;
|
||||
transformMatrix.MakeIdentity();
|
||||
transformMatrix.SetRotation(rotation);
|
||||
transformMatrix.SetTranslation(origin);
|
||||
|
||||
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 16);
|
||||
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
|
||||
|
||||
// On calcule le reste des points
|
||||
Vector3f base(Vector3f::Forward()*length);
|
||||
|
||||
// Il nous faut maintenant le rayon du cercle projeté à cette distance
|
||||
// Tangente = Opposé/Adjaçent <=> Opposé = Adjaçent*Tangente
|
||||
float radius = length*std::tan(DegreeToRadian(angle));
|
||||
Vector3f lExtend = Vector3f::Left()*radius;
|
||||
Vector3f uExtend = Vector3f::Up()*radius;
|
||||
|
||||
vertex->position.Set(transformMatrix * Vector3f::Zero());
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base + lExtend + uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * (base + lExtend + uExtend));
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base + lExtend - uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * Vector3f::Zero());
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base + lExtend - uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * (base + lExtend - uExtend));
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base - lExtend - uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * Vector3f::Zero());
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base - lExtend + uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * (base - lExtend + uExtend));
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base - lExtend - uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * Vector3f::Zero());
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base - lExtend - uExtend));
|
||||
vertex++;
|
||||
|
||||
vertex->position.Set(transformMatrix * (base - lExtend + uExtend));
|
||||
vertex++;
|
||||
vertex->position.Set(transformMatrix * (base + lExtend + uExtend));
|
||||
vertex++;
|
||||
|
||||
mapper.Unmap();
|
||||
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, 16);
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawLine(const Vector3f& p1, const Vector3f& p2)
|
||||
{
|
||||
if (!s_initialized && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
VertexStruct_XYZ buffer[2];
|
||||
buffer[0].position = p1;
|
||||
buffer[1].position = p2;
|
||||
|
||||
s_vertexBuffer.Fill(&buffer[0], 0, 2);
|
||||
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, 2);
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawPoints(const Vector3f* ptr, unsigned int pointCount)
|
||||
{
|
||||
static_assert(sizeof(VertexStruct_XYZ) == sizeof(Vector3f), "VertexStruct_XYZ is no longer equal to Vector3f, please rewrite this");
|
||||
|
||||
if (!s_initialized && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pointCount > 0)
|
||||
{
|
||||
s_vertexBuffer.Fill(ptr, 0, pointCount);
|
||||
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_PointList, 0, pointCount);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawNormals(const StaticMesh* subMesh)
|
||||
{
|
||||
if (!s_initialized && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int normalCount = subMesh->GetVertexCount();
|
||||
unsigned int vertexCount = normalCount*2;
|
||||
if (s_vertexBuffer.GetVertexCount() < vertexCount)
|
||||
{
|
||||
NazaraError("Debug buffer not large enougth to draw object");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly);
|
||||
BufferMapper<VertexBuffer> outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount);
|
||||
|
||||
MeshVertex* inputVertex = static_cast<MeshVertex*>(inputMapper.GetPointer());
|
||||
VertexStruct_XYZ* outputVertex = static_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
|
||||
|
||||
for (unsigned int i = 0; i < normalCount; ++i)
|
||||
{
|
||||
outputVertex->position = inputVertex->position;
|
||||
outputVertex++;
|
||||
|
||||
outputVertex->position = inputVertex->position + inputVertex->normal*0.01f;
|
||||
outputVertex++;
|
||||
|
||||
inputVertex++;
|
||||
}
|
||||
|
||||
inputMapper.Unmap();
|
||||
outputMapper.Unmap();
|
||||
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugDrawer::DrawTangents(const StaticMesh* subMesh)
|
||||
{
|
||||
if (!s_initialized && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize Debug Drawer");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int tangentCount = subMesh->GetVertexCount();
|
||||
unsigned int vertexCount = tangentCount*2;
|
||||
if (s_vertexBuffer.GetVertexCount() < vertexCount)
|
||||
{
|
||||
NazaraError("Debug buffer not large enougth to draw object");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferMapper<VertexBuffer> inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly);
|
||||
BufferMapper<VertexBuffer> outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount);
|
||||
|
||||
MeshVertex* inputVertex = static_cast<MeshVertex*>(inputMapper.GetPointer());
|
||||
VertexStruct_XYZ* outputVertex = static_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
|
||||
|
||||
for (unsigned int i = 0; i < tangentCount; ++i)
|
||||
{
|
||||
outputVertex->position = inputVertex->position;
|
||||
outputVertex++;
|
||||
|
||||
outputVertex->position = inputVertex->position + inputVertex->tangent*0.01f;
|
||||
outputVertex++;
|
||||
|
||||
inputVertex++;
|
||||
}
|
||||
|
||||
inputMapper.Unmap();
|
||||
outputMapper.Unmap();
|
||||
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
Renderer::DrawPrimitives(PrimitiveMode_LineList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugDrawer::EnableDepthBuffer(bool depthBuffer)
|
||||
{
|
||||
s_renderStates.depthBuffer = depthBuffer;
|
||||
}
|
||||
|
||||
float DebugDrawer::GetLineWidth()
|
||||
{
|
||||
return s_renderStates.lineWidth;
|
||||
}
|
||||
|
||||
float DebugDrawer::GetPointSize()
|
||||
{
|
||||
return s_renderStates.pointSize;
|
||||
}
|
||||
|
||||
Color DebugDrawer::GetPrimaryColor()
|
||||
{
|
||||
return s_primaryColor;
|
||||
}
|
||||
|
||||
Color DebugDrawer::GetSecondaryColor()
|
||||
{
|
||||
return s_secondaryColor;
|
||||
}
|
||||
|
||||
bool DebugDrawer::Initialize()
|
||||
{
|
||||
if (!s_initialized)
|
||||
{
|
||||
// s_shader
|
||||
s_shader = ShaderLibrary::Get("DebugSimple");
|
||||
s_colorLocation = s_shader->GetUniformLocation("Color");
|
||||
|
||||
// s_vertexBuffer
|
||||
try
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
s_vertexBuffer.Reset(VertexDeclaration::Get(VertexLayout_XYZ), 65365, DataStorage_Hardware, BufferUsage_Dynamic);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to create buffer: " + String(e.what()));
|
||||
|
||||
Uninitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
s_primaryColor = Color::Red;
|
||||
s_renderStates.depthBuffer = true;
|
||||
s_secondaryColor = Color::Green;
|
||||
|
||||
s_initialized = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DebugDrawer::IsDepthBufferEnabled()
|
||||
{
|
||||
return s_renderStates.depthBuffer;
|
||||
}
|
||||
|
||||
void DebugDrawer::SetLineWidth(float width)
|
||||
{
|
||||
s_renderStates.lineWidth = width;
|
||||
}
|
||||
|
||||
void DebugDrawer::SetPointSize(float size)
|
||||
{
|
||||
s_renderStates.pointSize = size;
|
||||
}
|
||||
|
||||
void DebugDrawer::SetPrimaryColor(const Color& color)
|
||||
{
|
||||
s_primaryColor = color;
|
||||
}
|
||||
|
||||
void DebugDrawer::SetSecondaryColor(const Color& color)
|
||||
{
|
||||
s_secondaryColor = color;
|
||||
}
|
||||
|
||||
void DebugDrawer::Uninitialize()
|
||||
{
|
||||
s_shader = nullptr;
|
||||
s_vertexBuffer.Reset();
|
||||
s_initialized = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,300 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/GLX/ContextImpl.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
using namespace GLX;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace
|
||||
{
|
||||
Display* m_display;
|
||||
int m_sharedDisplay = 0;
|
||||
|
||||
bool ctxErrorOccurred = false;
|
||||
int ctxErrorHandler( Display* /*dpy*/, XErrorEvent* /*ev*/ )
|
||||
{
|
||||
ctxErrorOccurred = true;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ContextImpl::ContextImpl() :
|
||||
m_colormap(0),
|
||||
m_context(0),
|
||||
m_window(0),
|
||||
m_ownsWindow(false)
|
||||
{
|
||||
if (m_sharedDisplay == 0)
|
||||
m_display = XOpenDisplay(nullptr);
|
||||
|
||||
++m_sharedDisplay;
|
||||
}
|
||||
|
||||
ContextImpl::~ContextImpl()
|
||||
{
|
||||
Destroy();
|
||||
|
||||
if (--m_sharedDisplay == 0)
|
||||
{
|
||||
XCloseDisplay(m_display);
|
||||
m_display = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool ContextImpl::Activate()
|
||||
{
|
||||
return glXMakeCurrent(m_display, m_window, m_context) == true;
|
||||
}
|
||||
|
||||
bool ContextImpl::Create(ContextParameters& parameters)
|
||||
{
|
||||
// En cas d'exception, la ressource sera quand même libérée
|
||||
CallOnExit onExit([this] ()
|
||||
{
|
||||
Destroy();
|
||||
});
|
||||
|
||||
// Get a matching FB config
|
||||
static int visual_attribs[] =
|
||||
{
|
||||
GLX_X_RENDERABLE, True,
|
||||
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
|
||||
GLX_BUFFER_SIZE, parameters.bitsPerPixel,
|
||||
GLX_ALPHA_SIZE, (parameters.bitsPerPixel == 32) ? 8 : 0,
|
||||
GLX_DEPTH_SIZE, parameters.depthBits,
|
||||
GLX_STENCIL_SIZE, parameters.stencilBits,
|
||||
GLX_DOUBLEBUFFER, True,
|
||||
GLX_SAMPLE_BUFFERS, (parameters.antialiasingLevel > 0) ? True : False,
|
||||
GLX_SAMPLES, parameters.antialiasingLevel,
|
||||
None
|
||||
};
|
||||
|
||||
int glx_major = 0;
|
||||
int glx_minor = 0;
|
||||
// FBConfigs were added in GLX version 1.3.
|
||||
if (!glXQueryVersion(m_display, &glx_major, &glx_minor) || ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1))
|
||||
{
|
||||
NazaraError("Invalid GLX version, version > 1.3 is required.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int fbcount;
|
||||
GLXFBConfig* fbc = glXChooseFBConfig(m_display, XDefaultScreen(m_display), visual_attribs, &fbcount);
|
||||
if (!fbc)
|
||||
{
|
||||
NazaraError("Failed to retrieve a framebuffer config");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pick the FB config/visual with the most samples per pixel
|
||||
int best_fbc = -1;
|
||||
int worst_fbc = -1;
|
||||
int best_num_samp = -1;
|
||||
int worst_num_samp = 999;
|
||||
|
||||
for (int i = 0; i < fbcount; ++i)
|
||||
{
|
||||
XVisualInfo* vi = glXGetVisualFromFBConfig(m_display, fbc[i]);
|
||||
|
||||
if (vi)
|
||||
{
|
||||
int samp_buf = 0, samples = 0;
|
||||
glXGetFBConfigAttrib(m_display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
|
||||
glXGetFBConfigAttrib(m_display, fbc[i], GLX_SAMPLES , &samples );
|
||||
|
||||
if ((best_fbc < 0) || (samp_buf && (samples > best_num_samp)))
|
||||
{
|
||||
best_fbc = i;
|
||||
best_num_samp = samples;
|
||||
}
|
||||
if ((worst_fbc < 0) || !samp_buf || (samples < worst_num_samp))
|
||||
{
|
||||
worst_fbc = i;
|
||||
worst_num_samp = samples;
|
||||
}
|
||||
}
|
||||
XFree(vi);
|
||||
}
|
||||
|
||||
GLXFBConfig bestFbc = fbc[best_fbc];
|
||||
|
||||
// Be sure to free the FBConfig list allocated by glXChooseFBConfig()
|
||||
XFree(fbc);
|
||||
|
||||
// Get a visual
|
||||
XVisualInfo* vi = glXGetVisualFromFBConfig(m_display, bestFbc);
|
||||
if (!vi)
|
||||
{
|
||||
NazaraError("Failed to get best VisualInfo");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If context is shared by multiple windows
|
||||
if (parameters.window)
|
||||
{
|
||||
m_window = parameters.window;
|
||||
m_ownsWindow = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
XSetWindowAttributes swa;
|
||||
swa.colormap = m_colormap = XCreateColormap(
|
||||
m_display,
|
||||
XRootWindow(
|
||||
m_display,
|
||||
vi->screen),
|
||||
vi->visual,
|
||||
AllocNone
|
||||
);
|
||||
|
||||
swa.background_pixmap = None;
|
||||
swa.border_pixel = 0;
|
||||
swa.event_mask = StructureNotifyMask;
|
||||
|
||||
if (!m_colormap)
|
||||
{
|
||||
NazaraError("Failed to create colormap for context");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_window = XCreateWindow(
|
||||
m_display,
|
||||
XRootWindow(
|
||||
m_display,
|
||||
vi->screen),
|
||||
0, 0, // X, Y
|
||||
1, 1, // W H
|
||||
0,
|
||||
vi->depth,
|
||||
InputOutput,
|
||||
vi->visual,
|
||||
CWBorderPixel | CWColormap | CWEventMask,
|
||||
&swa
|
||||
);
|
||||
|
||||
m_ownsWindow = true;
|
||||
}
|
||||
|
||||
if (!m_window)
|
||||
{
|
||||
NazaraError("Failed to create window");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Done with the visual info data
|
||||
XFree(vi);
|
||||
|
||||
// Install an X error handler so the application won't exit if GL 3.0
|
||||
// context allocation fails.
|
||||
//
|
||||
// Note this error handler is global. All display connections in all threads
|
||||
// of a process use the same error handler, so be sure to guard against other
|
||||
// threads issuing X commands while this code is running.
|
||||
ctxErrorOccurred = false;
|
||||
int (*oldHandler)(Display*, XErrorEvent*) =
|
||||
XSetErrorHandler(&ctxErrorHandler);
|
||||
|
||||
// Check for the GLX_ARB_create_context extension string and the function.
|
||||
// If either is not present, use GLX 1.3 context creation method.
|
||||
if (!glXCreateContextAttribs)
|
||||
{
|
||||
NazaraWarning("glXCreateContextAttribs() not found. Using old-style GLX context");
|
||||
m_context = glXCreateNewContext(m_display, bestFbc, GLX_RGBA_TYPE, parameters.shared ? parameters.shareContext->m_impl->m_context : 0, True);
|
||||
}
|
||||
// If it does, try to get a GL 3.0 context!
|
||||
else
|
||||
{
|
||||
int profile = parameters.compatibilityProfile ? GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB : GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
|
||||
int debug = parameters.debugMode ? GLX_CONTEXT_DEBUG_BIT_ARB : 0;
|
||||
|
||||
int major = 3;//parameters.majorVersion;
|
||||
int minor = 3;//parameters.minorVersion;
|
||||
|
||||
int context_attribs[] =
|
||||
{
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, major,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, minor,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, profile,
|
||||
GLX_CONTEXT_FLAGS_ARB, debug,
|
||||
None, None
|
||||
};
|
||||
|
||||
m_context = glXCreateContextAttribs(
|
||||
m_display,
|
||||
bestFbc,
|
||||
parameters.shared ? parameters.shareContext->m_impl->m_context : 0,
|
||||
True,
|
||||
context_attribs
|
||||
);
|
||||
}
|
||||
|
||||
// Sync to ensure any errors generated are processed.
|
||||
XSync(m_display, False);
|
||||
XSetErrorHandler(oldHandler);
|
||||
if (ctxErrorOccurred || !m_context)
|
||||
{
|
||||
NazaraError("Failed to create context, check the version");
|
||||
return false;
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ContextImpl::Destroy()
|
||||
{
|
||||
// Destroy the context
|
||||
if (m_context)
|
||||
{
|
||||
if (glXGetCurrentContext() == m_context)
|
||||
glXMakeCurrent(m_display, None, nullptr);
|
||||
glXDestroyContext(m_display, m_context);
|
||||
m_context = nullptr;
|
||||
}
|
||||
|
||||
// Destroy the window if we own it
|
||||
if (m_ownsWindow && m_window)
|
||||
{
|
||||
XFreeColormap(m_display, m_colormap);
|
||||
XDestroyWindow(m_display, m_window);
|
||||
m_ownsWindow = false;
|
||||
m_window = 0;
|
||||
XFlush(m_display);
|
||||
}
|
||||
}
|
||||
|
||||
void ContextImpl::EnableVerticalSync(bool enabled)
|
||||
{
|
||||
if (glXSwapIntervalEXT)
|
||||
glXSwapIntervalEXT(m_display, glXGetCurrentDrawable(), enabled ? 1 : 0);
|
||||
else if (NzglXSwapIntervalMESA)
|
||||
NzglXSwapIntervalMESA(enabled ? 1 : 0);
|
||||
else if (glXSwapIntervalSGI)
|
||||
glXSwapIntervalSGI(enabled ? 1 : 0);
|
||||
else
|
||||
NazaraError("Vertical sync not supported");
|
||||
}
|
||||
|
||||
void ContextImpl::SwapBuffers()
|
||||
{
|
||||
if (m_window)
|
||||
glXSwapBuffers(m_display, m_window);
|
||||
}
|
||||
|
||||
bool ContextImpl::Desactivate()
|
||||
{
|
||||
return glXMakeCurrent(m_display, None, nullptr) == true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2015 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_CONTEXTIMPL_HPP
|
||||
#define NAZARA_CONTEXTIMPL_HPP
|
||||
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ContextParameters;
|
||||
|
||||
class ContextImpl
|
||||
{
|
||||
public:
|
||||
ContextImpl();
|
||||
~ContextImpl();
|
||||
|
||||
bool Activate();
|
||||
|
||||
bool Create(ContextParameters& parameters);
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
void SwapBuffers();
|
||||
|
||||
static bool Desactivate();
|
||||
|
||||
private:
|
||||
GLX::Colormap m_colormap;
|
||||
GLX::GLXContext m_context;
|
||||
GLX::Window m_window;
|
||||
bool m_ownsWindow;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CONTEXTIMPL_HPP
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/GpuQuery.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
GpuQuery::GpuQuery() :
|
||||
m_id(0)
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
m_id = 0;
|
||||
glGenQueries(1, static_cast<GLuint*>(&m_id));
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Failed to create occlusion query");
|
||||
throw std::runtime_error("Constructor failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GpuQuery::~GpuQuery()
|
||||
{
|
||||
if (m_id)
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
GLuint query = static_cast<GLuint>(m_id);
|
||||
glDeleteQueries(1, &query);
|
||||
}
|
||||
}
|
||||
|
||||
void GpuQuery::Begin(GpuQueryMode mode)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (Context::GetCurrent() == nullptr)
|
||||
{
|
||||
NazaraError("No active context");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!IsModeSupported(mode))
|
||||
{
|
||||
NazaraError("Mode (0x" + String::Number(mode, 16) + ") not supported");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_mode = mode;
|
||||
glBeginQuery(OpenGL::QueryMode[mode], m_id);
|
||||
}
|
||||
|
||||
void GpuQuery::End()
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (Context::GetCurrent() == nullptr)
|
||||
{
|
||||
NazaraError("No active context");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glEndQuery(OpenGL::QueryMode[m_mode]);
|
||||
}
|
||||
|
||||
unsigned int GpuQuery::GetResult() const
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
GLuint result;
|
||||
glGetQueryObjectuiv(m_id, GL_QUERY_RESULT, &result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GpuQuery::IsResultAvailable() const
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
GLint available;
|
||||
glGetQueryObjectiv(m_id, GL_QUERY_RESULT_AVAILABLE, &available);
|
||||
|
||||
return available == GL_TRUE;
|
||||
}
|
||||
|
||||
unsigned int GpuQuery::GetOpenGLID() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool GpuQuery::IsModeSupported(GpuQueryMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case GpuQueryMode_AnySamplesPassedConservative:
|
||||
return OpenGL::GetVersion() >= 430;
|
||||
|
||||
case GpuQueryMode_AnySamplesPassed:
|
||||
case GpuQueryMode_PrimitiveGenerated:
|
||||
case GpuQueryMode_SamplesPassed:
|
||||
case GpuQueryMode_TimeElapsed:
|
||||
case GpuQueryMode_TransformFeedbackPrimitivesWritten:
|
||||
return true;
|
||||
}
|
||||
|
||||
NazaraError("Gpu Query mode not handled (0x" + String::Number(mode, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
// Copyright (C) 2015 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 <Nazara/Renderer/HardwareBuffer.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
HardwareBuffer::HardwareBuffer(Buffer* parent, BufferType type) :
|
||||
m_type(type),
|
||||
m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
HardwareBuffer::~HardwareBuffer() = default;
|
||||
|
||||
bool HardwareBuffer::Create(unsigned int size, BufferUsage usage)
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
m_buffer = 0;
|
||||
glGenBuffers(1, &m_buffer);
|
||||
|
||||
OpenGL::BindBuffer(m_type, m_buffer);
|
||||
|
||||
glBufferData(OpenGL::BufferTarget[m_type], size, nullptr, OpenGL::BufferUsage[usage]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HardwareBuffer::Destroy()
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
OpenGL::DeleteBuffer(m_type, m_buffer);
|
||||
}
|
||||
|
||||
bool HardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard)
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
unsigned int totalSize = m_parent->GetSize();
|
||||
|
||||
if (!forceDiscard)
|
||||
forceDiscard = (size == totalSize);
|
||||
|
||||
OpenGL::BindBuffer(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/Buffer_Object_Streaming
|
||||
if (forceDiscard)
|
||||
glBufferData(OpenGL::BufferTarget[m_type], totalSize, nullptr, OpenGL::BufferUsage[m_parent->GetUsage()]); // Discard
|
||||
|
||||
glBufferSubData(OpenGL::BufferTarget[m_type], offset, size, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
void* ptr = Map((forceDiscard) ? BufferAccess_DiscardAndWrite : BufferAccess_WriteOnly, offset, size);
|
||||
if (!ptr)
|
||||
{
|
||||
NazaraError("Failed to map buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::memcpy(ptr, data, size);
|
||||
|
||||
Unmap();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HardwareBuffer::IsHardware() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void* HardwareBuffer::Map(BufferAccess access, unsigned int offset, unsigned int size)
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
OpenGL::BindBuffer(m_type, m_buffer);
|
||||
|
||||
if (glMapBufferRange)
|
||||
return glMapBufferRange(OpenGL::BufferTarget[m_type], offset, size, OpenGL::BufferLockRange[access]);
|
||||
else
|
||||
{
|
||||
// http://www.opengl.org/wiki/Buffer_Object_Streaming
|
||||
if (access == BufferAccess_DiscardAndWrite)
|
||||
glBufferData(OpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, OpenGL::BufferUsage[m_parent->GetUsage()]); // Discard
|
||||
|
||||
UInt8* ptr = static_cast<UInt8*>(glMapBuffer(OpenGL::BufferTarget[m_type], OpenGL::BufferLock[access]));
|
||||
if (ptr)
|
||||
ptr += offset;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool HardwareBuffer::Unmap()
|
||||
{
|
||||
Context::EnsureContext();
|
||||
|
||||
OpenGL::BindBuffer(m_type, m_buffer);
|
||||
|
||||
if (glUnmapBuffer(OpenGL::BufferTarget[m_type]) != GL_TRUE)
|
||||
{
|
||||
glBufferData(OpenGL::BufferTarget[m_type], m_parent->GetSize(), nullptr, OpenGL::BufferUsage[m_parent->GetUsage()]);
|
||||
|
||||
// Une erreur rare est survenue, nous devons réinitialiser le buffer
|
||||
NazaraError("Failed to unmap buffer, reinitialising content... (OpenGL error : 0x" + String::Number(glGetError(), 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HardwareBuffer::Bind() const
|
||||
{
|
||||
OpenGL::BindBuffer(m_type, m_buffer);
|
||||
}
|
||||
|
||||
unsigned int HardwareBuffer::GetOpenGLID() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright (C) 2015 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_HARDWAREBUFFER_HPP
|
||||
#define NAZARA_HARDWAREBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class HardwareBuffer : public AbstractBuffer
|
||||
{
|
||||
public:
|
||||
HardwareBuffer(Buffer* parent, BufferType type);
|
||||
~HardwareBuffer();
|
||||
|
||||
bool Create(unsigned int size, BufferUsage usage = BufferUsage_Static);
|
||||
void Destroy();
|
||||
|
||||
bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard);
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
void* Map(BufferAccess access, unsigned int offset = 0, unsigned int size = 0);
|
||||
bool Unmap();
|
||||
|
||||
// Fonctions OpenGL
|
||||
void Bind() const;
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
private:
|
||||
GLuint m_buffer;
|
||||
BufferType m_type;
|
||||
Buffer* m_parent;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_HARDWAREBUFFER_HPP
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue