-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCustomSceneManager.cpp
More file actions
739 lines (651 loc) · 22.5 KB
/
CustomSceneManager.cpp
File metadata and controls
739 lines (651 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
#include "CustomSceneManager.h"
//#include <OgreNoMemoryMacros.h>
#include "OgreCamera.h"
#include "OgreRenderSystem.h"
#include "OgreMeshManager.h"
#include "OgreMesh.h"
#include "OgreSubMesh.h"
#include "OgreEntity.h"
#include "OgreSubEntity.h"
#include "OgreLight.h"
#include "OgreMath.h"
#include "OgreControllerManager.h"
#include "OgreMaterialManager.h"
#include "OgreAnimation.h"
#include "OgreAnimationTrack.h"
#include "OgreRenderQueueSortingGrouping.h"
#include "OgreOverlay.h"
#include "OgreOverlayManager.h"
#include "OgreStringConverter.h"
#include "OgreRenderQueueListener.h"
#include "OgreBillboardSet.h"
#include "OgrePass.h"
#include "OgreTechnique.h"
#include "OgreTextureUnitState.h"
#include "OgreException.h"
#include "OgreLogManager.h"
#include "OgreHardwareBufferManager.h"
#include "OgreRoot.h"
#include "OgreSpotShadowFadePng.h"
#include "OgreGpuProgramManager.h"
#include "OgreGpuProgram.h"
#include "OgreShadowVolumeExtrudeProgram.h"
#include "OgreDataStream.h"
#include "OgreStaticGeometry.h"
#include "OgreHardwarePixelBuffer.h"
#include "OgreManualObject.h"
#include "OgreRenderQueueInvocation.h"
#include "OgreBillboardChain.h"
#include "OgreRibbonTrail.h"
#include "OgreParticleSystemManager.h"
#include "OgreSceneQuery.h"
#include <OgreHardwareOcclusionQuery.h>
//#include <OgreMemoryMacros.h>
using namespace Ogre;
///
/// STATIC OCCLUSION QUERY LIST
///
std::list<RenderableOcclusionPair*> g_RenderableOcclusionPairList;
void CustomSceneManagerFactory::initMetaData(void) const
{
mMetaData.typeName = FACTORY_TYPE_NAME;
mMetaData.description = "The custom scene manager";
mMetaData.sceneTypeMask = Ogre::ST_GENERIC;
mMetaData.worldGeometrySupported = false;
}
const Ogre::String CustomSceneManagerFactory::FACTORY_TYPE_NAME = "CustomSceneManager";
Ogre::SceneManager* CustomSceneManagerFactory::createInstance(const Ogre::String& instanceName)
{
return new CustomSceneManager(instanceName);
}
void CustomSceneManagerFactory::destroyInstance(Ogre::SceneManager* instance)
{
delete instance;
}
LogDefineModule(CustomSceneManager);
CustomSceneManager::CustomSceneManager(const Ogre::String& name)
: Ogre::SceneManager(name)
{
g_InspectRenderable = 0;
}
CustomSceneManager::~CustomSceneManager()
{
}
const Ogre::String& CustomSceneManager::getTypeName(void) const
{
return CustomSceneManagerFactory::FACTORY_TYPE_NAME;
}
void CustomSceneManager::renderSingleObject(Renderable* rend, const Pass* pass,
bool lightScissoringClipping, bool doLightIteration,
const LightList* manualLightList)
{
/// <!-- START OF CUSTOM CODE -->
///
/// CREATE HardwareOcclusionQuery
///
static Ogre::HardwareOcclusionQuery* hardwareOcclusionQuery;
#ifndef OCCLUSION_CULLING
if (g_InspectRenderable == rend)
{
hardwareOcclusionQuery = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery();
assert (hardwareOcclusionQuery);
///
/// Start the HardwareOcclusionQuery
///
hardwareOcclusionQuery->beginOcclusionQuery();
}
#else
hardwareOcclusionQuery = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery();
assert (hardwareOcclusionQuery);
///
/// Start the HardwareOcclusionQuery
///
hardwareOcclusionQuery->beginOcclusionQuery();
#endif
#ifdef OCCLUSION_CULLING2
bool render;
hardwareOcclusionQuery = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery();
assert (hardwareOcclusionQuery);
///
/// Start the HardwareOcclusionQuery
///
hardwareOcclusionQuery->beginOcclusionQuery();
#endif
/// <!-- END OF CUSTOM CODE -->
unsigned short numMatrices;
static RenderOperation ro;
// Set up rendering operation
// I know, I know, const_cast is nasty but otherwise it requires all internal
// state of the Renderable assigned to the rop to be mutable
const_cast<Renderable*>(rend)->getRenderOperation(ro);
ro.srcRenderable = rend;
// Set world transformation
numMatrices = rend->getNumWorldTransforms();
if (numMatrices > 0)
{
rend->getWorldTransforms(mTempXform);
if (mCameraRelativeRendering && !rend->getUseIdentityView())
{
for (unsigned short i = 0; i < numMatrices; ++i)
{
mTempXform[i].setTrans(mTempXform[i].getTrans() - mCameraRelativePosition);
}
}
if (numMatrices > 1)
{
mDestRenderSystem->_setWorldMatrices(mTempXform, numMatrices);
}
else
{
mDestRenderSystem->_setWorldMatrix(*mTempXform);
}
}
// Issue view / projection changes if any
useRenderableViewProjMode(rend);
if (!mSuppressRenderStateChanges)
{
bool passSurfaceAndLightParams = true;
if (pass->isProgrammable())
{
// Tell auto params object about the renderable change
mAutoParamDataSource->setCurrentRenderable(rend);
// Tell auto params object about the world matrices, eliminated query from renderable again
mAutoParamDataSource->setWorldMatrices(mTempXform, numMatrices);
pass->_updateAutoParamsNoLights(mAutoParamDataSource);
if (pass->hasVertexProgram())
{
passSurfaceAndLightParams = pass->getVertexProgram()->getPassSurfaceAndLightStates();
}
}
// Reissue any texture gen settings which are dependent on view matrix
Pass::ConstTextureUnitStateIterator texIter = pass->getTextureUnitStateIterator();
size_t unit = 0;
while(texIter.hasMoreElements())
{
TextureUnitState* pTex = texIter.getNext();
if (pTex->hasViewRelativeTextureCoordinateGeneration())
{
mDestRenderSystem->_setTextureUnitSettings(unit, *pTex);
}
++unit;
}
// Sort out normalisation
// Assume first world matrix representative - shaders that use multiple
// matrices should control renormalisation themselves
if ((pass->getNormaliseNormals() || mNormaliseNormalsOnScale)
&& mTempXform[0].hasScale())
mDestRenderSystem->setNormaliseNormals(true);
else
mDestRenderSystem->setNormaliseNormals(false);
// Sort out negative scaling
// Assume first world matrix representative
if (mFlipCullingOnNegativeScale)
{
CullingMode cullMode = mPassCullingMode;
if (mTempXform[0].hasNegativeScale())
{
switch(mPassCullingMode)
{
case CULL_CLOCKWISE:
cullMode = CULL_ANTICLOCKWISE;
break;
case CULL_ANTICLOCKWISE:
cullMode = CULL_CLOCKWISE;
break;
};
}
// this also copes with returning from negative scale in previous render op
// for same pass
if (cullMode != mDestRenderSystem->_getCullingMode())
mDestRenderSystem->_setCullingMode(cullMode);
}
// Set up the solid / wireframe override
// Precedence is Camera, Object, Material
// Camera might not override object if not overrideable
PolygonMode reqMode = pass->getPolygonMode();
if (pass->getPolygonModeOverrideable() && rend->getPolygonModeOverrideable())
{
PolygonMode camPolyMode = mCameraInProgress->getPolygonMode();
// check camera detial only when render detail is overridable
if (reqMode > camPolyMode)
{
// only downgrade detail; if cam says wireframe we don't go up to solid
reqMode = camPolyMode;
}
}
mDestRenderSystem->_setPolygonMode(reqMode);
if (doLightIteration)
{
// Create local light list for faster light iteration setup
static LightList localLightList;
// Here's where we issue the rendering operation to the render system
// Note that we may do this once per light, therefore it's in a loop
// and the light parameters are updated once per traversal through the
// loop
const LightList& rendLightList = rend->getLights();
bool iteratePerLight = pass->getIteratePerLight();
// deliberately unsigned in case start light exceeds number of lights
// in which case this pass would be skipped
int lightsLeft = 1;
if (iteratePerLight)
{
lightsLeft = static_cast<int>(rendLightList.size()) - pass->getStartLight();
// Don't allow total light count for all iterations to exceed max per pass
if (lightsLeft > static_cast<int>(pass->getMaxSimultaneousLights()))
{
lightsLeft = static_cast<int>(pass->getMaxSimultaneousLights());
}
}
const LightList* pLightListToUse;
// Start counting from the start light
size_t lightIndex = pass->getStartLight();
size_t depthInc = 0;
while (lightsLeft > 0)
{
// Determine light list to use
if (iteratePerLight)
{
// Starting shadow texture index.
size_t shadowTexIndex = mShadowTextures.size();
if (mShadowTextureIndexLightList.size() > lightIndex)
shadowTexIndex = mShadowTextureIndexLightList[lightIndex];
localLightList.resize(pass->getLightCountPerIteration());
LightList::iterator destit = localLightList.begin();
unsigned short numShadowTextureLights = 0;
for (; destit != localLightList.end()
&& lightIndex < rendLightList.size();
++lightIndex, --lightsLeft)
{
Light* currLight = rendLightList[lightIndex];
// Check whether we need to filter this one out
if (pass->getRunOnlyForOneLightType() &&
pass->getOnlyLightType() != currLight->getType())
{
// Skip
// Also skip shadow texture(s)
if (isShadowTechniqueTextureBased())
{
shadowTexIndex += mShadowTextureCountPerType[currLight->getType()];
}
continue;
}
*destit++ = currLight;
// potentially need to update content_type shadow texunit
// corresponding to this light
if (isShadowTechniqueTextureBased())
{
size_t textureCountPerLight = mShadowTextureCountPerType[currLight->getType()];
for (size_t j = 0; j < textureCountPerLight && shadowTexIndex < mShadowTextures.size(); ++j)
{
// link the numShadowTextureLights'th shadow texture unit
unsigned short tuindex =
pass->_getTextureUnitWithContentTypeIndex(
TextureUnitState::CONTENT_SHADOW, numShadowTextureLights);
if (tuindex > pass->getNumTextureUnitStates()) break;
// I know, nasty const_cast
TextureUnitState* tu =
const_cast<TextureUnitState*>(
pass->getTextureUnitState(tuindex));
const TexturePtr& shadowTex = mShadowTextures[shadowTexIndex];
tu->_setTexturePtr(shadowTex);
Camera *cam = shadowTex->getBuffer()->getRenderTarget()->getViewport(0)->getCamera();
tu->setProjectiveTexturing(!pass->hasVertexProgram(), cam);
mAutoParamDataSource->setTextureProjector(cam, numShadowTextureLights);
++numShadowTextureLights;
++shadowTexIndex;
// Have to set TU on rendersystem right now, although
// autoparams will be set later
mDestRenderSystem->_setTextureUnitSettings(tuindex, *tu);
}
}
}
// Did we run out of lights before slots? e.g. 5 lights, 2 per iteration
if (destit != localLightList.end())
{
localLightList.erase(destit, localLightList.end());
lightsLeft = 0;
}
pLightListToUse = &localLightList;
// deal with the case where we found no lights
// since this is light iteration, we shouldn't render at all
if (pLightListToUse->empty())
return;
}
else // !iterate per light
{
// Use complete light list potentially adjusted by start light
if (pass->getStartLight() || pass->getMaxSimultaneousLights() != OGRE_MAX_SIMULTANEOUS_LIGHTS)
{
// out of lights?
// skip manual 2nd lighting passes onwards if we run out of lights, but never the first one
if (pass->getStartLight() > 0 &&
pass->getStartLight() >= rendLightList.size())
{
lightsLeft = 0;
break;
}
else
{
localLightList.clear();
LightList::const_iterator copyStart = rendLightList.begin();
std::advance(copyStart, pass->getStartLight());
LightList::const_iterator copyEnd = copyStart;
// Clamp lights to copy to avoid overrunning the end of the list
size_t lightsToCopy = std::min(
static_cast<size_t>(pass->getMaxSimultaneousLights()),
rendLightList.size() - pass->getStartLight());
std::advance(copyEnd, lightsToCopy);
localLightList.insert(localLightList.begin(),
copyStart, copyEnd);
pLightListToUse = &localLightList;
}
}
else
{
pLightListToUse = &rendLightList;
}
lightsLeft = 0;
}
// Do we need to update GPU program parameters?
if (pass->isProgrammable())
{
// Update any automatic gpu params for lights
// Other bits of information will have to be looked up
mAutoParamDataSource->setCurrentLightList(pLightListToUse);
pass->_updateAutoParamsLightsOnly(mAutoParamDataSource);
// NOTE: We MUST bind parameters AFTER updating the autos
if (pass->hasVertexProgram())
{
mDestRenderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM,
pass->getVertexProgramParameters());
}
if (pass->hasGeometryProgram())
{
mDestRenderSystem->bindGpuProgramParameters(GPT_GEOMETRY_PROGRAM,
pass->getGeometryProgramParameters());
}
if (pass->hasFragmentProgram())
{
mDestRenderSystem->bindGpuProgramParameters(GPT_FRAGMENT_PROGRAM,
pass->getFragmentProgramParameters());
}
}
// Do we need to update light states?
// Only do this if fixed-function vertex lighting applies
if (pass->getLightingEnabled() && passSurfaceAndLightParams)
{
mDestRenderSystem->_useLights(*pLightListToUse, pass->getMaxSimultaneousLights());
}
// optional light scissoring & clipping
ClipResult scissored = CLIPPED_NONE;
ClipResult clipped = CLIPPED_NONE;
if (lightScissoringClipping &&
(pass->getLightScissoringEnabled() || pass->getLightClipPlanesEnabled()))
{
// if there's no lights hitting the scene, then we might as
// well stop since clipping cannot include anything
if (pLightListToUse->empty())
continue;
if (pass->getLightScissoringEnabled())
scissored = buildAndSetScissor(*pLightListToUse, mCameraInProgress);
if (pass->getLightClipPlanesEnabled())
clipped = buildAndSetLightClip(*pLightListToUse);
if (scissored == CLIPPED_ALL || clipped == CLIPPED_ALL)
continue;
}
// issue the render op
// nfz: check for gpu_multipass
mDestRenderSystem->setCurrentPassIterationCount(pass->getPassIterationCount());
// We might need to update the depth bias each iteration
if (pass->getIterationDepthBias() != 0.0f)
{
float depthBiasBase = pass->getDepthBiasConstant() +
pass->getIterationDepthBias() * depthInc;
// depthInc deals with light iteration
// Note that we have to set the depth bias here even if the depthInc
// is zero (in which case you would think there is no change from
// what was set in _setPass(). The reason is that if there are
// multiple Renderables with this Pass, we won't go through _setPass
// again at the start of the iteration for the next Renderable
// because of Pass state grouping. So set it always
// Set modified depth bias right away
mDestRenderSystem->_setDepthBias(depthBiasBase, pass->getDepthBiasSlopeScale());
// Set to increment internally too if rendersystem iterates
mDestRenderSystem->setDeriveDepthBias(true,
depthBiasBase, pass->getIterationDepthBias(),
pass->getDepthBiasSlopeScale());
}
else
{
mDestRenderSystem->setDeriveDepthBias(false);
}
depthInc += pass->getPassIterationCount();
if (rend->preRender((SceneManager*)this, mDestRenderSystem))
mDestRenderSystem->_render(ro);
rend->postRender(this, mDestRenderSystem);
if (scissored == CLIPPED_SOME)
resetScissor();
if (clipped == CLIPPED_SOME)
resetLightClip();
} // possibly iterate per light
}
else // no automatic light processing
{
// Even if manually driving lights, check light type passes
bool skipBecauseOfLightType = false;
if (pass->getRunOnlyForOneLightType())
{
if (!manualLightList ||
(manualLightList->size() == 1 &&
manualLightList->at(0)->getType() != pass->getOnlyLightType()))
{
skipBecauseOfLightType = true;
}
}
if (!skipBecauseOfLightType)
{
// Do we need to update GPU program parameters?
if (pass->isProgrammable())
{
// Do we have a manual light list?
if (manualLightList)
{
// Update any automatic gpu params for lights
mAutoParamDataSource->setCurrentLightList(manualLightList);
pass->_updateAutoParamsLightsOnly(mAutoParamDataSource);
}
if (pass->hasVertexProgram())
{
mDestRenderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM,
pass->getVertexProgramParameters());
}
if (pass->hasGeometryProgram())
{
mDestRenderSystem->bindGpuProgramParameters(GPT_GEOMETRY_PROGRAM,
pass->getGeometryProgramParameters());
}
if (pass->hasFragmentProgram())
{
mDestRenderSystem->bindGpuProgramParameters(GPT_FRAGMENT_PROGRAM,
pass->getFragmentProgramParameters());
}
}
// Use manual lights if present, and not using vertex programs that don't use fixed pipeline
if (manualLightList &&
pass->getLightingEnabled() && passSurfaceAndLightParams)
{
mDestRenderSystem->_useLights(*manualLightList, pass->getMaxSimultaneousLights());
}
// optional light scissoring
ClipResult scissored = CLIPPED_NONE;
ClipResult clipped = CLIPPED_NONE;
if (lightScissoringClipping && manualLightList && pass->getLightScissoringEnabled())
{
scissored = buildAndSetScissor(*manualLightList, mCameraInProgress);
}
if (lightScissoringClipping && manualLightList && pass->getLightClipPlanesEnabled())
{
clipped = buildAndSetLightClip(*manualLightList);
}
// don't bother rendering if clipped / scissored entirely
if (scissored != CLIPPED_ALL && clipped != CLIPPED_ALL)
{
// issue the render op
// nfz: set up multipass rendering
mDestRenderSystem->setCurrentPassIterationCount(pass->getPassIterationCount());
if (rend->preRender((SceneManager*)this, mDestRenderSystem))
mDestRenderSystem->_render(ro);
rend->postRender((SceneManager*)this, mDestRenderSystem);
}
if (scissored == CLIPPED_SOME)
resetScissor();
if (clipped == CLIPPED_SOME)
resetLightClip();
} // !skipBecauseOfLightType
}
}
else // mSuppressRenderStateChanges
{
// Just render
mDestRenderSystem->setCurrentPassIterationCount(1);
if (rend->preRender((SceneManager*)this, mDestRenderSystem))
mDestRenderSystem->_render(ro);
rend->postRender((SceneManager*)this, mDestRenderSystem);
}
// Reset view / projection changes if any
resetViewProjMode();
/// <!-- START OF CUSTOM CODE -->
#ifndef OCCLUSION_CULLING
if (g_InspectRenderable == rend)
{
///
/// Stop the HardwareOcclusionQuery
///
hardwareOcclusionQuery->endOcclusionQuery();
///
/// GET THE PIXEL COUNT
///
hardwareOcclusionQuery->pullOcclusionQuery(&g_PixelCount);
///
/// DELETE HardwareOcclusionQuery
///
Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(hardwareOcclusionQuery);
hardwareOcclusionQuery = 0;
}
#else
hardwareOcclusionQuery->endOcclusionQuery();
///
/// GET THE PIXEL COUNT
///
hardwareOcclusionQuery->pullOcclusionQuery(&occ[rend]);
///
/// DELETE HardwareOcclusionQuery
///
Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(hardwareOcclusionQuery);
hardwareOcclusionQuery = 0;
#endif
#ifdef OCCLUSION_CULLING2
hardwareOcclusionQuery->endOcclusionQuery();
///
/// GET THE PIXEL COUNT
///
hardwareOcclusionQuery->pullOcclusionQuery(&occ[rend]);
///
/// DELETE HardwareOcclusionQuery
///
Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(hardwareOcclusionQuery);
hardwareOcclusionQuery = 0;
#endif
/// <!-- END OF CUSTOM CODE -->
}
RenderableOcclusionPair::RenderableOcclusionPair(Ogre::Renderable* _renderable) :
m_Renderable (_renderable),
m_PixelCount (0),
m_PixelState (RenderableOcclusionPair::READY_FOR_RENDER)
{
///
/// CREATE HardwareOcclusionQuery
///
m_HardwareOcclusionQuery = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery();
assert (m_HardwareOcclusionQuery);
}
RenderableOcclusionPair::~RenderableOcclusionPair()
{
///
/// DELETE HardwareOcclusionQuery
///
Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(m_HardwareOcclusionQuery);
m_HardwareOcclusionQuery = 0;
}
///
/// Returns the pixel count, and changes the state
/// to continue the next hardware query
///
unsigned int RenderableOcclusionPair::GetPixelCount()
{
switch (m_PixelState)
{
case RenderableOcclusionPair::READY_FOR_ACCESS :
{
///
/// GET THE PIXEL COUNT
///
m_HardwareOcclusionQuery->pullOcclusionQuery(&m_PixelCount);
///
/// CHANGE THE STATE
///
m_PixelState = RenderableOcclusionPair::READY_FOR_RENDER;
}
}
return m_PixelCount;
}
///
/// Returns the renderable to query
///
Ogre::Renderable* RenderableOcclusionPair::GetRenderable()
{
return m_Renderable;
}
///
/// Start the query, if the state
/// is ready to render.
///
void RenderableOcclusionPair::BeginOcclusionQuery()
{
switch (m_PixelState)
{
case RenderableOcclusionPair::READY_FOR_RENDER :
{
///
/// START THE QUERY
///
m_HardwareOcclusionQuery->beginOcclusionQuery();
///
/// CHANGE THE STATE
///
m_PixelState = RenderableOcclusionPair::QUERY_STARTED;
}
}
}
///
/// Finish the query, if the state
/// is ready to render. Changes
/// the state to wait for access
///
void RenderableOcclusionPair::EndOcclusionQuery()
{
switch (m_PixelState)
{
case RenderableOcclusionPair::QUERY_STARTED :
{
///
/// START THE QUERY
///
m_HardwareOcclusionQuery->endOcclusionQuery();
///
/// CHANGE THE STATE
///
m_PixelState = RenderableOcclusionPair::READY_FOR_ACCESS;
}
}
}