00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef N_RENDERER
00018 #define N_RENDERER
00019
00020 #include <sys/time.h>
00021 #include "dada.h"
00022 #include "deque"
00023 #include "map"
00024 #include "vector"
00025 #include "string"
00026 #include "Camera.h"
00027 #include "SceneGraph.h"
00028 #include "ImmediateMode.h"
00029 #include "Light.h"
00030 #include "TexturePainter.h"
00031
00032
00033 #ifndef GL_POLYGON_OFFSET_EXT
00034 #define GL_POLYGON_OFFSET_EXT ((GLenum)0x8037)
00035 #endif
00036
00037 using namespace std;
00038
00039 namespace Fluxus
00040 {
00041
00042 class State;
00043 class Primitive;
00044
00053
00057 class Renderer
00058 {
00059 public:
00060 Renderer();
00061 ~Renderer();
00062
00066 void Render();
00067 void Clear();
00069
00073 State *GetState();
00074 void ApplyState();
00075 void PushState();
00076 void PopState();
00078 void Grab(int ID);
00079 void UnGrab();
00080 Primitive *Grabbed() { return m_Grabbed; }
00082
00086 int AddPrimitive(Primitive *Prim);
00087 Primitive *GetPrimitive(int ID);
00089 void RemovePrimitive(int ID);
00092 void DetachPrimitive(int ID);
00093 dMatrix GetGlobalTransform(int ID);
00094 dBoundingBox GetBoundingBox(int ID);
00097 void RenderPrimitive(Primitive *Prim);
00099 int Select(unsigned int CamIndex, int x, int y, int size);
00101
00105 int AddLight(Light *l);
00106 Light *GetLight(int id);
00107 void ClearLights();
00109
00113 vector<Camera> &GetCameraVec() { return m_CameraVec; }
00114 unsigned int AddCamera(const Camera &cam) { m_CameraVec.push_back(cam); return m_CameraVec.size()-1; }
00116
00120 const SceneGraph &GetSceneGraph() { return m_World; }
00122
00123 enum stereo_mode_t {noStereo, crystalEyes, colourStereo};
00124
00128 void DrawText(const string &Text);
00129 void Reinitialise() { m_Initialised=false; }
00130 void SetMotionBlur(bool s, float a=0.02) { m_MotionBlur=s; m_Fade=a; }
00131 void SetResolution(int x, int y) { m_Width=x; m_Height=y; m_Initialised=false; }
00132 void GetResolution(int &x, int &y) { x=m_Width; y=m_Height; }
00133 TexturePainter *GetTexturePainter() { return TexturePainter::Get(); }
00134 void ShowAxis(bool s) { m_ShowAxis=s; }
00135 void ShowCursor(bool s);
00136 void SetBGColour(const dColour &s) { m_BGColour=s; }
00137 void SetClearFrame(bool s) { m_ClearFrame=s; }
00138 void SetClearZBuffer(bool s) { m_ClearZBuffer=s; }
00139 void SetClearAccum(bool s) { m_ClearAccum=s; }
00140 void SetDesiredFPS(float s) { m_Deadline=1/s; }
00141 void SetFPSDisplay(bool s) { m_FPSDisplay=s; }
00142 void SetFog(const dColour &c, float d, float s, float e)
00143 { m_FogColour=c; m_FogDensity=d; m_FogStart=s; m_FogEnd=e; m_Initialised=false; }
00144 void ShadowLight(unsigned int s) { m_ShadowLight=s; }
00145 void DebugShadows(bool s) { m_ShadowVolumeGen.SetDebug(s); }
00146 void ShadowLength(float s) { m_ShadowVolumeGen.SetLength(s); }
00147 double GetTime() { return m_Time; }
00148 double GetDelta() { return m_Delta; }
00149 bool SetStereoMode(stereo_mode_t mode);
00150 stereo_mode_t GetStereoMode(){ return m_StereoMode;}
00151 void PrintInfo();
00153
00157 void SetColourMask(bool inred, bool ingreen, bool inblue, bool inalpha);
00158 void Accum(int mode, float factor);
00159 void DrawBuffer(GLenum mode);
00160 void ReadBuffer(GLenum mode);
00162
00163
00164 private:
00165 void PreRender(unsigned int CamIndex, bool PickMode=false);
00166 void PostRender();
00167 void RenderLights(bool camera);
00168 void RenderStencilShadows(unsigned int CamIndex);
00169
00170 bool m_Initialised;
00171 bool m_InitLights;
00172 int m_Width,m_Height;
00173 bool m_MotionBlur;
00174 float m_Fade;
00175 bool m_ShowAxis;
00176 Primitive *m_Grabbed;
00177 dColour m_BGColour;
00178 bool m_ClearFrame;
00179 bool m_ClearZBuffer;
00180 bool m_ClearAccum;
00181 dColour m_FogColour;
00182 float m_FogDensity;
00183 float m_FogStart;
00184 float m_FogEnd;
00185 unsigned int m_ShadowLight;
00186
00187 deque<State> m_StateStack;
00188 SceneGraph m_World;
00189 vector<Light*> m_LightVec;
00190 vector<Camera> m_CameraVec;
00191 ImmediateMode m_ImmediateMode;
00192 ShadowVolumeGen m_ShadowVolumeGen;
00193
00194
00195 struct SelectInfo
00196 {
00197 int x,y;
00198 int size;
00199 };
00200
00201 SelectInfo m_SelectInfo;
00202 stereo_mode_t m_StereoMode;
00203 bool m_MaskRed,m_MaskGreen,m_MaskBlue,m_MaskAlpha;
00204
00205 timeval m_LastTime;
00206 float m_Deadline;
00207 bool m_FPSDisplay;
00208 double m_Time;
00209 double m_Delta;
00210 };
00211
00212 };
00213
00214 #endif