The C++ API

The nsi.hpp file provides C++ wrappers which are less tedious to use than the low level C interface. All the functionality is inline so no additional libraries are needed and there are no abi issues to consider.

Creating a Context

The core of these wrappers is the NSI::Context class. Its default construction will require linking with the renderer.

1#include "nsi.hpp"
2
3NSI::Context nsi;

The nsi_dynamic.hpp file provides an alternate api source which will load the renderer at runtime and thus requires no direct linking.

1#include "nsi.hpp"
2#include "nsi_dynamic.hpp"
3
4NSI::DynamicAPI nsi_api;
5NSI::Context nsi(nsi_api);

In both cases, a new nsi context can then be created with the Begin() method.

1nsi.Begin();

This will be bound to the NSI::Context object and released when the object is deleted. It is also possible to bind the object to a handle from the C API, in which case it will not be released unless the End() method is explicitly called.

Argument Passing

The NSI::Context class has methods for all the other ɴsɪ calls. The optional arguments of those can be set by several accessory classes and given in many ways. The most basic is a single argument.

1nsi.SetAttribute("handle", NSI::FloatArg("fov", 45.0f));

It is also possible to provide static lists:

1 nsi.SetAttribute(
2     "handle",(
3         NSI::FloatArg("fov", 45.0f),
4         NSI::DoubleArg("depthoffield.fstop", 4.0)
5     )
6 );

And finally a class supports dynamically building a list.

1 NSI::ArgumentList args;
2 args.Add(new NSI::FloatArg("fov", 45.0f));
3 args.Add(new NSI::DoubleArg("depthoffield.fstop", 4.0));
4 nsi.SetAttribute("handle", args);

The NSI::ArgumentList object will delete all the objects added to it when it is deleted.

Argument Classes

To be continued …