Project

General

Profile

SO3Engine
SO3SubEntityCameraSelectorBuffer.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
34#include "SO3Renderer/SO3Root.h"
37#include <OgreBitwise.h>
38#include <OgreDepthBuffer.h>
39
40namespace SO3
41{
42SSubEntityCameraSelectorBuffer::SSubEntityCameraSelectorBuffer(Ogre::Camera* camera, const std::string& name, unsigned int texwidth, unsigned int texheight, bool useDepth)
43{
44 mCamera = camera;
45 mBaseResourceName = std::string(SO3_INTERNAL_SUBENTITY_SELECTOR_RESOURCE_GROUP) + "/" + name;
46
47 Ogre::String rendererName = SRoot::getSingletonPtr()->GetOgreRenderSystem()->getName();
48 if (rendererName == "Vulkan Rendering Subsystem")
49 useDepth = false;
50
51 // Create a custom resource group
52 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(mBaseResourceName, false);
53
54 // Basic initializing
55 mRenderPickerBuffer = 0;
56 mOgrePixelBox = 0;
57 mOgreRenderTexture = 0;
58 mOgreRenderDepthTexture = 0;
59 mMrtTexture = 0;
60
61 mRealWidth = 0;
62 mRealHeight = 0;
63 mTextureWidth = texwidth;
64 mTextureHeight = texheight;
65 mCompensateNPOT = false;
66 mUseDepth = useDepth;
67
68 mOgrePickerRect = 0;
69 mOgrePickerRenderTexture = 0;
70 mOgrePickerScene = 0;
71 mOgrePickerCamera = 0;
72
73 Ogre::RenderSystem* ogreRenderSystem = SRoot::getSingleton().GetOgreRenderSystem();
74 const Ogre::RenderSystemCapabilities* caps = ogreRenderSystem->getCapabilities();
75 if (mUseDepth && caps && !caps->hasCapability(Ogre::RSC_MRT_SAME_BIT_DEPTHS))
76 mUseDepth = true;
77 else
78 mUseDepth = false;
79
80 //get materials
81 mPickerMat = Ogre::MaterialManager::getSingletonPtr()->getByName("SO3/Internal/EntitySelector/Material/MouseColor");
82
83 // Create the render texture.
84 CreateTexture(texwidth, texheight);
86
87 // Create our material switcher.
88 nodeSelectorMaterialSwitcher = new SSubEntitySelectorMaterialSwitcher(mBaseResourceName, UseDepthBuffer());
89}
90
91SSubEntityCameraSelectorBuffer::SSubEntityCameraSelectorBuffer()
92{
93 // Forbiden (private)
94}
95
97{
98 DeleteTexture();
100
101 Ogre::ResourceGroupManager::getSingleton().unloadResourceGroup(mBaseResourceName);
102 Ogre::ResourceGroupManager::getSingleton().clearResourceGroup(mBaseResourceName);
103 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(mBaseResourceName);
104
105 SO3_SAFE_DELETE(nodeSelectorMaterialSwitcher);
106}
107
109{
110 DeleteTexture();
111 DeletePicker();
112}
113
115{
116 DeleteTexture();
117 DeletePicker();
118
119 CreateTexture(mTextureWidth, mTextureHeight);
120 CreatePicker();
121}
122
124{
125 DeletePicker();
126
127 Ogre::PixelFormat rttpf = Ogre::PF_A8R8G8B8;
128 try
129 {
130 SRoot::getSingleton().GetRttPixelFormat(rttpf, mUseDepth ? true : false);
131 mOgrePickerTexture = Ogre::TextureManager::getSingleton().createManual(mBaseResourceName + "/Picker", SO3_INTERNAL_SUBENTITY_SELECTOR_RESOURCE_GROUP, Ogre::TEX_TYPE_2D, 1, 1, 0, rttpf, Ogre::TU_RENDERTARGET);
132 mOgrePickerTexture->load();
133 }
134 catch (Ogre::Exception &e)
135 {
136 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred in SSubEntityCameraSelectorBuffer::CreatePicker : " + e.getDescription());
137 mOgrePickerTexture.reset();
138 }
139
140 if (mOgrePickerTexture)
141 {
142 // Bind to a render texture
143 Ogre::HardwarePixelBufferSharedPtr ogrePixelBuffer = mOgrePickerTexture->getBuffer();
144 mOgrePickerRenderTexture = ogrePixelBuffer->getRenderTarget();
145 mOgrePickerRenderTexture->setAutoUpdated(false);
146
147#if defined(APPLE_IOS)
148 mOgrePickerRenderTexture->setDepthBufferPool(Ogre::DepthBuffer::POOL_NO_DEPTH);
149#endif
150
151 // Create our buffer
152 size_t bufferSize = ogrePixelBuffer->getSizeInBytes();
153 mRenderPickerBuffer = new Ogre::uint8[bufferSize];
154 mOgrePixelBox = new Ogre::PixelBox(ogrePixelBuffer->getWidth(), ogrePixelBuffer->getHeight(), ogrePixelBuffer->getDepth(), ogrePixelBuffer->getFormat(), mRenderPickerBuffer);
155
156 //create scene
157 mOgrePickerScene = Ogre::Root::getSingleton().createSceneManager(Ogre::SMT_DEFAULT, mBaseResourceName + "/Picker/Scene");
158
159 Ogre::AxisAlignedBox octreeBox(-1, -1, -1, 1, 1, 1);
160 int octreeDepth = 0;
161 mOgrePickerScene->setOption("Size", &octreeBox);
162 mOgrePickerScene->setOption("Depth", &octreeDepth);
163
164 Ogre::RenderQueue* rq = mOgrePickerScene->getRenderQueue();
165 rq->getQueueGroup(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_1)->setShadowsEnabled(false);
166 rq->getQueueGroup(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_2)->setShadowsEnabled(false);
167 rq->getQueueGroup(Ogre::RENDER_QUEUE_MAIN)->setShadowsEnabled(false);
168 rq->getQueueGroup(49)->setShadowsEnabled(false);
169
170 //set camera
171 mOgrePickerCamera = mOgrePickerScene->createCamera(mBaseResourceName + "/Picker/Camera");
172 mOgrePickerScene->getRootSceneNode()->attachObject(mOgrePickerCamera);
173 mOgrePickerCamera->setFarClipDistance(100.0f);
174 mOgrePickerCamera->setNearClipDistance(0.1f);
175
176 Ogre::Viewport* pickerViewport = mOgrePickerRenderTexture->addViewport(mOgrePickerCamera);
177 pickerViewport->setOverlaysEnabled(false);
178 pickerViewport->setShadowsEnabled(false);
179 //mOgrePickerViewport->setSkiesEnabled(false);
180
181 //create rect
182 mOgrePickerRect = new Ogre::Rectangle2D(true);
183 mOgrePickerRect->setCastShadows(false);
184
185 try
186 {
187 mOgrePickerRect->setMaterial(mPickerMat);
188 }
189 catch (Ogre::Exception &e)
190 {
191 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred: " + e.getDescription());
192 }
193
194 mOgrePickerRect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
195 mOgrePickerScene->getRootSceneNode()->attachObject(mOgrePickerRect);
196 mOgrePickerRect->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);
197
198 // Use infinite AAB to always stay visible
199 Ogre::AxisAlignedBox aabInf;
200 aabInf.setInfinite();
201 mOgrePickerRect->setBoundingBox(aabInf);
202 mOgrePickerRect->setVisible(true);
203 }
204}
205
207{
208 if (mOgrePickerRect != 0)
209 {
210 mOgrePickerRect->detachFromParent();
211 SAFE_DELETE(mOgrePickerRect);
212 }
213
214 if (mOgrePickerScene)
215 {
216 mOgrePickerScene->destroyAllCameras();
217 Ogre::Root::getSingleton().destroySceneManager(mOgrePickerScene);
218 mOgrePickerCamera = 0;
219 mOgrePickerScene = 0;
220 }
221
222 if (mOgrePickerRenderTexture)
223 {
224 mOgrePickerRenderTexture->removeAllViewports();
225 mOgrePickerRenderTexture = 0;
226 }
227
228 if (mOgrePickerTexture)
229 {
230 Ogre::TextureManager::getSingleton().remove(mOgrePickerTexture->getHandle());
231 mOgrePickerTexture.reset();
232 }
233
234 SO3_SAFE_DELETE(mOgrePixelBox);
235 SO3_SAFE_DELETE_ARRAY(mRenderPickerBuffer);
236}
237
239{
240 return mUseDepth && mOgreRenderDepthTexture;
241}
242
244{
245 if (!mPickerMat)
246 return 0;
247
248 if (mCompensateNPOT)
249 {
250 posX = (int)(((float)mTextureWidth / (float)mRealWidth) * (float)posX);
251 posY = (int)(((float)mTextureHeight / (float)mRealHeight) * (float)posY);
252 }
253
254 if (mOgrePickerRenderTexture && (posX >= 0) && (posY >= 0))
255 {
256 //set material parameters
257 Ogre::Technique* pickerTech = 0;
258 Ogre::Material::Techniques techs = mPickerMat->getTechniques();
259
260 if (techs.size() == 0)
261 return 0;
262
263 pickerTech = techs[0];
264
265 Ogre::Vector4 mousePos;
266 mousePos.x = (1.0f / (float)mTextureWidth) * (float)posX;
267 mousePos.y = (1.0f / (float)mTextureHeight) * (float)posY;
268
269 Ogre::ARGB argb(0);
270 Ogre::ColourValue ogreColour;
271
272 try
273 {
274 Ogre::Pass* pickerPass = pickerTech->getPass(0);
275 Ogre::GpuProgramParametersSharedPtr fparams = pickerPass->getFragmentProgramParameters();
276 fparams->setNamedConstant("inMouse", mousePos);
277
278 pickerPass->getTextureUnitState(0)->setTexture(mOgreTexture);
279
280 // debug
281 /*
282 Ogre::PixelBox pb(mOgreRenderTexture->getWidth(), mOgreRenderTexture->getHeight(), 1, mOgreRenderTexture->suggestPixelFormat());
283 pb.data = new uint8[pb.getConsecutiveSize()];
284 mOgreRenderTexture->copyContentsToMemory(pb, pb);
285
286 Ogre::Image finalImage;
287 finalImage.loadDynamicImage(static_cast<unsigned char*>(pb.data), pb.getWidth(), pb.getHeight(), mOgreRenderTexture->suggestPixelFormat());
288
289 //write the file on the Harddisk
290 finalImage.save("E:\\Documents\\OpenSpace3D\\dselector_debug.png");
291 delete[] pb.data;
292 */
293
294 mOgrePickerRenderTexture->update();
295 mOgrePickerRenderTexture->copyContentsToMemory(Ogre::Box(0, 0, 1, 1), *mOgrePixelBox, Ogre::RenderTarget::FB_AUTO);
296
297 if (mRenderPickerBuffer)
298 ogreColour = mOgrePixelBox->getColourAt(0, 0, 0);
299
300 ogreColour.a = 1.0f;
301 }
302 catch (Ogre::Exception&)
303 {
304 //Renderer not ready
305 return 0;
306 }
307
308 // Get sub entity
309 Ogre::SubEntity* selectedEntity = nodeSelectorMaterialSwitcher->GetSubEntity(ogreColour);
310 return selectedEntity;
311 }
312 return 0;
313}
314
316{
317 if (!mPickerMat)
318 return 0;
319
320 if (mCompensateNPOT)
321 {
322 posX = (int)(((float)mTextureWidth / (float)mRealWidth) * (float)posX);
323 posY = (int)(((float)mTextureHeight / (float)mRealHeight) * (float)posY);
324 }
325
326 if (mOgreDepthTexture && (posX >= 0) && (posY >= 0))
327 {
328 //set material parameters
329 Ogre::Technique* pickerTech = 0;
330 Ogre::Material::Techniques techs = mPickerMat->getTechniques();
331
332 if (techs.size() == 0)
333 return 0;
334
335 pickerTech = techs[0];
336
337 Ogre::Vector4 mousePos;
338 mousePos.x = (1.0f / (float)mTextureWidth) * (float)posX;
339 mousePos.y = (1.0f / (float)mTextureHeight) * (float)posY;
340
341 float zpos = 0.0f;
342 Ogre::ARGB argb(0);
343 Ogre::ColourValue ogreColour;
344 try
345 {
346 Ogre::Pass* pickerPass = pickerTech->getPass(0);
347 Ogre::GpuProgramParametersSharedPtr fparams = pickerPass->getFragmentProgramParameters();
348 fparams->setNamedConstant("inMouse", mousePos);
349
350 pickerPass->getTextureUnitState(0)->setTexture(mOgreDepthTexture);
351
352 // debug
353 /*
354 Ogre::PixelBox pb(mOgreRenderDepthTexture->getWidth(), mOgreRenderDepthTexture->getHeight(), 1, mOgreRenderDepthTexture->suggestPixelFormat());
355 pb.data = new uint8[pb.getConsecutiveSize()];
356 mOgreRenderDepthTexture->copyContentsToMemory(pb, pb);
357
358 Ogre::Image finalImage;
359 finalImage.loadDynamicImage(static_cast<unsigned char*>(pb.data), pb.getWidth(), pb.getHeight(), mOgreRenderDepthTexture->suggestPixelFormat());
360
361 //write the file on the Harddisk
362 finalImage.save("D:\\Documents\\OpenSpace3D\\depth_debug.png");
363 delete[] pb.data;
364 */
365
366 mOgrePickerRenderTexture->update();
367 mOgrePickerRenderTexture->copyContentsToMemory(Ogre::Box(0, 0, 1, 1), *mOgrePixelBox, Ogre::RenderTarget::FB_AUTO);
368
369 if (mRenderPickerBuffer)
370 ogreColour = mOgrePixelBox->getColourAt(0, 0, 0);
371
372 //unpack RGBA to float
373 Ogre::Vector4 shift(1.0f / (256.0f * 256.0f * 256.0f), 1.0f / (256.0f * 256.0f), 1.0f / 256.0f, 1.0f);
374 zpos = Ogre::Vector4(ogreColour.a, ogreColour.b, ogreColour.g, ogreColour.r).dotProduct(shift);
375 }
376 catch (Ogre::Exception&)
377 {
378 //Renderer not ready
379 return 0.0f;
380 }
381
382 return zpos;
383 }
384 return 0.0f;
385}
386
387void SSubEntityCameraSelectorBuffer::CreateTexture(const unsigned int& width, const unsigned int& height)
388{
389 // Check if size need pow2
390 Ogre::RenderSystem* ogreRenderSystem = SRoot::getSingleton().GetOgreRenderSystem();
391 const Ogre::RenderSystemCapabilities* caps = ogreRenderSystem->getCapabilities();
392
393 //optim test divide the texture size to get a faster frame rate on copyContentsToMemory
394 if (caps && (!caps->hasCapability(Ogre::RSC_NON_POWER_OF_2_TEXTURES)
395#ifdef APPLE_IOS
396 || caps->getNonPOW2TexturesLimited()
397#endif
398 ))
399 {
400 mTextureWidth = Ogre::Bitwise::firstPO2From(width / 3) / 2;
401 mTextureHeight = Ogre::Bitwise::firstPO2From(height / 3) / 2;
402
403 mTextureWidth = std::max(mTextureWidth, mTextureHeight);
404 mTextureHeight = mTextureWidth;
405 }
406 else
407 {
408 mTextureWidth = width;
409 mTextureHeight = height;
410 }
411
412 mCompensateNPOT = true;
413
414 mRealWidth = width;
415 mRealHeight = height;
416
417 // Generate a texture with an unique name.
418 std::string textureName = mBaseResourceName + "/Texture";
419 try
420 {
421 Ogre::PixelFormat rttpf = Ogre::PF_A8R8G8B8;
422 SRoot::getSingleton().GetRttPixelFormat(rttpf, mUseDepth ? true : false);
423 mOgreTexture = Ogre::TextureManager::getSingleton().createManual(textureName, SO3_INTERNAL_SUBENTITY_SELECTOR_RESOURCE_GROUP, Ogre::TEX_TYPE_2D, mTextureWidth, mTextureHeight, 0, rttpf, Ogre::TU_RENDERTARGET);
424 mOgreTexture->load();
425
426 if (mUseDepth)
427 {
429 mOgreDepthTexture = Ogre::TextureManager::getSingleton().createManual(textureName + "/Depth", SO3_INTERNAL_SUBENTITY_SELECTOR_RESOURCE_GROUP, Ogre::TEX_TYPE_2D, mTextureWidth, mTextureHeight, 0, rttpf, Ogre::TU_RENDERTARGET);
430 mOgreDepthTexture->load();
431 }
432 }
433 catch (Ogre::Exception &e)
434 {
435 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("An exception has occurred in SSubEntityCameraSelectorBuffer::CreateTexture : " + e.getDescription());
436 mOgreTexture.reset();
437 mOgreDepthTexture.reset();
438 }
439
440 if (mOgreTexture)
441 {
442 // Bind to a render texture
443 Ogre::HardwarePixelBufferSharedPtr ogrePixelBuffer = mOgreTexture->getBuffer();
444 mOgreRenderTexture = ogrePixelBuffer->getRenderTarget();
445 mOgreRenderTexture->setAutoUpdated(true);
446 mOgreRenderTexture->setPriority(100);
447
448#if defined(APPLE_IOS)
449 mOgreRenderTexture->setDepthBufferPool(Ogre::DepthBuffer::POOL_NO_DEPTH);
450#endif
451
452 if (mOgreDepthTexture)
453 {
454 Ogre::HardwarePixelBufferSharedPtr ogreDepthPixelBuffer = mOgreDepthTexture->getBuffer();
455 mOgreRenderDepthTexture = ogreDepthPixelBuffer->getRenderTarget();
456 mOgreRenderDepthTexture->setAutoUpdated(false);
457 mOgreRenderDepthTexture->setPriority(100);
458
459 //also disable auto render on entity texture for mrt
460 mOgreRenderTexture->setAutoUpdated(false);
461
462#if defined(APPLE_IOS)
463 mOgreRenderDepthTexture->setDepthBufferPool(Ogre::DepthBuffer::POOL_NO_DEPTH);
464#endif
465 mMrtTexture = Ogre::Root::getSingleton().getRenderSystem()->createMultiRenderTarget(textureName + "/MRT");
466 if (mMrtTexture)
467 {
468 mMrtTexture->bindSurface(0, mOgreRenderTexture);
469 mMrtTexture->bindSurface(1, mOgreRenderDepthTexture);
470 mMrtTexture->setAutoUpdated(true);
471 }
472 }
473
474 Ogre::Viewport* ogreRenderWindowViewport = mCamera->getViewport();
475 Ogre::Real ratio = mCamera->getAspectRatio();
476
477 Ogre::Viewport* ogreRenderTextureViewport = mOgreRenderTexture->addViewport(mCamera);
478
479 ogreRenderTextureViewport->setClearEveryFrame(true);
480 ogreRenderTextureViewport->setOverlaysEnabled(false);
481 ogreRenderTextureViewport->setMaterialScheme(mBaseResourceName);
482 ogreRenderTextureViewport->setShadowsEnabled(false);
483 ogreRenderTextureViewport->setSkiesEnabled(false);
484 ogreRenderTextureViewport->setVisibilityMask(ogreRenderTextureViewport->getVisibilityMask() & ~SO3_VISIBILITY_FLAG_INVISIBLE_ENVIRONMENT &~Ogre::SceneManager::FX_TYPE_MASK &~Ogre::SceneManager::LIGHT_TYPE_MASK); // Hide environment object in this rtt (skyx & hydrax).
485
486 Ogre::Viewport* ogreRenderDepthTextureViewport = 0;
487 if (mOgreRenderDepthTexture)
488 {
489 ogreRenderDepthTextureViewport = mOgreRenderDepthTexture->addViewport(mCamera);
490 ogreRenderDepthTextureViewport->setClearEveryFrame(true);
491 ogreRenderDepthTextureViewport->setOverlaysEnabled(false);
492 ogreRenderDepthTextureViewport->setMaterialScheme(mBaseResourceName);
493 ogreRenderDepthTextureViewport->setShadowsEnabled(false);
494 ogreRenderDepthTextureViewport->setSkiesEnabled(false);
495 ogreRenderDepthTextureViewport->setVisibilityMask(ogreRenderDepthTextureViewport->getVisibilityMask() & ~SO3_VISIBILITY_FLAG_INVISIBLE_ENVIRONMENT &~Ogre::SceneManager::FX_TYPE_MASK &~Ogre::SceneManager::LIGHT_TYPE_MASK); // Hide environment object in this rtt (skyx & hydrax).
496 }
497
498 Ogre::Viewport* ogreRenderMrtViewport = 0;
499 if (mMrtTexture)
500 {
501 ogreRenderMrtViewport = mMrtTexture->addViewport(mCamera);
502 ogreRenderMrtViewport->setClearEveryFrame(true);
503 ogreRenderMrtViewport->setOverlaysEnabled(false);
504 ogreRenderMrtViewport->setMaterialScheme(mBaseResourceName);
505 ogreRenderMrtViewport->setShadowsEnabled(false);
506 ogreRenderMrtViewport->setSkiesEnabled(false);
507 ogreRenderMrtViewport->setVisibilityMask(ogreRenderMrtViewport->getVisibilityMask() & ~SO3_VISIBILITY_FLAG_INVISIBLE_ENVIRONMENT &~Ogre::SceneManager::FX_TYPE_MASK &~Ogre::SceneManager::LIGHT_TYPE_MASK); // Hide environment object in this rtt (skyx & hydrax).
508 }
509
510 if (ogreRenderWindowViewport)
511 {
512 // Restore aspect ratio
513 mCamera->setAspectRatio(ratio);
514
515 // Restore viewport
516 mCamera->_notifyViewport(ogreRenderWindowViewport);
517 }
518
519 // Add a frame listener to detect each new frame (one selection buffer render per frame max).
520 if (!mMrtTexture)
521 mOgreRenderTexture->addListener(this);
522 else
523 mMrtTexture->addListener(this);
524 }
525}
526
527void SSubEntityCameraSelectorBuffer::DeleteTexture()
528{
529 if (mOgreRenderTexture)
530 {
531 if (!mMrtTexture)
532 mOgreRenderTexture->removeListener(this);
533 mOgreRenderTexture->removeAllViewports();
534
535 mOgreRenderTexture = 0;
536 }
537
538 if (mOgreRenderDepthTexture)
539 {
540 mOgreRenderDepthTexture->removeAllViewports();
541 mOgreRenderDepthTexture = 0;
542 }
543
544 if (mMrtTexture)
545 {
546 mMrtTexture->removeListener(this);
547 mMrtTexture->removeAllViewports();
548 Ogre::Root::getSingleton().getRenderSystem()->destroyRenderTarget(mBaseResourceName + "/Texture/MRT");
549 mMrtTexture = 0;
550 }
551
552 if (mOgreTexture)
553 {
554 Ogre::TextureManager::getSingleton().remove(mOgreTexture->getHandle());
555 mOgreTexture.reset();
556 }
557
558 if (mOgreDepthTexture)
559 {
560 Ogre::TextureManager::getSingleton().remove(mOgreDepthTexture->getHandle());
561 mOgreDepthTexture.reset();
562 }
563}
564
569
570void SSubEntityCameraSelectorBuffer::UpdateBufferSize(unsigned int texwidth, unsigned int texheight, const bool& forceRefresh)
571{
572 if ((texwidth != mRealWidth)
573 || (texheight != mRealHeight)
574 || forceRefresh
575 || (!mOgreRenderTexture))
576 {
577 DeleteTexture();
578 try
579 {
580 CreateTexture(texwidth, texheight);
581 }
582 catch (Ogre::Exception &)
583 {
584 // could not create the texture, renderer not ready ?
585 }
586 }
587}
588
589void SSubEntityCameraSelectorBuffer::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
590{
591 if (evt.source == mOgreRenderTexture || evt.source == mMrtTexture)
592 {
593 // Reset switcher
594 nodeSelectorMaterialSwitcher->ResetSwitcher();
595 Ogre::MaterialManager::getSingleton().addListener(nodeSelectorMaterialSwitcher, mBaseResourceName);
596 }
597}
598
599void SSubEntityCameraSelectorBuffer::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
600{
601 if (((evt.source == mOgreRenderTexture) && mOgreRenderTexture->isActive()) || ((evt.source == mMrtTexture) && mMrtTexture->isActive()))
602 {
603 nodeSelectorMaterialSwitcher->ResetPriorizedObject();
604 Ogre::MaterialManager::getSingleton().removeListener(nodeSelectorMaterialSwitcher, mBaseResourceName);
605 }
606}
607
608}
bool GetRttPixelFormat(Ogre::PixelFormat &format, bool alpha=false, bool floattex=false)
Definition SO3Root.cpp:650
Ogre::RenderSystem * GetOgreRenderSystem()
Definition SO3Root.cpp:865
static SRoot & getSingleton()
Definition SO3Root.cpp:116
static SRoot * getSingletonPtr()
Definition SO3Root.cpp:111
virtual void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
void UpdateBufferSize(unsigned int texwidth, unsigned int texheight, const bool &forceRefresh=false)
Ogre::SubEntity * GetSelectedSubEntity(int posX, int posY)
virtual void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
Ogre::SubEntity * GetSubEntity(const Ogre::ColourValue &searchedColour)