SRD

createscene

SRD
Nov 24th, 2017
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. /* My app works as follows.
  2. - User starts app.
  3. - User chooses File->Open to select a file to render.
  4. - App renders file.
  5.  
  6. createScene() builds the model after a user loads the file to be rendered.
  7. createScene() is called within frameRenderingQueued().
  8.  
  9. The problem is that createScene() builds the model using vertex buffers (i.e., createManual()) and if it's in frameRenderingQueued(), then it will get called multiple times, and the second time it's called, it creates the model that's already been created (resulting in error).
  10.  
  11. Normally to create the scene, I'd have createScene() called within initialize() where it only gets called on started, but in this case, I'm adding a mesh during runtime.
  12.  
  13. Can anyone help with where I should add this, or point to any examples? The following is what I currently have.
  14. */
  15.  
  16. class QtOgreWindow : public QWindow, public Ogre::FrameListener
  17. {
  18.    ...
  19. };
  20.  
  21. QtOgreWindow::render(QPainer* painter) { ... }
  22.  
  23. QtOgreWindow::initialize() {
  24.  ...
  25. }
  26.  
  27. QtOgreWindow::registerHlms() {
  28.  ...
  29. }
  30.  
  31. QtOgreWindow::createScene() {
  32.     static bool called = false;
  33.  
  34.     Ogre::HlmsManager* hlmsManager =
  35.         Ogre::Root::getSingleton().getHlmsManager();
  36.  
  37.     Ogre::HlmsDatablock* block = hlmsManager->getDefaultDatablock();
  38.  
  39.     Ogre::HlmsMacroblock macroblock = *block->getMacroblock();
  40.     macroblock.mPolygonMode = Ogre::PM_WIREFRAME;
  41.     block->setMacroblock(macroblock);
  42.  
  43.     if (called == false) {
  44.         omesh = createStaticMesh();
  45.         called = true;
  46.     }
  47.    
  48.     Ogre::Item *item = ogreSceneManager->createItem(omesh, Ogre::SCENE_DYNAMIC);
  49.     item->setDatablock(block);
  50.  
  51.     mSceneNode = ogreSceneManager->getRootSceneNode(Ogre::SCENE_DYNAMIC)->
  52.         createChildSceneNode(Ogre::SCENE_DYNAMIC);
  53.     mSceneNode->attachObject(item);
  54.     mSceneNode->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.0f));
  55. }
  56.  
  57. QtOgreWindow::createCompositor() {
  58.  ...
  59. }
  60.  
  61. QtOgreWindow::render() {
  62.  ...
  63. }
  64.  
  65. QtOgreWindow::renderLater() {
  66.  ...
  67. }
  68.  
  69. QtOgreWindow::event(QEvent* event) {
  70.  ...
  71. }
  72.  
  73. QtOgreWindow::exposeEvent(QExposeEvent* event) {
  74.  ...
  75. }
  76.  
  77. QtOgreWindow::renderNow() {
  78.  ...
  79. }
  80.  
  81. QtOgreWindow::setAnimating(bool animating) {
  82.  ...
  83. }
  84.  
  85. QtOgreWindow::frameRenderingQueue(const Ogre::FrameEvent& evt) {
  86.     cameraManager->frameRenderingQueued(evt);
  87.  
  88.     if (mesh_loaded)
  89.         createScene();
  90.  
  91.     return true;
  92.  
  93. }
  94.  
  95. ... mouse, wheel, key events ...
Advertisement
Add Comment
Please, Sign In to add comment