From 44c8e7a62785e29b6dea99d9712ba30e4d4182b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Tue, 25 May 2021 00:09:07 +0200 Subject: [PATCH] Upgrade example code --- examples/DeferredShading/main.cpp | 92 +++++++++++++++---------------- examples/GraphicsTest/main.cpp | 36 ++++++------ examples/HardwareInfo/main.cpp | 2 +- examples/RenderTest/main.cpp | 36 ++++++------ 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index fc885c29a..6f613e78c 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -83,9 +83,9 @@ int main() Nz::RenderWindow window; Nz::MeshParams meshParams; - meshParams.storage = Nz::DataStorage_Software; + meshParams.storage = Nz::DataStorage::Software; meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f)); - meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV); + meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV); std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); const Nz::RenderDeviceInfo& deviceInfo = device->GetDeviceInfo(); @@ -97,18 +97,18 @@ int main() return __LINE__; } - Nz::MeshRef spaceship = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); + std::shared_ptr spaceship = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); if (!spaceship) { NazaraError("Failed to load model"); return __LINE__; } - std::shared_ptr gfxMesh = std::make_shared(spaceship); + std::shared_ptr gfxMesh = std::make_shared(*spaceship); // Spaceship texture - Nz::ImageRef spaceshipDiffuse = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); - if (!spaceshipDiffuse || !spaceshipDiffuse->Convert(Nz::PixelFormat_RGBA8_SRGB)) + std::shared_ptr spaceshipDiffuse = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); + if (!spaceshipDiffuse || !spaceshipDiffuse->Convert(Nz::PixelFormat::RGBA8_SRGB)) { NazaraError("Failed to load image"); return __LINE__; @@ -129,8 +129,8 @@ int main() } // Plane texture - Nz::ImageRef devImage = Nz::Image::LoadFromFile(resourceDir / "dev_grey.png"); - if (!devImage || !devImage->Convert(Nz::PixelFormat_RGBA8_SRGB)) + std::shared_ptr devImage = Nz::Image::LoadFromFile(resourceDir / "dev_grey.png"); + if (!devImage || !devImage->Convert(Nz::PixelFormat::RGBA8_SRGB)) { NazaraError("Failed to load image"); return __LINE__; @@ -151,8 +151,8 @@ int main() } // Texture (alpha-map) - Nz::ImageRef alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png"); - if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat_RGBA8)) + std::shared_ptr alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png"); + if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat::RGBA8)) { NazaraError("Failed to load image"); return __LINE__; @@ -173,14 +173,14 @@ int main() } Nz::MeshParams planeParams; - planeParams.storage = Nz::DataStorage_Software; + planeParams.storage = Nz::DataStorage::Software; - Nz::MeshRef planeMesh = Nz::Mesh::New(); + std::shared_ptr planeMesh = std::make_shared(); planeMesh->CreateStatic(); planeMesh->BuildSubMesh(Nz::Primitive::Plane(Nz::Vector2f(10.f, 10.f), Nz::Vector2ui(0u), Nz::Matrix4f::Rotate(Nz::EulerAnglesf(180.f, 0.f, 0.f)), Nz::Rectf(0.f, 0.f, 10.f, 10.f)), planeParams); planeMesh->SetMaterialCount(1); - std::shared_ptr planeMeshGfx = std::make_shared(planeMesh); + std::shared_ptr planeMeshGfx = std::make_shared(*planeMesh); auto customSettings = Nz::BasicMaterial::GetSettings()->GetBuilderData(); customSettings.shaders[UnderlyingCast(Nz::ShaderStageType::Fragment)] = std::make_shared(Nz::ShaderStageType::Fragment, Nz::ShaderLang::Parse(resourceDir / "deferred_frag.nzsl")); @@ -205,8 +205,8 @@ int main() Nz::TextureSamplerInfo planeSampler; planeSampler.anisotropyLevel = 16; - planeSampler.wrapModeU = Nz::SamplerWrap_Repeat; - planeSampler.wrapModeV = Nz::SamplerWrap_Repeat; + planeSampler.wrapModeU = Nz::SamplerWrap::Repeat; + planeSampler.wrapModeV = Nz::SamplerWrap::Repeat; basicMat.SetDiffuseSampler(planeSampler); } @@ -288,12 +288,12 @@ int main() 3 }); - /*Nz::FieldOffsets pointLightOffsets(Nz::StructLayout_Std140); - std::size_t colorOffset = pointLightOffsets.AddField(Nz::StructFieldType_Float3); - std::size_t positionOffset = pointLightOffsets.AddField(Nz::StructFieldType_Float3); - std::size_t constantOffset = pointLightOffsets.AddField(Nz::StructFieldType_Float1); - std::size_t linearOffset = pointLightOffsets.AddField(Nz::StructFieldType_Float1); - std::size_t quadraticOffset = pointLightOffsets.AddField(Nz::StructFieldType_Float1); + /*Nz::FieldOffsets pointLightOffsets(Nz::StructLayout::Std140); + std::size_t colorOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float3); + std::size_t positionOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float3); + std::size_t constantOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float1); + std::size_t linearOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float1); + std::size_t quadraticOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float1); std::size_t alignedPointLightSize = Nz::Align(pointLightOffsets.GetSize(), static_cast(deviceInfo.limits.minUniformBufferOffsetAlignment));*/ @@ -314,22 +314,22 @@ int main() } */ - Nz::FieldOffsets spotLightOffsets(Nz::StructLayout_Std140); - std::size_t colorOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float3); - std::size_t positionOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float3); - std::size_t directionOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float3); - std::size_t constantOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float1); - std::size_t linearOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float1); - std::size_t quadraticOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float1); - std::size_t innerAngleOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float1); - std::size_t outerAngleOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float1); + Nz::FieldOffsets spotLightOffsets(Nz::StructLayout::Std140); + std::size_t colorOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float3); + std::size_t positionOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float3); + std::size_t directionOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float3); + std::size_t constantOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1); + std::size_t linearOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1); + std::size_t quadraticOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1); + std::size_t innerAngleOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1); + std::size_t outerAngleOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1); std::size_t alignedSpotLightSize = Nz::Align(spotLightOffsets.GetSize(), static_cast(deviceInfo.limits.minUniformBufferOffsetAlignment)); constexpr std::size_t MaxPointLight = 1000; - std::shared_ptr lightUbo = device->InstantiateBuffer(Nz::BufferType_Uniform); - if (!lightUbo->Initialize(MaxPointLight * alignedSpotLightSize, Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic)) + std::shared_ptr lightUbo = device->InstantiateBuffer(Nz::BufferType::Uniform); + if (!lightUbo->Initialize(MaxPointLight * alignedSpotLightSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic)) return __LINE__; std::vector spotLights; @@ -354,7 +354,7 @@ int main() } - const Nz::VertexDeclarationRef& vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_UV); + const std::shared_ptr& vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_UV); unsigned int offscreenWidth = window.GetSize().x; @@ -363,7 +363,7 @@ int main() // Fullscreen data Nz::RenderPipelineInfo fullscreenPipelineInfo; - fullscreenPipelineInfo.primitiveMode = Nz::PrimitiveMode_TriangleStrip; + fullscreenPipelineInfo.primitiveMode = Nz::PrimitiveMode::TriangleStrip; fullscreenPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(fullscreenPipelineLayoutInfo); fullscreenPipelineInfo.vertexBuffers.push_back({ 0, @@ -380,7 +380,7 @@ int main() lightingPipelineInfo.blending = true; lightingPipelineInfo.blend.dstColor = Nz::BlendFunc::One; lightingPipelineInfo.blend.srcColor = Nz::BlendFunc::One; - lightingPipelineInfo.primitiveMode = Nz::PrimitiveMode_TriangleStrip; + lightingPipelineInfo.primitiveMode = Nz::PrimitiveMode::TriangleStrip; lightingPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(lightingPipelineLayoutInfo); lightingPipelineInfo.vertexBuffers.push_back({ 0, @@ -431,8 +431,8 @@ int main() } };*/ - std::shared_ptr vertexBuffer = device->InstantiateBuffer(Nz::BufferType_Vertex); - if (!vertexBuffer->Initialize(vertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage_DeviceLocal)) + std::shared_ptr vertexBuffer = device->InstantiateBuffer(Nz::BufferType::Vertex); + if (!vertexBuffer->Initialize(vertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage::DeviceLocal)) return __LINE__; if (!vertexBuffer->Fill(vertexData.data(), 0, vertexBuffer->GetSize())) @@ -453,27 +453,27 @@ int main() colorTexture = graph.AddAttachment({ "Color", - Nz::PixelFormat_RGBA8 + Nz::PixelFormat::RGBA8 }); normalTexture = graph.AddAttachment({ "Normal", - Nz::PixelFormat_RGBA8 + Nz::PixelFormat::RGBA8 }); positionTexture = graph.AddAttachment({ "Position", - Nz::PixelFormat_RGBA32F + Nz::PixelFormat::RGBA32F }); depthBuffer = graph.AddAttachment({ "Depth buffer", - Nz::PixelFormat_Depth24Stencil8 + Nz::PixelFormat::Depth24Stencil8 }); backbuffer = graph.AddAttachment({ "Backbuffer", - Nz::PixelFormat_RGBA8 + Nz::PixelFormat::RGBA8 }); Nz::FramePass& gbufferPass = graph.AddPass("GBuffer"); @@ -661,11 +661,11 @@ int main() { switch (event.type) { - case Nz::WindowEventType_Quit: + case Nz::WindowEventType::Quit: window.Close(); break; - case Nz::WindowEventType_MouseMoved: // La souris a bougé + case Nz::WindowEventType::MouseMoved: // La souris a bougé { // Gestion de la caméra free-fly (Rotation) float sensitivity = 0.3f; // Sensibilité de la souris @@ -682,7 +682,7 @@ int main() break; } - case Nz::WindowEventType_KeyPressed: + case Nz::WindowEventType::KeyPressed: { if (event.key.scancode == Nz::Keyboard::Scancode::Space) { @@ -696,7 +696,7 @@ int main() break; } - case Nz::WindowEventType_Resized: + case Nz::WindowEventType::Resized: { Nz::Vector2ui windowSize = window.GetSize(); Nz::AccessByOffset(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f); diff --git a/examples/GraphicsTest/main.cpp b/examples/GraphicsTest/main.cpp index 2700e3605..1b495fb81 100644 --- a/examples/GraphicsTest/main.cpp +++ b/examples/GraphicsTest/main.cpp @@ -27,9 +27,9 @@ int main() Nz::RenderWindow window; Nz::MeshParams meshParams; - meshParams.storage = Nz::DataStorage_Software; + meshParams.storage = Nz::DataStorage::Software; meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f)); - meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV); + meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV); std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); @@ -40,40 +40,40 @@ int main() return __LINE__; } - Nz::MeshRef drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); - if (!drfreak) + std::shared_ptr spaceshipMesh = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); + if (!spaceshipMesh) { NazaraError("Failed to load model"); return __LINE__; } - std::shared_ptr gfxMesh = std::make_shared(drfreak); + std::shared_ptr gfxMesh = std::make_shared(*spaceshipMesh); // Texture - Nz::ImageRef drfreakImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); - if (!drfreakImage || !drfreakImage->Convert(Nz::PixelFormat_RGBA8_SRGB)) + std::shared_ptr diffuseImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); + if (!diffuseImage || !diffuseImage->Convert(Nz::PixelFormat::RGBA8_SRGB)) { NazaraError("Failed to load image"); return __LINE__; } Nz::TextureInfo texParams; - texParams.pixelFormat = drfreakImage->GetFormat(); - texParams.type = drfreakImage->GetType(); - texParams.width = drfreakImage->GetWidth(); - texParams.height = drfreakImage->GetHeight(); - texParams.depth = drfreakImage->GetDepth(); + texParams.pixelFormat = diffuseImage->GetFormat(); + texParams.type = diffuseImage->GetType(); + texParams.width = diffuseImage->GetWidth(); + texParams.height = diffuseImage->GetHeight(); + texParams.depth = diffuseImage->GetDepth(); std::shared_ptr texture = device->InstantiateTexture(texParams); - if (!texture->Update(drfreakImage->GetConstPixels())) + if (!texture->Update(diffuseImage->GetConstPixels())) { NazaraError("Failed to update texture"); return __LINE__; } // Texture (alpha-map) - Nz::ImageRef alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png"); - if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat_RGBA8)) + std::shared_ptr alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png"); + if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat::RGBA8)) { NazaraError("Failed to load image"); return __LINE__; @@ -207,11 +207,11 @@ int main() { switch (event.type) { - case Nz::WindowEventType_Quit: + case Nz::WindowEventType::Quit: window.Close(); break; - case Nz::WindowEventType_MouseMoved: // La souris a bougé + case Nz::WindowEventType::MouseMoved: // La souris a bougé { // Gestion de la caméra free-fly (Rotation) float sensitivity = 0.3f; // Sensibilité de la souris @@ -228,7 +228,7 @@ int main() break; } - case Nz::WindowEventType_Resized: + case Nz::WindowEventType::Resized: { Nz::Vector2ui windowSize = window.GetSize(); Nz::AccessByOffset(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f); diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index 0a328cfda..4173bf267 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -63,7 +63,7 @@ int main() std::cout << oss.str() << std::endl; Nz::File reportFile("HardwareInfo.txt"); - if (reportFile.Open(Nz::OpenMode_Text | Nz::OpenMode_Truncate | Nz::OpenMode_WriteOnly)) + if (reportFile.Open(Nz::OpenMode::Text | Nz::OpenMode::Truncate | Nz::OpenMode::WriteOnly)) { reportFile.Write(oss.str()); // Conversion implicite en std::string reportFile.Close(); diff --git a/examples/RenderTest/main.cpp b/examples/RenderTest/main.cpp index 335eba093..5b6ba47cd 100644 --- a/examples/RenderTest/main.cpp +++ b/examples/RenderTest/main.cpp @@ -88,7 +88,7 @@ int main() Nz::MeshParams meshParams; meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f)); - meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV); + meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV); std::shared_ptr device = Nz::Renderer::Instance()->InstanciateRenderDevice(0); @@ -110,27 +110,27 @@ int main() return __LINE__; } - Nz::MeshRef drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); + std::shared_ptr drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); if (!drfreak) { NazaraError("Failed to load model"); return __LINE__; } - Nz::StaticMesh* drfreakMesh = static_cast(drfreak->GetSubMesh(0)); + std::shared_ptr spaceshipMesh = std::static_pointer_cast(drfreak->GetSubMesh(0)); - const Nz::VertexBuffer* drfreakVB = drfreakMesh->GetVertexBuffer(); - const Nz::IndexBuffer* drfreakIB = drfreakMesh->GetIndexBuffer(); + const std::shared_ptr& meshVB = spaceshipMesh->GetVertexBuffer(); + const std::shared_ptr& meshIB = spaceshipMesh->GetIndexBuffer(); // Index buffer - std::cout << "Index count: " << drfreakIB->GetIndexCount() << std::endl; + std::cout << "Index count: " << meshIB->GetIndexCount() << std::endl; // Vertex buffer - std::cout << "Vertex count: " << drfreakVB->GetVertexCount() << std::endl; + std::cout << "Vertex count: " << meshVB->GetVertexCount() << std::endl; // Texture - Nz::ImageRef drfreakImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); - if (!drfreakImage || !drfreakImage->Convert(Nz::PixelFormat_RGBA8)) + std::shared_ptr drfreakImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); + if (!drfreakImage || !drfreakImage->Convert(Nz::PixelFormat::RGBA8)) { NazaraError("Failed to load image"); return __LINE__; @@ -182,8 +182,8 @@ int main() Nz::ShaderBindingPtr shaderBinding = renderPipelineLayout->AllocateShaderBinding(); - std::shared_ptr uniformBuffer = device->InstantiateBuffer(Nz::BufferType_Uniform); - if (!uniformBuffer->Initialize(uniformSize, Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic)) + std::shared_ptr uniformBuffer = device->InstantiateBuffer(Nz::BufferType::Uniform); + if (!uniformBuffer->Initialize(uniformSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic)) { NazaraError("Failed to create uniform buffer"); return __LINE__; @@ -212,7 +212,7 @@ int main() auto& vertexBuffer = pipelineInfo.vertexBuffers.emplace_back(); vertexBuffer.binding = 0; - vertexBuffer.declaration = drfreakVB->GetVertexDeclaration(); + vertexBuffer.declaration = meshVB->GetVertexDeclaration(); std::shared_ptr pipeline = device->InstantiateRenderPipeline(pipelineInfo); @@ -221,8 +221,8 @@ int main() Nz::RenderWindowImpl* windowImpl = window.GetImpl(); std::shared_ptr commandPool = windowImpl->CreateCommandPool(Nz::QueueType::Graphics); - Nz::RenderBuffer* renderBufferIB = static_cast(drfreakIB->GetBuffer()->GetImpl()); - Nz::RenderBuffer* renderBufferVB = static_cast(drfreakVB->GetBuffer()->GetImpl()); + Nz::RenderBuffer* renderBufferIB = static_cast(meshIB->GetBuffer()->GetImpl()); + Nz::RenderBuffer* renderBufferVB = static_cast(meshVB->GetBuffer()->GetImpl()); if (!renderBufferIB->Synchronize(renderDevice)) { @@ -265,7 +265,7 @@ int main() builder.SetScissor(Nz::Recti{ 0, 0, int(windowSize.x), int(windowSize.y) }); builder.SetViewport(Nz::Recti{ 0, 0, int(windowSize.x), int(windowSize.y) }); - builder.DrawIndexed(drfreakIB->GetIndexCount()); + builder.DrawIndexed(meshIB->GetIndexCount()); } builder.EndRenderPass(); } @@ -296,11 +296,11 @@ int main() { switch (event.type) { - case Nz::WindowEventType_Quit: + case Nz::WindowEventType::Quit: window.Close(); break; - case Nz::WindowEventType_MouseMoved: // La souris a bougé + case Nz::WindowEventType::MouseMoved: // La souris a bougé { // Gestion de la caméra free-fly (Rotation) float sensitivity = 0.3f; // Sensibilité de la souris @@ -317,7 +317,7 @@ int main() break; } - case Nz::WindowEventType_Resized: + case Nz::WindowEventType::Resized: { Nz::Vector2ui windowSize = window.GetSize(); ubo.projectionMatrix = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);