class RED::Factory

Factory class needed by REDsdk clients to create new REDsdk object instances. More...

#include <REDFactory.h>

Inherits: Object.

Public static functions:

static RED::Object *CreateAnimationClipController ( RED::Object & iResourceManager, const RED::AnimationClip & iAnimationClip, RED_RC & oErrorCode )
static RED::Object *CreateFileStream ( const RED::String & iPath )
static RED::Object *CreateInstance ( const RED::CID & iCID )
static RED::Object *CreateMaterialController ( RED::Object & iResourceManager, RED::Object * iMaterial, const RED::String & iCategory, const RED::String & iSubCategory, const RED::String & iDescription, const RED::String & iName, const RED::String & iAuthor, RED_RC & oErrorCode )
static RED::Object *CreateMemoryStream ( unsigned char * iStart, RED::uint64 iSize )
static RED::Object *CreateMemoryStream ( )
static RED::Object *CreatePeer ( )
static RED::Object *CreateREDWindow ( RED::Object & iResourceManager, void * iOSHandler, Display * iDisplay, int iScreen, Visual * iVisual, unsigned int iWidth, unsigned int iHeight, RED::WindowRenderInfo * iInfo, RED_RC & oErrorCode )
static RED::Object *CreateSkeletalAnimationBlender ( RED::Object & iResourceManager, RED_RC & oErrorCode )
static RED::Object *CreateSkeletalAnimationClipController ( RED::Object & iResourceManager, const RED::AnimationClip & iAnimationClip, RED_RC & oErrorCode )
static RED_RCDeleteInstance ( RED::Object * iInstance, const RED::State & iState )
static RED_RCDeletePeer ( RED::Object * iPeer )
static RED_RCDeleteStream ( RED::Object * iStream )
static boolIsRegistered ( const RED::CID & iCID )

Protected static variables:

static RED::Object *_resmgr

Detailed description:

Factory class needed by REDsdk clients to create new REDsdk object instances.

The RED::Factory class is used through static API calls to create and delete SDK objects instances. Users mostly manipulate RED::Object instances when working with REDsdk. To get access to instances specific features, one can first ask for an interface using one of the RED::IREDObject::As methods.

Every RED::Object instance can expose none or several interfaces. An interface is a set of methods accessible through an object after casting it using one of the RED::IREDObject::As methods. To do so, you'll need the Class ID (CID) of the interface you want to retrieve. Then call the RED::IREDObject::As method passing the CID of that interface to get a valid pointer on it (if it exists) or NULL otherwise. Please refer to the documentation index to get the full list of available interfaces in REDsdk.

To create instances using the factory, simply call the corresponding create method:

  RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
  RED::Object* mesh = RED::Factory::CreateInstance( CID_REDMeshShape );

and so on...

Whatever the instance you created is, you must explicitly call the deletion method of the factory to destroy it (except in case where deletion is automatically propagated as in DAGs for example):

  RED_RC result = RED::Factory::DeleteInstance( object, currentState );

Functions documentation

public static RED::Object * RED::Factory::CreateAnimationClipController(RED::Object &iResourceManager,
const RED::AnimationClip &iAnimationClip,
RED_RC &oErrorCode
)

Creates an object implementing the RED::IAnimationClipController interface.

Parameters:

iResourceManager:Reference to the resource manager.
iAnimationClip:Animation clip to be controlled.
oErrorCode:RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_ALLOC_FAILURE if an internal memory allocation has failed,
RED_FAIL otherwise.

Returns:

A pointer to the new object on success, NULL otherwise.

Creates a file stream at a given location.

Use the RED::IStream interface to manipulate the returned object.

Parameters:

iPath:Path to the location of the stream.

Returns:

A pointer on the newly created stream on success,
NULL otherwise.

Creates an instance of a given REDsdk class.

This method creates a new object instance for all types listed below:

Singleton objects such as the CID_REDResourceManager object are created on the first call to CreateInstance and then are returned each time the routine is called.

It's preferable to create the resource manager singleton before any other graphic operation in the application. The resource manager may change the setup of graphic card drivers and this will only work if the resource manager is created before doing any graphics in the application.

Windows are created through the dedicated RED::Factory::CreateREDWindow method of this class. Shareable graphical resources are created directly through the RED::IResourceManager interface of the resource manager.

