Skip to content

API Additions for Object Oriented Language Bindings #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/embree4/rtcore_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ RTC_API RTCBuffer rtcNewBuffer(RTCDevice device, size_t byteSize);
/* Creates a new shared buffer. */
RTC_API RTCBuffer rtcNewSharedBuffer(RTCDevice device, void* ptr, size_t byteSize);

/* Returns if the buffer is a shared buffer. */
RTC_API bool rtcIsBufferShared(RTCBuffer buffer);

/* Returns the size of the buffer in bytes. */
RTC_API size_t rtcGetBufferSize(RTCBuffer buffer);

/* Returns a pointer to the buffer data. */
RTC_API void* rtcGetBufferData(RTCBuffer buffer);

Expand Down
12 changes: 12 additions & 0 deletions include/embree4/rtcore_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,22 @@ typedef void (*RTCErrorFunction)(void* userPtr, enum RTCError code, const char*
/* Sets the error callback function. */
RTC_API void rtcSetDeviceErrorFunction(RTCDevice device, RTCErrorFunction error, void* userPtr);

/* Gets the error callback function pointer. */
RTC_API RTCErrorFunction rtcGetDeviceErrorFunction(RTCDevice device);

/* Gets the error callback function user pointer. */
RTC_API void* rtcGetDeviceErrorFunctionUserPtr(RTCDevice device);

/* Memory monitor callback function */
typedef bool (*RTCMemoryMonitorFunction)(void* ptr, ssize_t bytes, bool post);

/* Sets the memory monitor callback function. */
RTC_API void rtcSetDeviceMemoryMonitorFunction(RTCDevice device, RTCMemoryMonitorFunction memoryMonitor, void* userPtr);

/* Gets the memory monitor callback function pointer. */
RTC_API RTCMemoryMonitorFunction rtcGetDeviceMemoryMonitorFunction(RTCDevice device);

/* Gets the memory monitor callback function user pointer. */
RTC_API void* rtcGetDeviceMemoryMonitorFunctionUserPtr(RTCDevice device);

RTC_NAMESPACE_END
20 changes: 20 additions & 0 deletions include/embree4/rtcore_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ RTC_API void rtcAttachGeometryByID(RTCScene scene, RTCGeometry geometry, unsigne
/* Detaches the geometry from the scene. */
RTC_API void rtcDetachGeometry(RTCScene scene, unsigned int geomID);

/* Gets the number of geometry IDs attached to the scene. To get the array of valid IDs allocate an array of the correct size and pass it as geomIDs. */
RTC_API size_t rtcGetNumAttachedGeometryIDs(RTCScene scene);
RTC_API void rtcGetAttachedGeometryIDs(RTCScene scene, size_t* numGeomIDs, unsigned int* geomIDs RTC_DEFAULT_VALUE(nullptr));

/* Gets the number of geometries attached to the scene. To get the array of valid geometries allocate an array of the correct size and pass it as geometries. */
RTC_API size_t rtcGetNumAttachedGeometries(RTCScene scene);
RTC_API void rtcGetAttachedGeometries(RTCScene scene, size_t* numGeoms, RTCGeometry* geometries RTC_DEFAULT_VALUE(nullptr));

/* Gets a geometry handle from the scene. This function is not thread safe and should get used during rendering. */
RTC_API RTCGeometry rtcGetGeometry(RTCScene scene, unsigned int geomID);

Expand All @@ -121,16 +129,28 @@ RTC_API void rtcCommitScene(RTCScene scene);
/* Commits the scene from multiple threads. */
RTC_API void rtcJoinCommitScene(RTCScene scene);

/* Returns if the scene has been modified since it was last committed. */
RTC_API bool rtcIsSceneModified(RTCScene scene);


/* Progress monitor callback function */
typedef bool (*RTCProgressMonitorFunction)(void* ptr, double n);

/* Sets the progress monitor callback function of the scene. */
RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene scene, RTCProgressMonitorFunction progress, void* ptr);

/* Gets the progress monitor callback function of the scene. */
RTC_API RTCProgressMonitorFunction rtcGetSceneProgressMonitorFunction(RTCScene scene);

/* Gets the progress monitor callback function user pointer of the scene. */
RTC_API void* rtcGetSceneProgressMonitorFunctionUserPtr(RTCScene scene);

/* Sets the build quality of the scene. */
RTC_API void rtcSetSceneBuildQuality(RTCScene scene, enum RTCBuildQuality quality);

/* Gets the build quality of the scene. */
RTC_API enum RTCBuildQuality rtcGetSceneBuildQuality(RTCScene scene);

/* Sets the scene flags. */
RTC_API void rtcSetSceneFlags(RTCScene scene, enum RTCSceneFlags flags);

Expand Down
15 changes: 15 additions & 0 deletions kernels/common/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ namespace embree
__forceinline size_t bytes() const {
return numBytes;
}

/*! returns the number of bytes of the buffer */
__forceinline bool isShared() const {
return shared;
}

/*! returns true of the buffer is not empty */
__forceinline operator bool() const {
Expand Down Expand Up @@ -215,6 +220,16 @@ namespace embree
volatile int MAYBE_UNUSED w = *((int*)getPtr(size()-1)+3); // FIXME: is failing hard avoidable?
}

/*! returns the buffer object */
__forceinline Ref<Buffer> getBuffer() {
return buffer;
}

/*! returns the offset of the view from the base pointer */
__forceinline size_t getOffset() const {
return ptr_ofs - buffer->getPtr();
}

public:
char* ptr_ofs; //!< base pointer plus offset
size_t stride; //!< stride of the buffer in bytes
Expand Down
196 changes: 196 additions & 0 deletions kernels/common/rtcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END(device);
}

