Changeset 268
- Timestamp:
- 10/09/06 18:43:13 (2 years ago)
- Files:
-
- branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.cpp (modified) (6 diffs)
- branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.h (modified) (1 diff)
- branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderPartition.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.cpp
r267 r268 53 53 #include "OSGBaseFunctions.h" 54 54 #include "OSGRenderPartition.h" 55 #include "OSGRenderTraversalAction.h" 55 56 56 57 //#define OSG_DUMP_SORTING … … 64 65 OcclusionCullingTreeBuilder OcclusionCullingTreeBuilder::Proto; 65 66 66 UInt32 OcclusionCullingTreeBuilder::_extGL_SAMPLES_PASSED_ARB= Window::invalidExtensionID; 67 UInt32 OcclusionCullingTreeBuilder::_extGL_QUERY_RESULT_AVAILABLE_ARB= Window::invalidExtensionID; 68 UInt32 OcclusionCullingTreeBuilder::_extGL_QUERY_RESULT_ARB= Window::invalidExtensionID; 67 UInt32 OcclusionCullingTreeBuilder::_extOcclusionQuery= Window::invalidExtensionID; 69 68 UInt32 OcclusionCullingTreeBuilder::_funcGenQueriesARB= Window::invalidFunctionID; 70 UInt32 OcclusionCullingTreeBuilder::_funcGetQueryObjectivARB= Window::invalidFunctionID;71 69 UInt32 OcclusionCullingTreeBuilder::_funcGetQueryObjectuivARB= Window::invalidFunctionID; 72 70 UInt32 OcclusionCullingTreeBuilder::_funcBeginQueryARB= Window::invalidFunctionID; 73 71 UInt32 OcclusionCullingTreeBuilder::_funcEndQueryARB= Window::invalidFunctionID; 72 73 StatElemDesc<StatIntElem> OcclusionCullingTreeBuilder::statNOccTests( 74 "OC-Tests", 75 "number of occlusion tests"); 76 StatElemDesc<StatIntElem> OcclusionCullingTreeBuilder::statNOccInvisible( 77 "OC-Invisible", 78 "number of nodes found invisible through occlusion"); 79 80 // Some typedefs to clean up OpenGL extension handling 81 82 typedef void (OSG_APIENTRY *GenQueryT)(GLuint n, GLuint* ids); 83 typedef void (OSG_APIENTRY *GetQueryObjectuivT)(GLuint id, GLenum pname, 84 GLuint* param); 85 typedef void (OSG_APIENTRY *BeginQueryT)(GLenum target, GLuint id); 86 typedef void (OSG_APIENTRY *EndQueryT)(GLenum target); 87 88 74 89 /*-------------------------------------------------------------------------*/ 75 90 /* Constructors */ … … 79 94 : uNumNodes (0) 80 95 { 81 _extGL_SAMPLES_PASSED_ARB = Window::registerExtension("GL_SAMPLES_PASSED_ARB"); 82 _extGL_QUERY_RESULT_AVAILABLE_ARB = Window::registerExtension("GL_QUERY_RESULT_AVAILABLE"); 83 _extGL_QUERY_RESULT_ARB = Window::registerExtension("GL_QUERY_RESULT_ARB"); 84 _funcGenQueriesARB = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glGenQueriesARB"); 85 _funcBeginQueryARB = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glBeginQueryARB"); 86 _funcEndQueryARB = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glEndQueryARB"); 87 _funcGetQueryObjectuivARB = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glGetQueryObjectuivARB"); 88 _funcGetQueryObjectivARB = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glGetQueryObjectivARB"); 96 _extOcclusionQuery = Window::registerExtension("GL_ARB_occlusion_query"); 97 98 _funcGenQueriesARB = Window::registerFunction 99 (OSG_DLSYM_UNDERSCORE"glGenQueriesARB", _extOcclusionQuery); 100 _funcBeginQueryARB = Window::registerFunction 101 (OSG_DLSYM_UNDERSCORE"glBeginQueryARB", _extOcclusionQuery); 102 _funcEndQueryARB = Window::registerFunction 103 (OSG_DLSYM_UNDERSCORE"glEndQueryARB", _extOcclusionQuery); 104 _funcGetQueryObjectuivARB = Window::registerFunction 105 (OSG_DLSYM_UNDERSCORE"glGetQueryObjectuivARB", _extOcclusionQuery); 89 106 } 90 107 … … 102 119 void OcclusionCullingTreeBuilder::draw(DrawEnv &denv, RenderPartition *part) 103 120 { 121 Window* win = denv.getWindow(); 122 123 if(!win->hasExtension(_extOcclusionQuery)) 124 { 125 // Don't have it, just draw the whole tree. 126 TreeBuilderBase::draw(denv,part); 127 return; 128 } 129 104 130 _uiActiveMatrix = 0; 105 131 Real32 screen_covered_percentage = 0.f; 106 UInt32 current_node = 0;132 UInt32 current_node = 1; 107 133 GLuint queries[uNumNodes]; 108 134 std::cout << "Submitting " << uNumNodes << " queries" << std::endl; 109 135 110 void (OSG_APIENTRY *genquer)(GLuint n, GLuint* ids) = 111 (void (OSG_APIENTRY*)(GLuint n, GLuint* ids))denv.getWindow()->getFunction(_funcGenQueriesARB); 136 GenQueryT genquer = (GenQueryT)win->getFunction(_funcGenQueriesARB); 112 137 genquer(uNumNodes, queries); 113 138 114 139 //glGenQueriesARB(uNumNodes, queries); 115 drawNode(_pRoot, denv, part, screen_covered_percentage, current_node, queries);140 drawNode(_pRoot, denv, part, screen_covered_percentage, current_node, queries); 116 141 std::cout << "Calc Pixels" << std::endl; 117 142 118 void (OSG_APIENTRY *getqiv)(GLuint a, GLenum b, GLint* ids) = 119 (void (OSG_APIENTRY*)(GLuint a, GLenum b, GLint* ids))denv.getWindow()->getFunction(_funcGetQueryObjectivARB); 120 121 void (OSG_APIENTRY *getquiv)(GLuint a, GLenum b, GLuint* ids) = 122 (void (OSG_APIENTRY*)(GLuint a, GLenum b, GLuint* ids))denv.getWindow()->getFunction(_funcGetQueryObjectuivARB); 123 124 for(UInt32 i = 0; i<uNumNodes; i++) 125 { 126 GLint available = 0; 127 getqiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 128 while (!available) 129 { 143 GetQueryObjectuivT getquiv = 144 (GetQueryObjectuivT)win->getFunction(_funcGetQueryObjectuivARB); 145 146 StatCollector *sc = denv.getRTAction()->getStatistics(); 147 sc->getElem(statNOccTests )->set(uNumNodes); 148 sc->getElem(statNOccInvisible)->set(0); // Just create it 149 150 for(UInt32 i = 1; i<uNumNodes; i++) 151 { 152 GLuint available = 0; 153 getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 154 while (!available) 155 { 130 156 std::cout << "Waiting on " << i << "th query" << std::endl; 131 getq iv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available);157 getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 132 158 //glGetQueryObjectivARB(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 133 } 134 GLuint sampleCount = 0; 135 getquiv(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 136 //glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 137 std::cout << "Pixels covered: " << sampleCount << std::endl; 138 } 159 } 160 GLuint sampleCount = 0; 161 getquiv(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 162 //glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 163 std::cout << i << ":" << sampleCount << " "; 164 165 if(sampleCount == 0) 166 sc->getElem(statNOccInvisible)->inc(); 167 } 168 std::cout << std::endl; 139 169 140 170 // screen_covered_percentage = 1.0; … … 194 224 denv.activateState(pNewState, pNewStateOverride); 195 225 196 void (OSG_APIENTRY *beginq)(GLenum a, GLuint b) =197 (void (OSG_APIENTRY*)(GLenum a, GLuint b))denv.getWindow()->getFunction(_funcBeginQueryARB);198 226 Window* win = denv.getWindow(); 227 228 BeginQueryT beginq = (BeginQueryT) win->getFunction(_funcBeginQueryARB); 199 229 beginq(GL_SAMPLES_PASSED_ARB, queries[cur_node]); 200 230 //glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[cur_node]); … … 202 232 if(pNode->hasFunctor() == true) 203 233 pNode->getFunctor()(&denv); 204 205 void (OSG_APIENTRY *endq)(GLenum a) =206 (void (OSG_APIENTRY*)(GLenum a))denv.getWindow()->getFunction(_funcEndQueryARB);207 208 234 235 EndQueryT endq = (EndQueryT) win->getFunction(_funcEndQueryARB); 209 236 endq(GL_SAMPLES_PASSED_ARB); 210 237 //glEndQueryARB(GL_SAMPLES_PASSED_ARB); branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.h
r267 r268 172 172 UInt32 uNumNodes; 173 173 174 static UInt32 _extGL_SAMPLES_PASSED_ARB; 175 static UInt32 _extGL_QUERY_RESULT_AVAILABLE_ARB; 176 static UInt32 _extGL_QUERY_RESULT_ARB; 174 static UInt32 _extOcclusionQuery; 177 175 178 176 static UInt32 _funcGenQueriesARB; 179 static UInt32 _funcGetQueryObjectivARB;180 177 static UInt32 _funcGetQueryObjectuivARB; 181 178 static UInt32 _funcBeginQueryARB; 182 179 static UInt32 _funcEndQueryARB; 183 180 181 static StatElemDesc<StatIntElem> statNOccTests; 182 static StatElemDesc<StatIntElem> statNOccInvisible; 183 184 184 185 185 //----------------------------------------------------------------------- branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderPartition.cpp
r267 r268 495 495 else if( 1==1) 496 496 { 497 BuildKeyMapIt mapIt = _m TransMatRoots.lower_bound(iSortKey);498 499 if(mapIt == _m TransMatRoots.end() || mapIt->first != iSortKey)497 BuildKeyMapIt mapIt = _mMatRoots.lower_bound(iSortKey); 498 499 if(mapIt == _mMatRoots.end() || mapIt->first != iSortKey) 500 500 { 501 501 TreeBuilderBase *pBuilder = … … 504 504 pBuilder->setNodePool(_pNodePool); 505 505 506 mapIt = _m TransMatRoots.insert(mapIt,506 mapIt = _mMatRoots.insert(mapIt, 507 507 std::make_pair(iSortKey, pBuilder)); 508 508 }
