source file RED.h

Go to the documentation of this file.

#ifndef RED_H
#define RED_H

//******************************************************************************
// Copyright (c) 2005 Redway. All rights reserved.
//
// Redway3d is a registered trademark. Any reproduction and / or utilization
// of any material from this document without Redway?s express authorization
// are prohibited.
//******************************************************************************

#pragma warning( disable : 4482 )


//******************************************************************************
//*** System types *************************************************************
//******************************************************************************

#if defined( _WIN32 )

#if defined( _RED_DEBUG )

#include <assert.h>

#endif

#ifndef _WIN32_WINNT

#define _WIN32_WINNT  0x0500

#endif

#include <windows.h>

#undef CreateFont

#elif defined( _LIN32 )

#include <stdio.h>
#include <linux/types.h>

#elif defined( _MAC32 )

#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>

#endif


//******************************************************************************
//*** Defines encapsulating OS differences *************************************
//******************************************************************************

#if defined(_WIN32) || defined(_WIN64)

#define REDDllHandler HINSTANCE

#else

#define REDDllHandler void *

#endif


//******************************************************************************
//*** RED export symbols *******************************************************
//******************************************************************************

#if defined( _WIN32 )

  #if defined( _RED_SDK )
    #define REDExp            __declspec(dllexport)
    #define REDFullExp        __declspec(dllexport)
    #define REDExpExclusive   __declspec(dllexport)
  #else
    
    #define REDFullExp        __declspec(dllimport)
    
    #if defined( _RED_MODULE )
      #define REDMODExp         __declspec(dllexport)
      #define REDExpExclusive   __declspec(dllexport)
      #define REDExp            __declspec(dllimport)
    #else
      #define REDMODExp         __declspec(dllimport)
      #define REDExp
    #endif
  
  #endif
  
  #ifndef REDExpExclusive 
    #define REDExpExclusive 
  #endif

#else
  
  #define REDExp
  #define REDExpExclusive
  #define REDMODExp
  #define REDFullExp

#endif


//******************************************************************************
//*** 64-bit specific types & helpers ******************************************
//******************************************************************************

namespace RED
{
#if defined( _WIN32 )
  
#if defined( _WIN64 )
  
  typedef unsigned __int64 uint64;
  typedef __int64 int64;
  
#else
  
  typedef unsigned int __w64 uint64;
  typedef int __w64 int64;
  
#endif
  
#else
  
  typedef unsigned long uint64;
        typedef long int64;
  
#endif
  
};


//******************************************************************************
//*** RED insertion position in a list *****************************************
//******************************************************************************

namespace RED
{
  enum LIST_POS { LIST_LAST = -1,
                  LIST_FIRST = 0 };
};  


//******************************************************************************
//*** RED mathematical parameters **********************************************
//******************************************************************************

#define RED_TOL      (1e-6f)
#define RED_SQRTOL   (1e-3f)
#define RED_TOL2     (1e-12f)
#define RED_INVTOL   (1e6f)
#define RED_INVTOL2  (1e12f)


#define RED_PI      (3.141592653589f)
#define RED_2PI     (6.283185307179f)
#define RED_4PI     (12.566370614359f)
#define RED_PI2     (1.570796326794f)
#define RED_PI4     (0.785398163397f)
#define RED_INVPI   (0.318309886184f)


//******************************************************************************
//*** REDsdk return codes ******************************************************
//******************************************************************************

enum RED_RC
{
  
//******************************************************************************
//*** RED return codes - base set of RCs (0x0000 - 0x00ff) *********************
//******************************************************************************
  
  RED_OK                                  = 0x0000,
  RED_FAIL                                = 0x0001,
  RED_ALLOC_FAILURE                       = 0x0002,
  RED_WORKFLOW_ERROR                      = 0x0003,
  RED_INVALID_LICENSE                     = 0x0004,
  RED_ACCESS_DENIED                       = 0x0005,
  RED_BAD_PARAM                           = 0x0006,
  RED_INIT_FAILED                         = 0x0007,
  RED_DLL_NOT_FOUND                       = 0x0008,
  RED_FILE_NOT_FOUND                      = 0x0009,
  RED_FILE_DATA_ERROR                     = 0x000A,
  RED_MULTIPLE_NETWORK_ADAPTERS           = 0x000B,
  RED_INTERRUPT                           = 0x000C,
  RED_FILE_WRITE_ERROR                    = 0x000D,
  RED_END_OF_STREAM                       = 0x000E,
  RED_BAD_ACCESS_MODE                     = 0x000F,
  RED_ENCRYPTED_FILE                      = 0x0010,
  RED_UNKNOWN_CHUNK                       = 0x0011,
  RED_X64_DATA_ERROR                      = 0x0012,
  RED_FILE_CLOSE_ERROR                    = 0x0013,
  RED_NO_CONNECTION_TO_LICENSE_SERVER     = 0x0014,
  RED_ALL_LICENSES_IN_USE                 = 0x0015,
  RED_INVALID_CUSTOMER_ID                 = 0x0016,
  RED_TIME_OUT                            = 0x0017,
  
  
//******************************************************************************
//*** RED Graphic driver error codes (0x0100 - 0x01ff) *************************
//******************************************************************************
  