RTC_API RTCErrorFunction rtcGetDeviceErrorFunction(RTCDevice hdevice)
{
Device* device = (Device*) hdevice;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetDeviceErrorFunction);
RTC_VERIFY_HANDLE(hdevice);
return device->getErrorFunction();
RTC_CATCH_END(device);
return nullptr;
}

RTC_API void* rtcGetDeviceErrorFunctionUserPtr(RTCDevice hdevice)
{
Device* device = (Device*) hdevice;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetDeviceErrorFunctionUserPtr);
RTC_VERIFY_HANDLE(hdevice);
return device->getErrorFunctionUserPtr();
RTC_CATCH_END(device);
return nullptr;
}

RTC_API void rtcSetDeviceMemoryMonitorFunction(RTCDevice hdevice, RTCMemoryMonitorFunction memoryMonitor, void* userPtr)
{
Device* device = (Device*) hdevice;
Expand All @@ -172,6 +194,28 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END(device);
}

RTC_API RTCMemoryMonitorFunction rtcGetDeviceMemoryMonitorFunction(RTCDevice hdevice)
{
Device* device = (Device*) hdevice;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetDeviceMemoryMonitorFunction);
RTC_VERIFY_HANDLE(hdevice);
return device->getMemoryMonitorFunction();
RTC_CATCH_END(device);
return nullptr;
}

RTC_API void* rtcGetDeviceMemoryMonitorFunctionUserPtr(RTCDevice hdevice)
{
Device* device = (Device*) hdevice;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetDeviceMemoryMonitorFunctionUserPtr);
RTC_VERIFY_HANDLE(hdevice);
return device->getMemoryMonitorFunctionUserPtr();
RTC_CATCH_END(device);
return nullptr;
}

RTC_API RTCBuffer rtcNewBuffer(RTCDevice hdevice, size_t byteSize)
{
RTC_CATCH_BEGIN;
Expand All @@ -196,6 +240,30 @@ RTC_NAMESPACE_BEGIN;
return nullptr;
}

RTC_API bool rtcIsBufferShared(RTCBuffer hbuffer)
{
Buffer* buffer = (Buffer*)hbuffer;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcIsBufferShared);
RTC_VERIFY_HANDLE(hbuffer);
RTC_ENTER_DEVICE(hbuffer);
return buffer->isShared();
RTC_CATCH_END2(buffer);
return false;
}

RTC_API size_t rtcGetBufferSize(RTCBuffer hbuffer)
{
Buffer* buffer = (Buffer*)hbuffer;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetBufferSize);
RTC_VERIFY_HANDLE(hbuffer);
RTC_ENTER_DEVICE(hbuffer);
return buffer->bytes();
RTC_CATCH_END2(buffer);
return 0;
}

RTC_API void* rtcGetBufferData(RTCBuffer hbuffer)
{
Buffer* buffer = (Buffer*)hbuffer;
Expand Down Expand Up @@ -265,6 +333,32 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END2(scene);
}

RTC_API RTCProgressMonitorFunction rtcGetSceneProgressMonitorFunction(RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetSceneProgressMonitorFunction);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
Lock<MutexSys> lock(g_mutex);
return scene->getProgressMonitorFunction();
RTC_CATCH_END2(scene);
return nullptr;
}

