#include "primeCommon.h"
#include
#include
#include
#include
using namespace std;
int main()
{
//
// Create Prime context
//
RTPcontexttype contextType = RTP_CONTEXT_TYPE_CUDA;
RTPcontext context;
CHK_PRIME(rtpContextCreate(contextType, &context));
unsigned int device = 0;
CHK_PRIME(rtpContextSetCudaDeviceNumbers(context, 1, &device));
//
// Create buffers for geometry data
//
int3 triIndex = { 0,2,1 };
int numTri = 1;
//index
RTPbufferdesc indicesDesc;
CHK_PRIME(rtpBufferDescCreate(
context,
RTP_BUFFER_FORMAT_INDICES_INT3,
RTP_BUFFER_TYPE_HOST,
&triIndex,
&indicesDesc)
);
CHK_PRIME(rtpBufferDescSetRange(indicesDesc, 0, 1));
//vertex
float3 vert[3] = { make_float3(0.0,0.0,0.0), make_float3(1.0,0.0,0.0), make_float3(1.0,1.0,0.0) };
RTPbufferdesc verticesDesc;
CHK_PRIME(rtpBufferDescCreate(
context,
RTP_BUFFER_FORMAT_VERTEX_FLOAT3,
RTP_BUFFER_TYPE_HOST,
&vert,
&verticesDesc)
);
CHK_PRIME(rtpBufferDescSetRange(verticesDesc, 0, 3));
//
// Create the Model object
//
RTPmodel model;
CHK_PRIME(rtpModelCreate(context, &model));
CHK_PRIME(rtpModelSetTriangles(model, indicesDesc, verticesDesc));
CHK_PRIME(rtpModelUpdate(model, 0));
//
// Create buffer for ray input
//
RTPbuffertype bufferType = RTP_BUFFER_TYPE_HOST;
RTPbufferdesc raysDesc;
Buffer raysBuffer(0, bufferType, LOCKED);
Ray r = { make_float3(0.3,0.3,- 0.1),0.0,make_float3(0.0,0.0,0.99),1e34f };
raysBuffer.alloc(1);
Ray *p = raysBuffer.ptr();
p[0] = r;
CHK_PRIME(rtpBufferDescCreate(
context,
Ray::format, /*RTP_BUFFER_FORMAT_RAY_ORIGIN_TMIN_DIRECTION_TMAX*/
raysBuffer.type(),
raysBuffer.ptr(),
&raysDesc)
);
CHK_PRIME(rtpBufferDescSetRange(raysDesc, 0, raysBuffer.count()));
//
// Create buffer for returned hit descriptions
//
RTPbufferdesc hitsDesc;
Buffer hitsBuffer(raysBuffer.count(), bufferType, LOCKED);
CHK_PRIME(rtpBufferDescCreate(
context,
Hit::format, /*RTP_BUFFER_FORMAT_HIT_T_TRIID_U_V*/
hitsBuffer.type(),
hitsBuffer.ptr(),
&hitsDesc)
);
CHK_PRIME(rtpBufferDescSetRange(hitsDesc, 0, hitsBuffer.count()));
//
// Execute query
//
RTPquery query;
CHK_PRIME(rtpQueryCreate(model, RTP_QUERY_TYPE_CLOSEST, &query));
CHK_PRIME(rtpQuerySetRays(query, raysDesc));
CHK_PRIME(rtpQuerySetHits(query, hitsDesc));
CHK_PRIME(rtpQueryExecute(query, 0 /* hints */));
int totalHit=0;
Hit* hits = hitsBuffer.ptr();
for (int i = 0; i < 1; i++)
{
if (hits[i].t > 0.0 && hits[i].t <= 1e34f)
totalHit++;
}
cout << totalHit << endl;
//
// cleanup
//
CHK_PRIME(rtpContextDestroy(context));
}