Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored API sample hpp_texture_loading. #793

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions samples/api/hpp_compute_nbody/hpp_compute_nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ HPPComputeNBody::~HPPComputeNBody()

bool HPPComputeNBody::prepare(const vkb::ApplicationOptions &options)
{
if (!HPPApiVulkanSample::prepare(options))
{
return false;
}
assert(!prepared);

load_assets();
if (HPPApiVulkanSample::prepare(options))
{
load_assets();
descriptor_pool = create_descriptor_pool();
prepare_graphics();
prepare_compute();
build_command_buffers();

descriptor_pool = create_descriptor_pool();
prepared = true;
}

prepare_graphics();
prepare_compute();
build_command_buffers();
prepared = true;
return true;
return prepared;
}

bool HPPComputeNBody::resize(const uint32_t width, const uint32_t height)
Expand Down Expand Up @@ -145,13 +145,14 @@ void HPPComputeNBody::build_command_buffers()

void HPPComputeNBody::render(float delta_time)
{
if (!prepared)
return;
draw();
update_compute_uniform_buffers(delta_time);
if (camera.updated)
if (prepared)
{
update_graphics_uniform_buffers();
draw();
update_compute_uniform_buffers(delta_time);
if (camera.updated)
{
update_graphics_uniform_buffers();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,25 @@ void HPPDynamicUniformBuffers::aligned_free(void *data)

bool HPPDynamicUniformBuffers::prepare(const vkb::ApplicationOptions &options)
{
if (!HPPApiVulkanSample::prepare(options))
assert(!prepared);

if (HPPApiVulkanSample::prepare(options))
{
return false;
prepare_camera();
generate_cube();
prepare_uniform_buffers();
descriptor_set_layout = create_descriptor_set_layout();
pipeline_layout = get_device()->get_handle().createPipelineLayout({{}, descriptor_set_layout});
pipeline = create_pipeline();
descriptor_pool = create_descriptor_pool();
descriptor_set = vkb::common::allocate_descriptor_set(get_device()->get_handle(), descriptor_pool, descriptor_set_layout);
update_descriptor_set();
build_command_buffers();

prepared = true;
}

prepare_camera();
generate_cube();
prepare_uniform_buffers();

descriptor_set_layout = create_descriptor_set_layout();
pipeline_layout = get_device()->get_handle().createPipelineLayout({{}, descriptor_set_layout});
pipeline = create_pipeline();

descriptor_pool = create_descriptor_pool();
descriptor_set = vkb::common::allocate_descriptor_set(get_device()->get_handle(), descriptor_pool, descriptor_set_layout);

update_descriptor_set();
build_command_buffers();
prepared = true;
return true;
return prepared;
}

bool HPPDynamicUniformBuffers::resize(const uint32_t width, const uint32_t height)
Expand Down Expand Up @@ -152,18 +151,17 @@ void HPPDynamicUniformBuffers::build_command_buffers()

void HPPDynamicUniformBuffers::render(float delta_time)
{
if (!prepared)
{
return;
}
draw();
if (!paused)
{
update_dynamic_uniform_buffer(delta_time);
}
if (camera.updated)
if (prepared)
{
update_uniform_buffers();
draw();
if (!paused)
{
update_dynamic_uniform_buffer(delta_time);
}
if (camera.updated)
{
update_uniform_buffers();
}
}
}

Expand Down
41 changes: 20 additions & 21 deletions samples/api/hpp_hdr/hpp_hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ HPPHDR::~HPPHDR()

bool HPPHDR::prepare(const vkb::ApplicationOptions &options)
{
if (!HPPApiVulkanSample::prepare(options))
assert(!prepared);
if (HPPApiVulkanSample::prepare(options))
{
return false;
prepare_camera();
load_assets();
prepare_uniform_buffers();
prepare_offscreen_buffer();
descriptor_pool = create_descriptor_pool();
setup_bloom();
setup_composition();
setup_models();
build_command_buffers();

prepared = true;
}

prepare_camera();
load_assets();
prepare_uniform_buffers();
prepare_offscreen_buffer();

descriptor_pool = create_descriptor_pool();
setup_bloom();
setup_composition();
setup_models();
build_command_buffers();
prepared = true;
return true;
return prepared;
}

bool HPPHDR::resize(const uint32_t width, const uint32_t height)
Expand Down Expand Up @@ -210,14 +210,13 @@ void HPPHDR::on_update_ui_overlay(vkb::HPPDrawer &drawer)

void HPPHDR::render(float delta_time)
{
if (!prepared)
{
return;
}
draw();
if (camera.updated)
if (prepared)
{
update_uniform_buffers();
draw();
if (camera.updated)
{
update_uniform_buffers();
}
}
}

Expand Down
42 changes: 20 additions & 22 deletions samples/api/hpp_hello_triangle/hpp_hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,40 +195,38 @@ HPPHelloTriangle::~HPPHelloTriangle()

bool HPPHelloTriangle::prepare(const vkb::ApplicationOptions &options)
{
if (!Application::prepare(options))
if (Application::prepare(options))
{
return false;
}

instance = create_instance({VK_KHR_SURFACE_EXTENSION_NAME}, {});
instance = create_instance({VK_KHR_SURFACE_EXTENSION_NAME}, {});
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
debug_utils_messenger = instance.createDebugUtilsMessengerEXT(debug_utils_create_info);
debug_utils_messenger = instance.createDebugUtilsMessengerEXT(debug_utils_create_info);
#endif

select_physical_device_and_surface();
select_physical_device_and_surface();

const vkb::Window::Extent &extent = options.window->get_extent();
swapchain_data.extent.width = extent.width;
swapchain_data.extent.height = extent.height;
const vkb::Window::Extent &extent = options.window->get_extent();
swapchain_data.extent.width = extent.width;
swapchain_data.extent.height = extent.height;

// create a device
device = create_device({VK_KHR_SWAPCHAIN_EXTENSION_NAME});
// create a device
device = create_device({VK_KHR_SWAPCHAIN_EXTENSION_NAME});

// get the (graphics) queue
queue = device.getQueue(graphics_queue_index, 0);
// get the (graphics) queue
queue = device.getQueue(graphics_queue_index, 0);

init_swapchain();
init_swapchain();

// Create the necessary objects for rendering.
render_pass = create_render_pass();
// Create the necessary objects for rendering.
render_pass = create_render_pass();

// Create a blank pipeline layout.
// We are not binding any resources to the pipeline in this first sample.
pipeline_layout = device.createPipelineLayout({});
// Create a blank pipeline layout.
// We are not binding any resources to the pipeline in this first sample.
pipeline_layout = device.createPipelineLayout({});

pipeline = create_graphics_pipeline();
pipeline = create_graphics_pipeline();

init_framebuffers();
init_framebuffers();
}

return true;
}
Expand Down
60 changes: 30 additions & 30 deletions samples/api/hpp_hlsl_shaders/hpp_hlsl_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,37 @@ HPPHlslShaders::~HPPHlslShaders()

bool HPPHlslShaders::prepare(const vkb::ApplicationOptions &options)
{
if (!HPPApiVulkanSample::prepare(options))
assert(!prepared);

if (HPPApiVulkanSample::prepare(options))
{
return false;
load_assets();
generate_quad();

// Vertex shader uniform buffer block
uniform_buffer_vs = std::make_unique<vkb::core::HPPBuffer>(*get_device(),
sizeof(ubo_vs),
vk::BufferUsageFlagBits::eUniformBuffer,
VMA_MEMORY_USAGE_CPU_TO_GPU);
update_uniform_buffers();

// We separate the descriptor sets for the uniform buffer + image and samplers, so we don't need to duplicate the descriptors for the former
base_descriptor_set_layout = create_base_descriptor_set_layout();
sampler_descriptor_set_layout = create_sampler_descriptor_set_layout();

pipeline_layout = create_pipeline_layout();
shader_modules = {create_shader_module("hlsl_shaders/hlsl_shader.vert", vk::ShaderStageFlagBits::eVertex),
create_shader_module("hlsl_shaders/hlsl_shader.frag", vk::ShaderStageFlagBits::eFragment)};
pipeline = create_pipeline();
descriptor_pool = create_descriptor_pool();
base_descriptor_set = vkb::common::allocate_descriptor_set(get_device()->get_handle(), descriptor_pool, base_descriptor_set_layout);
update_descriptor_sets();
build_command_buffers();

prepared = true;
}
load_assets();
generate_quad();

// Vertex shader uniform buffer block
uniform_buffer_vs = std::make_unique<vkb::core::HPPBuffer>(*get_device(),
sizeof(ubo_vs),
vk::BufferUsageFlagBits::eUniformBuffer,
VMA_MEMORY_USAGE_CPU_TO_GPU);
update_uniform_buffers();

// We separate the descriptor sets for the uniform buffer + image and samplers, so we don't need to duplicate the descriptors for the former
base_descriptor_set_layout = create_base_descriptor_set_layout();
sampler_descriptor_set_layout = create_sampler_descriptor_set_layout();

pipeline_layout = create_pipeline_layout();
shader_modules.push_back(create_shader_module("hlsl_shaders/hlsl_shader.vert", vk::ShaderStageFlagBits::eVertex));
shader_modules.push_back(create_shader_module("hlsl_shaders/hlsl_shader.frag", vk::ShaderStageFlagBits::eFragment));
pipeline = create_pipeline();

descriptor_pool = create_descriptor_pool();
base_descriptor_set = vkb::common::allocate_descriptor_set(get_device()->get_handle(), descriptor_pool, base_descriptor_set_layout);
update_descriptor_sets();

build_command_buffers();
prepared = true;
return true;
return prepared;
}

// Enable physical device features required for this example
Expand Down Expand Up @@ -139,11 +140,10 @@ void HPPHlslShaders::build_command_buffers()

void HPPHlslShaders::render(float delta_time)
{
if (!prepared)
if (prepared)
{
return;
draw();
}
draw();
}

void HPPHlslShaders::view_changed()
Expand Down
58 changes: 29 additions & 29 deletions samples/api/hpp_instancing/hpp_instancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,38 @@ HPPInstancing::~HPPInstancing()

bool HPPInstancing::prepare(const vkb::ApplicationOptions &options)
{
if (!HPPApiVulkanSample::prepare(options))
assert(!prepared);

if (HPPApiVulkanSample::prepare(options))
{
return false;
initialize_camera();
load_assets();
prepare_instance_data();
prepare_uniform_buffers();
vk::Device device = get_device()->get_handle();
descriptor_set_layout = create_descriptor_set_layout();
pipeline_layout = device.createPipelineLayout({{}, descriptor_set_layout});
descriptor_pool = create_descriptor_pool();

// setup planet
planet.pipeline = create_planet_pipeline();
planet.descriptor_set = vkb::common::allocate_descriptor_set(device, descriptor_pool, descriptor_set_layout);
update_planet_descriptor_set();

// setup rocks
rocks.pipeline = create_rocks_pipeline();
rocks.descriptor_set = vkb::common::allocate_descriptor_set(device, descriptor_pool, descriptor_set_layout);
update_rocks_descriptor_set();

// setup starfield
starfield_pipeline = create_starfield_pipeline();

build_command_buffers();

prepared = true;
}

initialize_camera();
load_assets();
prepare_instance_data();
prepare_uniform_buffers();

vk::Device device = get_device()->get_handle();

descriptor_set_layout = create_descriptor_set_layout();
pipeline_layout = device.createPipelineLayout({{}, descriptor_set_layout});
descriptor_pool = create_descriptor_pool();

// setup planet
planet.pipeline = create_planet_pipeline();
planet.descriptor_set = vkb::common::allocate_descriptor_set(device, descriptor_pool, descriptor_set_layout);
update_planet_descriptor_set();

// setup rocks
rocks.pipeline = create_rocks_pipeline();
rocks.descriptor_set = vkb::common::allocate_descriptor_set(device, descriptor_pool, descriptor_set_layout);
update_rocks_descriptor_set();

// setup starfield
starfield_pipeline = create_starfield_pipeline();

build_command_buffers();
prepared = true;
return true;
return prepared;
}

bool HPPInstancing::resize(const uint32_t width, const uint32_t height)
Expand Down
Loading
Loading