Upgrade example code

This commit is contained in:
Jérôme Leclercq 2021-05-25 00:09:07 +02:00
parent 874fb3542e
commit 44c8e7a627
4 changed files with 83 additions and 83 deletions

View File

@ -83,9 +83,9 @@ int main()
Nz::RenderWindow window; Nz::RenderWindow window;
Nz::MeshParams meshParams; 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.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<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice(); std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
const Nz::RenderDeviceInfo& deviceInfo = device->GetDeviceInfo(); const Nz::RenderDeviceInfo& deviceInfo = device->GetDeviceInfo();
@ -97,18 +97,18 @@ int main()
return __LINE__; return __LINE__;
} }
Nz::MeshRef spaceship = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); std::shared_ptr<Nz::Mesh> spaceship = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
if (!spaceship) if (!spaceship)
{ {
NazaraError("Failed to load model"); NazaraError("Failed to load model");
return __LINE__; return __LINE__;
} }
std::shared_ptr<Nz::GraphicalMesh> gfxMesh = std::make_shared<Nz::GraphicalMesh>(spaceship); std::shared_ptr<Nz::GraphicalMesh> gfxMesh = std::make_shared<Nz::GraphicalMesh>(*spaceship);
// Spaceship texture // Spaceship texture
Nz::ImageRef spaceshipDiffuse = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); std::shared_ptr<Nz::Image> spaceshipDiffuse = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png");
if (!spaceshipDiffuse || !spaceshipDiffuse->Convert(Nz::PixelFormat_RGBA8_SRGB)) if (!spaceshipDiffuse || !spaceshipDiffuse->Convert(Nz::PixelFormat::RGBA8_SRGB))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load image");
return __LINE__; return __LINE__;
@ -129,8 +129,8 @@ int main()
} }
// Plane texture // Plane texture
Nz::ImageRef devImage = Nz::Image::LoadFromFile(resourceDir / "dev_grey.png"); std::shared_ptr<Nz::Image> devImage = Nz::Image::LoadFromFile(resourceDir / "dev_grey.png");
if (!devImage || !devImage->Convert(Nz::PixelFormat_RGBA8_SRGB)) if (!devImage || !devImage->Convert(Nz::PixelFormat::RGBA8_SRGB))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load image");
return __LINE__; return __LINE__;
@ -151,8 +151,8 @@ int main()
} }
// Texture (alpha-map) // Texture (alpha-map)
Nz::ImageRef alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png"); std::shared_ptr<Nz::Image> alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png");
if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat_RGBA8)) if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat::RGBA8))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load image");
return __LINE__; return __LINE__;
@ -173,14 +173,14 @@ int main()
} }
Nz::MeshParams planeParams; Nz::MeshParams planeParams;
planeParams.storage = Nz::DataStorage_Software; planeParams.storage = Nz::DataStorage::Software;
Nz::MeshRef planeMesh = Nz::Mesh::New(); std::shared_ptr<Nz::Mesh> planeMesh = std::make_shared<Nz::Mesh>();
planeMesh->CreateStatic(); 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->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); planeMesh->SetMaterialCount(1);
std::shared_ptr<Nz::GraphicalMesh> planeMeshGfx = std::make_shared<Nz::GraphicalMesh>(planeMesh); std::shared_ptr<Nz::GraphicalMesh> planeMeshGfx = std::make_shared<Nz::GraphicalMesh>(*planeMesh);
auto customSettings = Nz::BasicMaterial::GetSettings()->GetBuilderData(); auto customSettings = Nz::BasicMaterial::GetSettings()->GetBuilderData();
customSettings.shaders[UnderlyingCast(Nz::ShaderStageType::Fragment)] = std::make_shared<Nz::UberShader>(Nz::ShaderStageType::Fragment, Nz::ShaderLang::Parse(resourceDir / "deferred_frag.nzsl")); customSettings.shaders[UnderlyingCast(Nz::ShaderStageType::Fragment)] = std::make_shared<Nz::UberShader>(Nz::ShaderStageType::Fragment, Nz::ShaderLang::Parse(resourceDir / "deferred_frag.nzsl"));
@ -205,8 +205,8 @@ int main()
Nz::TextureSamplerInfo planeSampler; Nz::TextureSamplerInfo planeSampler;
planeSampler.anisotropyLevel = 16; planeSampler.anisotropyLevel = 16;
planeSampler.wrapModeU = Nz::SamplerWrap_Repeat; planeSampler.wrapModeU = Nz::SamplerWrap::Repeat;
planeSampler.wrapModeV = Nz::SamplerWrap_Repeat; planeSampler.wrapModeV = Nz::SamplerWrap::Repeat;
basicMat.SetDiffuseSampler(planeSampler); basicMat.SetDiffuseSampler(planeSampler);
} }
@ -288,12 +288,12 @@ int main()
3 3
}); });
/*Nz::FieldOffsets pointLightOffsets(Nz::StructLayout_Std140); /*Nz::FieldOffsets pointLightOffsets(Nz::StructLayout::Std140);
std::size_t colorOffset = pointLightOffsets.AddField(Nz::StructFieldType_Float3); std::size_t colorOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float3);
std::size_t positionOffset = 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 constantOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float1);
std::size_t linearOffset = 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 quadraticOffset = pointLightOffsets.AddField(Nz::StructFieldType::Float1);
std::size_t alignedPointLightSize = Nz::Align(pointLightOffsets.GetSize(), static_cast<std::size_t>(deviceInfo.limits.minUniformBufferOffsetAlignment));*/ std::size_t alignedPointLightSize = Nz::Align(pointLightOffsets.GetSize(), static_cast<std::size_t>(deviceInfo.limits.minUniformBufferOffsetAlignment));*/
@ -314,22 +314,22 @@ int main()
} }
*/ */
Nz::FieldOffsets spotLightOffsets(Nz::StructLayout_Std140); Nz::FieldOffsets spotLightOffsets(Nz::StructLayout::Std140);
std::size_t colorOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float3); std::size_t colorOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float3);
std::size_t positionOffset = 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 directionOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float3);
std::size_t constantOffset = spotLightOffsets.AddField(Nz::StructFieldType_Float1); std::size_t constantOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1);
std::size_t linearOffset = 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 quadraticOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1);
std::size_t innerAngleOffset = 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 outerAngleOffset = spotLightOffsets.AddField(Nz::StructFieldType::Float1);
std::size_t alignedSpotLightSize = Nz::Align(spotLightOffsets.GetSize(), static_cast<std::size_t>(deviceInfo.limits.minUniformBufferOffsetAlignment)); std::size_t alignedSpotLightSize = Nz::Align(spotLightOffsets.GetSize(), static_cast<std::size_t>(deviceInfo.limits.minUniformBufferOffsetAlignment));
constexpr std::size_t MaxPointLight = 1000; constexpr std::size_t MaxPointLight = 1000;
std::shared_ptr<Nz::AbstractBuffer> lightUbo = device->InstantiateBuffer(Nz::BufferType_Uniform); std::shared_ptr<Nz::AbstractBuffer> lightUbo = device->InstantiateBuffer(Nz::BufferType::Uniform);
if (!lightUbo->Initialize(MaxPointLight * alignedSpotLightSize, Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic)) if (!lightUbo->Initialize(MaxPointLight * alignedSpotLightSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
return __LINE__; return __LINE__;
std::vector<SpotLight> spotLights; std::vector<SpotLight> spotLights;
@ -354,7 +354,7 @@ int main()
} }
const Nz::VertexDeclarationRef& vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_UV); const std::shared_ptr<const Nz::VertexDeclaration>& vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_UV);
unsigned int offscreenWidth = window.GetSize().x; unsigned int offscreenWidth = window.GetSize().x;
@ -363,7 +363,7 @@ int main()
// Fullscreen data // Fullscreen data
Nz::RenderPipelineInfo fullscreenPipelineInfo; Nz::RenderPipelineInfo fullscreenPipelineInfo;
fullscreenPipelineInfo.primitiveMode = Nz::PrimitiveMode_TriangleStrip; fullscreenPipelineInfo.primitiveMode = Nz::PrimitiveMode::TriangleStrip;
fullscreenPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(fullscreenPipelineLayoutInfo); fullscreenPipelineInfo.pipelineLayout = device->InstantiateRenderPipelineLayout(fullscreenPipelineLayoutInfo);
fullscreenPipelineInfo.vertexBuffers.push_back({ fullscreenPipelineInfo.vertexBuffers.push_back({
0, 0,
@ -380,7 +380,7 @@ int main()
lightingPipelineInfo.blending = true; lightingPipelineInfo.blending = true;
lightingPipelineInfo.blend.dstColor = Nz::BlendFunc::One; lightingPipelineInfo.blend.dstColor = Nz::BlendFunc::One;
lightingPipelineInfo.blend.srcColor = 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.pipelineLayout = device->InstantiateRenderPipelineLayout(lightingPipelineLayoutInfo);
lightingPipelineInfo.vertexBuffers.push_back({ lightingPipelineInfo.vertexBuffers.push_back({
0, 0,
@ -431,8 +431,8 @@ int main()
} }
};*/ };*/
std::shared_ptr<Nz::AbstractBuffer> vertexBuffer = device->InstantiateBuffer(Nz::BufferType_Vertex); std::shared_ptr<Nz::AbstractBuffer> vertexBuffer = device->InstantiateBuffer(Nz::BufferType::Vertex);
if (!vertexBuffer->Initialize(vertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage_DeviceLocal)) if (!vertexBuffer->Initialize(vertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage::DeviceLocal))
return __LINE__; return __LINE__;
if (!vertexBuffer->Fill(vertexData.data(), 0, vertexBuffer->GetSize())) if (!vertexBuffer->Fill(vertexData.data(), 0, vertexBuffer->GetSize()))
@ -453,27 +453,27 @@ int main()
colorTexture = graph.AddAttachment({ colorTexture = graph.AddAttachment({
"Color", "Color",
Nz::PixelFormat_RGBA8 Nz::PixelFormat::RGBA8
}); });
normalTexture = graph.AddAttachment({ normalTexture = graph.AddAttachment({
"Normal", "Normal",
Nz::PixelFormat_RGBA8 Nz::PixelFormat::RGBA8
}); });
positionTexture = graph.AddAttachment({ positionTexture = graph.AddAttachment({
"Position", "Position",
Nz::PixelFormat_RGBA32F Nz::PixelFormat::RGBA32F
}); });
depthBuffer = graph.AddAttachment({ depthBuffer = graph.AddAttachment({
"Depth buffer", "Depth buffer",
Nz::PixelFormat_Depth24Stencil8 Nz::PixelFormat::Depth24Stencil8
}); });
backbuffer = graph.AddAttachment({ backbuffer = graph.AddAttachment({
"Backbuffer", "Backbuffer",
Nz::PixelFormat_RGBA8 Nz::PixelFormat::RGBA8
}); });
Nz::FramePass& gbufferPass = graph.AddPass("GBuffer"); Nz::FramePass& gbufferPass = graph.AddPass("GBuffer");
@ -661,11 +661,11 @@ int main()
{ {
switch (event.type) switch (event.type)
{ {
case Nz::WindowEventType_Quit: case Nz::WindowEventType::Quit:
window.Close(); window.Close();
break; 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) // Gestion de la caméra free-fly (Rotation)
float sensitivity = 0.3f; // Sensibilité de la souris float sensitivity = 0.3f; // Sensibilité de la souris
@ -682,7 +682,7 @@ int main()
break; break;
} }
case Nz::WindowEventType_KeyPressed: case Nz::WindowEventType::KeyPressed:
{ {
if (event.key.scancode == Nz::Keyboard::Scancode::Space) if (event.key.scancode == Nz::Keyboard::Scancode::Space)
{ {
@ -696,7 +696,7 @@ int main()
break; break;
} }
case Nz::WindowEventType_Resized: case Nz::WindowEventType::Resized:
{ {
Nz::Vector2ui windowSize = window.GetSize(); Nz::Vector2ui windowSize = window.GetSize();
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f); Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);

View File

@ -27,9 +27,9 @@ int main()
Nz::RenderWindow window; Nz::RenderWindow window;
Nz::MeshParams meshParams; 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.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<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice(); std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
@ -40,40 +40,40 @@ int main()
return __LINE__; return __LINE__;
} }
Nz::MeshRef drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); std::shared_ptr<Nz::Mesh> spaceshipMesh = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
if (!drfreak) if (!spaceshipMesh)
{ {
NazaraError("Failed to load model"); NazaraError("Failed to load model");
return __LINE__; return __LINE__;
} }
std::shared_ptr<Nz::GraphicalMesh> gfxMesh = std::make_shared<Nz::GraphicalMesh>(drfreak); std::shared_ptr<Nz::GraphicalMesh> gfxMesh = std::make_shared<Nz::GraphicalMesh>(*spaceshipMesh);
// Texture // Texture
Nz::ImageRef drfreakImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); std::shared_ptr<Nz::Image> diffuseImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png");
if (!drfreakImage || !drfreakImage->Convert(Nz::PixelFormat_RGBA8_SRGB)) if (!diffuseImage || !diffuseImage->Convert(Nz::PixelFormat::RGBA8_SRGB))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load image");
return __LINE__; return __LINE__;
} }
Nz::TextureInfo texParams; Nz::TextureInfo texParams;
texParams.pixelFormat = drfreakImage->GetFormat(); texParams.pixelFormat = diffuseImage->GetFormat();
texParams.type = drfreakImage->GetType(); texParams.type = diffuseImage->GetType();
texParams.width = drfreakImage->GetWidth(); texParams.width = diffuseImage->GetWidth();
texParams.height = drfreakImage->GetHeight(); texParams.height = diffuseImage->GetHeight();
texParams.depth = drfreakImage->GetDepth(); texParams.depth = diffuseImage->GetDepth();
std::shared_ptr<Nz::Texture> texture = device->InstantiateTexture(texParams); std::shared_ptr<Nz::Texture> texture = device->InstantiateTexture(texParams);
if (!texture->Update(drfreakImage->GetConstPixels())) if (!texture->Update(diffuseImage->GetConstPixels()))
{ {
NazaraError("Failed to update texture"); NazaraError("Failed to update texture");
return __LINE__; return __LINE__;
} }
// Texture (alpha-map) // Texture (alpha-map)
Nz::ImageRef alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png"); std::shared_ptr<Nz::Image> alphaImage = Nz::Image::LoadFromFile(resourceDir / "alphatile.png");
if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat_RGBA8)) if (!alphaImage || !alphaImage->Convert(Nz::PixelFormat::RGBA8))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load image");
return __LINE__; return __LINE__;
@ -207,11 +207,11 @@ int main()
{ {
switch (event.type) switch (event.type)
{ {
case Nz::WindowEventType_Quit: case Nz::WindowEventType::Quit:
window.Close(); window.Close();
break; 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) // Gestion de la caméra free-fly (Rotation)
float sensitivity = 0.3f; // Sensibilité de la souris float sensitivity = 0.3f; // Sensibilité de la souris
@ -228,7 +228,7 @@ int main()
break; break;
} }
case Nz::WindowEventType_Resized: case Nz::WindowEventType::Resized:
{ {
Nz::Vector2ui windowSize = window.GetSize(); Nz::Vector2ui windowSize = window.GetSize();
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f); Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);

View File

@ -63,7 +63,7 @@ int main()
std::cout << oss.str() << std::endl; std::cout << oss.str() << std::endl;
Nz::File reportFile("HardwareInfo.txt"); 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.Write(oss.str()); // Conversion implicite en std::string
reportFile.Close(); reportFile.Close();

View File

@ -88,7 +88,7 @@ int main()
Nz::MeshParams meshParams; Nz::MeshParams meshParams;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f)); 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<Nz::RenderDevice> device = Nz::Renderer::Instance()->InstanciateRenderDevice(0); std::shared_ptr<Nz::RenderDevice> device = Nz::Renderer::Instance()->InstanciateRenderDevice(0);
@ -110,27 +110,27 @@ int main()
return __LINE__; return __LINE__;
} }
Nz::MeshRef drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); std::shared_ptr<Nz::Mesh> drfreak = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);
if (!drfreak) if (!drfreak)
{ {
NazaraError("Failed to load model"); NazaraError("Failed to load model");
return __LINE__; return __LINE__;
} }
Nz::StaticMesh* drfreakMesh = static_cast<Nz::StaticMesh*>(drfreak->GetSubMesh(0)); std::shared_ptr<Nz::StaticMesh> spaceshipMesh = std::static_pointer_cast<Nz::StaticMesh>(drfreak->GetSubMesh(0));
const Nz::VertexBuffer* drfreakVB = drfreakMesh->GetVertexBuffer(); const std::shared_ptr<Nz::VertexBuffer>& meshVB = spaceshipMesh->GetVertexBuffer();
const Nz::IndexBuffer* drfreakIB = drfreakMesh->GetIndexBuffer(); const std::shared_ptr<const Nz::IndexBuffer>& meshIB = spaceshipMesh->GetIndexBuffer();
// Index buffer // Index buffer
std::cout << "Index count: " << drfreakIB->GetIndexCount() << std::endl; std::cout << "Index count: " << meshIB->GetIndexCount() << std::endl;
// Vertex buffer // Vertex buffer
std::cout << "Vertex count: " << drfreakVB->GetVertexCount() << std::endl; std::cout << "Vertex count: " << meshVB->GetVertexCount() << std::endl;
// Texture // Texture
Nz::ImageRef drfreakImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png"); std::shared_ptr<Nz::Image> drfreakImage = Nz::Image::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png");
if (!drfreakImage || !drfreakImage->Convert(Nz::PixelFormat_RGBA8)) if (!drfreakImage || !drfreakImage->Convert(Nz::PixelFormat::RGBA8))
{ {
NazaraError("Failed to load image"); NazaraError("Failed to load image");
return __LINE__; return __LINE__;
@ -182,8 +182,8 @@ int main()
Nz::ShaderBindingPtr shaderBinding = renderPipelineLayout->AllocateShaderBinding(); Nz::ShaderBindingPtr shaderBinding = renderPipelineLayout->AllocateShaderBinding();
std::shared_ptr<Nz::AbstractBuffer> uniformBuffer = device->InstantiateBuffer(Nz::BufferType_Uniform); std::shared_ptr<Nz::AbstractBuffer> uniformBuffer = device->InstantiateBuffer(Nz::BufferType::Uniform);
if (!uniformBuffer->Initialize(uniformSize, Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic)) if (!uniformBuffer->Initialize(uniformSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
{ {
NazaraError("Failed to create uniform buffer"); NazaraError("Failed to create uniform buffer");
return __LINE__; return __LINE__;
@ -212,7 +212,7 @@ int main()
auto& vertexBuffer = pipelineInfo.vertexBuffers.emplace_back(); auto& vertexBuffer = pipelineInfo.vertexBuffers.emplace_back();
vertexBuffer.binding = 0; vertexBuffer.binding = 0;
vertexBuffer.declaration = drfreakVB->GetVertexDeclaration(); vertexBuffer.declaration = meshVB->GetVertexDeclaration();
std::shared_ptr<Nz::RenderPipeline> pipeline = device->InstantiateRenderPipeline(pipelineInfo); std::shared_ptr<Nz::RenderPipeline> pipeline = device->InstantiateRenderPipeline(pipelineInfo);
@ -221,8 +221,8 @@ int main()
Nz::RenderWindowImpl* windowImpl = window.GetImpl(); Nz::RenderWindowImpl* windowImpl = window.GetImpl();
std::shared_ptr<Nz::CommandPool> commandPool = windowImpl->CreateCommandPool(Nz::QueueType::Graphics); std::shared_ptr<Nz::CommandPool> commandPool = windowImpl->CreateCommandPool(Nz::QueueType::Graphics);
Nz::RenderBuffer* renderBufferIB = static_cast<Nz::RenderBuffer*>(drfreakIB->GetBuffer()->GetImpl()); Nz::RenderBuffer* renderBufferIB = static_cast<Nz::RenderBuffer*>(meshIB->GetBuffer()->GetImpl());
Nz::RenderBuffer* renderBufferVB = static_cast<Nz::RenderBuffer*>(drfreakVB->GetBuffer()->GetImpl()); Nz::RenderBuffer* renderBufferVB = static_cast<Nz::RenderBuffer*>(meshVB->GetBuffer()->GetImpl());
if (!renderBufferIB->Synchronize(renderDevice)) if (!renderBufferIB->Synchronize(renderDevice))
{ {
@ -265,7 +265,7 @@ int main()
builder.SetScissor(Nz::Recti{ 0, 0, int(windowSize.x), int(windowSize.y) }); 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.SetViewport(Nz::Recti{ 0, 0, int(windowSize.x), int(windowSize.y) });
builder.DrawIndexed(drfreakIB->GetIndexCount()); builder.DrawIndexed(meshIB->GetIndexCount());
} }
builder.EndRenderPass(); builder.EndRenderPass();
} }
@ -296,11 +296,11 @@ int main()
{ {
switch (event.type) switch (event.type)
{ {
case Nz::WindowEventType_Quit: case Nz::WindowEventType::Quit:
window.Close(); window.Close();
break; 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) // Gestion de la caméra free-fly (Rotation)
float sensitivity = 0.3f; // Sensibilité de la souris float sensitivity = 0.3f; // Sensibilité de la souris
@ -317,7 +317,7 @@ int main()
break; break;
} }
case Nz::WindowEventType_Resized: case Nz::WindowEventType::Resized:
{ {
Nz::Vector2ui windowSize = window.GetSize(); Nz::Vector2ui windowSize = window.GetSize();
ubo.projectionMatrix = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f); ubo.projectionMatrix = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);