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

#include "../common/tutorial/tutorial_device.isph"
#include "../common/tutorial/scene_device.h"

extern uniform ISPCScene* uniform g_ispc_scene;
extern uniform Vec3fa g_dirlight_direction;
extern uniform Vec3fa g_dirlight_intensity;
extern uniform Vec3fa g_ambient_intensity;

struct TutorialData
{
  RTCScene scene;
  uniform ISPCScene* uniform ispc_scene;
  uniform Vec3f dirlight_direction;
  uniform Vec3f dirlight_intensity;
  uniform Vec3f ambient_intensity;
  
  /* accumulation buffer */
  uniform Vec3ff* uniform accu;
  uniform unsigned int accu_width;
  uniform unsigned int accu_height;
  uniform unsigned int accu_count;
  uniform Vec3f accu_vx;
  uniform Vec3f accu_vy;
  uniform Vec3f accu_vz;
  uniform Vec3f accu_p;
  uniform bool g_subdiv_mode;

  /* hair material */
  uniform Vec3f hair_K;
  uniform Vec3f hair_dK;
  uniform Vec3f hair_Kr;    //!< reflectivity of hair
  uniform Vec3f hair_Kt;    //!< transparency of hair
};

#if __SYCL_COMPILER_VERSION >= 20210801
}
namespace sycl {
  template<> struct is_device_copyable<embree::TutorialData> : std::true_type {};
  template<> struct is_device_copyable<const embree::TutorialData> : std::true_type {};
}
namespace embree {
#endif

void TutorialData_Constructor(uniform TutorialData* uniform This)
{
  This->scene = NULL;
  This->ispc_scene = g_ispc_scene;
  This->dirlight_direction = make_Vec3f(g_dirlight_direction);
  This->dirlight_intensity = make_Vec3f(g_dirlight_intensity);
  This->ambient_intensity = make_Vec3f(g_ambient_intensity);
  This->accu = NULL;
  This->accu_width = 0;
  This->accu_height = 0;
  This->accu_count = 0;
  This->g_subdiv_mode = false;
  
  /* initialize last seen camera */
  This->accu_vx = make_Vec3f(0.0f);
  This->accu_vy = make_Vec3f(0.0f);
  This->accu_vz = make_Vec3f(0.0f);
  This->accu_p  = make_Vec3f(0.0f);

  /* initialize hair colors */
  This->hair_K  = make_Vec3f(0.8f,0.57f,0.32f);
  This->hair_dK = make_Vec3f(0.1f,0.12f,0.08f);
  This->hair_Kr = 0.2f*This->hair_K;    //!< reflectivity of hair
  This->hair_Kt = 0.8f*This->hair_K;    //!< transparency of hair
}

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;
}
