void vkeGameRendererDynamic::generateDrawCommands(){

	//Start generating draw commands.

	VulkanDC *dc = VulkanDC::Get();
	VulkanDC::Device *device = dc->getDefaultDevice();
	VkClearValue clearValues[3];

	colorClearValues(&clearValues[0], 1.0, 1.0, 1.0);
	depthStencilClearValues(&clearValues[1]);//default#
	colorClearValues(&clearValues[2], 0.0, 0.0, 0.0);

	/*
	Dispatch threads to create the secondary
	command buffers.
	*/
	m_calls_generated = 0;
	for (uint32_t i = 0; i < m_max_draw_calls; ++i){
		m_draw_calls[i]->initDrawCommands(m_node_data->count(), m_current_buffer_index);
	}

	/*
	Begin setting up the primary command buffer.
	*/
	VkCommandBufferBeginInfo cmdBeginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
	cmdBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;

	VKA_CHECK_ERROR(vkResetCommandBuffer(m_primary_commands[m_current_buffer_index], 0),"Could not reset primary command buffer");
	VKA_CHECK_ERROR(vkBeginCommandBuffer(m_primary_commands[m_current_buffer_index], &cmdBeginInfo), "Could not begin primary command buffer.\n");


	uint32_t cnt = m_node_data->count();
	VkDeviceSize sz = (sizeof(VkeNodeUniform) * cnt) + (m_instance_count * 64);
	vkCmdUpdateBuffer(m_primary_commands[m_current_buffer_index], m_uniforms_buffer, 0, sz, (const uint32_t *)m_uniforms_local);
	m_camera->updateCameraCmd(m_primary_commands[m_current_buffer_index]);


	renderPassBegin(&m_primary_commands[m_current_buffer_index], m_render_pass, m_framebuffers[m_current_buffer_index], 0, 0, m_width, m_height, clearValues, 3, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);


	VkViewport vp;
	VkRect2D sc;
	vp.x = 0;
	vp.y = 0;
	vp.height = (float)(m_height);
	vp.width = (float)(m_width);
	vp.minDepth = 0.0f;
	vp.maxDepth = 1.0f;

	sc.offset.x = 0;
	sc.offset.y = 0;
	sc.extent.width = vp.width;
	sc.extent.height = vp.height;

	vkCmdSetViewport(m_primary_commands[m_current_buffer_index], 0, 1, &vp);
	vkCmdSetScissor(m_primary_commands[m_current_buffer_index], 0, 1, &sc);

	/*
	Wait here until the secondary commands are ready.
	*/

	VkCommandBuffer secondaryCommands[11];
	secondaryCommands[0] = m_terrain_command[m_current_buffer_index];
	for (uint32_t i = 0; i < m_max_draw_calls; ++i){
		secondaryCommands[i+1] = m_draw_calls[i]->getDrawCommand(m_current_buffer_index);
	}


	vkCmdExecuteCommands(m_primary_commands[m_current_buffer_index],  1+m_max_draw_calls, secondaryCommands);

	vkCmdEndRenderPass(m_primary_commands[m_current_buffer_index]);

	VkImageResolve blitInfo;
    blitInfo.srcOffset.x = 0;
	blitInfo.srcOffset.y = 0;
	blitInfo.srcOffset.z = 0;
	blitInfo.dstOffset.x = 0;
	blitInfo.dstOffset.y = 0;
	blitInfo.dstOffset.z = 0;
    blitInfo.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
    blitInfo.srcSubresource.mipLevel = 0;
    blitInfo.srcSubresource.baseArrayLayer = 0;
    blitInfo.srcSubresource.layerCount = 1;
    blitInfo.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
    blitInfo.dstSubresource.mipLevel = 0;
    blitInfo.dstSubresource.baseArrayLayer = 0;
    blitInfo.dstSubresource.layerCount = 1;
    blitInfo.extent.width = m_width;
    blitInfo.extent.height = m_height;
    blitInfo.extent.depth = 1;

	vkCmdResolveImage(
		m_primary_commands[m_current_buffer_index],
		m_color_attachment.image,
		VK_IMAGE_LAYOUT_GENERAL,
		m_resolve_attachment[m_current_buffer_index].image,
		VK_IMAGE_LAYOUT_GENERAL,
		1,
		&blitInfo);


	VKA_CHECK_ERROR(vkEndCommandBuffer(m_primary_commands[m_current_buffer_index]), "Could not end command buffer for draw command.\n");

}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void RendererVk::display(const InertiaCamera& camera, const mat4f& projection)
{
    PROFILE_SECTION("RendererVk::display");
    if(m_bValid == false) return;
    //NXPROFILEFUNC(__FUNCTION__);
    //
    // Update general params for all sub-sequent operations IN CMD BUFFER #1
    //
    g_globalMatrices.mV = camera.m4_view;
    g_globalMatrices.mP = projection;
    float w = (float)m_nvFBOBox.getBufferWidth();
    float h = (float)m_nvFBOBox.getBufferHeight();
    VkRenderPass    renderPass  = m_nvFBOBox.getScenePass();
    VkFramebuffer   framebuffer = m_nvFBOBox.getFramebuffer();
    NVK::VkRect2D   viewRect    = m_nvFBOBox.getViewRect();
    //
    // Create the primary command buffer
    //
    //
    // pingpong between 2 cmd-buffers to avoid waiting for them to be done
    //
    m_cmdSceneIdx ^= 1;
    if(m_cmdScene[m_cmdSceneIdx])
    {
        while(nvk.vkWaitForFences(1, &m_sceneFence[m_cmdSceneIdx], VK_TRUE, 100000000) == false) { }
        nvk.vkResetFences(1, &m_sceneFence[m_cmdSceneIdx]);
        nvk.vkFreeCommandBuffer(m_cmdPool, m_cmdScene[m_cmdSceneIdx]);
        m_cmdScene[m_cmdSceneIdx] = NULL;
    }
    m_cmdScene[m_cmdSceneIdx] = nvk.vkAllocateCommandBuffer(m_cmdPool, true);
    nvk.vkBeginCommandBuffer(m_cmdScene[m_cmdSceneIdx], false, NVK::VkCommandBufferInheritanceInfo(renderPass, 0, framebuffer, VK_FALSE, 0, 0) );
    vkCmdBeginRenderPass(m_cmdScene[m_cmdSceneIdx],
        NVK::VkRenderPassBeginInfo(
        renderPass, framebuffer, viewRect,
            NVK::VkClearValue(NVK::VkClearColorValue(0.0f, 0.1f, 0.15f, 1.0f))
                             (NVK::VkClearDepthStencilValue(1.0, 0))), 
        VK_SUBPASS_CONTENTS_INLINE );
    vkCmdUpdateBuffer       (m_cmdScene[m_cmdSceneIdx], m_matrix.buffer, 0, sizeof(g_globalMatrices), (uint32_t*)&g_globalMatrices);
    //
    // render the mesh
    //
    vkCmdBindPipeline(m_cmdScene[m_cmdSceneIdx], VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelinefur); 
    vkCmdSetViewport( m_cmdScene[m_cmdSceneIdx], 0, 1, NVK::VkViewport(0.0, 0.0, w, h, 0.0f, 1.0f) );
    vkCmdSetScissor(  m_cmdScene[m_cmdSceneIdx], 0, 1, NVK::VkRect2D(0.0, 0.0, w, h) );
    VkDeviceSize vboffsets[1] = {0};
    vkCmdBindVertexBuffers(m_cmdScene[m_cmdSceneIdx], 0, 1, &m_furBuffer.buffer, vboffsets);
    //
    // bind the descriptor set for global stuff
    //
    vkCmdBindDescriptorSets(m_cmdScene[m_cmdSceneIdx], VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, DSET_GLOBAL, 1, &m_descriptorSetGlobal, 0, NULL);

    vkCmdDraw(m_cmdScene[m_cmdSceneIdx], m_nElmts, 1, 0, 0);
    //
    //
    //
    vkCmdEndRenderPass(m_cmdScene[m_cmdSceneIdx]);
    vkEndCommandBuffer(m_cmdScene[m_cmdSceneIdx]);

    const VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
    nvk.vkQueueSubmit( NVK::VkSubmitInfo(
        1, &m_semOpenGLReadDone, &waitStages,
        1, &m_cmdScene[m_cmdSceneIdx], 
        1, &m_semVKRenderingDone),  
      m_sceneFence[m_cmdSceneIdx]
    );
    //
    // this is going to issue another command-buffer
    //
    m_nvFBOBox.Draw(downsamplingMode);

    w = m_nvFBOBox.getWidth();
    h = m_nvFBOBox.getHeight();
    // NO Depth test
    glDisable(GL_DEPTH_TEST);
    //
    // Wait for the queue of Our VK rendering to signal m_semVKRenderingDone so we know the image is ready
    //
    glWaitVkSemaphoreNV((GLuint64)m_semVKRenderingDone);
    //
    // Blit the image
    //
    glDrawVkImageNV((GLuint64)m_nvFBOBox.getColorImage(), 0, 0,0,w,h, 0, 0,1,1,0);
    //
    // Signal m_semOpenGLReadDone to tell the VK rendering queue that it can render the next one
    //
    glSignalVkSemaphoreNV((GLuint64)m_semOpenGLReadDone);
    //
    // Depth test back to ON (assuming we needed to put it back)
    //
    glEnable(GL_DEPTH_TEST);
}