// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "../common/math/random_sampler.isph"
#include "../common/math/sampling.isph"
#include "../common/core/differential_geometry.isph"
#include "../common/tutorial/tutorial_device.isph"
#include "../common/tutorial/scene_device.h"
#include "../common/tutorial/optics.isph"

extern uniform ISPCScene* uniform g_ispc_scene;
extern uniform int g_instancing_mode;
extern uniform int g_spp;
extern uniform int g_max_path_length;
extern uniform bool g_accumulate;
extern uniform bool g_changed;

struct TutorialData
{
  uniform ISPCScene* uniform ispc_scene;
  uniform int instancing_mode;
  RTCRayQueryFlags iflags_coherent;
  RTCRayQueryFlags iflags_incoherent;

  RTCFilterFunctionN occlusionFilterOpaque;
  RTCFilterFunctionN occlusionFilterHair;
  
  uniform int spp;
  uniform int max_path_length;

  /* accumulation buffer */
  uniform Vec3ff* uniform accu;
  uniform unsigned int accu_width;
  uniform unsigned int accu_height;
  uniform unsigned int accu_count;
  
  uniform bool animation;
  uniform bool use_smooth_normals;
  
  /* scene data */
  RTCScene scene;
};

void TutorialData_Constructor(uniform TutorialData* uniform This)
{
  This->ispc_scene = g_ispc_scene;
  This->instancing_mode = g_instancing_mode;
  This->iflags_coherent = g_iflags_coherent;
  This->iflags_incoherent = g_iflags_incoherent;

  This->occlusionFilterOpaque = NULL;
  This->occlusionFilterHair = NULL; 
  
  This->spp = g_spp;
  This->max_path_length = g_max_path_length;

  This->accu = NULL;
  This->accu_width = 0;
  This->accu_height = 0;
  This->accu_count = 0;

  This->animation = true;
  This->use_smooth_normals = false;
        
  This->scene = NULL;
}

void TutorialData_Destructor(uniform TutorialData* uniform This)
{
  rtcReleaseScene (This->scene); This->scene = NULL;
  delete[] This->accu; This->accu = NULL;
  This->accu_width = 0;
  This->accu_height = 0;
  This->accu_count = 0;
}
