neuray Services API Programmer's Manual

neuray.h File Reference

Description

neuray services command context for the neuray API

Code Example

neuray.h

‎/******************************************************************************
 * Copyright 2010-2020 MIGENIUS PTY LTD, Australia. All rights reserved.
 *
 * Portions Copyright 1986, 2011 NVIDIA Corporation. All rights reserved.
 *****************************************************************************/
//*****************************************************************************
#ifndef MI_NSERVICES_NEURAY_H
#define MI_NSERVICES_NEURAY_H

#include <mi/base/types.h>
#include <mi/base/interface_declare.h>
#include <mi/nservices/icommand.h>
#include <mi/nservices/iscene.h>
#include <mi/nservices/ievent.h>
#include <mi/neuraylib/irender_target.h>

namespace mi {

namespace nservices {



class ICommand_context_neuray : public
    mi::base::Interface_declare<0x2BB6D91C,0x0F96,0x4BF0,0xB9,0x78,0xA7,0x39,0x97,0x32,0x26,0x71,
    ICommand_context>
{
public:
    virtual IScene* get_scene(
        const char *name,
        bool blocking=false) = 0;

    virtual IScene* create_scene(
        const char *name,
        bool blocking=false) = 0;

    virtual Sint32 
               unblock_scene(const char *name) = 0;
};
 // end group mi_nservices_commands









typedef base::Uuid_t<0x165F8892,0xA75A,0x5EFD,0x75,0x47,0xD1,0xE5,0x3A,0xFB,0x66,0xFA>
               PRE_RENDER;
typedef base::Uuid_t<0x165F88A2,0xA33C,0x425F,0x52,0x31,0xB9,0x1E,0xA0,0xE5,0xE8,0xB2>
               POST_RENDER;

class Event_helper_neuray
{
public:
    static mi::Sint32 
               send_pre_render_event(IEvent_context *event_context,
        const mi::nservices::IScene *scene,
        const mi::neuraylib::ICanvas_parameters* canvas_params,
        const mi::IString *canvas_pixel_type,
        const mi::IString *renderer,
        const mi::INumber *resolution_x,
        const mi::INumber *resolution_y);

    static mi::Sint32 
               send_post_render_event(IEvent_context *event_context,
        const mi::nservices::IScene *scene,
        const mi::neuraylib::ICanvas *canvas,
        const mi::IString *renderer);
};
 // end group mi_nservices_events

inline 
    mi::Sint32 
               mi::nservices::Event_helper_neuray::send_pre_render_event(
    mi::nservices::IEvent_context *event_context,
    const mi::nservices::IScene *scene,
    const mi::neuraylib::ICanvas_parameters *canvas_params,
    const mi::IString *canvas_pixel_type,
    const mi::IString *renderer,
    const mi::INumber *resolution_x,
    const mi::INumber *resolution_y)
{
    mi::Sint32 res = mi::nservices::NRS_ERROR_INVALID_PARAMETERS;
    if ( NULL == event_context ||
        NULL == scene ||
        NULL == canvas_params ||
        NULL == canvas_pixel_type ||
        NULL == renderer ||
        NULL == resolution_x ||
        NULL == resolution_y)
        return res;

    mi::base::IInterface* event_argv[6] = {
        const_cast< mi::base::IInterface* >( 
        scene->get_interface< mi::base::IInterface >() ),
        const_cast< mi::base::IInterface* >( 
        canvas_params->get_interface< mi::base::IInterface >() ),
        const_cast< mi::base::IInterface* >( 
        canvas_pixel_type->get_interface< mi::base::IInterface >() ),
        const_cast< mi::base::IInterface* >( 
        renderer->get_interface< mi::base::IInterface >() ),
        const_cast< mi::base::IInterface* >( 
        resolution_x->get_interface< mi::base::IInterface >() ),
        const_cast< mi::base::IInterface* >( 
        resolution_y->get_interface< mi::base::IInterface >() ) };

        res = mi::nservices::Event_helper::send_event(
            event_context, mi::nservices::PRE_RENDER(), 
            6, 
            event_argv);
        mi::Uint32 i = 0;
        for(; i < 6; i++)
            event_argv[i]->release();
        return res;
}

inline
    mi::Sint32 
               mi::nservices::Event_helper_neuray::send_post_render_event(
    mi::nservices::IEvent_context *event_context,
    const mi::nservices::IScene *scene,
    const mi::neuraylib::ICanvas *canvas,
    const mi::IString *renderer)
{
    mi::Sint32 res = mi::nservices::NRS_ERROR_INVALID_PARAMETERS;
    if ( NULL == event_context ||
        NULL == scene ||
        NULL == canvas ||
        NULL == renderer)
        return res;


    mi::base::Handle< mi::nservices::IFactory > h_factory(
        event_context->get_factory() );
    if ( false == h_factory.is_valid_interface() )
        return NRS_ERROR_FAILED;
    mi::base::Handle< mi::INumber > h_event_phase(
        h_factory->create< mi::INumber >("Uint32") );
    h_event_phase->set_value(0);
    h_event_phase->retain();

    mi::base::IInterface* event_argv[4] = {
        const_cast< mi::base::IInterface* >( 
        scene->get_interface< mi::base::IInterface >() ),
        h_event_phase.get() ,
        const_cast< mi::base::IInterface* >( 
        canvas->get_interface< mi::base::IInterface >() ),
        const_cast< mi::base::IInterface* >( 
        renderer->get_interface< mi::base::IInterface >() ) };

        res = mi::nservices::Event_helper::send_event(event_context,
            mi::nservices::POST_RENDER(), 
            4, 
            event_argv);
        h_event_phase->set_value(1);
        res = mi::nservices::Event_helper::send_event(event_context,
            mi::nservices::POST_RENDER(), 
            4, 
            event_argv);
        mi::Uint32 i = 0;
        for(; i < 4; i++)
            event_argv[i]->release();
        return res;
}

} // namespace nservices
} // namespace mi

#endif // MI_NSERVICES_NEURAY_H

Namespaces

namespace mi
namespace 
Namespace for the neuray Services API. More...

Classes

class 
A helper class to facilitate neuray event creation and sending. More...
class 
The context is which neuray commands are executed. More...

Typedefs

typedef base::Uuid_t< 0x165F88A2, 0xA33C, 0x425F, 0x52, 0x31, 0xB9, 0x1E, 0xA0, 0xE5, 0xE8, 0xB2>  
Triggered after every render. More...
typedef base::Uuid_t< 0x165F8892, 0xA75A, 0x5EFD, 0x75, 0x47, 0xD1, 0xE5, 0x3A, 0xFB, 0x66, 0xFA>  
Triggered before every render. More...