  RED_DRV_FAIL                            = 0x0100,
  RED_DRV_ALLOC_FAILURE                   = 0x0101,
  RED_DRV_UNSUPPORTED_GPU                 = 0x0102,
  RED_DRV_LIMITED_RAYTRACE                = 0x0103,
  RED_DRV_CONTEXT_SHARING_NOT_ALLOWED     = 0x0104,
  RED_DRV_HOST_ERROR                      = 0x0105,
  RED_DRV_INIT_FAILED                     = 0x0106,
  RED_DRV_NO_PIXEL_FORMAT                 = 0x0107,
  RED_DRV_NO_RAYTRACE                     = 0x0108,
  RED_DRV_INVALID_SOFT_BUFFER             = 0x0109,
  RED_DRV_FRAMEBUFFER_CREATION_ERROR      = 0x010A,
  RED_DRV_CONTEXT_SHARING_ERROR           = 0x010B,
  RED_DRV_OGL_INVALID_ENUM                = 0x010C,
  RED_DRV_OGL_INVALID_VALUE               = 0x010D,
  RED_DRV_OGL_INVALID_OPERATION           = 0x010E,
  
  
//******************************************************************************
//*** RED Scene graph data errors (0x0200 - 0x02ff) ****************************
//******************************************************************************
  
  RED_SCG_INVALID_CAMERA_AXIS             = 0x0200,
  RED_SCG_NO_DATA_IN_SHAPE                = 0x0201,
  RED_SCG_INVALID_AUTO_CUBE_IMAGE_SETUP   = 0x0202,
  RED_SCG_INVALID_IMAGE_ADDRESS           = 0x0203,
  RED_SCG_GEOMETRY_ERROR                  = 0x0204,
  RED_SCG_INVALID_FONT                    = 0x0205,
  RED_SCG_INVALID_MATERIAL                = 0x0206,
  RED_SCG_UNKNOWN_SOFT_SHADER             = 0x0207,
  RED_SCG_DEAD_MATERIAL_ADDRESS           = 0x0208,
  RED_SCG_SOFT_SHADER_DESCRIPTION_ERROR   = 0x0209,
  RED_SCG_INVALID_PORTAL_MESH             = 0x020A,
  RED_SCG_MULTIPLE_BATCH_SHARING_ERROR    = 0x020B,
  RED_SCG_NOT_A_NUMBER_VERTEX             = 0x020C,
  RED_SCG_FONT_RENDER_MODE_CHANGE_ERROR   = 0x020D,
  RED_SCG_READ_ONLY_IMAGE                 = 0x020E,
  RED_SCG_NO_ROOT_DESTRUCTION             = 0x020F,
  RED_SCG_SHAPE_ALREADY_DESTROYED         = 0x0210,
  RED_SCG_INCONSISTENT_SCENE_UNITS        = 0x0211,
  RED_SCG_INVALID_SKIN_MESH_DATA          = 0x0212,

  
//******************************************************************************
//*** RED workflow errors (0x0300 - 0x03ff) ************************************
//******************************************************************************

  RED_WFLOW_NO_DRAW_STATE                 = 0x0300,
  RED_WFLOW_SOFT_TRACER_IS_DISABLED       = 0x0301,
  RED_WFLOW_USE_SOFT_RAYTRACE             = 0x0302,
  RED_WFLOW_NESTED_DRAW_CALL              = 0x0303,
  RED_WFLOW_WINDOW_DESTRUCTION_ERROR      = 0x0304,
  RED_WFLOW_INVALID_SAMPLER               = 0x0305,
  
  
//******************************************************************************
//*** RED material errors (0x0400 - 0x04ff) ************************************
//******************************************************************************
  
  RED_MAT_COMPILATION_FAILED              = 0x0400,
  RED_MAT_UNKNOWN_VAR                     = 0x0401,
  RED_MAT_SOFT_SHADER_LOAD_ERROR          = 0x0402,
  RED_MAT_SOFT_SHADER_UNSUPPORTED_VERSION = 0x0403,


//******************************************************************************
//*** RED image I/O errors (0x0500 - 0x05ff) ***********************************
//******************************************************************************
  
  RED_IMAGE_UNSUPPORTED_EXTENSION         = 0x0500,
  RED_IMAGE_UNSUPPORTED_FORMAT            = 0x0501,


//******************************************************************************
//*** RED net errors (0x0600 - 0x06ff) *****************************************
//******************************************************************************
  
