Context Creation

The Context Creation tutorial covers creating a basic RPR context.

The rpr_context object is a base object for all rendering operations. Creating a context normally takes the three steps:

  1. Register the plug-in backends to be used for rendering. For now, this is Northstar for offline rendering or Hybrid for real-time rendering.

  2. Create an rpr_context object with rprCreateContext(). When creating a context, you can specify the devices to be used for rendering, as well as other context constant parameters.

  3. Set the active plug-in for rendering on the context.


Every RPR call should be checked for a return value as this tutorial code does by wrapping each RPR call with the CHECK() function.

// The RPR context object
rpr_context context = nullptr;

// Register the RPR plug-in.  This must be done before context creation.
rpr_int pluginID = rprRegisterPlugin(RPR_PLUGIN_FILE_NAME); 
CHECK_NE(pluginID , -1)
rpr_int plugins[] = {pluginID };
size_t pluginCount = sizeof(plugins) / sizeof(plugins[0]);

// Create context using a single GPU
// Note that multiple GPUs can be enabled, for example with RPR_CREATION_FLAGS_ENABLE_GPU0 | RPR_CREATION_FLAGS_ENABLE_GPU1
CHECK(rprCreateContext(RPR_API_VERSION, plugins, pluginCount, RPR_CREATION_FLAGS_ENABLE_GPU0, NULL, NULL, &context) );

// Set the active plugin
CHECK(rprContextSetActivePlugin(context, plugins[0]) );

See full code

There are additional steps we can perform as part of this tutorial to play with the created context:

  1. Output the name of the GPU.

  2. Delete the created context object to release memory.

char deviceName_gpu0[1024]; deviceName_gpu0[0] = 0;
CHECK(rprContextGetInfo(context,RPR_CONTEXT_GPU0_NAME, sizeof(deviceName_gpu0), deviceName_gpu0, 0) );

// Output the name of the GPU  
std::cout << "GPU0 name : " << std::string(deviceName_gpu0) << std::endl;

// Release the stuff we created
CheckNoLeak(context);CHECK(rprObjectDelete(context));context=nullptr; // Always delete the RPR Context at the end.

See full code