#ifndef _SCENE_CACHE_H
#define _SCENE_CACHE_H
#include "GlFunctions.h"
class VBOMesh
{
public:
VBOMesh();
~VBOMesh();
bool Initialize(const FbxMesh * pMesh);
void UpdateVertexPosition(const FbxMesh * pMesh, const FbxVector4 * pVertices) const;
void BeginDraw(ShadingMode pShadingMode) const;
void Draw(int pMaterialIndex, ShadingMode pShadingMode) const;
void EndDraw() const;
int GetSubMeshCount() const { return mSubMeshes.GetCount(); }
private:
enum
{
VERTEX_VBO,
NORMAL_VBO,
UV_VBO,
INDEX_VBO,
VBO_COUNT,
};
struct SubMesh
{
SubMesh() : IndexOffset(0), TriangleCount(0) {}
int IndexOffset;
int TriangleCount;
};
GLuint mVBONames[VBO_COUNT];
FbxArray<SubMesh*> mSubMeshes;
bool mHasNormal;
bool mHasUV;
bool mAllByControlPoint;
};
class MaterialCache
{
public:
MaterialCache();
~MaterialCache();
bool Initialize(const FbxSurfaceMaterial * pMaterial);
void SetCurrentMaterial() const;
bool HasTexture() const { return mDiffuse.mTextureName != 0; }
static void SetDefaultMaterial();
private:
struct ColorChannel
{
ColorChannel() : mTextureName(0)
{
mColor[0] = 0.0f;
mColor[1] = 0.0f;
mColor[2] = 0.0f;
mColor[3] = 1.0f;
}
GLuint mTextureName;
GLfloat mColor[4];
};
ColorChannel mEmissive;
ColorChannel mAmbient;
ColorChannel mDiffuse;
ColorChannel mSpecular;
GLfloat mShinness;
};
struct PropertyChannel
{
PropertyChannel() : mAnimCurve(NULL), mValue(0.0f) {}
GLfloat Get(const FbxTime & pTime) const
{
if (mAnimCurve)
{
return mAnimCurve->Evaluate(pTime);
}
else
{
return mValue;
}
}
FbxAnimCurve * mAnimCurve;
GLfloat mValue;
};
class LightCache
{
public:
LightCache();
~LightCache();
static void IntializeEnvironment(const FbxColor & pAmbientLight);
bool Initialize(const FbxLight * pLight, FbxAnimLayer * pAnimLayer);
void SetLight(const FbxTime & pTime) const;
private:
static int sLightCount;
GLuint mLightIndex;
FbxLight::EType mType;
PropertyChannel mColorRed;
PropertyChannel mColorGreen;
PropertyChannel mColorBlue;
PropertyChannel mConeAngle;
};
#endif // _SCENE_CACHE_H