There are three reasons why a call to this method can fail:

  • The given CID is not a valid one,
  • The memory allocation has failed,
  • If we are not in a valid transaction (see the RED::IResourceManager class).

You can check that a CID is registered by calling the RED::Factory::IsRegistered method.

An example of use is given here: Creating and destroying objects using the RED::Factory.

Parameters:

iCID:ID of the class to instanciate.

Returns:

A pointer to the instantiated object on success, NULL in case of failure. A failure can occur if a memory error occurs or if we're not in a valid transaction defined by RED::IResourceManager::BeginState.
public static RED::Object * RED::Factory::CreateMaterialController(RED::Object &iResourceManager,
RED::Object *iMaterial,
const RED::String &iCategory,
const RED::String &iSubCategory,
const RED::String &iDescription,
const RED::String &iName,
const RED::String &iAuthor,
RED_RC &oErrorCode
)

Creates an object implementing the RED::IMaterialController interface.

A material controller is used to expose only a few, explicit, high-level parameters for a material. It can be saved and reloaded from .red files. Material controllers register themselves atomatically at their creation to the resource manager and can later be accessed by material using the RED::IResourceManager::GetMaterialController method.

Please go to the The material controller page to have details about material controllers.

Parameters:

iResourceManager:Reference to the resource manager.
iMaterial:Pointer to the material to be controlled.
iCategory:Category of the controller. There are a number of pre- defined material controllers categories; please, refer to the page: Review of the materials library categories for a full description of the categories.
iSubCategory:Sub-category of the controller. Same as for iCategory above.
iDescription:Description of the material being controlled.
iName:Public name of the material being controlled.
iAuthor:Author of the material.
oErrorCode:RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_ALLOC_FAILURE if an internal memory allocation has failed,
RED_FAIL otherwise.

Returns:

A pointer to the new object on success, NULL otherwise.
public static RED::Object * RED::Factory::CreateMemoryStream(unsigned char *iStart,
RED::uint64iSize
)

Creates a memory stream starting at a given memory address.

Use the RED::IStream interface to manipulate the returned object.

Parameters:

