00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _CELENGINE_RENDCONTEXT_H_
00011 #define _CELENGINE_RENDCONTEXT_H_
00012
00013 #include "mesh.h"
00014
00015
00016 static const unsigned int MaxLights = 8;
00017
00018 struct DirectionalLight
00019 {
00020 Color color;
00021 float irradiance;
00022 Vec3f direction_eye;
00023 Vec3f direction_obj;
00024
00025
00026
00027 Point3d position;
00028 float apparentSize;
00029 };
00030
00031 struct EclipseShadow
00032 {
00033 Point3f origin;
00034 Vec3f direction;
00035 float penumbraRadius;
00036 float umbraRadius;
00037 };
00038
00039 struct LightingState
00040 {
00041 LightingState() : nLights(0),
00042 eyeDir_obj(0.0f, 0.0f, -1.0f),
00043 eyePos_obj(0.0f, 0.0f, -1.0f)
00044 { shadows[0] = NULL; };
00045
00046 unsigned int nLights;
00047 DirectionalLight lights[MaxLights];
00048 std::vector<EclipseShadow>* shadows[MaxLights];
00049
00050 Vec3f eyeDir_obj;
00051 Point3f eyePos_obj;
00052 };
00053
00054
00055 class RenderContext
00056 {
00057 public:
00058 RenderContext(const Mesh::Material*);
00059 RenderContext();
00060
00061 virtual void makeCurrent(const Mesh::Material&) = 0;
00062 virtual void setVertexArrays(const Mesh::VertexDescription& desc,
00063 void* vertexData) = 0;
00064 virtual void drawGroup(const Mesh::PrimitiveGroup& group);
00065
00066 void setMaterial(const Mesh::Material*);
00067 void lock() { locked = true; }
00068 void unlock() { locked = false; }
00069 bool isLocked() const { return locked; }
00070
00071 enum RenderPass
00072 {
00073 PrimaryPass,
00074 EmissivePass,
00075 };
00076
00077 RenderPass getRenderPass() const { return renderPass; }
00078 void setRenderPass(RenderPass rp) { renderPass = rp; }
00079
00080 private:
00081 const Mesh::Material* material;
00082 bool locked;
00083 RenderPass renderPass;
00084 };
00085
00086
00087 class FixedFunctionRenderContext : public RenderContext
00088 {
00089 public:
00090 FixedFunctionRenderContext(const Mesh::Material*);
00091 FixedFunctionRenderContext();
00092
00093 virtual void makeCurrent(const Mesh::Material&);
00094 virtual void setVertexArrays(const Mesh::VertexDescription& desc,
00095 void* vertexData);
00096
00097 private:
00098 bool blendOn;
00099 bool specularOn;
00100 };
00101
00102
00103 class VP_FP_RenderContext : public RenderContext
00104 {
00105 public:
00106 VP_FP_RenderContext();
00107 VP_FP_RenderContext(const Mesh::Material*);
00108
00109 virtual void makeCurrent(const Mesh::Material&);
00110 virtual void setVertexArrays(const Mesh::VertexDescription& desc,
00111 void* vertexData);
00112 };
00113
00114
00115 class VP_Combiner_RenderContext : public RenderContext
00116 {
00117 public:
00118 VP_Combiner_RenderContext();
00119 VP_Combiner_RenderContext(const Mesh::Material*);
00120
00121 virtual void makeCurrent(const Mesh::Material&);
00122 virtual void setVertexArrays(const Mesh::VertexDescription& desc,
00123 void* vertexData);
00124 };
00125
00126
00127 class GLSL_RenderContext : public RenderContext
00128 {
00129 public:
00130 GLSL_RenderContext(const LightingState& ls);
00131 GLSL_RenderContext(const LightingState& ls,
00132 const Mesh::Material*);
00133
00134 virtual void makeCurrent(const Mesh::Material&);
00135 virtual void setVertexArrays(const Mesh::VertexDescription& desc,
00136 void* vertexData);
00137
00138 private:
00139 const LightingState& lightingState;
00140 };
00141
00142 #endif // _CELENGINE_RENDCONTEXT_H_
00143