00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015
00016 #ifndef __CHCRENDERER_H__
00017 #define __CHCRENDERER_H__
00018
00019 #include <vector>
00020 using namespace std;
00021 #include "OcclusionQuery.h"
00022
00023 #include "../../core/src/RenderGlModule.h"
00024
00025 #include "../../core/src/camera.h"
00026
00027
00028 namespace VRUT
00029 {
00031 const int MODULE_VERSION = 1;
00032
00033 struct ChcNodeInfo {
00034 int lastVisibleFrame;
00035 };
00036
00037 struct NodeInfo {
00039 unsigned int planeMask;
00041 BVHNode *node;
00043 float distance;
00044
00045 NodeInfo(){}
00046 NodeInfo(const unsigned int m, BVHNode *n, const float d):
00047 planeMask(m), node(n), distance(d) {}
00048
00049 friend bool operator<(const NodeInfo &a, const NodeInfo &b) {
00050 return a.distance < b.distance;
00051 }
00052 };
00053
00054
00055 struct QueryInfo {
00056 OcclusionQuery *query;
00057 NodeInfo info;
00058 QueryInfo() {}
00059 QueryInfo(OcclusionQuery *q, const NodeInfo &i):
00060 query(q), info(i) {}
00061 };
00062
00064 class ChcRenderer : public RenderGlModule
00065 {
00066 protected:
00068 int var;
00069
00071 Parameter::ParameterIdentificator varParamID;
00072
00074 int frame;
00075
00076 vector<ChcNodeInfo> nodeInfo;
00077
00079 virtual void processEvent(wxCommandEvent & evt)
00080 {
00082 RenderGlModule::processEvent(evt);
00083
00084 switch (evt.GetEventType()) {
00086 case Event::EVT_PARAM_SET:
00087 UPDATE_PARAM_FROM_EVENT_INT(varParamID, var, evt);
00088 break;
00089 }
00090 }
00091
00092 virtual bool Initialize();
00093
00095 stack<OcclusionQuery *> occlusionQueries;
00097 int renderedNodes;
00099 int renderedBlendedNodes;
00101 int queriedNodes;
00102
00103 public:
00105 ChcRenderer(const MODULE_ID & _id,
00106 const wxString & _name,
00107 EventHandler * msgSink)
00108 : RenderGlModule(_id, _name, msgSink),
00111 varParamID(_name, wxT("var"), _id)
00112 {
00114
00115 }
00116
00118 virtual ~ChcRenderer()
00119 {
00120 }
00121
00123 virtual wxString GetDesc() const
00124 {
00125 return wxT("Advanced Renderer using occlusion culling");
00126 }
00130 virtual void Draw();
00131
00135 virtual void Deinitialize()
00136 {
00137 }
00138
00140 void
00141 DrawItems(BVH::ItemsList &itemsList);
00142
00145 void
00146 DrawItemsReverse(BVH::BlendedList &itemsList);
00147
00149 void
00150 DrawNode(const GeometryNode *node);
00151
00153 void
00154 RenderBox(const AABB &box);
00155
00156 void
00157 ProcessNode(NodeInfo &info,
00158 const VECTOR3 &cameraPos,
00159 const int planeMask,
00160 vector<const GeometryNode *> &blendedNodes,
00161 priority_queue< NodeInfo > &nodeStack
00162 );
00163
00164 void
00165 PullUpInvisibility(BVHNode *node);
00166 void
00167 PullUpVisibility(BVHNode *node);
00168
00169 };
00170 };
00171
00172
00173 EXPORT_VRUT_MODULE_FUNCTIONS( ChcRenderer )
00174
00175 #endif