// Copyright 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "common/FeatureFlags.ih"

OSPRAY_BEGIN_ISPC_NAMESPACE

// Geometries are supposed to fill certain members of DifferentialGeometry:
// calculate Ng, Ns, st, color, and materialID if the respective bit DG_NG,
// DG_NS, DG_TEXCOORD, DG_COLOR, and DG_MATERIALID, in flags is set.
// Important with instancing: P and ray are in world-coordinates, whereas Ng
// and Ns are in object-coordinates and transformed to world-space by
// Instance_postIntersect.
// World::postIntersect already set the hit point P, color, geometry, and
// material before, and handles normalization/faceforwarding
// (DG_NORMALIZE/DG_FACEFORWARD) after Geometry_postIntersectFct is called.
// Thus the material pointer only needs to be set if different to
// geometry->material, or the color when different to vec4f(1.0f).
SYCL_EXTERNAL void Geometry_dispatch_postIntersect(const Geometry *uniform self,
    varying DifferentialGeometry &dg,
    const varying Ray &ray,
    uniform int64 flags,
    const uniform FeatureFlagsHandler &ffh);

// sample the given primitive uniformly wrt. area
SYCL_EXTERNAL SampleAreaRes Geometry_dispatch_sampleArea(
    const Geometry *const uniform,
    const int32 primID,
    const uniform affine3f &xfm, // instance transformation (obj2world)
    const uniform affine3f &rcp_xfm, // inverse transformation (world2obj)
    const vec2f &s, // random numbers to generate the sample
    const float time, // for deformation motion blur
    const uniform FeatureFlagsHandler &ffh);

RTC_SYCL_INDIRECTLY_CALLABLE unmasked void Geometry_dispatch_intersect(
    RTCIntersectFunctionNArguments *uniform args);

RTC_SYCL_INDIRECTLY_CALLABLE unmasked void Geometry_dispatch_occluded(
    RTCOccludedFunctionNArguments *uniform args);

OSPRAY_END_ISPC_NAMESPACE
