Merge branch 'master' into phong-lighting
This commit is contained in:
2
.github/workflows/linux-build.yml
vendored
2
.github/workflows/linux-build.yml
vendored
@@ -63,7 +63,7 @@ jobs:
|
|||||||
|
|
||||||
# Setup compilation mode and install project dependencies
|
# Setup compilation mode and install project dependencies
|
||||||
- name: Configure xmake and install dependencies
|
- name: Configure xmake and install dependencies
|
||||||
run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes
|
run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes
|
||||||
|
|
||||||
# Build the engine
|
# Build the engine
|
||||||
- name: Build Nazara
|
- name: Build Nazara
|
||||||
|
|||||||
2
.github/workflows/msys2-build.yml
vendored
2
.github/workflows/msys2-build.yml
vendored
@@ -72,7 +72,7 @@ jobs:
|
|||||||
|
|
||||||
# Setup compilation mode and install project dependencies
|
# Setup compilation mode and install project dependencies
|
||||||
- name: Configure xmake and install dependencies
|
- name: Configure xmake and install dependencies
|
||||||
run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes
|
run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes
|
||||||
|
|
||||||
# Build the engine
|
# Build the engine
|
||||||
- name: Build Nazara
|
- name: Build Nazara
|
||||||
|
|||||||
2
.github/workflows/windows-build.yml
vendored
2
.github/workflows/windows-build.yml
vendored
@@ -55,7 +55,7 @@ jobs:
|
|||||||
|
|
||||||
# Setup compilation mode and install project dependencies
|
# Setup compilation mode and install project dependencies
|
||||||
- name: Configure xmake and install dependencies
|
- name: Configure xmake and install dependencies
|
||||||
run: xmake.exe config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes
|
run: xmake.exe config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes
|
||||||
|
|
||||||
# Build the engine
|
# Build the engine
|
||||||
- name: Build Nazara
|
- name: Build Nazara
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ external
|
|||||||
|
|
||||||
struct FragIn
|
struct FragIn
|
||||||
{
|
{
|
||||||
[builtin(fragcoord)] fragcoord: vec4<f32>
|
[location(0)] uv: vec2<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FragOut
|
struct FragOut
|
||||||
@@ -31,21 +31,21 @@ struct FragOut
|
|||||||
|
|
||||||
struct VertIn
|
struct VertIn
|
||||||
{
|
{
|
||||||
[location(0)] pos: vec2<f32>
|
[location(0)] pos: vec2<f32>,
|
||||||
|
[location(1)] uv: vec2<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertOut
|
struct VertOut
|
||||||
{
|
{
|
||||||
|
[location(0)] uv: vec2<f32>,
|
||||||
[builtin(position)] position: vec4<f32>
|
[builtin(position)] position: vec4<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag)]
|
[entry(frag)]
|
||||||
fn main(input: FragIn) -> FragOut
|
fn main(input: FragIn) -> FragOut
|
||||||
{
|
{
|
||||||
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize;
|
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.color = /*colorTexture.Sample(fragcoord) + */bloomTexture.Sample(fragcoord);
|
output.color = /*colorTexture.Sample(fragcoord) + */bloomTexture.Sample(input.uv);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,7 @@ fn main(input: VertIn) -> VertOut
|
|||||||
{
|
{
|
||||||
let output: VertOut;
|
let output: VertOut;
|
||||||
output.position = vec4<f32>(input.pos, 0.0, 1.0);
|
output.position = vec4<f32>(input.pos, 0.0, 1.0);
|
||||||
|
output.uv = input.uv;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ external
|
|||||||
|
|
||||||
struct FragIn
|
struct FragIn
|
||||||
{
|
{
|
||||||
[builtin(fragcoord)] fragcoord: vec4<f32>
|
[location(0)] uv: vec2<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FragOut
|
struct FragOut
|
||||||
@@ -38,11 +38,13 @@ struct FragOut
|
|||||||
|
|
||||||
struct VertIn
|
struct VertIn
|
||||||
{
|
{
|
||||||
[location(0)] pos: vec2<f32>
|
[location(0)] pos: vec2<f32>,
|
||||||
|
[location(1)] uv: vec2<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertOut
|
struct VertOut
|
||||||
{
|
{
|
||||||
|
[location(0)] uv: vec2<f32>,
|
||||||
[builtin(position)] position: vec4<f32>
|
[builtin(position)] position: vec4<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,15 +52,14 @@ struct VertOut
|
|||||||
fn main(input: FragIn) -> FragOut
|
fn main(input: FragIn) -> FragOut
|
||||||
{
|
{
|
||||||
let invTargetSize = viewerData.invRenderTargetSize * blurData.sizeFactor;
|
let invTargetSize = viewerData.invRenderTargetSize * blurData.sizeFactor;
|
||||||
let fragcoord = input.fragcoord.xy * invTargetSize;
|
|
||||||
|
|
||||||
let color = colorTexture.Sample(fragcoord).rgb * 0.2270270270;
|
let color = colorTexture.Sample(input.uv).rgb * 0.2270270270;
|
||||||
|
|
||||||
color += colorTexture.Sample(fragcoord + blurData.direction * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
|
color += colorTexture.Sample(input.uv + blurData.direction * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
|
||||||
color += colorTexture.Sample(fragcoord - blurData.direction * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
|
color += colorTexture.Sample(input.uv - blurData.direction * 1.3846153846 * invTargetSize).rgb * 0.3162162162;
|
||||||
|
|
||||||
color += colorTexture.Sample(fragcoord + blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
|
color += colorTexture.Sample(input.uv + blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
|
||||||
color += colorTexture.Sample(fragcoord - blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
|
color += colorTexture.Sample(input.uv - blurData.direction * 3.2307692308 * invTargetSize).rgb * 0.0702702703;
|
||||||
|
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.color = vec4<f32>(color, 1.0);
|
output.color = vec4<f32>(color, 1.0);
|
||||||
@@ -71,6 +72,7 @@ fn main(input: VertIn) -> VertOut
|
|||||||
{
|
{
|
||||||
let output: VertOut;
|
let output: VertOut;
|
||||||
output.position = vec4<f32>(input.pos, 0.0, 1.0);
|
output.position = vec4<f32>(input.pos, 0.0, 1.0);
|
||||||
|
output.uv = input.uv;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ external
|
|||||||
|
|
||||||
struct FragIn
|
struct FragIn
|
||||||
{
|
{
|
||||||
[builtin(fragcoord)] fragcoord: vec4<f32>,
|
|
||||||
[location(0)] uv: vec2<f32>
|
[location(0)] uv: vec2<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ external
|
|||||||
|
|
||||||
struct FragIn
|
struct FragIn
|
||||||
{
|
{
|
||||||
[builtin(fragcoord)] fragcoord: vec4<f32>
|
[location(0)] uv: vec2<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FragOut
|
struct FragOut
|
||||||
@@ -30,11 +30,13 @@ struct FragOut
|
|||||||
|
|
||||||
struct VertIn
|
struct VertIn
|
||||||
{
|
{
|
||||||
[location(0)] pos: vec2<f32>
|
[location(0)] pos: vec2<f32>,
|
||||||
|
[location(1)] uv: vec2<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertOut
|
struct VertOut
|
||||||
{
|
{
|
||||||
|
[location(0)] uv: vec2<f32>,
|
||||||
[builtin(position)] position: vec4<f32>
|
[builtin(position)] position: vec4<f32>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +45,7 @@ fn main(input: FragIn) -> FragOut
|
|||||||
{
|
{
|
||||||
let exposure = 0.8;
|
let exposure = 0.8;
|
||||||
|
|
||||||
let fragcoord = input.fragcoord.xy * viewerData.invRenderTargetSize;
|
let hdrColor = inputTexture.Sample(input.uv).rgb;
|
||||||
|
|
||||||
let hdrColor = inputTexture.Sample(fragcoord).rgb;
|
|
||||||
|
|
||||||
// reinhard tone mapping
|
// reinhard tone mapping
|
||||||
let mapped = vec3<f32>(1.0, 1.0, 1.0) - exp(-hdrColor * exposure);
|
let mapped = vec3<f32>(1.0, 1.0, 1.0) - exp(-hdrColor * exposure);
|
||||||
@@ -61,6 +61,7 @@ fn main(input: VertIn) -> VertOut
|
|||||||
{
|
{
|
||||||
let output: VertOut;
|
let output: VertOut;
|
||||||
output.position = vec4<f32>(input.pos, 0.0, 1.0);
|
output.position = vec4<f32>(input.pos, 0.0, 1.0);
|
||||||
|
output.uv = input.uv;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ int main()
|
|||||||
Nz::RenderWindow window;
|
Nz::RenderWindow window;
|
||||||
|
|
||||||
Nz::MeshParams meshParams;
|
Nz::MeshParams meshParams;
|
||||||
meshParams.storage = Nz::DataStorage::Software;
|
|
||||||
meshParams.center = true;
|
meshParams.center = true;
|
||||||
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.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);
|
||||||
@@ -110,7 +109,7 @@ int main()
|
|||||||
|
|
||||||
// Plane
|
// Plane
|
||||||
Nz::MeshParams meshPrimitiveParams;
|
Nz::MeshParams meshPrimitiveParams;
|
||||||
meshPrimitiveParams.storage = Nz::DataStorage::Software;
|
meshPrimitiveParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV);
|
||||||
|
|
||||||
std::shared_ptr<Nz::Mesh> planeMesh = std::make_shared<Nz::Mesh>();
|
std::shared_ptr<Nz::Mesh> planeMesh = std::make_shared<Nz::Mesh>();
|
||||||
planeMesh->CreateStatic();
|
planeMesh->CreateStatic();
|
||||||
@@ -204,7 +203,7 @@ int main()
|
|||||||
std::shared_ptr<Nz::Material> flareMaterial = std::make_shared<Nz::Material>();
|
std::shared_ptr<Nz::Material> flareMaterial = std::make_shared<Nz::Material>();
|
||||||
std::shared_ptr<Nz::MaterialPass> flareMaterialPass;
|
std::shared_ptr<Nz::MaterialPass> flareMaterialPass;
|
||||||
{
|
{
|
||||||
flareMaterialPass = std::make_shared<Nz::MaterialPass>(customMatSettings);
|
flareMaterialPass = std::make_shared<Nz::MaterialPass>(Nz::BasicMaterial::GetSettings());
|
||||||
flareMaterialPass->EnableDepthBuffer(true);
|
flareMaterialPass->EnableDepthBuffer(true);
|
||||||
flareMaterialPass->EnableDepthWrite(false);
|
flareMaterialPass->EnableDepthWrite(false);
|
||||||
flareMaterialPass->EnableDepthClamp(true);
|
flareMaterialPass->EnableDepthClamp(true);
|
||||||
@@ -327,9 +326,7 @@ int main()
|
|||||||
|
|
||||||
constexpr std::size_t MaxPointLight = 2000;
|
constexpr std::size_t MaxPointLight = 2000;
|
||||||
|
|
||||||
std::shared_ptr<Nz::AbstractBuffer> lightUbo = device->InstantiateBuffer(Nz::BufferType::Uniform);
|
std::shared_ptr<Nz::RenderBuffer> lightUbo = device->InstantiateBuffer(Nz::BufferType::Uniform, MaxPointLight * alignedSpotLightSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic | Nz::BufferUsage::Write);
|
||||||
if (!lightUbo->Initialize(MaxPointLight * alignedSpotLightSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
|
|
||||||
return __LINE__;
|
|
||||||
|
|
||||||
std::vector<SpotLight> spotLights;
|
std::vector<SpotLight> spotLights;
|
||||||
/*auto& firstSpot = spotLights.emplace_back();
|
/*auto& firstSpot = spotLights.emplace_back();
|
||||||
@@ -414,7 +411,7 @@ int main()
|
|||||||
std::vector<std::shared_ptr<Nz::ShaderBinding>> gaussianBlurShaderBinding(BloomSubdivisionCount * 2);
|
std::vector<std::shared_ptr<Nz::ShaderBinding>> gaussianBlurShaderBinding(BloomSubdivisionCount * 2);
|
||||||
|
|
||||||
std::vector<Nz::UInt8> gaussianBlurData(gaussianBlurDataOffsets.GetSize());
|
std::vector<Nz::UInt8> gaussianBlurData(gaussianBlurDataOffsets.GetSize());
|
||||||
std::vector<std::shared_ptr<Nz::AbstractBuffer>> gaussianBlurUbos;
|
std::vector<std::shared_ptr<Nz::RenderBuffer>> gaussianBlurUbos;
|
||||||
|
|
||||||
float sizeFactor = 2.f;
|
float sizeFactor = 2.f;
|
||||||
for (std::size_t i = 0; i < BloomSubdivisionCount; ++i)
|
for (std::size_t i = 0; i < BloomSubdivisionCount; ++i)
|
||||||
@@ -422,19 +419,11 @@ int main()
|
|||||||
Nz::AccessByOffset<Nz::Vector2f&>(gaussianBlurData.data(), gaussianBlurDataDirection) = Nz::Vector2f(1.f, 0.f);
|
Nz::AccessByOffset<Nz::Vector2f&>(gaussianBlurData.data(), gaussianBlurDataDirection) = Nz::Vector2f(1.f, 0.f);
|
||||||
Nz::AccessByOffset<float&>(gaussianBlurData.data(), gaussianBlurDataSize) = sizeFactor;
|
Nz::AccessByOffset<float&>(gaussianBlurData.data(), gaussianBlurDataSize) = sizeFactor;
|
||||||
|
|
||||||
std::shared_ptr<Nz::AbstractBuffer> horizontalBlurData = device->InstantiateBuffer(Nz::BufferType::Uniform);
|
std::shared_ptr<Nz::RenderBuffer> horizontalBlurData = device->InstantiateBuffer(Nz::BufferType::Uniform, gaussianBlurDataOffsets.GetSize(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic | Nz::BufferUsage::Write, gaussianBlurData.data());
|
||||||
if (!horizontalBlurData->Initialize(gaussianBlurDataOffsets.GetSize(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
|
|
||||||
return __LINE__;
|
|
||||||
|
|
||||||
horizontalBlurData->Fill(gaussianBlurData.data(), 0, gaussianBlurDataOffsets.GetSize());
|
|
||||||
|
|
||||||
Nz::AccessByOffset<Nz::Vector2f&>(gaussianBlurData.data(), gaussianBlurDataDirection) = Nz::Vector2f(0.f, 1.f);
|
Nz::AccessByOffset<Nz::Vector2f&>(gaussianBlurData.data(), gaussianBlurDataDirection) = Nz::Vector2f(0.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Nz::AbstractBuffer> verticalBlurData = device->InstantiateBuffer(Nz::BufferType::Uniform);
|
std::shared_ptr<Nz::RenderBuffer> verticalBlurData = device->InstantiateBuffer(Nz::BufferType::Uniform, gaussianBlurDataOffsets.GetSize(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic | Nz::BufferUsage::Write, gaussianBlurData.data());
|
||||||
if (!verticalBlurData->Initialize(gaussianBlurDataOffsets.GetSize(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
|
|
||||||
return __LINE__;
|
|
||||||
|
|
||||||
verticalBlurData->Fill(gaussianBlurData.data(), 0, gaussianBlurDataOffsets.GetSize());
|
|
||||||
|
|
||||||
sizeFactor *= 2.f;
|
sizeFactor *= 2.f;
|
||||||
|
|
||||||
@@ -570,9 +559,7 @@ int main()
|
|||||||
Nz::AccessByOffset<float&>(godRaysData.data(), gr_weightOffset) = 5.65f;
|
Nz::AccessByOffset<float&>(godRaysData.data(), gr_weightOffset) = 5.65f;
|
||||||
Nz::AccessByOffset<Nz::Vector2f&>(godRaysData.data(), gr_lightPositionOffset) = Nz::Vector2f(0.5f, 0.1f);
|
Nz::AccessByOffset<Nz::Vector2f&>(godRaysData.data(), gr_lightPositionOffset) = Nz::Vector2f(0.5f, 0.1f);
|
||||||
|
|
||||||
std::shared_ptr<Nz::AbstractBuffer> godRaysUBO = device->InstantiateBuffer(Nz::BufferType::Uniform);
|
std::shared_ptr<Nz::RenderBuffer> godRaysUBO = device->InstantiateBuffer(Nz::BufferType::Uniform, godRaysData.size(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic | Nz::BufferUsage::Write, godRaysData.data());
|
||||||
godRaysUBO->Initialize(godRaysData.size(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic);
|
|
||||||
godRaysUBO->Fill(godRaysData.data(), 0, godRaysData.size());
|
|
||||||
|
|
||||||
std::shared_ptr<Nz::ShaderBinding> godRaysBlitShaderBinding;
|
std::shared_ptr<Nz::ShaderBinding> godRaysBlitShaderBinding;
|
||||||
|
|
||||||
@@ -667,12 +654,7 @@ int main()
|
|||||||
}
|
}
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
std::shared_ptr<Nz::AbstractBuffer> fullscreenVertexBuffer = device->InstantiateBuffer(Nz::BufferType::Vertex);
|
std::shared_ptr<Nz::RenderBuffer> fullscreenVertexBuffer = device->InstantiateBuffer(Nz::BufferType::Vertex, fullscreenVertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Write, vertexData.data());
|
||||||
if (!fullscreenVertexBuffer->Initialize(fullscreenVertexDeclaration->GetStride() * vertexData.size(), Nz::BufferUsage::DeviceLocal))
|
|
||||||
return __LINE__;
|
|
||||||
|
|
||||||
if (!fullscreenVertexBuffer->Fill(vertexData.data(), 0, fullscreenVertexBuffer->GetSize()))
|
|
||||||
return __LINE__;
|
|
||||||
|
|
||||||
std::shared_ptr<Nz::ShaderBinding> bloomSkipBlit;
|
std::shared_ptr<Nz::ShaderBinding> bloomSkipBlit;
|
||||||
std::shared_ptr<Nz::ShaderBinding> finalBlitBinding;
|
std::shared_ptr<Nz::ShaderBinding> finalBlitBinding;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ int main()
|
|||||||
|
|
||||||
Nz::MeshParams meshParams;
|
Nz::MeshParams meshParams;
|
||||||
meshParams.center = true;
|
meshParams.center = true;
|
||||||
meshParams.storage = Nz::DataStorage::Software;
|
|
||||||
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
||||||
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent);
|
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent);
|
||||||
|
|
||||||
@@ -79,12 +78,14 @@ int main()
|
|||||||
phongMat.SetNormalMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/normal.png", texParams));
|
phongMat.SetNormalMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/normal.png", texParams));
|
||||||
|
|
||||||
Nz::Model model(std::move(gfxMesh), spaceshipMesh->GetAABB());
|
Nz::Model model(std::move(gfxMesh), spaceshipMesh->GetAABB());
|
||||||
|
model.UpdateScissorBox(Nz::Recti(0, 0, 1920, 1080));
|
||||||
for (std::size_t i = 0; i < model.GetSubMeshCount(); ++i)
|
for (std::size_t i = 0; i < model.GetSubMeshCount(); ++i)
|
||||||
model.SetMaterial(i, material);
|
model.SetMaterial(i, material);
|
||||||
|
|
||||||
Nz::Vector2ui windowSize = window.GetSize();
|
Nz::Vector2ui windowSize = window.GetSize();
|
||||||
|
|
||||||
Nz::Camera camera(window.GetRenderTarget());
|
Nz::Camera camera(window.GetRenderTarget());
|
||||||
|
//camera.UpdateClearColor(Nz::Color::Gray);
|
||||||
|
|
||||||
Nz::ViewerInstance& viewerInstance = camera.GetViewerInstance();
|
Nz::ViewerInstance& viewerInstance = camera.GetViewerInstance();
|
||||||
viewerInstance.UpdateTargetSize(Nz::Vector2f(window.GetSize()));
|
viewerInstance.UpdateTargetSize(Nz::Vector2f(window.GetSize()));
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ int main()
|
|||||||
|
|
||||||
Nz::MeshParams meshParams;
|
Nz::MeshParams meshParams;
|
||||||
meshParams.center = true;
|
meshParams.center = true;
|
||||||
meshParams.storage = Nz::DataStorage::Software;
|
|
||||||
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
||||||
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_UV);
|
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_UV);
|
||||||
|
|
||||||
@@ -136,7 +135,7 @@ int main()
|
|||||||
|
|
||||||
Nz::Vector2ui windowSize = window.GetSize();
|
Nz::Vector2ui windowSize = window.GetSize();
|
||||||
|
|
||||||
Nz::VertexMapper vertexMapper(*spaceshipMesh->GetSubMesh(0), Nz::BufferAccess::ReadOnly);
|
Nz::VertexMapper vertexMapper(*spaceshipMesh->GetSubMesh(0));
|
||||||
Nz::SparsePtr<Nz::Vector3f> vertices = vertexMapper.GetComponentPtr<Nz::Vector3f>(Nz::VertexComponent::Position);
|
Nz::SparsePtr<Nz::Vector3f> vertices = vertexMapper.GetComponentPtr<Nz::Vector3f>(Nz::VertexComponent::Position);
|
||||||
|
|
||||||
entt::registry registry;
|
entt::registry registry;
|
||||||
@@ -165,6 +164,7 @@ int main()
|
|||||||
{
|
{
|
||||||
registry.emplace<Nz::NodeComponent>(viewer2D);
|
registry.emplace<Nz::NodeComponent>(viewer2D);
|
||||||
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(viewer2D, window.GetRenderTarget(), Nz::ProjectionType::Orthographic);
|
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(viewer2D, window.GetRenderTarget(), Nz::ProjectionType::Orthographic);
|
||||||
|
cameraComponent.UpdateClearColor(Nz::Color(0, 0, 0, 0));
|
||||||
cameraComponent.UpdateRenderOrder(1);
|
cameraComponent.UpdateRenderOrder(1);
|
||||||
cameraComponent.UpdateRenderMask(2);
|
cameraComponent.UpdateRenderMask(2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,15 +92,10 @@ int main()
|
|||||||
|
|
||||||
Nz::Modules<Nz::Renderer> nazara(rendererConfig);
|
Nz::Modules<Nz::Renderer> nazara(rendererConfig);
|
||||||
|
|
||||||
Nz::RenderWindow window;
|
|
||||||
|
|
||||||
Nz::MeshParams meshParams;
|
|
||||||
meshParams.center = true;
|
|
||||||
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
|
||||||
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);
|
||||||
|
|
||||||
|
Nz::RenderWindow window;
|
||||||
|
|
||||||
std::string windowTitle = "Render Test";
|
std::string windowTitle = "Render Test";
|
||||||
if (!window.Create(device, Nz::VideoMode(800, 600, 32), windowTitle))
|
if (!window.Create(device, Nz::VideoMode(800, 600, 32), windowTitle))
|
||||||
{
|
{
|
||||||
@@ -118,6 +113,12 @@ int main()
|
|||||||
return __LINE__;
|
return __LINE__;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Nz::MeshParams meshParams;
|
||||||
|
meshParams.bufferFactory = GetRenderBufferFactory(device);
|
||||||
|
meshParams.center = true;
|
||||||
|
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
||||||
|
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV);
|
||||||
|
|
||||||
std::shared_ptr<Nz::Mesh> 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)
|
||||||
{
|
{
|
||||||
@@ -180,12 +181,7 @@ int main()
|
|||||||
Nz::ShaderBindingPtr viewerShaderBinding = basePipelineLayout->AllocateShaderBinding(0);
|
Nz::ShaderBindingPtr viewerShaderBinding = basePipelineLayout->AllocateShaderBinding(0);
|
||||||
Nz::ShaderBindingPtr textureShaderBinding = renderPipelineLayout->AllocateShaderBinding(1);
|
Nz::ShaderBindingPtr textureShaderBinding = renderPipelineLayout->AllocateShaderBinding(1);
|
||||||
|
|
||||||
std::shared_ptr<Nz::AbstractBuffer> uniformBuffer = device->InstantiateBuffer(Nz::BufferType::Uniform);
|
std::shared_ptr<Nz::RenderBuffer> uniformBuffer = device->InstantiateBuffer(Nz::BufferType::Uniform, uniformSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic);
|
||||||
if (!uniformBuffer->Initialize(uniformSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create uniform buffer");
|
|
||||||
return __LINE__;
|
|
||||||
}
|
|
||||||
|
|
||||||
viewerShaderBinding->Update({
|
viewerShaderBinding->Update({
|
||||||
{
|
{
|
||||||
@@ -212,33 +208,18 @@ int main()
|
|||||||
pipelineInfo.depthBuffer = true;
|
pipelineInfo.depthBuffer = true;
|
||||||
pipelineInfo.shaderModules.emplace_back(fragVertShader);
|
pipelineInfo.shaderModules.emplace_back(fragVertShader);
|
||||||
|
|
||||||
auto& vertexBuffer = pipelineInfo.vertexBuffers.emplace_back();
|
auto& pipelineVertexBuffer = pipelineInfo.vertexBuffers.emplace_back();
|
||||||
vertexBuffer.binding = 0;
|
pipelineVertexBuffer.binding = 0;
|
||||||
vertexBuffer.declaration = meshVB->GetVertexDeclaration();
|
pipelineVertexBuffer.declaration = meshVB->GetVertexDeclaration();
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderPipeline> pipeline = device->InstantiateRenderPipeline(pipelineInfo);
|
std::shared_ptr<Nz::RenderPipeline> pipeline = device->InstantiateRenderPipeline(pipelineInfo);
|
||||||
|
|
||||||
Nz::RenderDevice* renderDevice = window.GetRenderDevice().get();
|
const std::shared_ptr<Nz::RenderDevice>& renderDevice = window.GetRenderDevice();
|
||||||
|
|
||||||
std::shared_ptr<Nz::CommandPool> commandPool = renderDevice->InstantiateCommandPool(Nz::QueueType::Graphics);
|
std::shared_ptr<Nz::CommandPool> commandPool = renderDevice->InstantiateCommandPool(Nz::QueueType::Graphics);
|
||||||
|
|
||||||
Nz::RenderBuffer* renderBufferIB = static_cast<Nz::RenderBuffer*>(meshIB->GetBuffer()->GetImpl());
|
Nz::RenderBuffer& renderBufferIB = static_cast<Nz::RenderBuffer&>(*meshIB->GetBuffer());
|
||||||
Nz::RenderBuffer* renderBufferVB = static_cast<Nz::RenderBuffer*>(meshVB->GetBuffer()->GetImpl());
|
Nz::RenderBuffer& renderBufferVB = static_cast<Nz::RenderBuffer&>(*meshVB->GetBuffer());
|
||||||
|
|
||||||
if (!renderBufferIB->Synchronize(renderDevice))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to synchronize render buffer");
|
|
||||||
return __LINE__;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!renderBufferVB->Synchronize(renderDevice))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to synchronize render buffer");
|
|
||||||
return __LINE__;
|
|
||||||
}
|
|
||||||
|
|
||||||
Nz::AbstractBuffer* indexBufferImpl = renderBufferIB->GetHardwareBuffer(renderDevice);
|
|
||||||
Nz::AbstractBuffer* vertexBufferImpl = renderBufferVB->GetHardwareBuffer(renderDevice);
|
|
||||||
|
|
||||||
Nz::Vector3f viewerPos = Nz::Vector3f::Zero();
|
Nz::Vector3f viewerPos = Nz::Vector3f::Zero();
|
||||||
|
|
||||||
@@ -367,9 +348,9 @@ int main()
|
|||||||
{
|
{
|
||||||
builder.BeginRenderPass(windowRT->GetFramebuffer(frame.GetFramebufferIndex()), windowRT->GetRenderPass(), renderRect, { clearValues[0], clearValues[1] });
|
builder.BeginRenderPass(windowRT->GetFramebuffer(frame.GetFramebufferIndex()), windowRT->GetRenderPass(), renderRect, { clearValues[0], clearValues[1] });
|
||||||
{
|
{
|
||||||
builder.BindIndexBuffer(*indexBufferImpl);
|
builder.BindIndexBuffer(renderBufferIB);
|
||||||
builder.BindPipeline(*pipeline);
|
builder.BindPipeline(*pipeline);
|
||||||
builder.BindVertexBuffer(0, *vertexBufferImpl);
|
builder.BindVertexBuffer(0, renderBufferVB);
|
||||||
builder.BindShaderBinding(0, *viewerShaderBinding);
|
builder.BindShaderBinding(0, *viewerShaderBinding);
|
||||||
builder.BindShaderBinding(1, *textureShaderBinding);
|
builder.BindShaderBinding(1, *textureShaderBinding);
|
||||||
|
|
||||||
|
|||||||
@@ -8,29 +8,32 @@
|
|||||||
#define NAZARA_CORE_CALLONEXIT_HPP
|
#define NAZARA_CORE_CALLONEXIT_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <functional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
template<typename F>
|
||||||
class CallOnExit
|
class CallOnExit
|
||||||
{
|
{
|
||||||
using Func = std::function<void()>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CallOnExit(Func func = nullptr);
|
CallOnExit() = default;
|
||||||
|
CallOnExit(F&& functor);
|
||||||
CallOnExit(const CallOnExit&) = delete;
|
CallOnExit(const CallOnExit&) = delete;
|
||||||
CallOnExit(CallOnExit&&) noexcept = delete;
|
CallOnExit(CallOnExit&&) noexcept = delete;
|
||||||
~CallOnExit();
|
~CallOnExit();
|
||||||
|
|
||||||
void CallAndReset(Func func = nullptr);
|
void CallAndReset();
|
||||||
void Reset(Func func = nullptr);
|
void Reset();
|
||||||
|
|
||||||
CallOnExit& operator=(const CallOnExit&) = delete;
|
CallOnExit& operator=(const CallOnExit&) = delete;
|
||||||
CallOnExit& operator=(CallOnExit&&) noexcept = default;
|
CallOnExit& operator=(CallOnExit&&) noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Func m_func;
|
std::optional<F> m_functor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
CallOnExit(F) -> CallOnExit<F>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Core/CallOnExit.inl>
|
#include <Nazara/Core/CallOnExit.inl>
|
||||||
|
|||||||
@@ -15,24 +15,24 @@ namespace Nz
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs a CallOnExit object with a function
|
* \brief Constructs a CallOnExit object with a functor
|
||||||
*
|
*
|
||||||
* \param func Function to call on exit
|
* \param func Function to call on exit
|
||||||
*/
|
*/
|
||||||
|
template<typename F>
|
||||||
inline CallOnExit::CallOnExit(Func func) :
|
CallOnExit<F>::CallOnExit(F&& functor) :
|
||||||
m_func(func)
|
m_functor(std::move(functor))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Destructs the object and calls the function
|
* \brief Destructs the object and calls the function
|
||||||
*/
|
*/
|
||||||
|
template<typename F>
|
||||||
inline CallOnExit::~CallOnExit()
|
CallOnExit<F>::~CallOnExit()
|
||||||
{
|
{
|
||||||
if (m_func)
|
if (m_functor)
|
||||||
m_func();
|
(*m_functor)();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -40,13 +40,13 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \param func Function to call on exit
|
* \param func Function to call on exit
|
||||||
*/
|
*/
|
||||||
|
template<typename F>
|
||||||
inline void CallOnExit::CallAndReset(Func func)
|
void CallOnExit<F>::CallAndReset()
|
||||||
{
|
{
|
||||||
if (m_func)
|
if (m_functor)
|
||||||
m_func();
|
(*m_functor)();
|
||||||
|
|
||||||
Reset(func);
|
m_functor.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -54,10 +54,10 @@ namespace Nz
|
|||||||
*
|
*
|
||||||
* \param func Function to call on exit
|
* \param func Function to call on exit
|
||||||
*/
|
*/
|
||||||
|
template<typename F>
|
||||||
inline void CallOnExit::Reset(Func func)
|
void CallOnExit<F>::Reset()
|
||||||
{
|
{
|
||||||
m_func = func;
|
m_functor.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ namespace Nz
|
|||||||
static NAZARA_CORE_API const Color Black;
|
static NAZARA_CORE_API const Color Black;
|
||||||
static NAZARA_CORE_API const Color Blue;
|
static NAZARA_CORE_API const Color Blue;
|
||||||
static NAZARA_CORE_API const Color Cyan;
|
static NAZARA_CORE_API const Color Cyan;
|
||||||
|
static NAZARA_CORE_API const Color Gray;
|
||||||
static NAZARA_CORE_API const Color Green;
|
static NAZARA_CORE_API const Color Green;
|
||||||
static NAZARA_CORE_API const Color Magenta;
|
static NAZARA_CORE_API const Color Magenta;
|
||||||
static NAZARA_CORE_API const Color Orange;
|
static NAZARA_CORE_API const Color Orange;
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ namespace Nz
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extension[0] == '.')
|
||||||
|
extension.erase(extension.begin());
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (const auto& saverPtr : m_savers)
|
for (const auto& saverPtr : m_savers)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ namespace Nz
|
|||||||
class SparsePtr
|
class SparsePtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using BytePtr = typename std::conditional<std::is_const<T>::value, const UInt8*, UInt8*>::type;
|
using BytePtr = std::conditional_t<std::is_const<T>::value, const UInt8*, UInt8*>;
|
||||||
using VoidPtr = typename std::conditional<std::is_const<T>::value, const void*, void*>::type;
|
using VoidPtr = std::conditional_t<std::is_const<T>::value, const void*, void*>;
|
||||||
|
|
||||||
SparsePtr();
|
SparsePtr();
|
||||||
SparsePtr(T* ptr);
|
SparsePtr(T* ptr);
|
||||||
@@ -46,18 +46,16 @@ namespace Nz
|
|||||||
explicit operator T*() const;
|
explicit operator T*() const;
|
||||||
T& operator*() const;
|
T& operator*() const;
|
||||||
T* operator->() const;
|
T* operator->() const;
|
||||||
T& operator[](std::size_t index) const;
|
template<typename U> T& operator[](U index) const;
|
||||||
|
|
||||||
SparsePtr& operator=(const SparsePtr& ptr) = default;
|
SparsePtr& operator=(const SparsePtr& ptr) = default;
|
||||||
|
|
||||||
SparsePtr operator+(int count) const;
|
template<typename U> SparsePtr operator+(U count) const;
|
||||||
SparsePtr operator+(unsigned int count) const;
|
template<typename U> SparsePtr operator-(U count) const;
|
||||||
SparsePtr operator-(int count) const;
|
|
||||||
SparsePtr operator-(unsigned int count) const;
|
|
||||||
std::ptrdiff_t operator-(const SparsePtr& ptr) const;
|
std::ptrdiff_t operator-(const SparsePtr& ptr) const;
|
||||||
|
|
||||||
SparsePtr& operator+=(int count);
|
template<typename U> SparsePtr& operator+=(U count);
|
||||||
SparsePtr& operator-=(int count);
|
template<typename U> SparsePtr& operator-=(U count);
|
||||||
|
|
||||||
SparsePtr& operator++();
|
SparsePtr& operator++();
|
||||||
SparsePtr operator++(int);
|
SparsePtr operator++(int);
|
||||||
|
|||||||
@@ -247,8 +247,11 @@ namespace Nz
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& SparsePtr<T>::operator[](std::size_t index) const
|
template<typename U>
|
||||||
|
T& SparsePtr<T>::operator[](U index) const
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_integral_v<U>, "index must be an integral type");
|
||||||
|
|
||||||
return *reinterpret_cast<T*>(m_ptr + index * m_stride);
|
return *reinterpret_cast<T*>(m_ptr + index * m_stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,8 +263,11 @@ namespace Nz
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SparsePtr<T> SparsePtr<T>::operator+(int count) const
|
template<typename U>
|
||||||
|
SparsePtr<T> SparsePtr<T>::operator+(U count) const
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_integral_v<U>, "count must be an integral type");
|
||||||
|
|
||||||
return SparsePtr(m_ptr + count * m_stride, m_stride);
|
return SparsePtr(m_ptr + count * m_stride, m_stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,34 +279,11 @@ namespace Nz
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SparsePtr<T> SparsePtr<T>::operator+(unsigned int count) const
|
template<typename U>
|
||||||
|
SparsePtr<T> SparsePtr<T>::operator-(U count) const
|
||||||
{
|
{
|
||||||
return SparsePtr(m_ptr + count * m_stride, m_stride);
|
static_assert(std::is_integral_v<U>, "count must be an integral type");
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Gets the SparsePtr with an offset
|
|
||||||
* \return A SparsePtr with the new stride
|
|
||||||
*
|
|
||||||
* \param count Number of stride to do
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
SparsePtr<T> SparsePtr<T>::operator-(int count) const
|
|
||||||
{
|
|
||||||
return SparsePtr(m_ptr - count * m_stride, m_stride);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Gets the SparsePtr with an offset
|
|
||||||
* \return A SparsePtr with the new stride
|
|
||||||
*
|
|
||||||
* \param count Number of stride to do
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
SparsePtr<T> SparsePtr<T>::operator-(unsigned int count) const
|
|
||||||
{
|
|
||||||
return SparsePtr(m_ptr - count * m_stride, m_stride);
|
return SparsePtr(m_ptr - count * m_stride, m_stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,25 +308,22 @@ namespace Nz
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SparsePtr<T>& SparsePtr<T>::operator+=(int count)
|
template<typename U>
|
||||||
|
SparsePtr<T>& SparsePtr<T>::operator+=(U count)
|
||||||
{
|
{
|
||||||
m_ptr += count * m_stride;
|
static_assert(std::is_integral_v<U>, "count must be an integral type");
|
||||||
|
|
||||||
|
m_ptr += count * m_stride;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Gets the SparsePtr with an offset
|
|
||||||
* \return A reference to this pointer with the new stride
|
|
||||||
*
|
|
||||||
* \param count Number of stride to do
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SparsePtr<T>& SparsePtr<T>::operator-=(int count)
|
template<typename U>
|
||||||
|
SparsePtr<T>& SparsePtr<T>::operator-=(U count)
|
||||||
{
|
{
|
||||||
m_ptr -= count * m_stride;
|
static_assert(std::is_integral_v<U>, "count must be an integral type");
|
||||||
|
|
||||||
|
m_ptr -= count * m_stride;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -23,9 +24,9 @@ namespace Nz
|
|||||||
GraphicalMesh(GraphicalMesh&&) noexcept = default;
|
GraphicalMesh(GraphicalMesh&&) noexcept = default;
|
||||||
~GraphicalMesh() = default;
|
~GraphicalMesh() = default;
|
||||||
|
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GetIndexBuffer(std::size_t subMesh) const;
|
inline const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMesh) const;
|
||||||
inline std::size_t GetIndexCount(std::size_t subMesh) const;
|
inline std::size_t GetIndexCount(std::size_t subMesh) const;
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GetVertexBuffer(std::size_t subMesh) const;
|
inline const std::shared_ptr<RenderBuffer>& GetVertexBuffer(std::size_t subMesh) const;
|
||||||
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration(std::size_t subMesh) const;
|
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration(std::size_t subMesh) const;
|
||||||
inline std::size_t GetSubMeshCount() const;
|
inline std::size_t GetSubMeshCount() const;
|
||||||
|
|
||||||
@@ -35,8 +36,8 @@ namespace Nz
|
|||||||
private:
|
private:
|
||||||
struct GraphicalSubMesh
|
struct GraphicalSubMesh
|
||||||
{
|
{
|
||||||
std::shared_ptr<AbstractBuffer> indexBuffer;
|
std::shared_ptr<RenderBuffer> indexBuffer;
|
||||||
std::shared_ptr<AbstractBuffer> vertexBuffer;
|
std::shared_ptr<RenderBuffer> vertexBuffer;
|
||||||
std::size_t indexCount;
|
std::size_t indexCount;
|
||||||
std::shared_ptr<const VertexDeclaration> vertexDeclaration;
|
std::shared_ptr<const VertexDeclaration> vertexDeclaration;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GraphicalMesh::GetIndexBuffer(std::size_t subMesh) const
|
inline const std::shared_ptr<RenderBuffer>& GraphicalMesh::GetIndexBuffer(std::size_t subMesh) const
|
||||||
{
|
{
|
||||||
assert(subMesh < m_subMeshes.size());
|
assert(subMesh < m_subMeshes.size());
|
||||||
return m_subMeshes[subMesh].indexBuffer;
|
return m_subMeshes[subMesh].indexBuffer;
|
||||||
@@ -20,7 +20,7 @@ namespace Nz
|
|||||||
return m_subMeshes[subMesh].indexCount;
|
return m_subMeshes[subMesh].indexCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GraphicalMesh::GetVertexBuffer(std::size_t subMesh) const
|
inline const std::shared_ptr<RenderBuffer>& GraphicalMesh::GetVertexBuffer(std::size_t subMesh) const
|
||||||
{
|
{
|
||||||
assert(subMesh < m_subMeshes.size());
|
assert(subMesh < m_subMeshes.size());
|
||||||
return m_subMeshes[subMesh].vertexBuffer;
|
return m_subMeshes[subMesh].vertexBuffer;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Nz
|
|||||||
inline const std::shared_ptr<RenderPipeline>& GetBlitPipeline(bool transparent) const;
|
inline const std::shared_ptr<RenderPipeline>& GetBlitPipeline(bool transparent) const;
|
||||||
inline const std::shared_ptr<RenderPipelineLayout>& GetBlitPipelineLayout() const;
|
inline const std::shared_ptr<RenderPipelineLayout>& GetBlitPipelineLayout() const;
|
||||||
inline const DefaultTextures& GetDefaultTextures() const;
|
inline const DefaultTextures& GetDefaultTextures() const;
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GetFullscreenVertexBuffer() const;
|
inline const std::shared_ptr<RenderBuffer>& GetFullscreenVertexBuffer() const;
|
||||||
inline const std::shared_ptr<VertexDeclaration>& GetFullscreenVertexDeclaration() const;
|
inline const std::shared_ptr<VertexDeclaration>& GetFullscreenVertexDeclaration() const;
|
||||||
inline MaterialPassRegistry& GetMaterialPassRegistry();
|
inline MaterialPassRegistry& GetMaterialPassRegistry();
|
||||||
inline const MaterialPassRegistry& GetMaterialPassRegistry() const;
|
inline const MaterialPassRegistry& GetMaterialPassRegistry() const;
|
||||||
@@ -66,7 +66,7 @@ namespace Nz
|
|||||||
|
|
||||||
std::optional<RenderPassCache> m_renderPassCache;
|
std::optional<RenderPassCache> m_renderPassCache;
|
||||||
std::optional<TextureSamplerCache> m_samplerCache;
|
std::optional<TextureSamplerCache> m_samplerCache;
|
||||||
std::shared_ptr<AbstractBuffer> m_fullscreenVertexBuffer;
|
std::shared_ptr<RenderBuffer> m_fullscreenVertexBuffer;
|
||||||
std::shared_ptr<RenderDevice> m_renderDevice;
|
std::shared_ptr<RenderDevice> m_renderDevice;
|
||||||
std::shared_ptr<RenderPipeline> m_blitPipeline;
|
std::shared_ptr<RenderPipeline> m_blitPipeline;
|
||||||
std::shared_ptr<RenderPipeline> m_blitPipelineTransparent;
|
std::shared_ptr<RenderPipeline> m_blitPipelineTransparent;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace Nz
|
|||||||
return m_defaultTextures;
|
return m_defaultTextures;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::shared_ptr<AbstractBuffer>& Graphics::GetFullscreenVertexBuffer() const
|
inline const std::shared_ptr<RenderBuffer>& Graphics::GetFullscreenVertexBuffer() const
|
||||||
{
|
{
|
||||||
return m_fullscreenVertexBuffer;
|
return m_fullscreenVertexBuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Nz
|
|||||||
inline const std::shared_ptr<UberShader>& GetShader(ShaderStageType shaderStage) const;
|
inline const std::shared_ptr<UberShader>& GetShader(ShaderStageType shaderStage) const;
|
||||||
inline const std::shared_ptr<Texture>& GetTexture(std::size_t textureIndex) const;
|
inline const std::shared_ptr<Texture>& GetTexture(std::size_t textureIndex) const;
|
||||||
inline const TextureSamplerInfo& GetTextureSampler(std::size_t textureIndex) const;
|
inline const TextureSamplerInfo& GetTextureSampler(std::size_t textureIndex) const;
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GetUniformBuffer(std::size_t bufferIndex) const;
|
inline const std::shared_ptr<RenderBuffer>& GetUniformBuffer(std::size_t bufferIndex) const;
|
||||||
inline const std::vector<UInt8>& GetUniformBufferConstData(std::size_t bufferIndex) const;
|
inline const std::vector<UInt8>& GetUniformBufferConstData(std::size_t bufferIndex) const;
|
||||||
inline std::vector<UInt8>& GetUniformBufferData(std::size_t bufferIndex);
|
inline std::vector<UInt8>& GetUniformBufferData(std::size_t bufferIndex);
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ namespace Nz
|
|||||||
inline void SetPrimitiveMode(PrimitiveMode mode);
|
inline void SetPrimitiveMode(PrimitiveMode mode);
|
||||||
inline void SetTexture(std::size_t textureIndex, std::shared_ptr<Texture> texture);
|
inline void SetTexture(std::size_t textureIndex, std::shared_ptr<Texture> texture);
|
||||||
inline void SetTextureSampler(std::size_t textureIndex, TextureSamplerInfo samplerInfo);
|
inline void SetTextureSampler(std::size_t textureIndex, TextureSamplerInfo samplerInfo);
|
||||||
inline void SetUniformBuffer(std::size_t bufferIndex, std::shared_ptr<AbstractBuffer> uniformBuffer);
|
inline void SetUniformBuffer(std::size_t bufferIndex, std::shared_ptr<RenderBuffer> uniformBuffer);
|
||||||
|
|
||||||
bool Update(RenderFrame& renderFrame, CommandBufferBuilder& builder);
|
bool Update(RenderFrame& renderFrame, CommandBufferBuilder& builder);
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ namespace Nz
|
|||||||
|
|
||||||
struct UniformBuffer
|
struct UniformBuffer
|
||||||
{
|
{
|
||||||
std::shared_ptr<AbstractBuffer> buffer;
|
std::shared_ptr<RenderBuffer> buffer;
|
||||||
std::vector<UInt8> data;
|
std::vector<UInt8> data;
|
||||||
bool dataInvalidated = true;
|
bool dataInvalidated = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ namespace Nz
|
|||||||
return m_textures[textureIndex].samplerInfo;
|
return m_textures[textureIndex].samplerInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::shared_ptr<AbstractBuffer>& MaterialPass::GetUniformBuffer(std::size_t bufferIndex) const
|
inline const std::shared_ptr<RenderBuffer>& MaterialPass::GetUniformBuffer(std::size_t bufferIndex) const
|
||||||
{
|
{
|
||||||
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
|
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
|
||||||
return m_uniformBuffers[bufferIndex].buffer;
|
return m_uniformBuffers[bufferIndex].buffer;
|
||||||
@@ -624,7 +624,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void MaterialPass::SetUniformBuffer(std::size_t bufferIndex, std::shared_ptr<AbstractBuffer> uniformBuffer)
|
inline void MaterialPass::SetUniformBuffer(std::size_t bufferIndex, std::shared_ptr<RenderBuffer> uniformBuffer)
|
||||||
{
|
{
|
||||||
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid shared uniform buffer index");
|
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid shared uniform buffer index");
|
||||||
if (m_uniformBuffers[bufferIndex].buffer != uniformBuffer)
|
if (m_uniformBuffers[bufferIndex].buffer != uniformBuffer)
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ namespace Nz
|
|||||||
|
|
||||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
||||||
|
|
||||||
const std::shared_ptr<AbstractBuffer>& GetIndexBuffer(std::size_t subMeshIndex) const;
|
const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMeshIndex) const;
|
||||||
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
|
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
|
||||||
const std::shared_ptr<Material>& GetMaterial(std::size_t subMeshIndex) const override;
|
const std::shared_ptr<Material>& GetMaterial(std::size_t subMeshIndex) const override;
|
||||||
std::size_t GetMaterialCount() const override;
|
std::size_t GetMaterialCount() const override;
|
||||||
inline std::size_t GetSubMeshCount() const;
|
inline std::size_t GetSubMeshCount() const;
|
||||||
const std::vector<RenderPipelineInfo::VertexBufferData>& GetVertexBufferData(std::size_t subMeshIndex) const;
|
const std::vector<RenderPipelineInfo::VertexBufferData>& GetVertexBufferData(std::size_t subMeshIndex) const;
|
||||||
const std::shared_ptr<AbstractBuffer>& GetVertexBuffer(std::size_t subMeshIndex) const;
|
const std::shared_ptr<RenderBuffer>& GetVertexBuffer(std::size_t subMeshIndex) const;
|
||||||
|
|
||||||
inline void SetMaterial(std::size_t subMeshIndex, std::shared_ptr<Material> material);
|
inline void SetMaterial(std::size_t subMeshIndex, std::shared_ptr<Material> material);
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Nz
|
|||||||
inline std::size_t FetchLayerIndex(int renderLayer) const;
|
inline std::size_t FetchLayerIndex(int renderLayer) const;
|
||||||
inline std::size_t FetchMaterialPassIndex(const MaterialPass* materialPass) const;
|
inline std::size_t FetchMaterialPassIndex(const MaterialPass* materialPass) const;
|
||||||
inline std::size_t FetchPipelineIndex(const RenderPipeline* pipeline) const;
|
inline std::size_t FetchPipelineIndex(const RenderPipeline* pipeline) const;
|
||||||
inline std::size_t FetchVertexBuffer(const AbstractBuffer* vertexBuffer) const;
|
inline std::size_t FetchVertexBuffer(const RenderBuffer* vertexBuffer) const;
|
||||||
inline std::size_t FetchVertexDeclaration(const VertexDeclaration* vertexDeclaration) const;
|
inline std::size_t FetchVertexDeclaration(const VertexDeclaration* vertexDeclaration) const;
|
||||||
|
|
||||||
inline void Finalize();
|
inline void Finalize();
|
||||||
@@ -37,7 +37,7 @@ namespace Nz
|
|||||||
inline void RegisterLayer(int renderLayer);
|
inline void RegisterLayer(int renderLayer);
|
||||||
inline void RegisterMaterialPass(const MaterialPass* materialPass);
|
inline void RegisterMaterialPass(const MaterialPass* materialPass);
|
||||||
inline void RegisterPipeline(const RenderPipeline* pipeline);
|
inline void RegisterPipeline(const RenderPipeline* pipeline);
|
||||||
inline void RegisterVertexBuffer(const AbstractBuffer* vertexBuffer);
|
inline void RegisterVertexBuffer(const RenderBuffer* vertexBuffer);
|
||||||
inline void RegisterVertexDeclaration(const VertexDeclaration* vertexDeclaration);
|
inline void RegisterVertexDeclaration(const VertexDeclaration* vertexDeclaration);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -45,7 +45,7 @@ namespace Nz
|
|||||||
robin_hood::unordered_map<int, std::size_t> m_renderLayerRegistry;
|
robin_hood::unordered_map<int, std::size_t> m_renderLayerRegistry;
|
||||||
robin_hood::unordered_map<const MaterialPass*, std::size_t> m_materialPassRegistry;
|
robin_hood::unordered_map<const MaterialPass*, std::size_t> m_materialPassRegistry;
|
||||||
robin_hood::unordered_map<const RenderPipeline*, std::size_t> m_pipelineRegistry;
|
robin_hood::unordered_map<const RenderPipeline*, std::size_t> m_pipelineRegistry;
|
||||||
robin_hood::unordered_map<const AbstractBuffer*, std::size_t> m_vertexBufferRegistry;
|
robin_hood::unordered_map<const RenderBuffer*, std::size_t> m_vertexBufferRegistry;
|
||||||
robin_hood::unordered_map<const VertexDeclaration*, std::size_t> m_vertexDeclarationRegistry;
|
robin_hood::unordered_map<const VertexDeclaration*, std::size_t> m_vertexDeclarationRegistry;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace Nz
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t RenderQueueRegistry::FetchVertexBuffer(const AbstractBuffer* vertexBuffer) const
|
inline std::size_t RenderQueueRegistry::FetchVertexBuffer(const RenderBuffer* vertexBuffer) const
|
||||||
{
|
{
|
||||||
auto it = m_vertexBufferRegistry.find(vertexBuffer);
|
auto it = m_vertexBufferRegistry.find(vertexBuffer);
|
||||||
assert(it != m_vertexBufferRegistry.end());
|
assert(it != m_vertexBufferRegistry.end());
|
||||||
@@ -80,7 +80,7 @@ namespace Nz
|
|||||||
m_pipelineRegistry.try_emplace(pipeline, m_pipelineRegistry.size());
|
m_pipelineRegistry.try_emplace(pipeline, m_pipelineRegistry.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void RenderQueueRegistry::RegisterVertexBuffer(const AbstractBuffer* vertexBuffer)
|
inline void RenderQueueRegistry::RegisterVertexBuffer(const RenderBuffer* vertexBuffer)
|
||||||
{
|
{
|
||||||
m_vertexBufferRegistry.try_emplace(vertexBuffer, m_vertexBufferRegistry.size());
|
m_vertexBufferRegistry.try_emplace(vertexBuffer, m_vertexBufferRegistry.size());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,24 +24,24 @@ namespace Nz
|
|||||||
class RenderSubmesh : public RenderElement
|
class RenderSubmesh : public RenderElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer, const Recti& scissorBox);
|
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<RenderBuffer> indexBuffer, std::shared_ptr<RenderBuffer> vertexBuffer, const Recti& scissorBox);
|
||||||
~RenderSubmesh() = default;
|
~RenderSubmesh() = default;
|
||||||
|
|
||||||
inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override;
|
inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override;
|
||||||
|
|
||||||
inline const AbstractBuffer* GetIndexBuffer() const;
|
inline const RenderBuffer* GetIndexBuffer() const;
|
||||||
inline std::size_t GetIndexCount() const;
|
inline std::size_t GetIndexCount() const;
|
||||||
inline const MaterialPass& GetMaterialPass() const;
|
inline const MaterialPass& GetMaterialPass() const;
|
||||||
inline const RenderPipeline* GetRenderPipeline() const;
|
inline const RenderPipeline* GetRenderPipeline() const;
|
||||||
inline const Recti& GetScissorBox() const;
|
inline const Recti& GetScissorBox() const;
|
||||||
inline const AbstractBuffer* GetVertexBuffer() const;
|
inline const RenderBuffer* GetVertexBuffer() const;
|
||||||
inline const WorldInstance& GetWorldInstance() const;
|
inline const WorldInstance& GetWorldInstance() const;
|
||||||
|
|
||||||
inline void Register(RenderQueueRegistry& registry) const override;
|
inline void Register(RenderQueueRegistry& registry) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<AbstractBuffer> m_indexBuffer;
|
std::shared_ptr<RenderBuffer> m_indexBuffer;
|
||||||
std::shared_ptr<AbstractBuffer> m_vertexBuffer;
|
std::shared_ptr<RenderBuffer> m_vertexBuffer;
|
||||||
std::shared_ptr<MaterialPass> m_materialPass;
|
std::shared_ptr<MaterialPass> m_materialPass;
|
||||||
std::shared_ptr<RenderPipeline> m_renderPipeline;
|
std::shared_ptr<RenderPipeline> m_renderPipeline;
|
||||||
std::size_t m_indexCount;
|
std::size_t m_indexCount;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer, const Recti& scissorBox) :
|
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<RenderBuffer> indexBuffer, std::shared_ptr<RenderBuffer> vertexBuffer, const Recti& scissorBox) :
|
||||||
RenderElement(BasicRenderElement::Submesh),
|
RenderElement(BasicRenderElement::Submesh),
|
||||||
m_indexBuffer(std::move(indexBuffer)),
|
m_indexBuffer(std::move(indexBuffer)),
|
||||||
m_vertexBuffer(std::move(vertexBuffer)),
|
m_vertexBuffer(std::move(vertexBuffer)),
|
||||||
@@ -70,7 +70,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const AbstractBuffer* RenderSubmesh::GetIndexBuffer() const
|
inline const RenderBuffer* RenderSubmesh::GetIndexBuffer() const
|
||||||
{
|
{
|
||||||
return m_indexBuffer.get();
|
return m_indexBuffer.get();
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ namespace Nz
|
|||||||
return m_scissorBox;
|
return m_scissorBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const AbstractBuffer* RenderSubmesh::GetVertexBuffer() const
|
inline const RenderBuffer* RenderSubmesh::GetVertexBuffer() const
|
||||||
{
|
{
|
||||||
return m_vertexBuffer.get();
|
return m_vertexBuffer.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace Nz
|
|||||||
|
|
||||||
inline void Sprite::UpdateVertices()
|
inline void Sprite::UpdateVertices()
|
||||||
{
|
{
|
||||||
Boxf aabb = Boxf::Zero();
|
Boxf aabb(-1.f, -1.f, -1.f);
|
||||||
|
|
||||||
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
|
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
|
||||||
|
|
||||||
|
|||||||
@@ -38,17 +38,17 @@ namespace Nz
|
|||||||
private:
|
private:
|
||||||
struct BufferCopy
|
struct BufferCopy
|
||||||
{
|
{
|
||||||
AbstractBuffer* targetBuffer;
|
RenderBuffer* targetBuffer;
|
||||||
UploadPool::Allocation* allocation;
|
UploadPool::Allocation* allocation;
|
||||||
std::size_t size;
|
std::size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexBufferPool
|
struct VertexBufferPool
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<AbstractBuffer>> vertexBuffers;
|
std::vector<std::shared_ptr<RenderBuffer>> vertexBuffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> m_indexBuffer;
|
std::shared_ptr<RenderBuffer> m_indexBuffer;
|
||||||
std::shared_ptr<VertexBufferPool> m_vertexBufferPool;
|
std::shared_ptr<VertexBufferPool> m_vertexBufferPool;
|
||||||
std::size_t m_maxVertexBufferSize;
|
std::size_t m_maxVertexBufferSize;
|
||||||
std::size_t m_maxVertexCount;
|
std::size_t m_maxVertexCount;
|
||||||
@@ -61,7 +61,7 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
struct DrawCall
|
struct DrawCall
|
||||||
{
|
{
|
||||||
const AbstractBuffer* vertexBuffer;
|
const RenderBuffer* vertexBuffer;
|
||||||
const RenderPipeline* renderPipeline;
|
const RenderPipeline* renderPipeline;
|
||||||
const ShaderBinding* shaderBinding;
|
const ShaderBinding* shaderBinding;
|
||||||
std::size_t firstIndex;
|
std::size_t firstIndex;
|
||||||
@@ -77,7 +77,7 @@ namespace Nz
|
|||||||
|
|
||||||
std::unordered_map<const RenderSpriteChain*, DrawCallIndices> drawCallPerElement;
|
std::unordered_map<const RenderSpriteChain*, DrawCallIndices> drawCallPerElement;
|
||||||
std::vector<DrawCall> drawCalls;
|
std::vector<DrawCall> drawCalls;
|
||||||
std::vector<std::shared_ptr<AbstractBuffer>> vertexBuffers;
|
std::vector<std::shared_ptr<RenderBuffer>> vertexBuffers;
|
||||||
std::vector<ShaderBindingPtr> shaderBindings;
|
std::vector<ShaderBindingPtr> shaderBindings;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
struct DrawCall
|
struct DrawCall
|
||||||
{
|
{
|
||||||
const AbstractBuffer* indexBuffer;
|
const RenderBuffer* indexBuffer;
|
||||||
const AbstractBuffer* vertexBuffer;
|
const RenderBuffer* vertexBuffer;
|
||||||
const RenderPipeline* renderPipeline;
|
const RenderPipeline* renderPipeline;
|
||||||
const ShaderBinding* shaderBinding;
|
const ShaderBinding* shaderBinding;
|
||||||
std::size_t indexCount;
|
std::size_t indexCount;
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ namespace Nz
|
|||||||
inline const Vector2f& GetTargetSize() const;
|
inline const Vector2f& GetTargetSize() const;
|
||||||
inline const Matrix4f& GetViewMatrix() const;
|
inline const Matrix4f& GetViewMatrix() const;
|
||||||
inline const Matrix4f& GetViewProjMatrix() const;
|
inline const Matrix4f& GetViewProjMatrix() const;
|
||||||
inline std::shared_ptr<AbstractBuffer>& GetViewerBuffer();
|
inline std::shared_ptr<RenderBuffer>& GetViewerBuffer();
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GetViewerBuffer() const;
|
inline const std::shared_ptr<RenderBuffer>& GetViewerBuffer() const;
|
||||||
|
|
||||||
void UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder);
|
void UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder);
|
||||||
inline void UpdateEyePosition(const Vector3f& eyePosition);
|
inline void UpdateEyePosition(const Vector3f& eyePosition);
|
||||||
@@ -54,7 +54,7 @@ namespace Nz
|
|||||||
ViewerInstance& operator=(ViewerInstance&&) noexcept = default;
|
ViewerInstance& operator=(ViewerInstance&&) noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<AbstractBuffer> m_viewerDataBuffer;
|
std::shared_ptr<RenderBuffer> m_viewerDataBuffer;
|
||||||
Matrix4f m_invProjectionMatrix;
|
Matrix4f m_invProjectionMatrix;
|
||||||
Matrix4f m_invViewProjMatrix;
|
Matrix4f m_invViewProjMatrix;
|
||||||
Matrix4f m_invViewMatrix;
|
Matrix4f m_invViewMatrix;
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ namespace Nz
|
|||||||
return m_viewProjMatrix;
|
return m_viewProjMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::shared_ptr<AbstractBuffer>& ViewerInstance::GetViewerBuffer()
|
inline std::shared_ptr<RenderBuffer>& ViewerInstance::GetViewerBuffer()
|
||||||
{
|
{
|
||||||
return m_viewerDataBuffer;
|
return m_viewerDataBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::shared_ptr<AbstractBuffer>& ViewerInstance::GetViewerBuffer() const
|
inline const std::shared_ptr<RenderBuffer>& ViewerInstance::GetViewerBuffer() const
|
||||||
{
|
{
|
||||||
return m_viewerDataBuffer;
|
return m_viewerDataBuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ namespace Nz
|
|||||||
WorldInstance(WorldInstance&&) noexcept = default;
|
WorldInstance(WorldInstance&&) noexcept = default;
|
||||||
~WorldInstance() = default;
|
~WorldInstance() = default;
|
||||||
|
|
||||||
inline std::shared_ptr<AbstractBuffer>& GetInstanceBuffer();
|
inline std::shared_ptr<RenderBuffer>& GetInstanceBuffer();
|
||||||
inline const std::shared_ptr<AbstractBuffer>& GetInstanceBuffer() const;
|
inline const std::shared_ptr<RenderBuffer>& GetInstanceBuffer() const;
|
||||||
inline const Matrix4f& GetInvWorldMatrix() const;
|
inline const Matrix4f& GetInvWorldMatrix() const;
|
||||||
inline const Matrix4f& GetWorldMatrix() const;
|
inline const Matrix4f& GetWorldMatrix() const;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace Nz
|
|||||||
WorldInstance& operator=(WorldInstance&&) noexcept = default;
|
WorldInstance& operator=(WorldInstance&&) noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<AbstractBuffer> m_instanceDataBuffer;
|
std::shared_ptr<RenderBuffer> m_instanceDataBuffer;
|
||||||
Matrix4f m_invWorldMatrix;
|
Matrix4f m_invWorldMatrix;
|
||||||
Matrix4f m_worldMatrix;
|
Matrix4f m_worldMatrix;
|
||||||
bool m_dataInvalided;
|
bool m_dataInvalided;
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline std::shared_ptr<AbstractBuffer>& WorldInstance::GetInstanceBuffer()
|
inline std::shared_ptr<RenderBuffer>& WorldInstance::GetInstanceBuffer()
|
||||||
{
|
{
|
||||||
return m_instanceDataBuffer;
|
return m_instanceDataBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::shared_ptr<AbstractBuffer>& WorldInstance::GetInstanceBuffer() const
|
inline const std::shared_ptr<RenderBuffer>& WorldInstance::GetInstanceBuffer() const
|
||||||
{
|
{
|
||||||
return m_instanceDataBuffer;
|
return m_instanceDataBuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,30 +11,25 @@
|
|||||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
|
#include <Nazara/OpenGLRenderer/OpenGLDevice.hpp>
|
||||||
#include <Nazara/OpenGLRenderer/Wrapper/Buffer.hpp>
|
#include <Nazara/OpenGLRenderer/Wrapper/Buffer.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_OPENGLRENDERER_API OpenGLBuffer : public AbstractBuffer
|
class NAZARA_OPENGLRENDERER_API OpenGLBuffer : public RenderBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OpenGLBuffer(OpenGLDevice& device, BufferType type);
|
OpenGLBuffer(OpenGLDevice& device, BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData = nullptr);
|
||||||
OpenGLBuffer(const OpenGLBuffer&) = delete;
|
OpenGLBuffer(const OpenGLBuffer&) = delete;
|
||||||
OpenGLBuffer(OpenGLBuffer&&) = delete;
|
OpenGLBuffer(OpenGLBuffer&&) = delete;
|
||||||
~OpenGLBuffer() = default;
|
~OpenGLBuffer() = default;
|
||||||
|
|
||||||
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
||||||
|
|
||||||
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
|
|
||||||
|
|
||||||
inline const GL::Buffer& GetBuffer() const;
|
inline const GL::Buffer& GetBuffer() const;
|
||||||
UInt64 GetSize() const override;
|
|
||||||
DataStorage GetStorage() const override;
|
|
||||||
inline BufferType GetType() const;
|
|
||||||
|
|
||||||
void* Map(BufferAccess access, UInt64 offset, UInt64 size) override;
|
void* Map(UInt64 offset, UInt64 size) override;
|
||||||
bool Unmap() override;
|
bool Unmap() override;
|
||||||
|
|
||||||
OpenGLBuffer& operator=(const OpenGLBuffer&) = delete;
|
OpenGLBuffer& operator=(const OpenGLBuffer&) = delete;
|
||||||
@@ -42,9 +37,6 @@ namespace Nz
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
GL::Buffer m_buffer;
|
GL::Buffer m_buffer;
|
||||||
BufferType m_type;
|
|
||||||
BufferUsageFlags m_usage;
|
|
||||||
UInt64 m_size;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline BufferType OpenGLBuffer::GetType() const
|
|
||||||
{
|
|
||||||
return m_type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ namespace Nz
|
|||||||
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
||||||
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
||||||
|
|
||||||
void BindIndexBuffer(const AbstractBuffer& indexBuffer, UInt64 offset = 0) override;
|
void BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset = 0) override;
|
||||||
void BindPipeline(const RenderPipeline& pipeline) override;
|
void BindPipeline(const RenderPipeline& pipeline) override;
|
||||||
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
||||||
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
||||||
void BindVertexBuffer(UInt32 binding, const AbstractBuffer& vertexBuffer, UInt64 offset = 0) override;
|
void BindVertexBuffer(UInt32 binding, const RenderBuffer& vertexBuffer, UInt64 offset = 0) override;
|
||||||
|
|
||||||
void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) override;
|
void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) override;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Nz
|
|||||||
const RenderDeviceFeatures& GetEnabledFeatures() const override;
|
const RenderDeviceFeatures& GetEnabledFeatures() const override;
|
||||||
inline const GL::Context& GetReferenceContext() const;
|
inline const GL::Context& GetReferenceContext() const;
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
std::shared_ptr<RenderBuffer> InstantiateBuffer(BufferType type, UInt64 size, BufferUsageFlags usageFlags, const void* initialData = nullptr) override;
|
||||||
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
||||||
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
||||||
std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) override;
|
std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) override;
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ namespace Nz
|
|||||||
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect);
|
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect);
|
||||||
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, std::initializer_list<ClearValues> clearValues);
|
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, std::initializer_list<ClearValues> clearValues);
|
||||||
|
|
||||||
virtual void BindIndexBuffer(const AbstractBuffer& indexBuffer, UInt64 offset = 0) = 0;
|
virtual void BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset = 0) = 0;
|
||||||
virtual void BindPipeline(const RenderPipeline& pipeline) = 0;
|
virtual void BindPipeline(const RenderPipeline& pipeline) = 0;
|
||||||
virtual void BindShaderBinding(UInt32 set, const ShaderBinding& binding) = 0;
|
virtual void BindShaderBinding(UInt32 set, const ShaderBinding& binding) = 0;
|
||||||
virtual void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) = 0;
|
virtual void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) = 0;
|
||||||
virtual void BindVertexBuffer(UInt32 binding, const AbstractBuffer& vertexBuffer, UInt64 offset = 0) = 0;
|
virtual void BindVertexBuffer(UInt32 binding, const RenderBuffer& vertexBuffer, UInt64 offset = 0) = 0;
|
||||||
|
|
||||||
virtual void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) = 0;
|
virtual void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -7,61 +7,34 @@
|
|||||||
#ifndef NAZARA_RENDERER_RENDERBUFFER_HPP
|
#ifndef NAZARA_RENDERER_RENDERBUFFER_HPP
|
||||||
#define NAZARA_RENDERER_RENDERBUFFER_HPP
|
#define NAZARA_RENDERER_RENDERBUFFER_HPP
|
||||||
|
|
||||||
#include <Nazara/Core/MovablePtr.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/RenderDevice.hpp>
|
#include <Nazara/Utility/Buffer.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class RenderDevice;
|
class RenderDevice;
|
||||||
|
|
||||||
class NAZARA_RENDERER_API RenderBuffer : public AbstractBuffer
|
class NAZARA_RENDERER_API RenderBuffer : public Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline RenderBuffer(Buffer* parent, BufferType type);
|
inline RenderBuffer(RenderDevice& renderDevice, BufferType type, UInt64 size, BufferUsageFlags usage);
|
||||||
RenderBuffer(const RenderBuffer&) = delete;
|
RenderBuffer(const RenderBuffer&) = delete;
|
||||||
RenderBuffer(RenderBuffer&&) = default;
|
RenderBuffer(RenderBuffer&&) = delete;
|
||||||
~RenderBuffer() = default;
|
~RenderBuffer();
|
||||||
|
|
||||||
bool Fill(const void* data, UInt64 offset, UInt64 size) final;
|
inline RenderDevice& GetRenderDevice();
|
||||||
|
inline const RenderDevice& GetRenderDevice() const;
|
||||||
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
|
|
||||||
|
|
||||||
AbstractBuffer* GetHardwareBuffer(RenderDevice* device);
|
|
||||||
UInt64 GetSize() const override;
|
|
||||||
DataStorage GetStorage() const override;
|
|
||||||
|
|
||||||
void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) final;
|
|
||||||
bool Unmap() final;
|
|
||||||
|
|
||||||
RenderBuffer& operator=(const RenderBuffer&) = delete;
|
RenderBuffer& operator=(const RenderBuffer&) = delete;
|
||||||
RenderBuffer& operator=(RenderBuffer&&) = default;
|
RenderBuffer& operator=(RenderBuffer&&) = delete;
|
||||||
|
|
||||||
public: //< temp
|
|
||||||
bool Synchronize(RenderDevice* device);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct HardwareBuffer;
|
RenderDevice& m_renderDevice;
|
||||||
|
|
||||||
HardwareBuffer* GetHardwareBufferData(RenderDevice* device);
|
|
||||||
|
|
||||||
struct HardwareBuffer
|
|
||||||
{
|
|
||||||
std::shared_ptr<AbstractBuffer> buffer;
|
|
||||||
bool synchronized = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
BufferUsageFlags m_usage;
|
|
||||||
SoftwareBuffer m_softwareBuffer;
|
|
||||||
Buffer* m_parent;
|
|
||||||
BufferType m_type;
|
|
||||||
std::size_t m_size;
|
|
||||||
std::unordered_map<RenderDevice*, HardwareBuffer> m_hardwareBuffers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_RENDERER_API BufferFactory GetRenderBufferFactory(std::shared_ptr<RenderDevice> device);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Renderer/RenderBuffer.inl>
|
#include <Nazara/Renderer/RenderBuffer.inl>
|
||||||
|
|||||||
@@ -3,17 +3,25 @@
|
|||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <memory>
|
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline RenderBuffer::RenderBuffer(Buffer* parent, BufferType type) :
|
inline RenderBuffer::RenderBuffer(RenderDevice& renderDevice, BufferType type, UInt64 size, BufferUsageFlags usage) :
|
||||||
m_softwareBuffer(parent, type),
|
Buffer(DataStorage::Hardware, type, size, usage),
|
||||||
m_parent(parent),
|
m_renderDevice(renderDevice)
|
||||||
m_type(type)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline RenderDevice& RenderBuffer::GetRenderDevice()
|
||||||
|
{
|
||||||
|
return m_renderDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const RenderDevice& RenderBuffer::GetRenderDevice() const
|
||||||
|
{
|
||||||
|
return m_renderDevice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Renderer/DebugOff.hpp>
|
#include <Nazara/Renderer/DebugOff.hpp>
|
||||||
|
|||||||
@@ -9,20 +9,20 @@
|
|||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/MovablePtr.hpp>
|
#include <Nazara/Core/MovablePtr.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class RenderBufferView
|
class RenderBufferView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline RenderBufferView(AbstractBuffer* buffer);
|
inline RenderBufferView(RenderBuffer* buffer);
|
||||||
inline RenderBufferView(AbstractBuffer* buffer, UInt64 offset, UInt64 size);
|
inline RenderBufferView(RenderBuffer* buffer, UInt64 offset, UInt64 size);
|
||||||
RenderBufferView(const RenderBufferView&) = default;
|
RenderBufferView(const RenderBufferView&) = default;
|
||||||
RenderBufferView(RenderBufferView&&) = default;
|
RenderBufferView(RenderBufferView&&) = default;
|
||||||
~RenderBufferView() = default;
|
~RenderBufferView() = default;
|
||||||
|
|
||||||
inline AbstractBuffer* GetBuffer() const;
|
inline RenderBuffer* GetBuffer() const;
|
||||||
inline UInt64 GetOffset() const;
|
inline UInt64 GetOffset() const;
|
||||||
inline UInt64 GetSize() const;
|
inline UInt64 GetSize() const;
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ namespace Nz
|
|||||||
private:
|
private:
|
||||||
UInt64 m_offset;
|
UInt64 m_offset;
|
||||||
UInt64 m_size;
|
UInt64 m_size;
|
||||||
AbstractBuffer* m_buffer;
|
RenderBuffer* m_buffer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,19 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline RenderBufferView::RenderBufferView(AbstractBuffer* buffer) :
|
inline RenderBufferView::RenderBufferView(RenderBuffer* buffer) :
|
||||||
RenderBufferView(buffer, 0, buffer->GetSize())
|
RenderBufferView(buffer, 0, buffer->GetSize())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline RenderBufferView::RenderBufferView(AbstractBuffer* buffer, UInt64 offset, UInt64 size) :
|
inline RenderBufferView::RenderBufferView(RenderBuffer* buffer, UInt64 offset, UInt64 size) :
|
||||||
m_offset(offset),
|
m_offset(offset),
|
||||||
m_size(size),
|
m_size(size),
|
||||||
m_buffer(buffer)
|
m_buffer(buffer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline AbstractBuffer* RenderBufferView::GetBuffer() const
|
inline RenderBuffer* RenderBufferView::GetBuffer() const
|
||||||
{
|
{
|
||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
#include <Nazara/Renderer/Framebuffer.hpp>
|
#include <Nazara/Renderer/Framebuffer.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||||
#include <Nazara/Renderer/RenderPass.hpp>
|
#include <Nazara/Renderer/RenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||||
@@ -19,7 +20,6 @@
|
|||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
#include <Nazara/Shader/ShaderWriter.hpp>
|
#include <Nazara/Shader/ShaderWriter.hpp>
|
||||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/PixelFormat.hpp>
|
#include <Nazara/Utility/PixelFormat.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -38,7 +38,7 @@ namespace Nz
|
|||||||
virtual const RenderDeviceInfo& GetDeviceInfo() const = 0;
|
virtual const RenderDeviceInfo& GetDeviceInfo() const = 0;
|
||||||
virtual const RenderDeviceFeatures& GetEnabledFeatures() const = 0;
|
virtual const RenderDeviceFeatures& GetEnabledFeatures() const = 0;
|
||||||
|
|
||||||
virtual std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) = 0;
|
virtual std::shared_ptr<RenderBuffer> InstantiateBuffer(BufferType type, UInt64 size, BufferUsageFlags usageFlags, const void* initialData = nullptr) = 0;
|
||||||
virtual std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) = 0;
|
virtual std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) = 0;
|
||||||
virtual std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) = 0;
|
virtual std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) = 0;
|
||||||
virtual std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) = 0;
|
virtual std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) = 0;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class AbstractBuffer;
|
class RenderBuffer;
|
||||||
class ShaderBinding;
|
class ShaderBinding;
|
||||||
class ShaderBindingDeleter;
|
class ShaderBindingDeleter;
|
||||||
class Texture;
|
class Texture;
|
||||||
@@ -48,7 +48,7 @@ namespace Nz
|
|||||||
|
|
||||||
struct UniformBufferBinding
|
struct UniformBufferBinding
|
||||||
{
|
{
|
||||||
AbstractBuffer* buffer;
|
RenderBuffer* buffer;
|
||||||
UInt64 offset;
|
UInt64 offset;
|
||||||
UInt64 range;
|
UInt64 range;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
#define NAZARA_GLOBAL_UTILITY_HPP
|
#define NAZARA_GLOBAL_UTILITY_HPP
|
||||||
|
|
||||||
#include <Nazara/Utility/AbstractAtlas.hpp>
|
#include <Nazara/Utility/AbstractAtlas.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/AbstractImage.hpp>
|
#include <Nazara/Utility/AbstractImage.hpp>
|
||||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||||
#include <Nazara/Utility/Algorithm.hpp>
|
#include <Nazara/Utility/Algorithm.hpp>
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
|
||||||
// This file is part of the "Nazara Engine - Utility module"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_UTILITY_ABSTRACTBUFFER_HPP
|
|
||||||
#define NAZARA_UTILITY_ABSTRACTBUFFER_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Utility/Config.hpp>
|
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
class NAZARA_UTILITY_API AbstractBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AbstractBuffer() = default;
|
|
||||||
virtual ~AbstractBuffer();
|
|
||||||
|
|
||||||
virtual bool Fill(const void* data, UInt64 offset, UInt64 size) = 0;
|
|
||||||
|
|
||||||
virtual bool Initialize(UInt64 size, BufferUsageFlags usage) = 0;
|
|
||||||
|
|
||||||
virtual UInt64 GetSize() const = 0;
|
|
||||||
virtual DataStorage GetStorage() const = 0;
|
|
||||||
|
|
||||||
virtual void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) = 0;
|
|
||||||
virtual bool Unmap() = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NAZARA_UTILITY_ABSTRACTBUFFER_HPP
|
|
||||||
@@ -44,7 +44,7 @@ namespace Nz
|
|||||||
|
|
||||||
NAZARA_UTILITY_API Boxf ComputeAABB(SparsePtr<const Vector3f> positionPtr, std::size_t vertexCount);
|
NAZARA_UTILITY_API Boxf ComputeAABB(SparsePtr<const Vector3f> positionPtr, std::size_t vertexCount);
|
||||||
NAZARA_UTILITY_API void ComputeBoxIndexVertexCount(const Vector3ui& subdivision, std::size_t* indexCount, std::size_t* vertexCount);
|
NAZARA_UTILITY_API void ComputeBoxIndexVertexCount(const Vector3ui& subdivision, std::size_t* indexCount, std::size_t* vertexCount);
|
||||||
NAZARA_UTILITY_API unsigned int ComputeCacheMissCount(IndexIterator indices, std::size_t indexCount);
|
NAZARA_UTILITY_API UInt64 ComputeCacheMissCount(IndexIterator indices, std::size_t indexCount);
|
||||||
NAZARA_UTILITY_API void ComputeConeIndexVertexCount(unsigned int subdivision, std::size_t* indexCount, std::size_t* vertexCount);
|
NAZARA_UTILITY_API void ComputeConeIndexVertexCount(unsigned int subdivision, std::size_t* indexCount, std::size_t* vertexCount);
|
||||||
NAZARA_UTILITY_API void ComputeCubicSphereIndexVertexCount(unsigned int subdivision, std::size_t* indexCount, std::size_t* vertexCount);
|
NAZARA_UTILITY_API void ComputeCubicSphereIndexVertexCount(unsigned int subdivision, std::size_t* indexCount, std::size_t* vertexCount);
|
||||||
NAZARA_UTILITY_API void ComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, std::size_t* indexCount, std::size_t* vertexCount);
|
NAZARA_UTILITY_API void ComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, std::size_t* indexCount, std::size_t* vertexCount);
|
||||||
|
|||||||
@@ -8,68 +8,45 @@
|
|||||||
#define NAZARA_UTILITY_BUFFER_HPP
|
#define NAZARA_UTILITY_BUFFER_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/Config.hpp>
|
#include <Nazara/Utility/Config.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
#include <array>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
class Buffer;
|
||||||
|
|
||||||
|
using BufferFactory = std::function<std::shared_ptr<Buffer>(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData)>;
|
||||||
|
|
||||||
class NAZARA_UTILITY_API Buffer
|
class NAZARA_UTILITY_API Buffer
|
||||||
{
|
{
|
||||||
friend class Utility;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using BufferFactory = std::function<std::unique_ptr<AbstractBuffer>(Buffer* parent, BufferType type)>;
|
inline Buffer(DataStorage storage, BufferType type, UInt64 size, BufferUsageFlags usage);
|
||||||
|
|
||||||
Buffer(BufferType type);
|
|
||||||
Buffer(BufferType type, UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0);
|
|
||||||
Buffer(const Buffer&) = delete;
|
Buffer(const Buffer&) = delete;
|
||||||
Buffer(Buffer&&) = delete;
|
Buffer(Buffer&&) = delete;
|
||||||
~Buffer() = default;
|
virtual ~Buffer();
|
||||||
|
|
||||||
bool CopyContent(const Buffer& buffer);
|
std::shared_ptr<Buffer> CopyContent(const BufferFactory& bufferFactory);
|
||||||
|
|
||||||
bool Create(UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0);
|
virtual bool Fill(const void* data, UInt64 offset, UInt64 size) = 0;
|
||||||
void Destroy();
|
|
||||||
|
|
||||||
bool Fill(const void* data, UInt32 offset, UInt32 size);
|
inline UInt64 GetSize() const;
|
||||||
|
|
||||||
inline AbstractBuffer* GetImpl() const;
|
|
||||||
inline UInt32 GetSize() const;
|
|
||||||
inline DataStorage GetStorage() const;
|
inline DataStorage GetStorage() const;
|
||||||
inline BufferType GetType() const;
|
inline BufferType GetType() const;
|
||||||
inline BufferUsageFlags GetUsage() const;
|
inline BufferUsageFlags GetUsageFlags() const;
|
||||||
|
|
||||||
inline bool HasStorage(DataStorage storage) const;
|
virtual void* Map(UInt64 offset, UInt64 size) = 0;
|
||||||
|
virtual bool Unmap() = 0;
|
||||||
inline bool IsValid() const;
|
|
||||||
|
|
||||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
|
|
||||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
|
|
||||||
|
|
||||||
bool SetStorage(DataStorage storage);
|
|
||||||
|
|
||||||
void Unmap() const;
|
|
||||||
|
|
||||||
Buffer& operator=(const Buffer&) = delete;
|
Buffer& operator=(const Buffer&) = delete;
|
||||||
Buffer& operator=(Buffer&&) = delete;
|
Buffer& operator=(Buffer&&) = delete;
|
||||||
|
|
||||||
static bool IsStorageSupported(DataStorage storage);
|
|
||||||
static void SetBufferFactory(DataStorage storage, BufferFactory func);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool Initialize();
|
|
||||||
static void Uninitialize();
|
|
||||||
|
|
||||||
std::unique_ptr<AbstractBuffer> m_impl;
|
|
||||||
BufferType m_type;
|
BufferType m_type;
|
||||||
BufferUsageFlags m_usage;
|
BufferUsageFlags m_usage;
|
||||||
UInt32 m_size;
|
DataStorage m_storage;
|
||||||
|
UInt64 m_size;
|
||||||
static std::array<BufferFactory, DataStorageCount> s_bufferFactories;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,22 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline AbstractBuffer* Buffer::GetImpl() const
|
inline Buffer::Buffer(DataStorage storage, BufferType type, UInt64 size, BufferUsageFlags usage) :
|
||||||
|
m_type(type),
|
||||||
|
m_usage(usage),
|
||||||
|
m_storage(storage),
|
||||||
|
m_size(size)
|
||||||
{
|
{
|
||||||
return m_impl.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline UInt32 Buffer::GetSize() const
|
inline UInt64 Nz::Buffer::GetSize() const
|
||||||
{
|
{
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline DataStorage Buffer::GetStorage() const
|
inline DataStorage Buffer::GetStorage() const
|
||||||
{
|
{
|
||||||
return m_impl->GetStorage();
|
return m_storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline BufferType Buffer::GetType() const
|
inline BufferType Buffer::GetType() const
|
||||||
@@ -28,20 +31,10 @@ namespace Nz
|
|||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline BufferUsageFlags Buffer::GetUsage() const
|
inline BufferUsageFlags Buffer::GetUsageFlags() const
|
||||||
{
|
{
|
||||||
return m_usage;
|
return m_usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Buffer::HasStorage(DataStorage storage) const
|
|
||||||
{
|
|
||||||
return GetStorage() == storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Buffer::IsValid() const
|
|
||||||
{
|
|
||||||
return m_impl != nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Utility/DebugOff.hpp>
|
#include <Nazara/Utility/DebugOff.hpp>
|
||||||
|
|||||||
@@ -16,16 +16,10 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BufferMapper();
|
BufferMapper();
|
||||||
BufferMapper(T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
BufferMapper(T& buffer, UInt64 offset, UInt64 length);
|
||||||
BufferMapper(T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
|
||||||
BufferMapper(const T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
|
||||||
BufferMapper(const T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
|
||||||
~BufferMapper();
|
~BufferMapper();
|
||||||
|
|
||||||
bool Map(T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
bool Map(T& buffer, UInt64 offset, UInt64 length);
|
||||||
bool Map(T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
|
||||||
bool Map(const T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
|
||||||
bool Map(const T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
|
||||||
|
|
||||||
const T* GetBuffer() const;
|
const T* GetBuffer() const;
|
||||||
void* GetPointer() const;
|
void* GetPointer() const;
|
||||||
@@ -33,7 +27,7 @@ namespace Nz
|
|||||||
void Unmap();
|
void Unmap();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const T* m_buffer;
|
T* m_buffer;
|
||||||
void* m_ptr;
|
void* m_ptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,33 +17,13 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
BufferMapper<T>::BufferMapper(T* buffer, BufferAccess access, unsigned int offset, unsigned int length) :
|
BufferMapper<T>::BufferMapper(T& buffer, UInt64 offset, UInt64 length) :
|
||||||
m_buffer(nullptr)
|
m_buffer(nullptr)
|
||||||
{
|
{
|
||||||
if (!Map(buffer, access, offset, length))
|
if (!Map(buffer, offset, length))
|
||||||
NazaraError("Failed to map buffer"); ///TODO: Unexpected
|
NazaraError("Failed to map buffer"); ///TODO: Unexpected
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
BufferMapper<T>::BufferMapper(T& buffer, BufferAccess access, unsigned int offset, unsigned int length) :
|
|
||||||
BufferMapper(&buffer, access, offset, length)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
BufferMapper<T>::BufferMapper(const T* buffer, BufferAccess access, unsigned int offset, unsigned int length) :
|
|
||||||
m_buffer(nullptr)
|
|
||||||
{
|
|
||||||
if (!Map(buffer, access, offset, length))
|
|
||||||
NazaraError("Failed to map buffer"); ///TODO: Unexpected
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
BufferMapper<T>::BufferMapper(const T& buffer, BufferAccess access, unsigned int offset, unsigned int length) :
|
|
||||||
BufferMapper(&buffer, access, offset, length)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
BufferMapper<T>::~BufferMapper()
|
BufferMapper<T>::~BufferMapper()
|
||||||
{
|
{
|
||||||
@@ -64,63 +44,21 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool BufferMapper<T>::Map(T* buffer, BufferAccess access, unsigned int offset, unsigned int length)
|
bool BufferMapper<T>::Map(T& buffer, UInt64 offset, UInt64 length)
|
||||||
{
|
{
|
||||||
Unmap();
|
Unmap();
|
||||||
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
m_buffer = &buffer;
|
||||||
if (!buffer)
|
m_ptr = buffer.Map(offset, length);
|
||||||
|
if (!m_ptr)
|
||||||
{
|
{
|
||||||
NazaraError("Buffer must be valid");
|
NazaraError("Failed to map buffer"); ///TODO: Unexpected
|
||||||
m_ptr = nullptr;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
m_buffer = buffer;
|
|
||||||
m_ptr = buffer->Map(access, offset, length);
|
|
||||||
if (!m_ptr)
|
|
||||||
NazaraError("Failed to map buffer"); ///TODO: Unexpected
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool BufferMapper<T>::Map(T& buffer, BufferAccess access, unsigned int offset, unsigned int length)
|
|
||||||
{
|
|
||||||
return Map(&buffer, access, offset, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool BufferMapper<T>::Map(const T* buffer, BufferAccess access, unsigned int offset, unsigned int length)
|
|
||||||
{
|
|
||||||
Unmap();
|
|
||||||
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
|
||||||
if (!buffer)
|
|
||||||
{
|
|
||||||
NazaraError("Buffer must be valid");
|
|
||||||
m_ptr = nullptr;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_buffer = buffer;
|
|
||||||
m_ptr = buffer->Map(access, offset, length);
|
|
||||||
if (!m_ptr)
|
|
||||||
NazaraError("Failed to map buffer"); ///TODO: Unexpected
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool BufferMapper<T>::Map(const T& buffer, BufferAccess access, unsigned int offset, unsigned int length)
|
|
||||||
{
|
|
||||||
return Map(&buffer, access, offset, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void BufferMapper<T>::Unmap()
|
void BufferMapper<T>::Unmap()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ namespace Nz
|
|||||||
DeviceLocal,
|
DeviceLocal,
|
||||||
DirectMapping,
|
DirectMapping,
|
||||||
Dynamic,
|
Dynamic,
|
||||||
|
Read,
|
||||||
PersistentMapping,
|
PersistentMapping,
|
||||||
|
Write,
|
||||||
|
|
||||||
Max = DirectMapping
|
Max = DirectMapping
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,40 +17,34 @@ namespace Nz
|
|||||||
public:
|
public:
|
||||||
IndexBuffer() = default;
|
IndexBuffer() = default;
|
||||||
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer);
|
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer);
|
||||||
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
|
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||||
IndexBuffer(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
|
IndexBuffer(bool largeIndices, UInt64 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||||
IndexBuffer(const IndexBuffer&) = default;
|
IndexBuffer(const IndexBuffer&) = default;
|
||||||
IndexBuffer(IndexBuffer&&) noexcept = default;
|
IndexBuffer(IndexBuffer&&) noexcept = default;
|
||||||
~IndexBuffer() = default;
|
~IndexBuffer() = default;
|
||||||
|
|
||||||
unsigned int ComputeCacheMissCount() const;
|
unsigned int ComputeCacheMissCount();
|
||||||
|
|
||||||
bool Fill(const void* data, std::size_t startIndex, std::size_t length);
|
bool Fill(const void* data, UInt64 startIndex, UInt64 length);
|
||||||
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
|
bool FillRaw(const void* data, UInt64 offset, UInt64 size);
|
||||||
|
|
||||||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||||
inline std::size_t GetEndOffset() const;
|
inline UInt64 GetEndOffset() const;
|
||||||
inline std::size_t GetIndexCount() const;
|
inline UInt64 GetIndexCount() const;
|
||||||
inline std::size_t GetStride() const;
|
inline UInt64 GetStride() const;
|
||||||
inline std::size_t GetStartOffset() const;
|
inline UInt64 GetStartOffset() const;
|
||||||
|
|
||||||
inline bool HasLargeIndices() const;
|
inline bool HasLargeIndices() const;
|
||||||
|
|
||||||
inline bool IsValid() const;
|
inline bool IsValid() const;
|
||||||
|
|
||||||
inline void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0);
|
inline void* Map(UInt64 startIndex, UInt64 length);
|
||||||
inline void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0) const;
|
inline void* Map(UInt64 startIndex, UInt64 length) const;
|
||||||
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0);
|
void* MapRaw(UInt64 offset, UInt64 size);
|
||||||
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
|
void* MapRaw(UInt64 offset, UInt64 size) const;
|
||||||
|
|
||||||
void Optimize();
|
void Optimize();
|
||||||
|
|
||||||
void Reset();
|
|
||||||
void Reset(bool largeIndices, std::shared_ptr<Buffer> buffer);
|
|
||||||
void Reset(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
|
|
||||||
void Reset(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
|
|
||||||
void Reset(const IndexBuffer& indexBuffer);
|
|
||||||
|
|
||||||
void Unmap() const;
|
void Unmap() const;
|
||||||
|
|
||||||
IndexBuffer& operator=(const IndexBuffer&) = default;
|
IndexBuffer& operator=(const IndexBuffer&) = default;
|
||||||
@@ -58,9 +52,9 @@ namespace Nz
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Buffer> m_buffer;
|
std::shared_ptr<Buffer> m_buffer;
|
||||||
std::size_t m_endOffset;
|
UInt64 m_endOffset;
|
||||||
std::size_t m_indexCount;
|
UInt64 m_indexCount;
|
||||||
std::size_t m_startOffset;
|
UInt64 m_startOffset;
|
||||||
bool m_largeIndices;
|
bool m_largeIndices;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,22 +13,22 @@ namespace Nz
|
|||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t IndexBuffer::GetEndOffset() const
|
inline UInt64 IndexBuffer::GetEndOffset() const
|
||||||
{
|
{
|
||||||
return m_endOffset;
|
return m_endOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t IndexBuffer::GetIndexCount() const
|
inline UInt64 IndexBuffer::GetIndexCount() const
|
||||||
{
|
{
|
||||||
return m_indexCount;
|
return m_indexCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t IndexBuffer::GetStride() const
|
inline UInt64 IndexBuffer::GetStride() const
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>((m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16));
|
return (m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t IndexBuffer::GetStartOffset() const
|
inline UInt64 IndexBuffer::GetStartOffset() const
|
||||||
{
|
{
|
||||||
return m_startOffset;
|
return m_startOffset;
|
||||||
}
|
}
|
||||||
@@ -43,16 +43,16 @@ namespace Nz
|
|||||||
return m_buffer != nullptr;
|
return m_buffer != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length)
|
inline void* IndexBuffer::Map(UInt64 startIndex, UInt64 length)
|
||||||
{
|
{
|
||||||
std::size_t stride = GetStride();
|
UInt64 stride = GetStride();
|
||||||
return MapRaw(access, startIndex*stride, length*stride);
|
return MapRaw(startIndex * stride, length * stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length) const
|
inline void* IndexBuffer::Map(UInt64 startIndex, UInt64 length) const
|
||||||
{
|
{
|
||||||
std::size_t stride = GetStride();
|
UInt64 stride = GetStride();
|
||||||
return MapRaw(access, startIndex*stride, length*stride);
|
return MapRaw(startIndex * stride, length * stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ namespace Nz
|
|||||||
class NAZARA_UTILITY_API IndexMapper
|
class NAZARA_UTILITY_API IndexMapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IndexMapper(IndexBuffer& indexBuffer, BufferAccess access = BufferAccess::ReadWrite, std::size_t indexCount = 0);
|
IndexMapper(IndexBuffer& indexBuffer, std::size_t indexCount = 0);
|
||||||
IndexMapper(SubMesh& subMesh, BufferAccess access = BufferAccess::ReadWrite);
|
IndexMapper(SubMesh& subMes);
|
||||||
IndexMapper(const IndexBuffer& indexBuffer, BufferAccess access = BufferAccess::ReadOnly, std::size_t indexCount = 0);
|
|
||||||
IndexMapper(const SubMesh& subMesh, BufferAccess access = BufferAccess::ReadOnly);
|
|
||||||
~IndexMapper() = default;
|
~IndexMapper() = default;
|
||||||
|
|
||||||
UInt32 Get(std::size_t i) const;
|
UInt32 Get(std::size_t i) const;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <Nazara/Utility/Config.hpp>
|
#include <Nazara/Utility/Config.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
#include <Nazara/Utility/Skeleton.hpp>
|
#include <Nazara/Utility/Skeleton.hpp>
|
||||||
|
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||||
#include <Nazara/Utility/SubMesh.hpp>
|
#include <Nazara/Utility/SubMesh.hpp>
|
||||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||||
#include <Nazara/Utility/VertexStruct.hpp>
|
#include <Nazara/Utility/VertexStruct.hpp>
|
||||||
@@ -28,20 +29,35 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
|
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
|
||||||
{
|
{
|
||||||
MeshParams();
|
// How buffer will be allocated (by default in RAM)
|
||||||
|
BufferFactory bufferFactory = &SoftwareBufferFactory;
|
||||||
|
|
||||||
BufferUsageFlags indexBufferFlags = 0; ///< Buffer usage flags used to build the index buffers
|
// Buffer usage flags used to build the index buffers
|
||||||
BufferUsageFlags vertexBufferFlags = 0; ///< Buffer usage flags used to build the vertex buffers
|
BufferUsageFlags indexBufferFlags = BufferUsage::DirectMapping | BufferUsage::Read | BufferUsage::Write;
|
||||||
Matrix4f matrix = Matrix4f::Identity(); ///< A matrix which will transform every vertex position
|
|
||||||
DataStorage storage = DataStorage::Hardware; ///< The place where the buffers will be allocated
|
// Buffer usage flags used to build the vertex buffers
|
||||||
Vector2f texCoordOffset = {0.f, 0.f}; ///< Offset to apply on the texture coordinates (not scaled)
|
BufferUsageFlags vertexBufferFlags = BufferUsage::DirectMapping | BufferUsage::Read | BufferUsage::Write;
|
||||||
Vector2f texCoordScale = {1.f, 1.f}; ///< Scale to apply on the texture coordinates
|
|
||||||
bool animated = true; ///< If true, will load an animated version of the model if possible
|
// A matrix which will transform every vertex position
|
||||||
bool center = false; ///< If true, will center the mesh vertices around the origin
|
Matrix4f matrix = Matrix4f::Identity();
|
||||||
|
|
||||||
|
// Offset to apply on the texture coordinates (not scaled)
|
||||||
|
Vector2f texCoordOffset = {0.f, 0.f};
|
||||||
|
|
||||||
|
// Scale to apply on the texture coordinates
|
||||||
|
Vector2f texCoordScale = {1.f, 1.f};
|
||||||
|
|
||||||
|
// If true, will load an animated version of the model if possible
|
||||||
|
bool animated = true;
|
||||||
|
|
||||||
|
// If true, will center the mesh vertices around the origin
|
||||||
|
bool center = false;
|
||||||
|
|
||||||
|
// Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
|
||||||
#ifndef NAZARA_DEBUG
|
#ifndef NAZARA_DEBUG
|
||||||
bool optimizeIndexBuffers = true; ///< Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
|
bool optimizeIndexBuffers = true;
|
||||||
#else
|
#else
|
||||||
bool optimizeIndexBuffers = false; ///< Since this optimization take a lot of time, especially in debug mode, don't enable it by default in debug.
|
bool optimizeIndexBuffers = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The declaration must have a Vector3f position component enabled
|
/* The declaration must have a Vector3f position component enabled
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ namespace Nz
|
|||||||
class NAZARA_UTILITY_API SkeletalMesh final : public SubMesh
|
class NAZARA_UTILITY_API SkeletalMesh final : public SubMesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer);
|
SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer);
|
||||||
~SkeletalMesh() = default;
|
~SkeletalMesh() = default;
|
||||||
|
|
||||||
const Boxf& GetAABB() const override;
|
const Boxf& GetAABB() const override;
|
||||||
AnimationType GetAnimationType() const final;
|
AnimationType GetAnimationType() const final;
|
||||||
const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const override;
|
const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override;
|
||||||
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
|
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
|
||||||
std::size_t GetVertexCount() const override;
|
std::size_t GetVertexCount() const override;
|
||||||
|
|
||||||
@@ -30,11 +30,11 @@ namespace Nz
|
|||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
void SetAABB(const Boxf& aabb);
|
void SetAABB(const Boxf& aabb);
|
||||||
void SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer);
|
void SetIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Boxf m_aabb;
|
Boxf m_aabb;
|
||||||
std::shared_ptr<const IndexBuffer> m_indexBuffer;
|
std::shared_ptr<IndexBuffer> m_indexBuffer;
|
||||||
std::shared_ptr<VertexBuffer> m_vertexBuffer;
|
std::shared_ptr<VertexBuffer> m_vertexBuffer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,34 +8,30 @@
|
|||||||
#define NAZARA_UTILITY_SOFTWAREBUFFER_HPP
|
#define NAZARA_UTILITY_SOFTWAREBUFFER_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
#include <Nazara/Utility/Buffer.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class Buffer;
|
class NAZARA_UTILITY_API SoftwareBuffer : public Buffer
|
||||||
|
|
||||||
class NAZARA_UTILITY_API SoftwareBuffer : public AbstractBuffer
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SoftwareBuffer(Buffer* parent, BufferType type);
|
SoftwareBuffer(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData);
|
||||||
~SoftwareBuffer() = default;
|
~SoftwareBuffer() = default;
|
||||||
|
|
||||||
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
||||||
|
|
||||||
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
|
|
||||||
|
|
||||||
const UInt8* GetData() const;
|
const UInt8* GetData() const;
|
||||||
UInt64 GetSize() const override;
|
|
||||||
DataStorage GetStorage() const override;
|
|
||||||
|
|
||||||
void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) override;
|
void* Map(UInt64 offset = 0, UInt64 size = 0) override;
|
||||||
bool Unmap() override;
|
bool Unmap() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<UInt8> m_buffer;
|
std::unique_ptr<UInt8[]> m_buffer;
|
||||||
bool m_mapped;
|
bool m_mapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAZARA_UTILITY_API std::shared_ptr<Buffer> SoftwareBufferFactory(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData = nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NAZARA_UTILITY_SOFTWAREBUFFER_HPP
|
#endif // NAZARA_UTILITY_SOFTWAREBUFFER_HPP
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Nz
|
|||||||
class NAZARA_UTILITY_API StaticMesh final : public SubMesh
|
class NAZARA_UTILITY_API StaticMesh final : public SubMesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer);
|
StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer);
|
||||||
~StaticMesh() = default;
|
~StaticMesh() = default;
|
||||||
|
|
||||||
void Center();
|
void Center();
|
||||||
@@ -24,7 +24,7 @@ namespace Nz
|
|||||||
|
|
||||||
const Boxf& GetAABB() const override;
|
const Boxf& GetAABB() const override;
|
||||||
AnimationType GetAnimationType() const final;
|
AnimationType GetAnimationType() const final;
|
||||||
const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const override;
|
const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override;
|
||||||
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
|
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
|
||||||
std::size_t GetVertexCount() const override;
|
std::size_t GetVertexCount() const override;
|
||||||
|
|
||||||
@@ -32,11 +32,11 @@ namespace Nz
|
|||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
void SetAABB(const Boxf& aabb);
|
void SetAABB(const Boxf& aabb);
|
||||||
void SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer);
|
void SetIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Boxf m_aabb;
|
Boxf m_aabb;
|
||||||
std::shared_ptr<const IndexBuffer> m_indexBuffer;
|
std::shared_ptr<IndexBuffer> m_indexBuffer;
|
||||||
std::shared_ptr<VertexBuffer> m_vertexBuffer;
|
std::shared_ptr<VertexBuffer> m_vertexBuffer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Nz
|
|||||||
|
|
||||||
virtual const Boxf& GetAABB() const = 0;
|
virtual const Boxf& GetAABB() const = 0;
|
||||||
virtual AnimationType GetAnimationType() const = 0;
|
virtual AnimationType GetAnimationType() const = 0;
|
||||||
virtual const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const = 0;
|
virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
|
||||||
std::size_t GetMaterialIndex() const;
|
std::size_t GetMaterialIndex() const;
|
||||||
PrimitiveMode GetPrimitiveMode() const;
|
PrimitiveMode GetPrimitiveMode() const;
|
||||||
std::size_t GetTriangleCount() const;
|
std::size_t GetTriangleCount() const;
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace Nz
|
|||||||
class NAZARA_UTILITY_API TriangleIterator
|
class NAZARA_UTILITY_API TriangleIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TriangleIterator(PrimitiveMode primitiveMode, const IndexBuffer& indexBuffer);
|
TriangleIterator(PrimitiveMode primitiveMode, IndexBuffer& indexBuffer);
|
||||||
TriangleIterator(const SubMesh& subMesh);
|
TriangleIterator(SubMesh& subMesh);
|
||||||
~TriangleIterator() = default;
|
~TriangleIterator() = default;
|
||||||
|
|
||||||
bool Advance();
|
bool Advance();
|
||||||
|
|||||||
@@ -15,30 +15,21 @@ namespace Nz
|
|||||||
class NAZARA_UTILITY_API UniformBuffer
|
class NAZARA_UTILITY_API UniformBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniformBuffer() = default;
|
|
||||||
UniformBuffer(std::shared_ptr<Buffer> buffer);
|
UniformBuffer(std::shared_ptr<Buffer> buffer);
|
||||||
UniformBuffer(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size);
|
UniformBuffer(std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||||
UniformBuffer(UInt32 length, DataStorage storage, BufferUsageFlags usage);
|
UniformBuffer(UInt64 size, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||||
UniformBuffer(const UniformBuffer&) = default;
|
UniformBuffer(const UniformBuffer&) = default;
|
||||||
UniformBuffer(UniformBuffer&&) noexcept = default;
|
UniformBuffer(UniformBuffer&&) noexcept = default;
|
||||||
~UniformBuffer() = default;
|
~UniformBuffer() = default;
|
||||||
|
|
||||||
bool Fill(const void* data, UInt32 offset, UInt32 size);
|
bool Fill(const void* data, UInt64 offset, UInt64 size);
|
||||||
|
|
||||||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||||
inline UInt32 GetEndOffset() const;
|
inline UInt64 GetEndOffset() const;
|
||||||
inline UInt32 GetStartOffset() const;
|
inline UInt64 GetStartOffset() const;
|
||||||
|
|
||||||
inline bool IsValid() const;
|
void* Map(UInt64 offset = 0, UInt64 size = 0);
|
||||||
|
void* Map(UInt64 offset = 0, UInt64 size = 0) const;
|
||||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
|
|
||||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
|
|
||||||
|
|
||||||
void Reset();
|
|
||||||
void Reset(std::shared_ptr<Buffer> buffer);
|
|
||||||
void Reset(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size);
|
|
||||||
void Reset(UInt32 size, DataStorage storage, BufferUsageFlags usage);
|
|
||||||
void Reset(const UniformBuffer& uniformBuffer);
|
|
||||||
|
|
||||||
void Unmap() const;
|
void Unmap() const;
|
||||||
|
|
||||||
@@ -47,8 +38,8 @@ namespace Nz
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Buffer> m_buffer;
|
std::shared_ptr<Buffer> m_buffer;
|
||||||
UInt32 m_endOffset;
|
UInt64 m_endOffset;
|
||||||
UInt32 m_startOffset;
|
UInt64 m_startOffset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,20 +13,15 @@ namespace Nz
|
|||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline UInt32 UniformBuffer::GetEndOffset() const
|
inline UInt64 UniformBuffer::GetEndOffset() const
|
||||||
{
|
{
|
||||||
return m_endOffset;
|
return m_endOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline UInt32 UniformBuffer::GetStartOffset() const
|
inline UInt64 UniformBuffer::GetStartOffset() const
|
||||||
{
|
{
|
||||||
return m_startOffset;
|
return m_startOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool UniformBuffer::IsValid() const
|
|
||||||
{
|
|
||||||
return m_buffer != nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Utility/DebugOff.hpp>
|
#include <Nazara/Utility/DebugOff.hpp>
|
||||||
|
|||||||
@@ -18,34 +18,28 @@ namespace Nz
|
|||||||
public:
|
public:
|
||||||
VertexBuffer() = default;
|
VertexBuffer() = default;
|
||||||
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
|
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
|
||||||
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
|
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||||
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
|
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, UInt64 vertexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||||
VertexBuffer(const VertexBuffer&) = default;
|
VertexBuffer(const VertexBuffer&) = default;
|
||||||
VertexBuffer(VertexBuffer&&) noexcept = default;
|
VertexBuffer(VertexBuffer&&) noexcept = default;
|
||||||
~VertexBuffer() = default;
|
~VertexBuffer() = default;
|
||||||
|
|
||||||
bool Fill(const void* data, std::size_t startVertex, std::size_t length);
|
bool Fill(const void* data, UInt64 startVertex, UInt64 length);
|
||||||
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
|
bool FillRaw(const void* data, UInt64 offset, UInt64 size);
|
||||||
|
|
||||||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||||
inline std::size_t GetEndOffset() const;
|
inline UInt64 GetEndOffset() const;
|
||||||
inline std::size_t GetStartOffset() const;
|
inline UInt64 GetStartOffset() const;
|
||||||
inline std::size_t GetStride() const;
|
inline UInt64 GetStride() const;
|
||||||
inline std::size_t GetVertexCount() const;
|
inline UInt64 GetVertexCount() const;
|
||||||
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration() const;
|
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration() const;
|
||||||
|
|
||||||
inline bool IsValid() const;
|
inline bool IsValid() const;
|
||||||
|
|
||||||
void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0);
|
void* Map(UInt64 startVertex, UInt64 length);
|
||||||
void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0) const;
|
void* Map(UInt64 startVertex, UInt64 length) const;
|
||||||
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0);
|
void* MapRaw(UInt64 offset, UInt64 size);
|
||||||
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
|
void* MapRaw(UInt64 offset, UInt64 size) const;
|
||||||
|
|
||||||
void Reset();
|
|
||||||
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
|
|
||||||
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
|
|
||||||
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
|
|
||||||
void Reset(const VertexBuffer& vertexBuffer);
|
|
||||||
|
|
||||||
void SetVertexDeclaration(std::shared_ptr<const VertexDeclaration> vertexDeclaration);
|
void SetVertexDeclaration(std::shared_ptr<const VertexDeclaration> vertexDeclaration);
|
||||||
|
|
||||||
@@ -57,9 +51,9 @@ namespace Nz
|
|||||||
private:
|
private:
|
||||||
std::shared_ptr<Buffer> m_buffer;
|
std::shared_ptr<Buffer> m_buffer;
|
||||||
std::shared_ptr<const VertexDeclaration> m_vertexDeclaration;
|
std::shared_ptr<const VertexDeclaration> m_vertexDeclaration;
|
||||||
std::size_t m_endOffset;
|
UInt64 m_endOffset;
|
||||||
std::size_t m_startOffset;
|
UInt64 m_startOffset;
|
||||||
std::size_t m_vertexCount;
|
UInt64 m_vertexCount;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,22 +13,22 @@ namespace Nz
|
|||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t VertexBuffer::GetEndOffset() const
|
inline UInt64 VertexBuffer::GetEndOffset() const
|
||||||
{
|
{
|
||||||
return m_endOffset;
|
return m_endOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t VertexBuffer::GetStride() const
|
inline UInt64 VertexBuffer::GetStride() const
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(m_vertexDeclaration->GetStride());
|
return static_cast<UInt64>(m_vertexDeclaration->GetStride());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t VertexBuffer::GetStartOffset() const
|
inline UInt64 VertexBuffer::GetStartOffset() const
|
||||||
{
|
{
|
||||||
return m_startOffset;
|
return m_startOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t VertexBuffer::GetVertexCount() const
|
inline UInt64 VertexBuffer::GetVertexCount() const
|
||||||
{
|
{
|
||||||
return m_vertexCount;
|
return m_vertexCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ namespace Nz
|
|||||||
class NAZARA_UTILITY_API VertexMapper
|
class NAZARA_UTILITY_API VertexMapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VertexMapper(SubMesh& subMesh, BufferAccess access = BufferAccess::ReadWrite);
|
VertexMapper(SubMesh& subMesh);
|
||||||
VertexMapper(VertexBuffer& vertexBuffer, BufferAccess access = BufferAccess::ReadWrite);
|
VertexMapper(VertexBuffer& vertexBuffer);
|
||||||
VertexMapper(const SubMesh& subMesh, BufferAccess access = BufferAccess::ReadOnly);
|
|
||||||
VertexMapper(const VertexBuffer& vertexBuffer, BufferAccess access = BufferAccess::ReadOnly);
|
|
||||||
~VertexMapper();
|
~VertexMapper();
|
||||||
|
|
||||||
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component, std::size_t componentIndex = 0);
|
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component, std::size_t componentIndex = 0);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#define NAZARA_VULKANRENDERER_VULKANBUFFER_HPP
|
#define NAZARA_VULKANRENDERER_VULKANBUFFER_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Wrapper/Buffer.hpp>
|
#include <Nazara/VulkanRenderer/Wrapper/Buffer.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp>
|
#include <Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp>
|
||||||
@@ -18,36 +18,30 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
class NAZARA_VULKANRENDERER_API VulkanBuffer : public AbstractBuffer
|
class NAZARA_VULKANRENDERER_API VulkanBuffer : public RenderBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline VulkanBuffer(Vk::Device& device, BufferType type);
|
inline VulkanBuffer(VulkanDevice& device, BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData = nullptr);
|
||||||
VulkanBuffer(const VulkanBuffer&) = delete;
|
VulkanBuffer(const VulkanBuffer&) = delete;
|
||||||
VulkanBuffer(VulkanBuffer&&) = delete; ///TODO
|
VulkanBuffer(VulkanBuffer&&) = delete; ///TODO
|
||||||
virtual ~VulkanBuffer();
|
virtual ~VulkanBuffer();
|
||||||
|
|
||||||
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
||||||
|
|
||||||
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
|
|
||||||
|
|
||||||
inline VkBuffer GetBuffer() const;
|
inline VkBuffer GetBuffer() const;
|
||||||
UInt64 GetSize() const override;
|
|
||||||
DataStorage GetStorage() const override;
|
|
||||||
|
|
||||||
void* Map(BufferAccess access, UInt64 offset, UInt64 size) override;
|
void* Map(UInt64 offset, UInt64 size) override;
|
||||||
bool Unmap() override;
|
bool Unmap() override;
|
||||||
|
|
||||||
VulkanBuffer& operator=(const VulkanBuffer&) = delete;
|
VulkanBuffer& operator=(const VulkanBuffer&) = delete;
|
||||||
VulkanBuffer& operator=(VulkanBuffer&&) = delete; ///TODO
|
VulkanBuffer& operator=(VulkanBuffer&&) = delete; ///TODO
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BufferType m_type;
|
|
||||||
BufferUsageFlags m_usage;
|
|
||||||
UInt64 m_size;
|
|
||||||
VkBuffer m_buffer;
|
VkBuffer m_buffer;
|
||||||
VkBuffer m_stagingBuffer;
|
VkBuffer m_stagingBuffer;
|
||||||
VmaAllocation m_allocation;
|
VmaAllocation m_allocation;
|
||||||
VmaAllocation m_stagingAllocation;
|
VmaAllocation m_stagingAllocation;
|
||||||
|
UInt64 m_stagingBufferSize;
|
||||||
Vk::Device& m_device;
|
Vk::Device& m_device;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,6 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline VulkanBuffer::VulkanBuffer(Vk::Device& device, BufferType type) :
|
|
||||||
m_type(type),
|
|
||||||
m_device(device)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline VkBuffer VulkanBuffer::GetBuffer() const
|
inline VkBuffer VulkanBuffer::GetBuffer() const
|
||||||
{
|
{
|
||||||
return m_buffer;
|
return m_buffer;
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ namespace Nz
|
|||||||
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
||||||
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
||||||
|
|
||||||
void BindIndexBuffer(const AbstractBuffer& indexBuffer, UInt64 offset = 0) override;
|
void BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset = 0) override;
|
||||||
void BindPipeline(const RenderPipeline& pipeline) override;
|
void BindPipeline(const RenderPipeline& pipeline) override;
|
||||||
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
||||||
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
||||||
void BindVertexBuffer(UInt32 binding, const AbstractBuffer& vertexBuffer, UInt64 offset = 0) override;
|
void BindVertexBuffer(UInt32 binding, const RenderBuffer& vertexBuffer, UInt64 offset = 0) override;
|
||||||
|
|
||||||
void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) override;
|
void BlitTexture(const Texture& fromTexture, const Boxui& fromBox, TextureLayout fromLayout, const Texture& toTexture, const Boxui& toBox, TextureLayout toLayout, SamplerFilter filter) override;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Nz
|
|||||||
const RenderDeviceInfo& GetDeviceInfo() const override;
|
const RenderDeviceInfo& GetDeviceInfo() const override;
|
||||||
const RenderDeviceFeatures& GetEnabledFeatures() const override;
|
const RenderDeviceFeatures& GetEnabledFeatures() const override;
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> InstantiateBuffer(BufferType type) override;
|
std::shared_ptr<RenderBuffer> InstantiateBuffer(BufferType type, UInt64 size, BufferUsageFlags usageFlags, const void* initialData = nullptr) override;
|
||||||
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
std::shared_ptr<CommandPool> InstantiateCommandPool(QueueType queueType) override;
|
||||||
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
std::shared_ptr<Framebuffer> InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr<RenderPass>& renderPass, const std::vector<std::shared_ptr<Texture>>& attachments) override;
|
||||||
std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) override;
|
std::shared_ptr<RenderPass> InstantiateRenderPass(std::vector<RenderPass::Attachment> attachments, std::vector<RenderPass::SubpassDescription> subpassDescriptions, std::vector<RenderPass::SubpassDependency> subpassDependencies) override;
|
||||||
|
|||||||
@@ -307,9 +307,9 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||||||
// Index buffer
|
// Index buffer
|
||||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||||
|
|
||||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.storage, parameters.indexBufferFlags);
|
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
IndexMapper indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
|
IndexMapper indexMapper(*indexBuffer);
|
||||||
IndexIterator index = indexMapper.begin();
|
IndexIterator index = indexMapper.begin();
|
||||||
|
|
||||||
for (unsigned int faceIdx = 0; faceIdx < iMesh->mNumFaces; ++faceIdx)
|
for (unsigned int faceIdx = 0; faceIdx < iMesh->mNumFaces; ++faceIdx)
|
||||||
@@ -329,8 +329,8 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||||||
if (normalTangentMatrix.HasScale())
|
if (normalTangentMatrix.HasScale())
|
||||||
normalTangentMatrix.ApplyScale(1.f / normalTangentMatrix.GetScale());
|
normalTangentMatrix.ApplyScale(1.f / normalTangentMatrix.GetScale());
|
||||||
|
|
||||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.storage, parameters.vertexBufferFlags);
|
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||||
BufferMapper<VertexBuffer> vertexMapper(*vertexBuffer, BufferAccess::ReadWrite);
|
BufferMapper<VertexBuffer> vertexMapper(*vertexBuffer, 0, vertexBuffer->GetVertexCount());
|
||||||
SkeletalMeshVertex* vertices = static_cast<SkeletalMeshVertex*>(vertexMapper.GetPointer());
|
SkeletalMeshVertex* vertices = static_cast<SkeletalMeshVertex*>(vertexMapper.GetPointer());
|
||||||
|
|
||||||
for (std::size_t vertexIdx = 0; vertexIdx < vertexCount; ++vertexIdx)
|
for (std::size_t vertexIdx = 0; vertexIdx < vertexCount; ++vertexIdx)
|
||||||
@@ -465,9 +465,9 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||||||
// Index buffer
|
// Index buffer
|
||||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||||
|
|
||||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.storage, parameters.indexBufferFlags);
|
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
IndexMapper indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
|
IndexMapper indexMapper(*indexBuffer);
|
||||||
IndexIterator index = indexMapper.begin();
|
IndexIterator index = indexMapper.begin();
|
||||||
|
|
||||||
for (unsigned int faceIdx = 0; faceIdx < iMesh->mNumFaces; ++faceIdx)
|
for (unsigned int faceIdx = 0; faceIdx < iMesh->mNumFaces; ++faceIdx)
|
||||||
@@ -489,9 +489,9 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||||||
if (normalTangentMatrix.HasScale())
|
if (normalTangentMatrix.HasScale())
|
||||||
normalTangentMatrix.ApplyScale(1.f / normalTangentMatrix.GetScale());
|
normalTangentMatrix.ApplyScale(1.f / normalTangentMatrix.GetScale());
|
||||||
|
|
||||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, vertexCount, parameters.storage, parameters.vertexBufferFlags);
|
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, vertexCount, parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
|
VertexMapper vertexMapper(*vertexBuffer);
|
||||||
|
|
||||||
// Vertex positions
|
// Vertex positions
|
||||||
if (auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position))
|
if (auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position))
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
add_requires("assimp")
|
option("assimp")
|
||||||
|
set_default(true)
|
||||||
|
set_showmenu(true)
|
||||||
|
set_description("Build Assimp plugin")
|
||||||
|
|
||||||
target("PluginAssimp")
|
option_end()
|
||||||
set_kind("shared")
|
|
||||||
set_group("Plugins")
|
|
||||||
|
|
||||||
add_deps("NazaraUtility")
|
if has_config("assimp") then
|
||||||
add_packages("assimp")
|
add_requires("assimp")
|
||||||
|
|
||||||
add_headerfiles("**.hpp")
|
target("PluginAssimp")
|
||||||
add_headerfiles("**.inl")
|
set_kind("shared")
|
||||||
add_includedirs(".")
|
set_group("Plugins")
|
||||||
add_files("**.cpp")
|
|
||||||
|
add_deps("NazaraUtility")
|
||||||
|
add_packages("assimp")
|
||||||
|
|
||||||
|
add_headerfiles("**.hpp")
|
||||||
|
add_headerfiles("**.inl")
|
||||||
|
add_includedirs(".")
|
||||||
|
add_files("**.cpp")
|
||||||
|
end
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Nz
|
|||||||
const Color Color::Black(0, 0, 0);
|
const Color Color::Black(0, 0, 0);
|
||||||
const Color Color::Blue(0, 0, 255);
|
const Color Color::Blue(0, 0, 255);
|
||||||
const Color Color::Cyan(0, 255, 255);
|
const Color Color::Cyan(0, 255, 255);
|
||||||
|
const Color Color::Gray(80, 80, 80);
|
||||||
const Color Color::Green(0, 255, 0);
|
const Color Color::Green(0, 255, 0);
|
||||||
const Color Color::Magenta(255, 0, 255);
|
const Color Color::Magenta(255, 0, 255);
|
||||||
const Color Color::Orange(255, 165, 0);
|
const Color Color::Orange(255, 165, 0);
|
||||||
|
|||||||
@@ -28,25 +28,19 @@ namespace Nz
|
|||||||
const std::shared_ptr<VertexBuffer>& vertexBuffer = staticMesh.GetVertexBuffer();
|
const std::shared_ptr<VertexBuffer>& vertexBuffer = staticMesh.GetVertexBuffer();
|
||||||
|
|
||||||
assert(indexBuffer->GetBuffer()->GetStorage() == DataStorage::Software);
|
assert(indexBuffer->GetBuffer()->GetStorage() == DataStorage::Software);
|
||||||
const SoftwareBuffer* indexBufferContent = static_cast<const SoftwareBuffer*>(indexBuffer->GetBuffer()->GetImpl());
|
const SoftwareBuffer* indexBufferContent = static_cast<const SoftwareBuffer*>(indexBuffer->GetBuffer().get());
|
||||||
|
|
||||||
assert(vertexBuffer->GetBuffer()->GetStorage() == DataStorage::Software);
|
assert(vertexBuffer->GetBuffer()->GetStorage() == DataStorage::Software);
|
||||||
const SoftwareBuffer* vertexBufferContent = static_cast<const SoftwareBuffer*>(vertexBuffer->GetBuffer()->GetImpl());
|
const SoftwareBuffer* vertexBufferContent = static_cast<const SoftwareBuffer*>(vertexBuffer->GetBuffer().get());
|
||||||
|
|
||||||
auto& submeshData = m_subMeshes.emplace_back();
|
auto& submeshData = m_subMeshes.emplace_back();
|
||||||
submeshData.indexBuffer = renderDevice->InstantiateBuffer(BufferType::Index);
|
submeshData.indexBuffer = renderDevice->InstantiateBuffer(BufferType::Index, indexBuffer->GetStride() * indexBuffer->GetIndexCount(), BufferUsage::DeviceLocal | BufferUsage::Write);
|
||||||
if (!submeshData.indexBuffer->Initialize(indexBuffer->GetStride() * indexBuffer->GetIndexCount(), BufferUsage::DeviceLocal))
|
|
||||||
throw std::runtime_error("failed to create index buffer");
|
|
||||||
|
|
||||||
if (!submeshData.indexBuffer->Fill(indexBufferContent->GetData() + indexBuffer->GetStartOffset(), 0, indexBuffer->GetEndOffset() - indexBuffer->GetStartOffset()))
|
if (!submeshData.indexBuffer->Fill(indexBufferContent->GetData() + indexBuffer->GetStartOffset(), 0, indexBuffer->GetEndOffset() - indexBuffer->GetStartOffset()))
|
||||||
throw std::runtime_error("failed to fill index buffer");
|
throw std::runtime_error("failed to fill index buffer");
|
||||||
|
|
||||||
submeshData.indexCount = indexBuffer->GetIndexCount();
|
submeshData.indexCount = indexBuffer->GetIndexCount();
|
||||||
|
|
||||||
submeshData.vertexBuffer = renderDevice->InstantiateBuffer(BufferType::Vertex);
|
submeshData.vertexBuffer = renderDevice->InstantiateBuffer(BufferType::Vertex, vertexBuffer->GetStride() * vertexBuffer->GetVertexCount(), BufferUsage::DeviceLocal | BufferUsage::Write);
|
||||||
if (!submeshData.vertexBuffer->Initialize(vertexBuffer->GetStride() * vertexBuffer->GetVertexCount(), BufferUsage::DeviceLocal))
|
|
||||||
throw std::runtime_error("failed to create vertex buffer");
|
|
||||||
|
|
||||||
if (!submeshData.vertexBuffer->Fill(vertexBufferContent->GetData() + vertexBuffer->GetStartOffset(), 0, vertexBuffer->GetEndOffset() - vertexBuffer->GetStartOffset()))
|
if (!submeshData.vertexBuffer->Fill(vertexBufferContent->GetData() + vertexBuffer->GetStartOffset(), 0, vertexBuffer->GetEndOffset() - vertexBuffer->GetStartOffset()))
|
||||||
throw std::runtime_error("failed to fill vertex buffer");
|
throw std::runtime_error("failed to fill vertex buffer");
|
||||||
|
|
||||||
|
|||||||
@@ -197,12 +197,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_fullscreenVertexBuffer = m_renderDevice->InstantiateBuffer(BufferType::Vertex);
|
m_fullscreenVertexBuffer = m_renderDevice->InstantiateBuffer(BufferType::Vertex, m_fullscreenVertexDeclaration->GetStride() * vertexData.size(), BufferUsage::DeviceLocal | BufferUsage::Write, vertexData.data());
|
||||||
if (!m_fullscreenVertexBuffer->Initialize(m_fullscreenVertexDeclaration->GetStride() * vertexData.size(), BufferUsage::DeviceLocal))
|
|
||||||
throw std::runtime_error("failed to initialize fullscreen vertex buffer");
|
|
||||||
|
|
||||||
if (!m_fullscreenVertexBuffer->Fill(vertexData.data(), 0, m_fullscreenVertexDeclaration->GetStride() * vertexData.size()))
|
|
||||||
throw std::runtime_error("failed to fill fullscreen vertex buffer");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::RegisterMaterialPasses()
|
void Graphics::RegisterMaterialPasses()
|
||||||
|
|||||||
@@ -50,9 +50,7 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
auto& uniformBuffer = m_uniformBuffers.emplace_back();
|
auto& uniformBuffer = m_uniformBuffers.emplace_back();
|
||||||
|
|
||||||
uniformBuffer.buffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform);
|
uniformBuffer.buffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform, uniformBufferInfo.blockSize, BufferUsage::Dynamic | BufferUsage::Write);
|
||||||
if (!uniformBuffer.buffer->Initialize(uniformBufferInfo.blockSize, BufferUsage::Dynamic))
|
|
||||||
throw std::runtime_error("failed to initialize UBO memory");
|
|
||||||
|
|
||||||
assert(uniformBufferInfo.defaultValues.size() <= uniformBufferInfo.blockSize);
|
assert(uniformBufferInfo.defaultValues.size() <= uniformBufferInfo.blockSize);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<AbstractBuffer>& Model::GetIndexBuffer(std::size_t subMeshIndex) const
|
const std::shared_ptr<RenderBuffer>& Model::GetIndexBuffer(std::size_t subMeshIndex) const
|
||||||
{
|
{
|
||||||
return m_graphicalMesh->GetIndexBuffer(subMeshIndex);
|
return m_graphicalMesh->GetIndexBuffer(subMeshIndex);
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ namespace Nz
|
|||||||
return subMeshData.vertexBufferData;
|
return subMeshData.vertexBufferData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<AbstractBuffer>& Model::GetVertexBuffer(std::size_t subMeshIndex) const
|
const std::shared_ptr<RenderBuffer>& Model::GetVertexBuffer(std::size_t subMeshIndex) const
|
||||||
{
|
{
|
||||||
return m_graphicalMesh->GetVertexBuffer(subMeshIndex);
|
return m_graphicalMesh->GetVertexBuffer(subMeshIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ namespace Nz
|
|||||||
std::size_t maxQuadCount = m_maxVertexCount / 4;
|
std::size_t maxQuadCount = m_maxVertexCount / 4;
|
||||||
std::size_t indexCount = 6 * maxQuadCount;
|
std::size_t indexCount = 6 * maxQuadCount;
|
||||||
|
|
||||||
m_indexBuffer = m_device.InstantiateBuffer(BufferType::Index);
|
|
||||||
if (!m_indexBuffer->Initialize(indexCount * sizeof(UInt16), BufferUsage::DeviceLocal))
|
|
||||||
throw std::runtime_error("failed to initialize index buffer");
|
|
||||||
|
|
||||||
// Generate indices for quad (0, 1, 2, 2, 1, 3, ...)
|
// Generate indices for quad (0, 1, 2, 2, 1, 3, ...)
|
||||||
std::vector<UInt16> indices(indexCount);
|
std::vector<UInt16> indices(indexCount);
|
||||||
UInt16* indexPtr = indices.data();
|
UInt16* indexPtr = indices.data();
|
||||||
@@ -45,7 +41,7 @@ namespace Nz
|
|||||||
*indexPtr++ = index * 4 + 3;
|
*indexPtr++ = index * 4 + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_indexBuffer->Fill(indices.data(), 0, indexCount * sizeof(UInt16));
|
m_indexBuffer = m_device.InstantiateBuffer(BufferType::Index, indexCount * sizeof(UInt16), BufferUsage::DeviceLocal | BufferUsage::Write, indices.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ElementRendererData> SpriteChainRenderer::InstanciateData()
|
std::unique_ptr<ElementRendererData> SpriteChainRenderer::InstanciateData()
|
||||||
@@ -66,7 +62,7 @@ namespace Nz
|
|||||||
UploadPool::Allocation* currentAllocation = nullptr;
|
UploadPool::Allocation* currentAllocation = nullptr;
|
||||||
UInt8* currentAllocationMemPtr = nullptr;
|
UInt8* currentAllocationMemPtr = nullptr;
|
||||||
const VertexDeclaration* currentVertexDeclaration = nullptr;
|
const VertexDeclaration* currentVertexDeclaration = nullptr;
|
||||||
AbstractBuffer* currentVertexBuffer = nullptr;
|
RenderBuffer* currentVertexBuffer = nullptr;
|
||||||
const MaterialPass* currentMaterialPass = nullptr;
|
const MaterialPass* currentMaterialPass = nullptr;
|
||||||
const RenderPipeline* currentPipeline = nullptr;
|
const RenderPipeline* currentPipeline = nullptr;
|
||||||
const ShaderBinding* currentShaderBinding = nullptr;
|
const ShaderBinding* currentShaderBinding = nullptr;
|
||||||
@@ -170,7 +166,7 @@ namespace Nz
|
|||||||
currentAllocation = ¤tFrame.GetUploadPool().Allocate(m_maxVertexBufferSize);
|
currentAllocation = ¤tFrame.GetUploadPool().Allocate(m_maxVertexBufferSize);
|
||||||
currentAllocationMemPtr = static_cast<UInt8*>(currentAllocation->mappedPtr);
|
currentAllocationMemPtr = static_cast<UInt8*>(currentAllocation->mappedPtr);
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> vertexBuffer;
|
std::shared_ptr<RenderBuffer> vertexBuffer;
|
||||||
|
|
||||||
// Try to reuse vertex buffers from pool if any
|
// Try to reuse vertex buffers from pool if any
|
||||||
if (!m_vertexBufferPool->vertexBuffers.empty())
|
if (!m_vertexBufferPool->vertexBuffers.empty())
|
||||||
@@ -179,10 +175,7 @@ namespace Nz
|
|||||||
m_vertexBufferPool->vertexBuffers.pop_back();
|
m_vertexBufferPool->vertexBuffers.pop_back();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
vertexBuffer = m_device.InstantiateBuffer(BufferType::Vertex, m_maxVertexBufferSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic | BufferUsage::Write);
|
||||||
vertexBuffer = m_device.InstantiateBuffer(BufferType::Vertex);
|
|
||||||
vertexBuffer->Initialize(m_maxVertexBufferSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentVertexBuffer = vertexBuffer.get();
|
currentVertexBuffer = vertexBuffer.get();
|
||||||
|
|
||||||
@@ -318,7 +311,7 @@ namespace Nz
|
|||||||
Vector2f targetSize = viewerInstance.GetTargetSize();
|
Vector2f targetSize = viewerInstance.GetTargetSize();
|
||||||
Recti fullscreenScissorBox(0, 0, SafeCast<int>(std::floor(targetSize.x)), SafeCast<int>(std::floor(targetSize.y)));
|
Recti fullscreenScissorBox(0, 0, SafeCast<int>(std::floor(targetSize.x)), SafeCast<int>(std::floor(targetSize.y)));
|
||||||
|
|
||||||
const AbstractBuffer* currentVertexBuffer = nullptr;
|
const RenderBuffer* currentVertexBuffer = nullptr;
|
||||||
const RenderPipeline* currentPipeline = nullptr;
|
const RenderPipeline* currentPipeline = nullptr;
|
||||||
const ShaderBinding* currentShaderBinding = nullptr;
|
const ShaderBinding* currentShaderBinding = nullptr;
|
||||||
Recti currentScissorBox(-1, -1, -1, -1);
|
Recti currentScissorBox(-1, -1, -1, -1);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ namespace Nz
|
|||||||
|
|
||||||
Recti invalidScissorBox(-1, -1, -1, -1);
|
Recti invalidScissorBox(-1, -1, -1, -1);
|
||||||
|
|
||||||
const AbstractBuffer* currentIndexBuffer = nullptr;
|
const RenderBuffer* currentIndexBuffer = nullptr;
|
||||||
const AbstractBuffer* currentVertexBuffer = nullptr;
|
const RenderBuffer* currentVertexBuffer = nullptr;
|
||||||
const MaterialPass* currentMaterialPass = nullptr;
|
const MaterialPass* currentMaterialPass = nullptr;
|
||||||
const RenderPipeline* currentPipeline = nullptr;
|
const RenderPipeline* currentPipeline = nullptr;
|
||||||
const ShaderBinding* currentShaderBinding = nullptr;
|
const ShaderBinding* currentShaderBinding = nullptr;
|
||||||
@@ -65,13 +65,13 @@ namespace Nz
|
|||||||
currentMaterialPass = materialPass;
|
currentMaterialPass = materialPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const AbstractBuffer* indexBuffer = submesh.GetIndexBuffer(); currentIndexBuffer != indexBuffer)
|
if (const RenderBuffer* indexBuffer = submesh.GetIndexBuffer(); currentIndexBuffer != indexBuffer)
|
||||||
{
|
{
|
||||||
FlushDrawCall();
|
FlushDrawCall();
|
||||||
currentIndexBuffer = indexBuffer;
|
currentIndexBuffer = indexBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const AbstractBuffer* vertexBuffer = submesh.GetVertexBuffer(); currentVertexBuffer != vertexBuffer)
|
if (const RenderBuffer* vertexBuffer = submesh.GetVertexBuffer(); currentVertexBuffer != vertexBuffer)
|
||||||
{
|
{
|
||||||
FlushDrawCall();
|
FlushDrawCall();
|
||||||
currentVertexBuffer = vertexBuffer;
|
currentVertexBuffer = vertexBuffer;
|
||||||
@@ -170,8 +170,8 @@ namespace Nz
|
|||||||
Vector2f targetSize = viewerInstance.GetTargetSize();
|
Vector2f targetSize = viewerInstance.GetTargetSize();
|
||||||
Recti fullscreenScissorBox(0, 0, SafeCast<int>(std::floor(targetSize.x)), SafeCast<int>(std::floor(targetSize.y)));
|
Recti fullscreenScissorBox(0, 0, SafeCast<int>(std::floor(targetSize.x)), SafeCast<int>(std::floor(targetSize.y)));
|
||||||
|
|
||||||
const AbstractBuffer* currentIndexBuffer = nullptr;
|
const RenderBuffer* currentIndexBuffer = nullptr;
|
||||||
const AbstractBuffer* currentVertexBuffer = nullptr;
|
const RenderBuffer* currentVertexBuffer = nullptr;
|
||||||
const RenderPipeline* currentPipeline = nullptr;
|
const RenderPipeline* currentPipeline = nullptr;
|
||||||
const ShaderBinding* currentShaderBinding = nullptr;
|
const ShaderBinding* currentShaderBinding = nullptr;
|
||||||
Recti currentScissorBox(-1, -1, -1, -1);
|
Recti currentScissorBox(-1, -1, -1, -1);
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
PredefinedViewerData viewerUboOffsets = PredefinedViewerData::GetOffsets();
|
PredefinedViewerData viewerUboOffsets = PredefinedViewerData::GetOffsets();
|
||||||
|
|
||||||
m_viewerDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform);
|
m_viewerDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform, viewerUboOffsets.totalSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic | BufferUsage::Write);
|
||||||
if (!m_viewerDataBuffer->Initialize(viewerUboOffsets.totalSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic))
|
|
||||||
throw std::runtime_error("failed to initialize viewer data UBO");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewerInstance::UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder)
|
void ViewerInstance::UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder)
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
PredefinedInstanceData instanceUboOffsets = PredefinedInstanceData::GetOffsets();
|
PredefinedInstanceData instanceUboOffsets = PredefinedInstanceData::GetOffsets();
|
||||||
|
|
||||||
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform);
|
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform, instanceUboOffsets.totalSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic | BufferUsage::Write);
|
||||||
if (!m_instanceDataBuffer->Initialize(instanceUboOffsets.totalSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic))
|
|
||||||
throw std::runtime_error("failed to initialize viewer data UBO");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldInstance::UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder)
|
void WorldInstance::UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder)
|
||||||
|
|||||||
@@ -45,15 +45,11 @@ namespace Nz
|
|||||||
Disconnect();
|
Disconnect();
|
||||||
Open(remoteAddress.GetProtocol());
|
Open(remoteAddress.GetProtocol());
|
||||||
|
|
||||||
CallOnExit restoreBlocking;
|
CallOnExit restoreBlocking([this] { SocketImpl::SetBlocking(m_handle, true); });
|
||||||
if (m_isBlockingEnabled)
|
if (m_isBlockingEnabled)
|
||||||
{
|
|
||||||
SocketImpl::SetBlocking(m_handle, false);
|
SocketImpl::SetBlocking(m_handle, false);
|
||||||
restoreBlocking.Reset([this] ()
|
else
|
||||||
{
|
restoreBlocking.Reset();
|
||||||
SocketImpl::SetBlocking(m_handle, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
SocketState state = SocketImpl::Connect(m_handle, remoteAddress, &m_lastError);
|
SocketState state = SocketImpl::Connect(m_handle, remoteAddress, &m_lastError);
|
||||||
m_peerAddress = (state != SocketState::NotConnected) ? remoteAddress : IpAddress::Invalid;
|
m_peerAddress = (state != SocketState::NotConnected) ? remoteAddress : IpAddress::Invalid;
|
||||||
@@ -363,14 +359,13 @@ namespace Nz
|
|||||||
|
|
||||||
std::size_t totalByteSent = 0;
|
std::size_t totalByteSent = 0;
|
||||||
|
|
||||||
CallOnExit updateSent;
|
CallOnExit updateSent([sent, &totalByteSent]
|
||||||
if (sent)
|
|
||||||
{
|
{
|
||||||
updateSent.Reset([sent, &totalByteSent] ()
|
*sent = totalByteSent;
|
||||||
{
|
});
|
||||||
*sent = totalByteSent;
|
|
||||||
});
|
if (!sent)
|
||||||
}
|
updateSent.Reset();
|
||||||
|
|
||||||
while (totalByteSent < size || !IsBlockingEnabled())
|
while (totalByteSent < size || !IsBlockingEnabled())
|
||||||
{
|
{
|
||||||
@@ -502,7 +497,7 @@ namespace Nz
|
|||||||
if (newState == SocketState::Connecting)
|
if (newState == SocketState::Connecting)
|
||||||
newState = SocketState::NotConnected;
|
newState = SocketState::NotConnected;
|
||||||
|
|
||||||
// Prevent valid stats in non-connected state
|
// Prevent valid data in non-connected state
|
||||||
if (newState == SocketState::NotConnected)
|
if (newState == SocketState::NotConnected)
|
||||||
{
|
{
|
||||||
m_openMode = OpenMode::NotOpen;
|
m_openMode = OpenMode::NotOpen;
|
||||||
@@ -582,15 +577,11 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle");
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
CallOnExit restoreBlocking;
|
CallOnExit restoreBlocking([this] { SocketImpl::SetBlocking(m_handle, true); });
|
||||||
if (!m_isBlockingEnabled)
|
if (m_isBlockingEnabled)
|
||||||
{
|
SocketImpl::SetBlocking(m_handle, false);
|
||||||
SocketImpl::SetBlocking(m_handle, true);
|
else
|
||||||
restoreBlocking.Reset([this] ()
|
restoreBlocking.Reset();
|
||||||
{
|
|
||||||
SocketImpl::SetBlocking(m_handle, false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t received;
|
std::size_t received;
|
||||||
if (!Receive(buffer, size, &received))
|
if (!Receive(buffer, size, &received))
|
||||||
@@ -630,15 +621,11 @@ namespace Nz
|
|||||||
NazaraAssert(buffer, "Invalid buffer");
|
NazaraAssert(buffer, "Invalid buffer");
|
||||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle");
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
CallOnExit restoreBlocking;
|
CallOnExit restoreBlocking([this] { SocketImpl::SetBlocking(m_handle, true); });
|
||||||
if (!m_isBlockingEnabled)
|
if (m_isBlockingEnabled)
|
||||||
{
|
SocketImpl::SetBlocking(m_handle, false);
|
||||||
SocketImpl::SetBlocking(m_handle, true);
|
else
|
||||||
restoreBlocking.Reset([this] ()
|
restoreBlocking.Reset();
|
||||||
{
|
|
||||||
SocketImpl::SetBlocking(m_handle, false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t sent;
|
std::size_t sent;
|
||||||
if (!Send(buffer, size, &sent))
|
if (!Send(buffer, size, &sent))
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ struct tcp_keepalive
|
|||||||
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
|
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <winsock2.h>
|
#include <WinSock2.h>
|
||||||
|
|
||||||
#include <Nazara/Network/Debug.hpp>
|
#include <Nazara/Network/Debug.hpp>
|
||||||
|
|
||||||
|
|||||||
@@ -9,34 +9,21 @@
|
|||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
OpenGLBuffer::OpenGLBuffer(OpenGLDevice& device, BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData) :
|
||||||
OpenGLBuffer::OpenGLBuffer(OpenGLDevice& device, BufferType type) :
|
RenderBuffer(device, type, size, usage)
|
||||||
m_type(type)
|
|
||||||
{
|
{
|
||||||
if (!m_buffer.Create(device))
|
if (!m_buffer.Create(device))
|
||||||
throw std::runtime_error("failed to create buffer"); //< TODO: Handle error
|
throw std::runtime_error("failed to create buffer"); //< TODO: Handle OpenGL error
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenGLBuffer::Fill(const void* data, UInt64 offset, UInt64 size)
|
|
||||||
{
|
|
||||||
m_buffer.SubData(GLintptr(offset), GLsizeiptr(size), data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenGLBuffer::Initialize(UInt64 size, BufferUsageFlags usage)
|
|
||||||
{
|
|
||||||
m_size = size;
|
|
||||||
m_usage = usage;
|
|
||||||
|
|
||||||
GL::BufferTarget target;
|
GL::BufferTarget target;
|
||||||
switch (m_type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case BufferType::Index: target = GL::BufferTarget::ElementArray; break;
|
case BufferType::Index: target = GL::BufferTarget::ElementArray; break;
|
||||||
case BufferType::Uniform: target = GL::BufferTarget::Uniform; break;
|
case BufferType::Uniform: target = GL::BufferTarget::Uniform; break;
|
||||||
case BufferType::Vertex: target = GL::BufferTarget::Array; break;
|
case BufferType::Vertex: target = GL::BufferTarget::Array; break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("unknown buffer type 0x" + NumberToString(UnderlyingCast(m_type), 16));
|
throw std::runtime_error("unknown buffer type 0x" + NumberToString(UnderlyingCast(type), 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum hint = GL_STREAM_COPY;
|
GLenum hint = GL_STREAM_COPY;
|
||||||
@@ -49,49 +36,23 @@ namespace Nz
|
|||||||
if (usage & BufferUsage::DirectMapping)
|
if (usage & BufferUsage::DirectMapping)
|
||||||
hint = GL_DYNAMIC_COPY;
|
hint = GL_DYNAMIC_COPY;
|
||||||
|
|
||||||
m_buffer.Reset(target, size, nullptr, hint);
|
m_buffer.Reset(target, size, initialData, hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLBuffer::Fill(const void* data, UInt64 offset, UInt64 size)
|
||||||
|
{
|
||||||
|
m_buffer.SubData(GLintptr(offset), GLsizeiptr(size), data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt64 OpenGLBuffer::GetSize() const
|
void* OpenGLBuffer::Map(UInt64 offset, UInt64 size)
|
||||||
{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataStorage OpenGLBuffer::GetStorage() const
|
|
||||||
{
|
|
||||||
return DataStorage::Hardware;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* OpenGLBuffer::Map(BufferAccess access, UInt64 offset, UInt64 size)
|
|
||||||
{
|
{
|
||||||
GLbitfield accessBit = 0;
|
GLbitfield accessBit = 0;
|
||||||
switch (access)
|
if (GetUsageFlags() & BufferUsage::Read)
|
||||||
{
|
accessBit |= GL_MAP_READ_BIT;
|
||||||
case BufferAccess::DiscardAndWrite:
|
|
||||||
accessBit |= GL_MAP_WRITE_BIT;
|
|
||||||
if (offset == 0 && size == m_size)
|
|
||||||
accessBit |= GL_MAP_INVALIDATE_BUFFER_BIT;
|
|
||||||
else
|
|
||||||
accessBit |= GL_MAP_INVALIDATE_RANGE_BIT;
|
|
||||||
|
|
||||||
break;
|
if (GetUsageFlags() & BufferUsage::Write)
|
||||||
|
accessBit |= GL_MAP_WRITE_BIT;
|
||||||
case BufferAccess::ReadOnly:
|
|
||||||
accessBit |= GL_MAP_READ_BIT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BufferAccess::ReadWrite:
|
|
||||||
accessBit |= GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BufferAccess::WriteOnly:
|
|
||||||
accessBit |= GL_MAP_WRITE_BIT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_buffer.MapRange(offset, size, accessBit);
|
return m_buffer.MapRange(offset, size, accessBit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Nz
|
|||||||
m_commandBuffer.SetFramebuffer(static_cast<const OpenGLFramebuffer&>(framebuffer), static_cast<const OpenGLRenderPass&>(renderPass), clearValues, clearValueCount);
|
m_commandBuffer.SetFramebuffer(static_cast<const OpenGLFramebuffer&>(framebuffer), static_cast<const OpenGLRenderPass&>(renderPass), clearValues, clearValueCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLCommandBufferBuilder::BindIndexBuffer(const AbstractBuffer& indexBuffer, UInt64 offset)
|
void OpenGLCommandBufferBuilder::BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset)
|
||||||
{
|
{
|
||||||
const OpenGLBuffer& glBuffer = static_cast<const OpenGLBuffer&>(indexBuffer);
|
const OpenGLBuffer& glBuffer = static_cast<const OpenGLBuffer&>(indexBuffer);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ namespace Nz
|
|||||||
m_commandBuffer.BindShaderBinding(glPipelineLayout, set, &glBinding);
|
m_commandBuffer.BindShaderBinding(glPipelineLayout, set, &glBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLCommandBufferBuilder::BindVertexBuffer(UInt32 binding, const AbstractBuffer& vertexBuffer, UInt64 offset)
|
void OpenGLCommandBufferBuilder::BindVertexBuffer(UInt32 binding, const RenderBuffer& vertexBuffer, UInt64 offset)
|
||||||
{
|
{
|
||||||
const OpenGLBuffer& glBuffer = static_cast<const OpenGLBuffer&>(vertexBuffer);
|
const OpenGLBuffer& glBuffer = static_cast<const OpenGLBuffer&>(vertexBuffer);
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace Nz
|
|||||||
|
|
||||||
OpenGLDevice::~OpenGLDevice()
|
OpenGLDevice::~OpenGLDevice()
|
||||||
{
|
{
|
||||||
// Free context first as it will unregister itself from m_contexts
|
// Free reference context first as it will unregister itself from m_contexts
|
||||||
m_referenceContext.reset();
|
m_referenceContext.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,9 +114,9 @@ namespace Nz
|
|||||||
return m_deviceInfo.features;
|
return m_deviceInfo.features;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AbstractBuffer> OpenGLDevice::InstantiateBuffer(BufferType type)
|
std::shared_ptr<RenderBuffer> OpenGLDevice::InstantiateBuffer(BufferType type, UInt64 size, BufferUsageFlags usageFlags, const void* initialData)
|
||||||
{
|
{
|
||||||
return std::make_shared<OpenGLBuffer>(*this, type);
|
return std::make_shared<OpenGLBuffer>(*this, type, size, usageFlags, initialData);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CommandPool> OpenGLDevice::InstantiateCommandPool(QueueType /*queueType*/)
|
std::shared_ptr<CommandPool> OpenGLDevice::InstantiateCommandPool(QueueType /*queueType*/)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <Nazara/Core/PrimitiveList.hpp>
|
#include <Nazara/Core/PrimitiveList.hpp>
|
||||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||||
|
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||||
#include <newton/Newton.h>
|
#include <newton/Newton.h>
|
||||||
@@ -168,11 +169,8 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
std::shared_ptr<VertexBuffer> colliderVB = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ), colliderVertices.size(), DataStorage::Software, 0);
|
std::shared_ptr<VertexBuffer> colliderVB = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ), colliderVertices.size(), BufferUsage::Write, SoftwareBufferFactory, colliderVertices.data());
|
||||||
colliderVB->Fill(colliderVertices.data(), 0, colliderVertices.size());
|
std::shared_ptr<IndexBuffer> colliderIB = std::make_shared<IndexBuffer>(false, colliderIndices.size(), BufferUsage::Write, SoftwareBufferFactory, colliderIndices.data());
|
||||||
|
|
||||||
std::shared_ptr<IndexBuffer> colliderIB = std::make_shared<IndexBuffer>(false, colliderIndices.size(), DataStorage::Software, 0);
|
|
||||||
colliderIB->Fill(colliderIndices.data(), 0, colliderIndices.size());
|
|
||||||
|
|
||||||
std::shared_ptr<StaticMesh> colliderSubMesh = std::make_shared<StaticMesh>(std::move(colliderVB), std::move(colliderIB));
|
std::shared_ptr<StaticMesh> colliderSubMesh = std::make_shared<StaticMesh>(std::move(colliderVB), std::move(colliderIB));
|
||||||
colliderSubMesh->GenerateAABB();
|
colliderSubMesh->GenerateAABB();
|
||||||
|
|||||||
@@ -3,100 +3,18 @@
|
|||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Renderer/RenderDevice.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
bool RenderBuffer::Fill(const void* data, UInt64 offset, UInt64 size)
|
RenderBuffer::~RenderBuffer() = default;
|
||||||
|
|
||||||
|
BufferFactory GetRenderBufferFactory(std::shared_ptr<RenderDevice> device)
|
||||||
{
|
{
|
||||||
if (m_softwareBuffer.Fill(data, offset, size))
|
return [device = std::move(device)](BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData) -> std::shared_ptr<Buffer>
|
||||||
{
|
{
|
||||||
for (auto& bufferPair : m_hardwareBuffers)
|
return device->InstantiateBuffer(type, size, usage, initialData);
|
||||||
bufferPair.second.synchronized = false;
|
};
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderBuffer::Initialize(UInt64 size, BufferUsageFlags usage)
|
|
||||||
{
|
|
||||||
m_size = size;
|
|
||||||
m_softwareBuffer.Initialize(size, usage);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractBuffer* RenderBuffer::GetHardwareBuffer(RenderDevice* device)
|
|
||||||
{
|
|
||||||
if (HardwareBuffer* hwBuffer = GetHardwareBufferData(device))
|
|
||||||
return hwBuffer->buffer.get();
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt64 RenderBuffer::GetSize() const
|
|
||||||
{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataStorage RenderBuffer::GetStorage() const
|
|
||||||
{
|
|
||||||
return DataStorage::Hardware;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* RenderBuffer::Map(BufferAccess access, UInt64 offset, UInt64 size)
|
|
||||||
{
|
|
||||||
if (void* ptr = m_softwareBuffer.Map(access, offset, size))
|
|
||||||
{
|
|
||||||
if (access != BufferAccess::ReadOnly)
|
|
||||||
{
|
|
||||||
for (auto& bufferPair : m_hardwareBuffers)
|
|
||||||
bufferPair.second.synchronized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderBuffer::Unmap()
|
|
||||||
{
|
|
||||||
return m_softwareBuffer.Unmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderBuffer::Synchronize(RenderDevice* device)
|
|
||||||
{
|
|
||||||
HardwareBuffer* hwBuffer = GetHardwareBufferData(device);
|
|
||||||
if (!hwBuffer)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (hwBuffer->synchronized)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return hwBuffer->buffer->Fill(m_softwareBuffer.GetData(), 0, m_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto RenderBuffer::GetHardwareBufferData(RenderDevice* device) -> HardwareBuffer*
|
|
||||||
{
|
|
||||||
auto it = m_hardwareBuffers.find(device);
|
|
||||||
if (it == m_hardwareBuffers.end())
|
|
||||||
{
|
|
||||||
HardwareBuffer hwBuffer;
|
|
||||||
hwBuffer.buffer = device->InstantiateBuffer(m_type);
|
|
||||||
if (!hwBuffer.buffer->Initialize(m_size, m_usage))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to initialize hardware buffer");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
it = m_hardwareBuffers.emplace(device, std::move(hwBuffer)).first;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include <Nazara/Core/StringExt.hpp>
|
#include <Nazara/Core/StringExt.hpp>
|
||||||
#include <Nazara/Platform/Platform.hpp>
|
#include <Nazara/Platform/Platform.hpp>
|
||||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/Buffer.hpp>
|
#include <Nazara/Utility/Buffer.hpp>
|
||||||
#include <Nazara/Utility/Image.hpp>
|
#include <Nazara/Utility/Image.hpp>
|
||||||
#include <Nazara/Utility/Utility.hpp>
|
#include <Nazara/Utility/Utility.hpp>
|
||||||
@@ -35,15 +34,11 @@ namespace Nz
|
|||||||
ModuleBase("Renderer", this)
|
ModuleBase("Renderer", this)
|
||||||
{
|
{
|
||||||
LoadBackend(config);
|
LoadBackend(config);
|
||||||
|
|
||||||
Buffer::SetBufferFactory(DataStorage::Hardware, [](Buffer* parent, BufferType type) -> std::unique_ptr<AbstractBuffer> { return std::make_unique<RenderBuffer>(parent, type); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer()
|
Renderer::~Renderer()
|
||||||
{
|
{
|
||||||
// Uninitialize module here
|
// reset Renderer impl before unloading library
|
||||||
Buffer::SetBufferFactory(DataStorage::Hardware, nullptr);
|
|
||||||
|
|
||||||
m_rendererImpl.reset();
|
m_rendererImpl.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,54 +57,81 @@ namespace Nz
|
|||||||
std::shared_ptr<Texture> Texture::LoadFromFile(const std::filesystem::path& filePath, const TextureParams& params)
|
std::shared_ptr<Texture> Texture::LoadFromFile(const std::filesystem::path& filePath, const TextureParams& params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadFromFile(filePath, params);
|
std::shared_ptr<Image> image = Image::LoadFromFile(filePath, params);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, params);
|
return CreateFromImage(*image, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadFromMemory(const void* data, std::size_t size, const TextureParams& params)
|
std::shared_ptr<Texture> Texture::LoadFromMemory(const void* data, std::size_t size, const TextureParams& params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadFromMemory(data, size, params);
|
std::shared_ptr<Image> image = Image::LoadFromMemory(data, size, params);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, params);
|
return CreateFromImage(*image, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadFromStream(Stream& stream, const TextureParams& params)
|
std::shared_ptr<Texture> Texture::LoadFromStream(Stream& stream, const TextureParams& params)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadFromStream(stream, params);
|
std::shared_ptr<Image> image = Image::LoadFromStream(stream, params);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, params);
|
return CreateFromImage(*image, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadArrayFromFile(const std::filesystem::path& filePath, const TextureParams& textureParams, const Vector2ui& atlasSize)
|
std::shared_ptr<Texture> Texture::LoadArrayFromFile(const std::filesystem::path& filePath, const TextureParams& textureParams, const Vector2ui& atlasSize)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadArrayFromFile(filePath, textureParams, atlasSize);
|
std::shared_ptr<Image> image = Image::LoadArrayFromFile(filePath, textureParams, atlasSize);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, textureParams);
|
return CreateFromImage(*image, textureParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadArrayFromMemory(const void* data, std::size_t size, const TextureParams& textureParams, const Vector2ui& atlasSize)
|
std::shared_ptr<Texture> Texture::LoadArrayFromMemory(const void* data, std::size_t size, const TextureParams& textureParams, const Vector2ui& atlasSize)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadArrayFromMemory(data, size, textureParams, atlasSize);
|
std::shared_ptr<Image> image = Image::LoadArrayFromMemory(data, size, textureParams, atlasSize);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, textureParams);
|
return CreateFromImage(*image, textureParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadArrayFromStream(Stream& stream, const TextureParams& textureParams, const Vector2ui& atlasSize)
|
std::shared_ptr<Texture> Texture::LoadArrayFromStream(Stream& stream, const TextureParams& textureParams, const Vector2ui& atlasSize)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadArrayFromStream(stream, textureParams, atlasSize);
|
std::shared_ptr<Image> image = Image::LoadArrayFromStream(stream, textureParams, atlasSize);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, textureParams);
|
return CreateFromImage(*image, textureParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadCubemapFromFile(const std::filesystem::path& filePath, const TextureParams& textureParams, const CubemapParams& cubemapParams)
|
std::shared_ptr<Texture> Texture::LoadCubemapFromFile(const std::filesystem::path& filePath, const TextureParams& textureParams, const CubemapParams& cubemapParams)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadCubemapFromFile(filePath, textureParams, cubemapParams);
|
std::shared_ptr<Image> image = Image::LoadCubemapFromFile(filePath, textureParams, cubemapParams);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, textureParams);
|
return CreateFromImage(*image, textureParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadCubemapFromMemory(const void* data, std::size_t size, const TextureParams& textureParams, const CubemapParams& cubemapParams)
|
std::shared_ptr<Texture> Texture::LoadCubemapFromMemory(const void* data, std::size_t size, const TextureParams& textureParams, const CubemapParams& cubemapParams)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadCubemapFromMemory(data, size, textureParams, cubemapParams);
|
std::shared_ptr<Image> image = Image::LoadCubemapFromMemory(data, size, textureParams, cubemapParams);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, textureParams);
|
return CreateFromImage(*image, textureParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Texture> Texture::LoadCubemapFromStream(Stream& stream, const TextureParams& textureParams, const CubemapParams& cubemapParams)
|
std::shared_ptr<Texture> Texture::LoadCubemapFromStream(Stream& stream, const TextureParams& textureParams, const CubemapParams& cubemapParams)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Image> image = Image::LoadCubemapFromStream(stream, textureParams, cubemapParams);
|
std::shared_ptr<Image> image = Image::LoadCubemapFromStream(stream, textureParams, cubemapParams);
|
||||||
|
if (!image)
|
||||||
|
return {};
|
||||||
|
|
||||||
return CreateFromImage(*image, textureParams);
|
return CreateFromImage(*image, textureParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
|
||||||
// This file is part of the "Nazara Engine - Utility module"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
|
||||||
#include <Nazara/Utility/Debug.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
AbstractBuffer::~AbstractBuffer() = default;
|
|
||||||
}
|
|
||||||
@@ -76,32 +76,32 @@ namespace Nz
|
|||||||
triangles.reserve(20 * IntegralPow(4, recursionLevel));
|
triangles.reserve(20 * IntegralPow(4, recursionLevel));
|
||||||
|
|
||||||
// Cinq triangles autour du premier point
|
// Cinq triangles autour du premier point
|
||||||
triangles.push_back({0, 11, 5});
|
triangles.emplace_back(0, 11, 5);
|
||||||
triangles.push_back({0, 5, 1});
|
triangles.emplace_back(0, 5, 1);
|
||||||
triangles.push_back({0, 1, 7});
|
triangles.emplace_back(0, 1, 7);
|
||||||
triangles.push_back({0, 7, 10});
|
triangles.emplace_back(0, 7, 10);
|
||||||
triangles.push_back({0, 10, 11});
|
triangles.emplace_back(0, 10, 11);
|
||||||
|
|
||||||
// Cinq faces adjaçentes
|
// Cinq faces adjaçentes
|
||||||
triangles.push_back({ 1, 5, 9});
|
triangles.emplace_back(1, 5, 9);
|
||||||
triangles.push_back({ 5, 11, 4});
|
triangles.emplace_back(5, 11, 4);
|
||||||
triangles.push_back({11, 10, 2});
|
triangles.emplace_back(11, 10, 2);
|
||||||
triangles.push_back({10, 7, 6});
|
triangles.emplace_back(10, 7, 6);
|
||||||
triangles.push_back({ 7, 1, 8});
|
triangles.emplace_back(7, 1, 8);
|
||||||
|
|
||||||
// Cinq triangles autour du troisième point
|
// Cinq triangles autour du troisième point
|
||||||
triangles.push_back({3, 9, 4});
|
triangles.emplace_back(3, 9, 4);
|
||||||
triangles.push_back({3, 4, 2});
|
triangles.emplace_back(3, 4, 2);
|
||||||
triangles.push_back({3, 2, 6});
|
triangles.emplace_back(3, 2, 6);
|
||||||
triangles.push_back({3, 6, 8});
|
triangles.emplace_back(3, 6, 8);
|
||||||
triangles.push_back({3, 8, 9});
|
triangles.emplace_back(3, 8, 9);
|
||||||
|
|
||||||
// Cinq faces adjaçentes
|
// Cinq faces adjaçentes
|
||||||
triangles.push_back({4, 9, 5});
|
triangles.emplace_back(4, 9, 5);
|
||||||
triangles.push_back({2, 4, 11});
|
triangles.emplace_back(2, 4, 11);
|
||||||
triangles.push_back({6, 2, 10});
|
triangles.emplace_back(6, 2, 10);
|
||||||
triangles.push_back({8, 6, 7});
|
triangles.emplace_back(8, 6, 7);
|
||||||
triangles.push_back({9, 8, 1});
|
triangles.emplace_back(9, 8, 1);
|
||||||
|
|
||||||
// Et maintenant on affine la sphère
|
// Et maintenant on affine la sphère
|
||||||
for (unsigned int i = 0; i < recursionLevel; ++i)
|
for (unsigned int i = 0; i < recursionLevel; ++i)
|
||||||
@@ -115,11 +115,11 @@ namespace Nz
|
|||||||
unsigned int b = GetMiddleVertex(triangle.y, triangle.z);
|
unsigned int b = GetMiddleVertex(triangle.y, triangle.z);
|
||||||
unsigned int c = GetMiddleVertex(triangle.z, triangle.x);
|
unsigned int c = GetMiddleVertex(triangle.z, triangle.x);
|
||||||
|
|
||||||
triangles.push_back({triangle.x, a, c});
|
triangles.emplace_back(triangle.x, a, c);
|
||||||
triangles.push_back({triangle.y, b, a});
|
triangles.emplace_back(triangle.y, b, a);
|
||||||
triangles.push_back({triangle.z, c, b});
|
triangles.emplace_back(triangle.z, c, b);
|
||||||
|
|
||||||
triangle.Set(a, b, c); // Réutilisation du triangle
|
triangle.Set(a, b, c); // Reuse triangle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,29 +175,28 @@ namespace Nz
|
|||||||
///TODO: Déplacer dans un fichier à part ?
|
///TODO: Déplacer dans un fichier à part ?
|
||||||
struct VertexCacheData
|
struct VertexCacheData
|
||||||
{
|
{
|
||||||
int position_in_cache = -1;
|
int positionInCache = -1;
|
||||||
float current_score = 0.f;
|
float score = 0.f;
|
||||||
int total_valence = 0; // toatl number of triangles using this vertex
|
int totalValence = 0; // total number of triangles using this vertex
|
||||||
int remaining_valence = 0; // number of triangles using it but not yet rendered
|
int remainingValence = 0; // number of triangles using it but not yet rendered
|
||||||
std::vector<int> tri_indices; // indices to the indices that use this vertex
|
std::vector<int> triIndices; // indices to the indices that use this vertex
|
||||||
bool calculated; // was the score calculated during this iteration?
|
bool calculated; // was the score calculated during this iteration?
|
||||||
|
|
||||||
|
|
||||||
int FindTriangle(int tri)
|
int FindTriangle(int tri)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < tri_indices.size(); ++i)
|
for (unsigned int i = 0; i < triIndices.size(); ++i)
|
||||||
if (tri_indices[i] == tri) return i;
|
if (triIndices[i] == tri) return i;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveTriangleToEnd(int tri)
|
void MoveTriangleToEnd(int tri)
|
||||||
{
|
{
|
||||||
auto it = std::find(tri_indices.begin(), tri_indices.end(), tri);
|
auto it = std::find(triIndices.begin(), triIndices.end(), tri);
|
||||||
NazaraAssert(it != tri_indices.end(), "Triangle not found");
|
NazaraAssert(it != triIndices.end(), "Triangle not found");
|
||||||
|
|
||||||
tri_indices.erase(it);
|
triIndices.erase(it);
|
||||||
tri_indices.push_back(tri);
|
triIndices.push_back(tri);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -217,18 +216,18 @@ namespace Nz
|
|||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexCache(IndexIterator indices, unsigned int indexCount)
|
VertexCache(IndexIterator indices, UInt32 indexCount)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < indexCount; ++i)
|
for (UInt32 i = 0; i < indexCount; ++i)
|
||||||
AddVertex(*indices++);
|
AddVertex(*indices++);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the vertex will be placed on top
|
// the vertex will be placed on top
|
||||||
// if the vertex didn't exist previewsly in
|
// if the vertex didn't exist previously in
|
||||||
// the cache, then miss count is incermented
|
// the cache, then miss count is incremented
|
||||||
void AddVertex(unsigned int v)
|
void AddVertex(UInt32 v)
|
||||||
{
|
{
|
||||||
int w = FindVertex(v);
|
int w = FindVertex(v);
|
||||||
if (w >= 0)
|
if (w >= 0)
|
||||||
@@ -239,7 +238,7 @@ namespace Nz
|
|||||||
m_misses++;
|
m_misses++;
|
||||||
|
|
||||||
// shift all vertices down (to make room for the new top vertex)
|
// shift all vertices down (to make room for the new top vertex)
|
||||||
for (int i=39; i>0; i--)
|
for (int i = 39; i > 0; i--)
|
||||||
m_cache[i] = m_cache[i-1];
|
m_cache[i] = m_cache[i-1];
|
||||||
|
|
||||||
// add the new vertex on top
|
// add the new vertex on top
|
||||||
@@ -248,13 +247,11 @@ namespace Nz
|
|||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
for (int i=0; i<40; i++)
|
m_cache.fill(-1);
|
||||||
m_cache[i] = -1;
|
|
||||||
|
|
||||||
m_misses = 0;
|
m_misses = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetMissCount() const
|
UInt64 GetMissCount() const
|
||||||
{
|
{
|
||||||
return m_misses;
|
return m_misses;
|
||||||
}
|
}
|
||||||
@@ -276,14 +273,14 @@ namespace Nz
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveVertex(int stack_index)
|
void RemoveVertex(int stackIndex)
|
||||||
{
|
{
|
||||||
for (int i=stack_index; i<38; i++)
|
for (int i = stackIndex; i < 38; i++)
|
||||||
m_cache[i] = m_cache[i+1];
|
m_cache[i] = m_cache[i+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_cache[40];
|
std::array<int, 40> m_cache;
|
||||||
int m_misses; // cache miss count
|
UInt64 m_misses; // cache miss count
|
||||||
};
|
};
|
||||||
|
|
||||||
class VertexCacheOptimizer
|
class VertexCacheOptimizer
|
||||||
@@ -337,18 +334,19 @@ namespace Nz
|
|||||||
private:
|
private:
|
||||||
float CalculateVertexScore(VertexCacheData& vertex) const
|
float CalculateVertexScore(VertexCacheData& vertex) const
|
||||||
{
|
{
|
||||||
if (vertex.remaining_valence <= 0)
|
if (vertex.remainingValence <= 0)
|
||||||
// No tri needs this vertex!
|
// No tri needs this vertex!
|
||||||
return -1.0f;
|
return -1.0f;
|
||||||
|
|
||||||
float ret = 0.0f;
|
float ret;
|
||||||
if (vertex.position_in_cache < 0)
|
if (vertex.positionInCache < 0)
|
||||||
{
|
{
|
||||||
// Vertex is not in FIFO cache - no score.
|
// Vertex is not in FIFO cache - no score.
|
||||||
|
ret = 0.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (vertex.position_in_cache < 3)
|
if (vertex.positionInCache < 3)
|
||||||
{
|
{
|
||||||
// This vertex was used in the last triangle,
|
// This vertex was used in the last triangle,
|
||||||
// so it has a fixed score, whichever of the three
|
// so it has a fixed score, whichever of the three
|
||||||
@@ -361,14 +359,14 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
// Points for being high in the cache.
|
// Points for being high in the cache.
|
||||||
const float Scaler = 1.0f / (32 - 3);
|
const float Scaler = 1.0f / (32 - 3);
|
||||||
ret = 1.0f - (vertex.position_in_cache - 3) * Scaler;
|
ret = 1.0f - (vertex.positionInCache - 3) * Scaler;
|
||||||
ret = std::pow(ret, m_cacheDecayPower);
|
ret = std::pow(ret, m_cacheDecayPower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bonus points for having a low number of tris still to
|
// Bonus points for having a low number of tris still to
|
||||||
// use the vert, so we get rid of lone verts quickly.
|
// use the vert, so we get rid of lone verts quickly.
|
||||||
float valence_boost = std::pow(static_cast<float>(vertex.remaining_valence), -m_valenceBoostPower);
|
float valence_boost = std::pow(static_cast<float>(vertex.remainingValence), -m_valenceBoostPower);
|
||||||
ret += m_valenceBoostScale * valence_boost;
|
ret += m_valenceBoostScale * valence_boost;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -380,11 +378,11 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
// calculate score for all vertices
|
// calculate score for all vertices
|
||||||
for (VertexCacheData& vertex : m_vertices)
|
for (VertexCacheData& vertex : m_vertices)
|
||||||
vertex.current_score = CalculateVertexScore(vertex);
|
vertex.score = CalculateVertexScore(vertex);
|
||||||
|
|
||||||
// calculate scores for all active triangles
|
// calculate scores for all active triangles
|
||||||
float max_score = std::numeric_limits<float>::lowest();
|
float maxScore = std::numeric_limits<float>::lowest();
|
||||||
int max_score_tri = -1;
|
int maxScoreTri = -1;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < m_triangles.size(); ++i)
|
for (unsigned int i = 0; i < m_triangles.size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -392,20 +390,20 @@ namespace Nz
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// sum the score of all the triangle's vertices
|
// sum the score of all the triangle's vertices
|
||||||
float sc = m_vertices[m_triangles[i].verts[0]].current_score +
|
float sc = m_vertices[m_triangles[i].verts[0]].score +
|
||||||
m_vertices[m_triangles[i].verts[1]].current_score +
|
m_vertices[m_triangles[i].verts[1]].score +
|
||||||
m_vertices[m_triangles[i].verts[2]].current_score;
|
m_vertices[m_triangles[i].verts[2]].score;
|
||||||
|
|
||||||
m_triangles[i].current_score = sc;
|
m_triangles[i].current_score = sc;
|
||||||
|
|
||||||
if (sc > max_score)
|
if (sc > maxScore)
|
||||||
{
|
{
|
||||||
max_score = sc;
|
maxScore = sc;
|
||||||
max_score_tri = i;
|
maxScoreTri = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return max_score_tri;
|
return maxScoreTri;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InitialPass()
|
Result InitialPass()
|
||||||
@@ -416,10 +414,10 @@ namespace Nz
|
|||||||
if (index < 0 || index >= static_cast<int>(m_vertices.size()))
|
if (index < 0 || index >= static_cast<int>(m_vertices.size()))
|
||||||
return Fail_BadIndex;
|
return Fail_BadIndex;
|
||||||
|
|
||||||
m_vertices[index].total_valence++;
|
m_vertices[index].totalValence++;
|
||||||
m_vertices[index].remaining_valence++;
|
m_vertices[index].remainingValence++;
|
||||||
|
|
||||||
m_vertices[index].tri_indices.push_back(i/3);
|
m_vertices[index].triIndices.push_back(i/3);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bestTri = FullScoreRecalculation();
|
m_bestTri = FullScoreRecalculation();
|
||||||
@@ -427,14 +425,14 @@ namespace Nz
|
|||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Init(IndexIterator indices, unsigned int indexCount, int vertex_count)
|
Result Init(IndexIterator indices, unsigned int indexCount, int vertexCount)
|
||||||
{
|
{
|
||||||
// clear the draw list
|
// clear the draw list
|
||||||
m_drawList.clear();
|
m_drawList.clear();
|
||||||
|
|
||||||
// allocate and initialize vertices and triangles
|
// allocate and initialize vertices and triangles
|
||||||
m_vertices.clear(); // Pour reconstruire tous les éléments
|
m_vertices.clear(); // Pour reconstruire tous les éléments
|
||||||
m_vertices.resize(vertex_count);
|
m_vertices.resize(vertexCount);
|
||||||
|
|
||||||
m_triangles.clear();
|
m_triangles.clear();
|
||||||
for (unsigned int i = 0; i < indexCount; i += 3)
|
for (unsigned int i = 0; i < indexCount; i += 3)
|
||||||
@@ -466,22 +464,22 @@ namespace Nz
|
|||||||
if (ind < 0)
|
if (ind < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_vertices[ind].position_in_cache = -1;
|
m_vertices[ind].positionInCache = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TriangleCacheData* t = &m_triangles[tri];
|
TriangleCacheData* t = &m_triangles[tri];
|
||||||
if (t->rendered)
|
if (t->rendered)
|
||||||
return; // triangle is already in the draw list
|
return; // triangle is already in the draw list
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 3; ++i)
|
for (int vert : t->verts)
|
||||||
{
|
{
|
||||||
// add all triangle vertices to the cache
|
// add all triangle vertices to the cache
|
||||||
m_vertexCache.AddVertex(t->verts[i]);
|
m_vertexCache.AddVertex(vert);
|
||||||
|
|
||||||
VertexCacheData *v = &m_vertices[t->verts[i]];
|
VertexCacheData *v = &m_vertices[vert];
|
||||||
|
|
||||||
// decrease remaining velence
|
// decrease remaining valence
|
||||||
v->remaining_valence--;
|
v->remainingValence--;
|
||||||
|
|
||||||
// move the added triangle to the end of the vertex's
|
// move the added triangle to the end of the vertex's
|
||||||
// triangle index list, so that the first 'remaining_valence'
|
// triangle index list, so that the first 'remaining_valence'
|
||||||
@@ -500,11 +498,11 @@ namespace Nz
|
|||||||
if (ind < 0)
|
if (ind < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_vertices[ind].position_in_cache = i;
|
m_vertices[ind].positionInCache = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optimization: to avoid duplicate calculations durind the same iteration,
|
// Optimization: to avoid duplicate calculations during the same iteration,
|
||||||
// both vertices and triangles have a 'calculated' flag. This flag
|
// both vertices and triangles have a 'calculated' flag. This flag
|
||||||
// must be cleared at the beginning of the iteration to all *active* triangles
|
// must be cleared at the beginning of the iteration to all *active* triangles
|
||||||
// that have one or more of their vertices currently cached, and all their
|
// that have one or more of their vertices currently cached, and all their
|
||||||
@@ -522,9 +520,9 @@ namespace Nz
|
|||||||
|
|
||||||
VertexCacheData *v = &m_vertices[vert];
|
VertexCacheData *v = &m_vertices[vert];
|
||||||
|
|
||||||
for (int j = 0; j < v->remaining_valence; j++)
|
for (int j = 0; j < v->remainingValence; j++)
|
||||||
{
|
{
|
||||||
TriangleCacheData *t = &m_triangles[v->tri_indices[j]];
|
TriangleCacheData *t = &m_triangles[v->triIndices[j]];
|
||||||
|
|
||||||
// we actually found a triangle to process
|
// we actually found a triangle to process
|
||||||
ret = true;
|
ret = true;
|
||||||
@@ -533,8 +531,8 @@ namespace Nz
|
|||||||
t->calculated = false;
|
t->calculated = false;
|
||||||
|
|
||||||
// clear vertex flags
|
// clear vertex flags
|
||||||
for (unsigned int k = 0; k < 3; ++k)
|
for (int i : t->verts)
|
||||||
m_vertices[t->verts[k]].calculated = false;
|
m_vertices[i].calculated = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,14 +545,14 @@ namespace Nz
|
|||||||
|
|
||||||
// calculate vertex scores
|
// calculate vertex scores
|
||||||
float sum = 0.f;
|
float sum = 0.f;
|
||||||
for (unsigned int i = 0; i < 3; ++i)
|
for (int vert : t->verts)
|
||||||
{
|
{
|
||||||
VertexCacheData& v = m_vertices[t->verts[i]];
|
VertexCacheData& v = m_vertices[vert];
|
||||||
float sc = v.current_score;
|
float sc = v.score;
|
||||||
if (!v.calculated)
|
if (!v.calculated)
|
||||||
sc = CalculateVertexScore(v);
|
sc = CalculateVertexScore(v);
|
||||||
|
|
||||||
v.current_score = sc;
|
v.score = sc;
|
||||||
v.calculated = true;
|
v.calculated = true;
|
||||||
sum += sc;
|
sum += sc;
|
||||||
}
|
}
|
||||||
@@ -566,8 +564,8 @@ namespace Nz
|
|||||||
int PartialScoreRecalculation()
|
int PartialScoreRecalculation()
|
||||||
{
|
{
|
||||||
// iterate through all the vertices of the cache
|
// iterate through all the vertices of the cache
|
||||||
float max_score = std::numeric_limits<float>::lowest();
|
float maxScore = std::numeric_limits<float>::lowest();
|
||||||
int max_score_tri = -1;
|
int maxScoreTri = -1;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 32; ++i)
|
for (unsigned int i = 0; i < 32; ++i)
|
||||||
{
|
{
|
||||||
@@ -578,9 +576,9 @@ namespace Nz
|
|||||||
const VertexCacheData* v = &m_vertices[vert];
|
const VertexCacheData* v = &m_vertices[vert];
|
||||||
|
|
||||||
// iterate through all *active* triangles of this vertex
|
// iterate through all *active* triangles of this vertex
|
||||||
for (int j = 0; j < v->remaining_valence; j++)
|
for (int j = 0; j < v->remainingValence; j++)
|
||||||
{
|
{
|
||||||
int tri = v->tri_indices[j];
|
int tri = v->triIndices[j];
|
||||||
TriangleCacheData* t = &m_triangles[tri];
|
TriangleCacheData* t = &m_triangles[tri];
|
||||||
if (!t->calculated)
|
if (!t->calculated)
|
||||||
// calculate triangle score
|
// calculate triangle score
|
||||||
@@ -589,15 +587,15 @@ namespace Nz
|
|||||||
float sc = t->current_score;
|
float sc = t->current_score;
|
||||||
|
|
||||||
// we actually found a triangle to process
|
// we actually found a triangle to process
|
||||||
if (sc > max_score)
|
if (sc > maxScore)
|
||||||
{
|
{
|
||||||
max_score = sc;
|
maxScore = sc;
|
||||||
max_score_tri = tri;
|
maxScoreTri = tri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return max_score_tri;
|
return maxScoreTri;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true while there are more steps to take
|
// returns true while there are more steps to take
|
||||||
@@ -667,7 +665,7 @@ namespace Nz
|
|||||||
*vertexCount = xVertexCount*2 + yVertexCount*2 + zVertexCount*2;
|
*vertexCount = xVertexCount*2 + yVertexCount*2 + zVertexCount*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ComputeCacheMissCount(IndexIterator indices, std::size_t indexCount)
|
UInt64 ComputeCacheMissCount(IndexIterator indices, std::size_t indexCount)
|
||||||
{
|
{
|
||||||
VertexCache cache(indices, indexCount);
|
VertexCache cache(indices, indexCount);
|
||||||
return cache.GetMissCount();
|
return cache.GetMissCount();
|
||||||
|
|||||||
@@ -3,174 +3,26 @@
|
|||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Utility/Buffer.hpp>
|
#include <Nazara/Utility/Buffer.hpp>
|
||||||
#include <Nazara/Core/Algorithm.hpp>
|
|
||||||
#include <Nazara/Core/CallOnExit.hpp>
|
|
||||||
#include <Nazara/Core/Error.hpp>
|
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
|
||||||
#include <Nazara/Utility/BufferMapper.hpp>
|
#include <Nazara/Utility/BufferMapper.hpp>
|
||||||
#include <Nazara/Utility/Config.hpp>
|
#include <stdexcept>
|
||||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
#include <vector>
|
||||||
#include <memory>
|
|
||||||
#include <Nazara/Utility/Debug.hpp>
|
#include <Nazara/Utility/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
Buffer::Buffer(BufferType type) :
|
Buffer::~Buffer() = default;
|
||||||
m_type(type),
|
|
||||||
m_usage(0),
|
std::shared_ptr<Buffer> Buffer::CopyContent(const BufferFactory& bufferFactory)
|
||||||
m_size(0)
|
|
||||||
{
|
{
|
||||||
}
|
if (GetUsageFlags() & BufferUsage::DirectMapping)
|
||||||
|
|
||||||
Buffer::Buffer(BufferType type, UInt32 size, DataStorage storage, BufferUsageFlags usage) :
|
|
||||||
Buffer(type)
|
|
||||||
{
|
|
||||||
ErrorFlags flags(ErrorMode::ThrowException, true);
|
|
||||||
|
|
||||||
Create(size, storage, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Buffer::CopyContent(const Buffer& buffer)
|
|
||||||
{
|
|
||||||
NazaraAssert(m_impl, "Invalid buffer");
|
|
||||||
NazaraAssert(buffer.IsValid(), "Invalid source buffer");
|
|
||||||
|
|
||||||
BufferMapper<Buffer> mapper(buffer, BufferAccess::ReadOnly);
|
|
||||||
return Fill(mapper.GetPointer(), 0, buffer.GetSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Buffer::Create(UInt32 size, DataStorage storage, BufferUsageFlags usage)
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
|
|
||||||
// Notre buffer est-il supporté ?
|
|
||||||
if (!IsStorageSupported(storage))
|
|
||||||
{
|
{
|
||||||
NazaraError("Buffer storage not supported");
|
BufferMapper<Buffer> mapper(*this, 0, GetSize());
|
||||||
return false;
|
return bufferFactory(GetType(), GetSize(), GetUsageFlags(), mapper.GetPointer());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
std::unique_ptr<AbstractBuffer> impl = s_bufferFactories[UnderlyingCast(storage)](this, m_type);
|
|
||||||
if (!impl->Initialize(size, usage))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create buffer");
|
// TODO: Implement GPU to CPU
|
||||||
return false;
|
throw std::runtime_error("buffer is not mappable not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl = std::move(impl);
|
|
||||||
m_size = size;
|
|
||||||
m_usage = usage;
|
|
||||||
|
|
||||||
return true; // Si on arrive ici c'est que tout s'est bien passé.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Destroy()
|
|
||||||
{
|
|
||||||
m_impl.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Buffer::Fill(const void* data, UInt32 offset, UInt32 size)
|
|
||||||
{
|
|
||||||
NazaraAssert(m_impl, "Invalid buffer");
|
|
||||||
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
|
|
||||||
|
|
||||||
return m_impl->Fill(data, offset, (size == 0) ? m_size - offset : size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* Buffer::Map(BufferAccess access, UInt32 offset, UInt32 size)
|
|
||||||
{
|
|
||||||
NazaraAssert(m_impl, "Invalid buffer");
|
|
||||||
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
|
|
||||||
|
|
||||||
return m_impl->Map(access, offset, (size == 0) ? m_size - offset : size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* Buffer::Map(BufferAccess access, UInt32 offset, UInt32 size) const
|
|
||||||
{
|
|
||||||
NazaraAssert(m_impl, "Invalid buffer");
|
|
||||||
NazaraAssert(access == BufferAccess::ReadOnly, "Buffer access must be read-only when used const");
|
|
||||||
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
|
|
||||||
|
|
||||||
return m_impl->Map(access, offset, (size == 0) ? m_size - offset : size);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Buffer::SetStorage(DataStorage storage)
|
|
||||||
{
|
|
||||||
NazaraAssert(m_impl, "Invalid buffer");
|
|
||||||
|
|
||||||
if (HasStorage(storage))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!IsStorageSupported(storage))
|
|
||||||
{
|
|
||||||
NazaraError("Storage not supported");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* ptr = m_impl->Map(BufferAccess::ReadOnly, 0, m_size);
|
|
||||||
if (!ptr)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to map buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CallOnExit unmapMyImpl([this]()
|
|
||||||
{
|
|
||||||
m_impl->Unmap();
|
|
||||||
});
|
|
||||||
|
|
||||||
std::unique_ptr<AbstractBuffer> impl(s_bufferFactories[UnderlyingCast(storage)](this, m_type));
|
|
||||||
if (!impl->Initialize(m_size, m_usage))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!impl->Fill(ptr, 0, m_size))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to fill buffer");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unmapMyImpl.CallAndReset();
|
|
||||||
|
|
||||||
m_impl = std::move(impl);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Buffer::Unmap() const
|
|
||||||
{
|
|
||||||
NazaraAssert(m_impl, "Invalid buffer");
|
|
||||||
|
|
||||||
if (!m_impl->Unmap())
|
|
||||||
NazaraWarning("Failed to unmap buffer (it's content may be undefined)"); ///TODO: Unexpected ?
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Buffer::IsStorageSupported(DataStorage storage)
|
|
||||||
{
|
|
||||||
return s_bufferFactories[UnderlyingCast(storage)] != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Buffer::SetBufferFactory(DataStorage storage, BufferFactory func)
|
|
||||||
{
|
|
||||||
s_bufferFactories[UnderlyingCast(storage)] = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Buffer::Initialize()
|
|
||||||
{
|
|
||||||
SetBufferFactory(DataStorage::Software, [](Buffer* parent, BufferType type) -> std::unique_ptr<AbstractBuffer>
|
|
||||||
{
|
|
||||||
return std::make_unique<SoftwareBuffer>(parent, type);
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Buffer::Uninitialize()
|
|
||||||
{
|
|
||||||
std::fill(s_bufferFactories.begin(), s_bufferFactories.end(), nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<Buffer::BufferFactory, DataStorageCount> Buffer::s_bufferFactories;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(false, header.num_tris*3, parameters.storage, parameters.indexBufferFlags);
|
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(false, 3 * header.num_tris, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
// Extract triangles data
|
// Extract triangles data
|
||||||
std::vector<MD2_Triangle> triangles(header.num_tris);
|
std::vector<MD2_Triangle> triangles(header.num_tris);
|
||||||
@@ -117,7 +117,7 @@ namespace Nz
|
|||||||
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
|
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
|
||||||
|
|
||||||
// And convert them into an index buffer
|
// And convert them into an index buffer
|
||||||
BufferMapper<IndexBuffer> indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
|
BufferMapper<IndexBuffer> indexMapper(*indexBuffer, 0, indexBuffer->GetIndexCount());
|
||||||
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
|
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
|
||||||
|
|
||||||
for (unsigned int i = 0; i < header.num_tris; ++i)
|
for (unsigned int i = 0; i < header.num_tris; ++i)
|
||||||
@@ -159,7 +159,7 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, header.num_vertices, parameters.storage, parameters.vertexBufferFlags);
|
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, header.num_vertices, parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||||
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
|
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
|
||||||
|
|
||||||
// Extracting vertices
|
// Extracting vertices
|
||||||
@@ -187,7 +187,7 @@ namespace Nz
|
|||||||
scale *= ScaleAdjust;
|
scale *= ScaleAdjust;
|
||||||
translate *= ScaleAdjust;
|
translate *= ScaleAdjust;
|
||||||
|
|
||||||
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
|
VertexMapper vertexMapper(*vertexBuffer);
|
||||||
|
|
||||||
// Loading texture coordinates
|
// Loading texture coordinates
|
||||||
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord))
|
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord))
|
||||||
@@ -247,7 +247,7 @@ namespace Nz
|
|||||||
|
|
||||||
vertexMapper.Unmap();
|
vertexMapper.Unmap();
|
||||||
|
|
||||||
subMesh->SetIndexBuffer(indexBuffer);
|
subMesh->SetIndexBuffer(std::move(indexBuffer));
|
||||||
subMesh->SetMaterialIndex(0);
|
subMesh->SetMaterialIndex(0);
|
||||||
|
|
||||||
subMesh->GenerateAABB();
|
subMesh->GenerateAABB();
|
||||||
|
|||||||
@@ -91,16 +91,16 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
|
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
|
||||||
|
|
||||||
std::size_t indexCount = md5Mesh.triangles.size()*3;
|
UInt64 indexCount = md5Mesh.triangles.size() * 3;
|
||||||
std::size_t vertexCount = md5Mesh.vertices.size();
|
UInt64 vertexCount = md5Mesh.vertices.size();
|
||||||
|
|
||||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||||
|
|
||||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, UInt32(indexCount), parameters.storage, parameters.indexBufferFlags);
|
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent_Skinning), UInt32(vertexCount), parameters.storage, parameters.vertexBufferFlags);
|
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent_Skinning), UInt32(vertexCount), parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
// Index buffer
|
// Index buffer
|
||||||
IndexMapper indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
|
IndexMapper indexMapper(*indexBuffer);
|
||||||
|
|
||||||
// Le format définit un set de triangles nous permettant de retrouver facilement les indices
|
// Le format définit un set de triangles nous permettant de retrouver facilement les indices
|
||||||
// Cependant les sommets des triangles ne sont pas spécifiés dans le même ordre que ceux du moteur
|
// Cependant les sommets des triangles ne sont pas spécifiés dans le même ordre que ceux du moteur
|
||||||
@@ -128,7 +128,7 @@ namespace Nz
|
|||||||
|
|
||||||
std::vector<Weight> tempWeights;
|
std::vector<Weight> tempWeights;
|
||||||
|
|
||||||
BufferMapper<VertexBuffer> vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
|
BufferMapper<VertexBuffer> vertexMapper(*vertexBuffer, 0, vertexBuffer->GetVertexCount());
|
||||||
SkeletalMeshVertex* vertices = static_cast<SkeletalMeshVertex*>(vertexMapper.GetPointer());
|
SkeletalMeshVertex* vertices = static_cast<SkeletalMeshVertex*>(vertexMapper.GetPointer());
|
||||||
|
|
||||||
for (const MD5MeshParser::Vertex& vertex : md5Mesh.vertices)
|
for (const MD5MeshParser::Vertex& vertex : md5Mesh.vertices)
|
||||||
@@ -235,15 +235,15 @@ namespace Nz
|
|||||||
for (UInt32 i = 0; i < meshCount; ++i)
|
for (UInt32 i = 0; i < meshCount; ++i)
|
||||||
{
|
{
|
||||||
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
|
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
|
||||||
std::size_t indexCount = md5Mesh.triangles.size()*3;
|
UInt64 indexCount = md5Mesh.triangles.size() * 3;
|
||||||
std::size_t vertexCount = md5Mesh.vertices.size();
|
UInt64 vertexCount = md5Mesh.vertices.size();
|
||||||
|
|
||||||
// Index buffer
|
// Index buffer
|
||||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||||
|
|
||||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, UInt32(indexCount), parameters.storage, parameters.indexBufferFlags);
|
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
IndexMapper indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
|
IndexMapper indexMapper(*indexBuffer);
|
||||||
IndexIterator index = indexMapper.begin();
|
IndexIterator index = indexMapper.begin();
|
||||||
|
|
||||||
for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles)
|
for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles)
|
||||||
@@ -259,9 +259,9 @@ namespace Nz
|
|||||||
indexBuffer->Optimize();
|
indexBuffer->Optimize();
|
||||||
|
|
||||||
// Vertex buffer
|
// Vertex buffer
|
||||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, UInt32(vertexCount), parameters.storage, parameters.vertexBufferFlags);
|
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, vertexCount, parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
|
VertexMapper vertexMapper(*vertexBuffer);
|
||||||
|
|
||||||
// Vertex positions
|
// Vertex positions
|
||||||
if (auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position))
|
if (auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position))
|
||||||
|
|||||||
@@ -33,17 +33,16 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
m_currentStream = &stream;
|
m_currentStream = &stream;
|
||||||
|
|
||||||
// Force stream in text mode, reset it at the end
|
// force stream in text mode, reset it at the end
|
||||||
Nz::CallOnExit resetTextMode;
|
CallOnExit resetTextMode([&stream]
|
||||||
if ((stream.GetStreamOptions() & StreamOption::Text) == 0)
|
|
||||||
{
|
{
|
||||||
stream.EnableTextMode(true);
|
stream.EnableTextMode(false);
|
||||||
|
});
|
||||||
|
|
||||||
resetTextMode.Reset([&stream] ()
|
if ((stream.GetStreamOptions() & StreamOption::Text) == 0)
|
||||||
{
|
stream.EnableTextMode(true);
|
||||||
stream.EnableTextMode(false);
|
else
|
||||||
});
|
resetTextMode.Reset();
|
||||||
}
|
|
||||||
|
|
||||||
m_keepLastLine = false;
|
m_keepLastLine = false;
|
||||||
m_lineCount = 0;
|
m_lineCount = 0;
|
||||||
@@ -489,17 +488,16 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
m_currentStream = &stream;
|
m_currentStream = &stream;
|
||||||
|
|
||||||
// Force stream in text mode, reset it at the end
|
// force stream in text mode, reset it at the end
|
||||||
Nz::CallOnExit resetTextMode;
|
CallOnExit resetTextMode([&stream]
|
||||||
if ((stream.GetStreamOptions() & StreamOption::Text) == 0)
|
|
||||||
{
|
{
|
||||||
stream.EnableTextMode(true);
|
stream.EnableTextMode(false);
|
||||||
|
});
|
||||||
|
|
||||||
resetTextMode.Reset([&stream] ()
|
if ((stream.GetStreamOptions() & StreamOption::Text) == 0)
|
||||||
{
|
stream.EnableTextMode(true);
|
||||||
stream.EnableTextMode(false);
|
else
|
||||||
});
|
resetTextMode.Reset();
|
||||||
}
|
|
||||||
|
|
||||||
m_outputStream.str({});
|
m_outputStream.str({});
|
||||||
|
|
||||||
|
|||||||
@@ -185,15 +185,15 @@ namespace Nz
|
|||||||
texCoords != nullptr && meshes != nullptr && meshCount > 0,
|
texCoords != nullptr && meshes != nullptr && meshCount > 0,
|
||||||
"Invalid OBJParser output");
|
"Invalid OBJParser output");
|
||||||
|
|
||||||
// Un conteneur temporaire pour contenir les indices de face avant triangulation
|
// Triangulation temporary vector
|
||||||
std::vector<std::size_t> faceIndices(3); // Comme il y aura au moins trois sommets
|
std::vector<UInt32> faceIndices;
|
||||||
for (std::size_t i = 0; i < meshCount; ++i)
|
for (std::size_t i = 0; i < meshCount; ++i)
|
||||||
{
|
{
|
||||||
std::size_t faceCount = meshes[i].faces.size();
|
std::size_t faceCount = meshes[i].faces.size();
|
||||||
if (faceCount == 0)
|
if (faceCount == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::vector<std::size_t> indices;
|
std::vector<UInt32> indices;
|
||||||
indices.reserve(faceCount*3); // Pire cas si les faces sont des triangles
|
indices.reserve(faceCount*3); // Pire cas si les faces sont des triangles
|
||||||
|
|
||||||
// Afin d'utiliser OBJParser::FaceVertex comme clé dans un unordered_map,
|
// Afin d'utiliser OBJParser::FaceVertex comme clé dans un unordered_map,
|
||||||
@@ -227,7 +227,7 @@ namespace Nz
|
|||||||
std::unordered_map<OBJParser::FaceVertex, unsigned int, FaceVertexHasher, FaceVertexComparator> vertices;
|
std::unordered_map<OBJParser::FaceVertex, unsigned int, FaceVertexHasher, FaceVertexComparator> vertices;
|
||||||
vertices.reserve(meshes[i].vertices.size());
|
vertices.reserve(meshes[i].vertices.size());
|
||||||
|
|
||||||
unsigned int vertexCount = 0;
|
UInt32 vertexCount = 0;
|
||||||
for (unsigned int j = 0; j < faceCount; ++j)
|
for (unsigned int j = 0; j < faceCount; ++j)
|
||||||
{
|
{
|
||||||
std::size_t faceVertexCount = meshes[i].faces[j].vertexCount;
|
std::size_t faceVertexCount = meshes[i].faces[j].vertexCount;
|
||||||
@@ -254,13 +254,13 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Création des buffers
|
// Création des buffers
|
||||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), std::size_t(indices.size()), parameters.storage, parameters.indexBufferFlags);
|
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indices.size(), parameters.indexBufferFlags, parameters.bufferFactory);
|
||||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, std::size_t(vertexCount), parameters.storage, parameters.vertexBufferFlags);
|
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, vertexCount, parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||||
|
|
||||||
// Remplissage des indices
|
// Remplissage des indices
|
||||||
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
|
IndexMapper indexMapper(*indexBuffer);
|
||||||
for (std::size_t j = 0; j < indices.size(); ++j)
|
for (std::size_t j = 0; j < indices.size(); ++j)
|
||||||
indexMapper.Set(j, UInt32(indices[j]));
|
indexMapper.Set(j, indices[j]);
|
||||||
|
|
||||||
indexMapper.Unmap(); // Pour laisser les autres tâches affecter l'index buffer
|
indexMapper.Unmap(); // Pour laisser les autres tâches affecter l'index buffer
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ namespace Nz
|
|||||||
bool hasNormals = true;
|
bool hasNormals = true;
|
||||||
bool hasTexCoords = true;
|
bool hasTexCoords = true;
|
||||||
|
|
||||||
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
|
VertexMapper vertexMapper(*vertexBuffer);
|
||||||
|
|
||||||
auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
|
auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
|
||||||
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
|
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
|
||||||
@@ -325,8 +325,8 @@ namespace Nz
|
|||||||
// Official .obj files have no vertex color, fill it with white
|
// Official .obj files have no vertex color, fill it with white
|
||||||
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
|
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < vertexCount; ++i)
|
for (UInt32 j = 0; j < vertexCount; ++j)
|
||||||
colorPtr[i] = Color::White;
|
colorPtr[j] = Color::White;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexMapper.Unmap();
|
vertexMapper.Unmap();
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user