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

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

extern uniform float cube_vertices[8][4];
extern uniform unsigned int cube_triangle_indices[36];
extern uniform unsigned int cube_quad_indices[24];
  
struct Sphere
{
  ALIGNED_STRUCT_(16)
  Vec3f p;                      //!< position of the sphere
  float r;                      //!< radius of the sphere
  unsigned int geomID;
  unsigned int num_time_steps;
};

struct TutorialData
{
  uniform int frameID;
  
  RTCScene g_scene;
  uniform Vec3f* uniform face_colors;
  uniform float g_time;
  
  /* accumulation buffer */
  uniform Vec3ff* uniform g_accu;
  uniform unsigned int g_accu_width;
  uniform unsigned int g_accu_height;
  uniform unsigned int g_accu_count;
  uniform Vec3f g_accu_vx;
  uniform Vec3f g_accu_vy;
  uniform Vec3f g_accu_vz;
  uniform Vec3f g_accu_p;

  float* cube_vertices;
  int* cube_triangle_indices;
  int* cube_quad_indices;

  RTCScene scene0;
  RTCScene scene1;
  RTCScene scene2;
  RTCScene scene3;
  uniform Sphere* uniform sphere0;
  uniform Sphere* uniform sphere1;
};

#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

inline void TutorialData_Constructor(uniform TutorialData* uniform This)
{
  This->frameID = 50;
  This->g_scene = NULL;
  This->face_colors = uniform new uniform Vec3f[12];
  This->g_time = 0;
  This->g_accu = NULL;
  This->g_accu_width = 0;
  This->g_accu_height = 0;
  This->g_accu_count = 0;
  This->g_accu_vx = make_Vec3f(0.0f);
  This->g_accu_vy = make_Vec3f(0.0f);
  This->g_accu_vz = make_Vec3f(0.0f);
  This->g_accu_p  = make_Vec3f(0.0f);

  This->scene0 = NULL;
  This->scene1 = NULL;
  This->scene2 = NULL;
  This->scene3 = NULL;
  This->sphere0 = NULL;
  This->sphere1 = NULL;

  This->cube_vertices = uniform new uniform float[8*4];
  This->cube_triangle_indices = uniform new uniform int[36];
  This->cube_quad_indices = uniform new uniform int[24];

  memcpy(This->cube_vertices, cube_vertices, 8*4*sizeof(uniform float));
  memcpy(This->cube_triangle_indices, cube_triangle_indices, 36*sizeof(uniform int));
  memcpy(This->cube_quad_indices, cube_quad_indices, 24*sizeof(uniform int));
}

inline void TutorialData_Destructor(uniform TutorialData* uniform This)
{
  delete[] This->face_colors; This->face_colors = NULL;
  delete This->sphere0; This->sphere0 = NULL;
  delete This->sphere1; This->sphere1 = NULL;
  rtcReleaseScene(This->scene0); This->scene0 = NULL;
  rtcReleaseScene(This->scene1); This->scene1 = NULL;
  rtcReleaseScene(This->scene2); This->scene2 = NULL;
  rtcReleaseScene(This->scene3); This->scene3 = NULL;
  rtcReleaseScene (This->g_scene); This->g_scene = NULL;
  delete[] This->g_accu; This->g_accu = NULL;
  This->g_accu_width = 0;
  This->g_accu_height = 0;
  This->g_accu_count = 0;
  delete[] This->cube_vertices;
  delete[] This->cube_triangle_indices;
  delete[] This->cube_quad_indices;
}
