VRenderer class

The first thing you need to implement is a renderer class. This class extends the abstract class OSL::RendererServices, which is part of the open shading language. Create a header file named vrenderer.cpp using you favourite text editor, I use vi, pronounced ve-eye:
# vi vrenderer.cpp

Once in the editor press the i button on the keyboard before you start writing any text.

In order for the compiler to see the base class OSL::RendererServices, you need to include a header file called oslexec.h.
We also want to avoid prefixing all all symbols defined in the OSL namespace by OSL::, therfore I give the using namespace instruction to the complier.
I also write some pre-processor directives at the beginnig and at the end of the file, so that there will not be multiple class definitions, if you by mistake includes the same header file twice:

#ifndef _VRenderer_H
#define _VRenderer_H

#include <OSL/oslexec.h>

using namespace OSL;

#endif

Once you have entered this text, quit vi by giving the following command:
:wq

Now we define the VRenderer class as a subclass of RendererServices by editing the same text file again, please note that the whole file is listed inclduding the code we wrote in the last step:

#ifndef _VRenderer_H
#define _VRenderer_H

#include <OSL/oslexec.h>

using namespace OSL;

class VRenderer : public OSL::RendererServices
{
public:
    VRenderer();
    virtual ~VRenderer() { }

    virtual bool get_matrix(Matrix44 &result,
                            TransformationPtr xform,
                            float time);
    virtual bool get_matrix(Matrix44 &result,
                            TransformationPtr xform);
    virtual bool get_matrix(Matrix44 &result,
                            ustring from,
                            float time);
    virtual bool get_matrix(Matrix44 &result,
                            ustring from);

    virtual bool get_attribute(void *renderstate,
                               bool derivatives,
                               ustring object,
                               TypeDesc type,
                               ustring name,
                               void *val);

    virtual bool get_array_attribute(void *renderstate,
                                     bool derivatives,
                                     ustring object,
                                     TypeDesc type,
                                     ustring name,
                                     int index,
                                     void *val);

    virtual bool get_userdata(bool derivatives,
                              ustring name,
                              TypeDesc type,
                              void *renderstate,
                              void *val);
    virtual bool has_userdata(ustring name,
                              TypeDesc type,
                              void *renderstate);

    virtual int pointcloud_search(ShaderGlobals *sg,
                                  ustring filename,
                                  const Vec3 &center,
                                  float radius,
                                  int max_points,
                                  bool sort,
                                  size_t *out_indices,
                                  float *out_distances,
                                  int derivs_offset);

    virtual int pointcloud_get(ustring filename,
                               size_t *indices,
                               int count,
                               ustring attr_name,
                               TypeDesc attr_type,
                               void *out_data);
private:
};

#endif

Next you also need to provide the implmentations for these methods as well, they will be located in a file called vrenderer.cpp. Enter the following text in your favourite editor:

#include "vrenderer.h"

VRenderer::VRenderer()
{
    std::cout << "Initialize VRenderer" << std::endl;
}

bool VRenderer::get_matrix(Matrix44 &result,
                           TransformationPtr xform,
                           float time)
{
    return false;
}

bool VRenderer::get_matrix(Matrix44 &result,
                           TransformationPtr xform)
{
    return false;
}

bool VRenderer::get_matrix(Matrix44 &result,
                         ustring from,
                         float time)
{
    return false;
}

bool VRenderer::get_matrix(Matrix44 &result,
                           ustring from)
{
    return false;
}

bool VRenderer::get_attribute(void *renderstate,
                              bool derivatives,
                              ustring object,
                              TypeDesc type,
                              ustring name,
                              void *val)
{
    return false;
}

bool VRenderer::get_array_attribute(void *renderstate,
                                    bool derivatives,
                                    ustring object,
                                    TypeDesc type,
                                    ustring name,
                                    int index,
                                    void *val)
{
    return false;
}

bool VRenderer::get_userdata(bool derivatives,
                             ustring name,
                             TypeDesc type,
                             void *renderstate,
                             void *val)
{
    return false;
}

bool VRenderer::has_userdata(ustring name,
                             TypeDesc type,
                             void *renderstate)
{
    return false;
}

int VRenderer::pointcloud_search(ShaderGlobals *sg,
                                 ustring filename,
                                 const Vec3 &center,
                                 float radius,
                                 int max_points,
                                 bool sort,
                                 size_t *out_indices,
                                 float *out_distances,
                                 int derivs_offset)
{
    return 0;
}

int VRenderer::pointcloud_get(ustring filename,
                              size_t *indices,
                              int count,
                              ustring attr_name,
                              TypeDesc attr_type,
                              void *out_data)
{
    return 0;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License