cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Memory management : is it allowed ?

Hi,

//---- Definitions

typedef struct
{
Spectrum kd;
} BxDFParam_Lambert;

typedef struct
{
Spectrum ks;
FresnelParam fresnel;
} BxDFParam_Specular;

typedef struct
{
   union
   {
      BxDFParam_Lambert lambert;
      BxDFParam_Specular specular;
   } param;
} BSDF;



//---- Copy parameters from buffer

void* buffer = ...

if (reference->materialId == BSDF_DIFFUSE)
   param.diffuse = *((BxDFParam_Lambert)buffer);
else if (reference->materialId == BSDF_SPECULAR)
   param.specular = *((BxDFParam_Specular)buffer);



Tags (1)
0 Likes
1 Reply
MicahVillmow
Staff
Staff

Memory management : is it allowed ?

That isn't forbidden, but the current SDK might have trouble generating code for that correctly. There is a issue in SDK 2.2 with aliasing pointers in a struct that will be fixed in 2.3.
0 Likes