RTC_API void* rtcGetSceneProgressMonitorFunctionUserPtr(RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetSceneProgressMonitorFunctionUserPtr);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
Lock<MutexSys> lock(g_mutex);
return scene->getProgressMonitorFunctionUserPtr();
RTC_CATCH_END2(scene);
return nullptr;
}

RTC_API void rtcSetSceneBuildQuality (RTCScene hscene, RTCBuildQuality quality)
{
Scene* scene = (Scene*) hscene;
Expand All @@ -280,6 +374,18 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END2(scene);
}

RTC_API RTCBuildQuality rtcGetSceneBuildQuality (RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetSceneBuildQuality);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
return scene->getBuildQuality();
RTC_CATCH_END2(scene);
return RTC_BUILD_QUALITY_MEDIUM;
}

RTC_API void rtcSetSceneFlags (RTCScene hscene, RTCSceneFlags flags)
{
Scene* scene = (Scene*) hscene;
Expand Down Expand Up @@ -332,6 +438,18 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END2(scene);
}

RTC_API bool rtcIsSceneModified(RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcIsSceneModified);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
return scene->isModified();
RTC_CATCH_END2(scene);
return false;
}

RTC_API void rtcGetSceneBounds(RTCScene hscene, RTCBounds* bounds_o)
{
Scene* scene = (Scene*) hscene;
Expand Down Expand Up @@ -2041,6 +2159,84 @@ RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeSte
RTC_CATCH_END2(geometry);
}

RTC_API size_t rtcGetNumAttachedGeometryIDs (RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetNumAttachedGeometryIDs);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
unsigned int numGeomIDs = scene->size();
for (unsigned int i = 0; i < scene->size(); ++i) {
Geometry* ptr = scene->get(i);
if (!ptr) {
numGeomIDs -= 1;
}
}
return numGeomIDs;
RTC_CATCH_END2(scene);
return 0;
}

RTC_API void rtcGetAttachedGeometryIDs (RTCScene hscene, size_t* numGeomIDs, unsigned int* geomIDs)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetAttachedGeometryIDs);
RTC_VERIFY_HANDLE(hscene);
RTC_VERIFY_HANDLE(numGeomIDs);
RTC_ENTER_DEVICE(hscene);
*numGeomIDs = scene->size();
for (unsigned int i = 0; i < scene->size(); ++i) {
Geometry* ptr = scene->get(i);
if (!ptr) {
*numGeomIDs -= 1;
} else if (geomIDs) {
*geomIDs++ = i;
}
}
RTC_CATCH_END2(scene);
}

RTC_API size_t rtcGetNumAttachedGeometries (RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetNumAttachedGeometryIDs);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
unsigned int numGeomIDs = scene->size();
for (unsigned int i = 0; i < scene->size(); ++i) {
Geometry* ptr = scene->get(i);
if (!ptr) {
numGeomIDs -= 1;
}
}
return numGeomIDs;
RTC_CATCH_END2(scene);
return 0;
}

RTC_API void rtcGetAttachedGeometries (RTCScene hscene, size_t* numGeoms, RTCGeometry* geometries)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetAttachedGeometries);
RTC_VERIFY_HANDLE(hscene);
RTC_VERIFY_HANDLE(numGeoms);
RTC_ENTER_DEVICE(hscene);
*numGeoms = scene->size();
for (unsigned int i = 0; i < scene->size(); ++i) {
Geometry* ptr = scene->get(i);
if (!ptr) {
*numGeoms -= 1;
} else if (geometries) {
*geometries++ = (RTCGeometry) ptr;
}
}
RTC_CATCH_END2(scene);
}

RTC_API RTCGeometry rtcGetGeometry (RTCScene hscene, unsigned int geomID)
{
Scene* scene = (Scene*) hscene;
Expand Down
10 changes: 10 additions & 0 deletions kernels/common/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,16 @@ namespace embree
progress_monitor_ptr = ptr;
}

RTCProgressMonitorFunction Scene::getProgressMonitorFunction() const
{
return progress_monitor_function;
}

void* Scene::getProgressMonitorFunctionUserPtr() const
{
return progress_monitor_ptr;
}

void Scene::progressMonitor(double dn)
{
if (progress_monitor_function) {
Expand Down
2 changes: 2 additions & 0 deletions kernels/common/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ namespace embree
std::atomic<size_t> progress_monitor_counter;
void progressMonitor(double nprims);
void setProgressMonitorFunction(RTCProgressMonitorFunction func, void* ptr);
RTCProgressMonitorFunction getProgressMonitorFunction() const;
void* getProgressMonitorFunctionUserPtr() const;

private:
GeometryCounts world; //!< counts for geometry
Expand Down
Loading