Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_CSPLUGINCOMMON_RENDERMANAGER_RENDERVIEW_H__
00021 #define __CS_CSPLUGINCOMMON_RENDERMANAGER_RENDERVIEW_H__
00022
00027 #include "csutil/pooledscfclass.h"
00028 #include "csutil/scf_implementation.h"
00029 #include "iengine/engine.h"
00030 #include "iengine/portal.h"
00031 #include "iengine/rview.h"
00032 #include "ivaria/view.h"
00033 #include "cstool/rviewclipper.h"
00034 #include "csutil/refcount.h"
00035 #include "csutil/weakref.h"
00036
00037 namespace CS
00038 {
00039 namespace RenderManager
00040 {
00041
00047 class CS_CRYSTALSPACE_EXPORT RenderView :
00048 public scfImplementationPooled<scfImplementation1<RenderView, iRenderView> >
00049 {
00050 private:
00055 uint32 context_id;
00056
00058 csRenderContext* ctxt;
00059
00061 iEngine* engine;
00063 iGraphics3D* g3d;
00065 iGraphics2D* g2d;
00069 iCamera* original_camera;
00070
00072 float leftx, rightx, topy, boty;
00073
00077 void UpdateFrustum ();
00082 void SetFrustumFromBox (const csBox2& box);
00083
00085 int viewWidth, viewHeight;
00086
00088 CS::Utility::MeshFilter meshFilter;
00089 public:
00091 RenderView ();
00093 RenderView (iCamera* c);
00095 RenderView (iCamera* c, iClipper2D* v, iGraphics3D* ig3d);
00097 RenderView (iView* v);
00099 RenderView (const RenderView& other);
00101 RenderView (const RenderView& other, bool keepCamera);
00102
00103 virtual ~RenderView ();
00104
00106 void InitialiseFromView (iView* view);
00107
00109 void InitialiseFromCamera (iCamera* camera);
00110
00112 void SetEngine (iEngine* engine);
00114 void SetCamera (iCamera* camera);
00116 void SetOriginalCamera (iCamera* camera);
00118 virtual iCamera* GetOriginalCamera () const { return original_camera; }
00119
00121 csRenderContext* GetCsRenderContext () const { return ctxt; }
00123 void SetCsRenderContext (csRenderContext* c) { ctxt = c; }
00124
00132 void CreateRenderContext ();
00138 void RestoreRenderContext ();
00139
00145 iCamera* CreateNewCamera ();
00146
00150 void SetPreviousSector (iSector* s) { ctxt->previous_sector = s; }
00154 void SetThisSector (iSector* s) { ctxt->this_sector = s; }
00155
00159 int GetRenderRecursionLevel () const { return ctxt->draw_rec_level; }
00163 void SetRenderRecursionLevel (int rec)
00164 {
00165 ctxt->draw_rec_level = rec;
00166 }
00168 void SetLastPortal (iPortal* por)
00169 {
00170 ctxt->last_portal = por;
00171 }
00173 void SetClipper (iClipper2D* clip);
00175 void SetFrustum (float lx, float rx, float ty, float by);
00176
00178 void UseClipPlane (bool u) { ctxt->do_clip_plane = u; }
00180 void UseClipFrustum (bool u) { ctxt->do_clip_frustum = u; }
00184 void SetClipPlane (const csPlane3& p) { ctxt->clip_plane = p; }
00191 bool GetClipPlane (csPlane3& pl) const
00192 {
00193 pl = ctxt->clip_plane;
00194 return ctxt->do_clip_plane;
00195 }
00197 const csPlane3& GetClipPlane () const
00198 {
00199 return ctxt->clip_plane;
00200 }
00202 csPlane3& GetClipPlane ()
00203 {
00204 return ctxt->clip_plane;
00205 }
00212 bool IsClipperRequired () const { return ctxt->do_clip_frustum; }
00213
00219 csFogInfo* GetFirstFogInfo () { return ctxt->fog_info; }
00223 void SetFirstFogInfo (csFogInfo* fi)
00224 {
00225 ctxt->fog_info = fi;
00226 ctxt->added_fog_info = true;
00227 }
00231 bool AddedFogInfo () const { return ctxt->added_fog_info; }
00235 void ResetFogInfo () { ctxt->added_fog_info = false; }
00236
00238 virtual csRenderContext* GetRenderContext () { return ctxt; }
00239
00241 virtual iEngine* GetEngine ();
00243 virtual iGraphics2D* GetGraphics2D () { return g2d; }
00245 virtual iGraphics3D* GetGraphics3D () { return g3d; }
00247 virtual void GetFrustum (float& lx, float& rx, float& ty, float& by)
00248 {
00249 lx = leftx;
00250 rx = rightx;
00251 ty = topy;
00252 by = boty;
00253 }
00254
00256 int GetViewWidth() const { return viewWidth; }
00258 int GetViewHeight() const { return viewHeight; }
00263 void SetViewDimensions (int w, int h) { viewWidth = w; viewHeight = h; }
00264
00265
00266
00267
00268
00270 virtual iClipper2D* GetClipper () { return ctxt->iview; }
00271
00275 virtual iCamera* GetCamera () { return ctxt->icamera; }
00276
00280 virtual iSector* GetThisSector () { return ctxt->this_sector; }
00281
00285 virtual iSector* GetPreviousSector () { return ctxt->previous_sector; }
00286
00288 virtual iPortal* GetLastPortal () { return ctxt->last_portal; }
00289
00291 virtual uint GetCurrentFrameNumber () const;
00292
00294 virtual void DestroyRenderContext (csRenderContext* context);
00295
00297 const CS::Utility::MeshFilter& GetMeshFilter () const { return meshFilter; }
00298
00300 void SetMeshFilter (const CS::Utility::MeshFilter& filter);
00301 };
00302
00306 class CS_CRYSTALSPACE_EXPORT RenderViewCache
00307 {
00308 public:
00310 RenderView* GetRenderView (iView* view);
00311
00313 RenderView* GetRenderView (RenderView* view, iPortal* portal, iCamera* camera);
00314
00316 csPtr<RenderView> CreateRenderView ();
00317
00319 csPtr<RenderView> CreateRenderView (RenderView* view);
00320
00322 csPtr<RenderView> CreateRenderView (RenderView* view, bool keepCamera);
00323
00324 private:
00326 RenderView::Pool renderViewPool;
00327
00328 struct View2RenderView : public csRefCount
00329 {
00330 csWeakRef<iView> view;
00331 csRef<RenderView> rview;
00332
00333 View2RenderView (iView* view, CS::RenderManager::RenderView* rview)
00334 : view (view), rview (rview) {}
00335 };
00336
00338 csRefArray<View2RenderView> iView2RenderViews;
00339
00340 struct RViewPortal2RenderView : public csRefCount
00341 {
00342 csWeakRef<RenderView> view;
00343 csWeakRef<iPortal> portal;
00344 csRef<RenderView> rview;
00345
00346 RViewPortal2RenderView (RenderView* view, iPortal* portal, CS::RenderManager::RenderView* rview)
00347 : view (view), portal (portal), rview (rview) {}
00348 };
00349
00351 csRefArray<RViewPortal2RenderView> rViewPortal2RenderViews;
00352 };
00353
00354 }
00355 }
00356
00357 #endif