
local elapsed_time = gh_utils.get_elapsed_time()





if (gh_vk.swapchain_has_changed() == 1) then
  if (fixed_rt_size == 0) then

    rt_w = winW
    rt_h = winH

    gh_render_target.kill(rt01)
    rt01 = gh_render_target.create(rt_w, rt_h)


    local tex_binding_point = 1
    local color_index = 0
    gh_vk.descriptorset_update_resource_rt_color(ds2, rt_tex_res_index, rt01, color_index, sampler1, tex_binding_point, SHADER_STAGE_FRAGMENT)
    gh_vk.descriptorset_update(ds2)

  end
end







gh_object.set_euler_angles(mesh, elapsed_time * 3.0, elapsed_time * 7.0, elapsed_time * 11.0)
UpdateMeshTransform(ub1, mesh)

gh_object.set_euler_angles(quad, elapsed_time * 7.0, elapsed_time * 11.0, elapsed_time * 17.0)
UpdateMesh2Transform(ub1, quad)




-- Ortho cam for the background texture.
local w2 = rt_w/2
local h2 = rt_h/2
gh_camera.update_ortho(camera_ortho, -w2, w2, -h2, h2, 1.0, 10.0)
gh_camera.set_viewport(camera_ortho, 0, 0, rt_w, rt_h)
UpdateCameraOrtho1Transform(ub1, camera_ortho)



-- Perspective camera settings for drawingf the torus in the render target
--
local aspect = rt_w / rt_h
gh_camera.update_persp(camera, camera_params.fov, aspect, camera_params.znear, camera_params.zfar)
gh_camera.set_viewport(camera, 0, 0, rt_w, rt_h)
gh_camera.set_position(camera, 0, 5, 15)
gh_camera.set_lookat(camera, 0, 0, 0, 1)
UpdateCamera1Transform(ub1, camera)



-- Perspective camera settings for drawing the box that displays the render target texture on all faces.
--
aspect = winW / winH
gh_camera.update_persp(camera, camera_params.fov, aspect, camera_params.znear, camera_params.zfar)
gh_camera.set_viewport(camera, 0, 0, winW, winH)
gh_camera.set_position(camera, 0, 0, 10)
gh_camera.set_lookat(camera, 0, 0, 0, 1)
UpdateCamera2Transform(ub1, camera)







gh_vk.clear_color_depth_buffers(0.0, 0.8, 0.0, 1.0, 1.0)
gh_render_target.bind(rt01)

gh_vk.set_viewport_scissor(0, 0, rt_w, rt_h)

gh_vk.descriptorset_bind(ds1)
gh_vk.pipeline_bind(pso03)
gh_object.render(fullscreen_quad)

gh_vk.descriptorset_bind(ds1)
gh_vk.pipeline_bind(pso01)
gh_object.render(mesh)

gh_render_target.unbind(rt01)

gh_render_target.execute_cmd_buffer(rt01)













gh_vk.command_buffer_begin(cmd)

gh_vk.clear_color_depth_buffers(0.3, 0.3, 0.35, 1.0, 1.0)
gh_vk.render_pass_begin(cmd, 0)
   

gh_vk.set_viewport_scissor(0, 0, winW, winH)

gh_vk.descriptorset_bind(ds2)
gh_vk.pipeline_bind(pso02)
gh_object.render(quad)


gh_vk.render_pass_end(cmd)
gh_vk.command_buffer_end(cmd)
gh_vk.command_buffer_execute(cmd)