iStart:Starting memory address of the stream.
iSize:Allocated size of the memory stream (can't be 0).

Returns:

A pointer on the newly created stream on success,
NULL otherwise.

Creates a memory stream that owns its memory.

Unlike for the other RED::Factory::CreateMemoryStream method, this method lets the memory stream manages it's own memory. The memory stream will grow in memory upon write requests that are made to it.

Use the RED::IStream interface to manipulate the returned object.

Returns:

A pointer on the newly created stream on success,
NULL otherwise, if an error has occurred.

Creates a REDnet peer.

The returned peer implements the RNET::IPeer interface.

Note that if REDnet is not correctly registered with a valid license, the call will fail returning NULL each time.

Have a look at Introduction to REDnet to have more information about peers with REDnet.

Returns:

a pointer to the new REDnet peer on success,
NULL otherwise.
public static RED::Object * RED::Factory::CreateREDWindow(RED::Object &iResourceManager,
void *iOSHandler,
Display *iDisplay,
intiScreen,
Visual *iVisual,
unsigned intiWidth,
unsigned intiHeight,
RED::WindowRenderInfo *iInfo,
RED_RC &oErrorCode
)

Creates a window.

A window must be created before image operations can occur if a GPU has to be used. Similarly, file operations with images require a window to be created first.

Please note that on MacOS / Cocoa environments, the NSView must be shown and ready for the display, otherwise, the internal context creation may return an 'invalid drawable' error code while trying to link with the window.

Please refer to the Building a REDsdk application for Operating system specific window initialization and creation code.

An example of use can be seen here: Creating a REDsdk window using the RED::Factory.

Parameters:

iResourceManager:Cluster's resource manager.
iOSHandler:OS handler. The HWND on Windows, the X-Window id on Linux/UNIX or the NSView address on MacOS / Cocoa.
iDisplay:(Linux/UNIX only) pointer to the X display.
iScreen:(Linux/UNIX only) index of the screen.
iVisual:(Linux/UNIX only) pointer to the X visual.
iWidth:Window pixel width.
iHeight:Window pixel height.
iInfo:Optional address of a RED::WindowRenderInfo class whose parameters can change the created window hardware parameters. Can be set to NULL to let all default window behaviors unmodified. Any supplied iInfo is duplicated internally by the method, so it can be discarded after the call.
oErrorCode:RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_BAD_PARAM if iWidth or iHeight is zero or below zero,
RED_DRV_INIT_FAILED if an internal OpenGL error was found,
RED_DRV_CONTEXT_SHARING_NOT_ALLOWED if two windows are using the same external rendering context (every window must own its rendering context),
RED_DRV_CONTEXT_SHARING_ERROR if a global context pool sharing error has occurred (on windows platforms). Please refer to the RED::WindowRenderInfo class for all details on the external context sharing mechanism,
RED_DRV_HOST_ERROR if an error was found using the external window and rendering contexts supplied through iInfo. Check that there's no pending OpenGL error in the external context before creating the window,
RED_DRV_ALLOC_FAILURE if a driver memory allocation has failed,
RED_DRV_UNSUPPORTED_GPU if the computer's primary GPU is not supported by the engine,
RED_DRV_FRAMEBUFFER_CREATION_ERROR if the window (the first created window) can't initialize internal auxiliary buffers used by REDsdk,
RED_ALLOC_FAILURE if an internal memory allocation has failed,
RED_WORKFLOW_ERROR if there's no valid transaction open at the time of the operation,
RED_FAIL otherwise.

Returns:

A pointer to the new window on success, NULL otherwise.
public static RED::Object * RED::Factory::CreateSkeletalAnimationBlender(RED::Object &iResourceManager,
RED_RC &oErrorCode
)

Creates an object implementing the RED::ISkeletalAnimationBlender interface.

Parameters:

iResourceManager:Reference to the resource manager.
oErrorCode:RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_ALLOC_FAILURE if an internal memory allocation has failed,
RED_FAIL otherwise.

Returns:

A pointer to the new object on success, NULL otherwise.
public static RED::Object * RED::Factory::CreateSkeletalAnimationClipController(RED::Object &iResourceManager,
const RED::AnimationClip &iAnimationClip,
RED_RC &oErrorCode
)

Creates an object implementing the RED::IAnimationClipController and RED::ISkeletalAnimationController interfaces.

Parameters:

iResourceManager:Reference to the resource manager.
iAnimationClip:Animation clip to be controlled.
oErrorCode:RED_OK if the operation has succeeded,
RED_BAD_PARAM if the method has received an invalid parameter,
RED_ALLOC_FAILURE if an internal memory allocation has failed,
RED_FAIL otherwise.

Returns:

A pointer to the new object on success, NULL otherwise.
public static RED_RC RED::Factory::DeleteInstance(RED::Object *iInstance,
const RED::State &iState
)

Deletes an object instance that was previously created using the RED::Factory.

Please refer to Life cycle of REDsdk objects for all details on object destruction mechanisms in REDsdk.

An example of use is given here: Creating and destroying objects using the RED::Factory.

Parameters:

iInstance:Object address.
iState:The current transaction parameter.

Returns:

RED_OK when the method has succeeded,
RED_BAD_PARAM if the method has received an invalid iInstance address,
RED_WORKFLOW_ERROR if a transaction error has occurred,
RED_SCG_NO_ROOT_DESTRUCTION if iInstance is the root of a scene graph. The destruction of scene graph roots is the responsibility of REDsdk,
RED_SCG_SHAPE_ALREADY_DESTROYED if iInstance is a shape object and if this shape has been already destroyed during the transaction (from a hierarchical destruction of a scene graph tree),
RED_WFLOW_WINDOW_DESTRUCTION_ERROR if a window is being released and it's system window has been already released,
RED_FAIL otherwise.

Deletes a REDnet peer previously created with a call to CreatePeer.

Have a look at Introduction to REDnet to have more information about peers with REDnet.

Returns:

RED_OK on success,
RED_BAD_PARAM if iPeer is not a valid pointer to a peer,
RED_FAIL otherwise.

Deletes a memory or file stream previously created with a call to CreateMemoryStream or CreateFileStream.

Parameters:

iStreampointer to the stream to delete.

Returns:

RED_BAD_PARAM if iStream is not a valid pointer to a stream,
RED_OK otherwise.
public static bool RED::Factory::IsRegistered(const RED::CID &iCID)

Checks that a class with the given CID is registered.

This call can be used to verify that a client application will have all creation and usage rights for a given class ID.

Returns:

true if a class with the given CID is registered, false otherwise.

Variables documentation

Internal pointer to the resource manager.