  RED_NET_LOG_FAIL                       = 0x0600,
  RED_NET_SEND_FAIL                      = 0x0601,
  RED_NET_PROCESSED                      = 0x0602,
  RED_NET_NOT_INITIALIZED                = 0x0603,
  RED_NET_INVALID_PROTOCOL               = 0x0604,
  RED_NET_INVALID_SOCKET                 = 0x0605,
  RED_NET_INVALID_CONNECTION             = 0x0606,
  RED_NET_WEBSERVER_FAIL                 = 0x0607,
  RED_NET_SOCKET_FAIL                    = 0x0608,
  RED_NET_SOCKET_NOT_CONNECTED           = 0x0609,
  RED_NET_SOCKET_CLOSED                  = 0x060a,
  RED_NET_CANT_RESOLVE_DESTINATION       = 0x060b,
  RED_NET_CANT_CREATE_SOCKET             = 0x060c,
  

//******************************************************************************
//*** RED Intel Embree (0x0700 - 0x07ff) ***************************************
//******************************************************************************
  
  RED_EMBREE_UNSUPPORTED_CPU             = 0x0700,
  RED_EMBREE_DLL_NOT_FOUND               = 0x0701,


//******************************************************************************
//*** RED GI errors (0x0800 - 0x08ff) ******************************************
//******************************************************************************
  
  RED_GI_CACHE_DOESNT_MATCH               = 0x800,
  RED_GI_TOO_MANY_CACHES_SET              = 0x801,


//******************************************************************************
//*** RED I/O errors (0x0900 - 0x09ff) *****************************************
//******************************************************************************

  RED_UNSUPPORTED_EXTENSION               = 0x0900,
  RED_FBX_DLL_NOT_FOUND                   = 0x0901,
  RED_FBX_DLL_ERROR                       = 0x0902,
  RED_FBX_LOAD_ERROR                      = 0x0903,
  RED_FBX_SAVE_ERROR                      = 0x0904,
};


//******************************************************************************
//*** Miscellaneous functions **************************************************
//******************************************************************************

namespace RED
{
  class String;
  class Object;
  
  RED_RC REDFullExp GetREDErrorMessage( RED::String& oErrorMessage,
                                        RED_RC       iRC );
  
  
  void REDFullExp REDBreak( RED_RC      iRC,
                            const char* iCaller,
                            const void* iObject,
                            const char* iExpression,
                            const char* iInfo );
  
  
  typedef void (*ProgressCallback)( const RED::String& iMessage,
                                    float              iProgression,
                                    void*              iUserData );
};


//******************************************************************************
//*** RED return codes helpers *************************************************
//******************************************************************************

#define RED_RC_RETURN( exp, object, expression, info )\
{\
  RED_RC red_rc_return = exp;\
  if( red_rc_return != RED_OK )\
  {\
    if( red_rc_return != RED_INTERRUPT )\
    {\
      RED::REDBreak( red_rc_return, __FUNCTION__, object, expression, info );\
    }\
    \
    return red_rc_return;\
  }\
}


#define RED_RCA( exp )                        RED_RC_RETURN( exp, this, NULL, NULL )
#define RED_RCF( exp )                        RED_RC_RETURN( exp, NULL, NULL, NULL )
#define RED_RCI( exp, obj, info1, info2 )     RED_RC_RETURN( exp, obj, info1, info2 )


#define RED_RC_NORETURN( exp, object, expression, info )\
{\
  rc = exp;\
  if( rc != RED_OK )\
  {\
    if( rc != RED_INTERRUPT )\
    {\
      RED::REDBreak( rc, __FUNCTION__, object, expression, info );\
    }\
    \
    return;\
  }\
}


#define RED_RCO( exp )      RED_RC_NORETURN( exp, this, NULL, NULL )
#define RED_RCOF( exp )     RED_RC_NORETURN( exp, NULL, NULL, NULL )


#define RED_RC_NULLRETURN( exp, object, expression, info )\
{\
  RED_RC red_rc_nullreturn = exp;\
  if( red_rc_nullreturn != RED_OK )\
  {\
    if( red_rc_nullreturn != RED_INTERRUPT )\
    {\
      RED::REDBreak( red_rc_nullreturn, __FUNCTION__, object, expression, info );\
    }\
    \
    return NULL;\
  }\
}


#define RED_RCN( exp )                         RED_RC_NULLRETURN( exp, this, NULL, NULL )
#define RED_RCNF( exp )                        RED_RC_NULLRETURN( exp, NULL, NULL, NULL )
#define RED_RCNI( exp, obj, info1, info2 )     RED_RC_NULLRETURN( exp, obj, info1, info2 )


#endif