renderManager.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "renderManager.h"
  2. //Dummy constructors / Destructors
  3. RenderManager::RenderManager(){}
  4. RenderManager::~RenderManager(){}
  5. bool RenderManager::startUp(DisplayManager &displayManager,SceneManager &sceneManager ){
  6. screen = &displayManager;
  7. sceneLocator = &sceneManager;
  8. if( !initSoftwareRenderer() ){
  9. printf("Failed to initialize software Renderer!\n");
  10. return false;
  11. }
  12. return true;
  13. }
  14. void RenderManager::shutDown(){
  15. sceneLocator = nullptr;
  16. screen = nullptr;
  17. renderInstance.shutDown();
  18. }
  19. void RenderManager::render(){
  20. //Clear screen and reset current buffers
  21. screen->clear();
  22. renderInstance.clearBuffers();
  23. //Build a render Queue for drawing multiple models
  24. //Also assigns the current camera to the software renderer
  25. buildRenderQueue();
  26. //Draw all meshes in the render queue so far we assume they are
  27. //normal triangular meshes.
  28. while( !renderObjectQueue->empty() ){
  29. renderInstance.drawTriangularMesh(renderObjectQueue->front());
  30. renderObjectQueue->pop();
  31. }
  32. //Swapping pixel buffer with final rendered image with the
  33. //display buffer
  34. screen->swapBuffers(renderInstance.getRenderTarget());
  35. //Set camera pointer to null just in case a scene change occurs
  36. renderInstance.setCameraToRenderFrom(nullptr);
  37. }
  38. //Gets the list of visible models from the current scene
  39. //Done every frame in case scene changes
  40. void RenderManager::buildRenderQueue(){
  41. //Set renderer camera
  42. Scene* currentScene = sceneLocator->getCurrentScene();
  43. renderInstance.setCameraToRenderFrom(currentScene->getCurrentCamera());
  44. //Get pointers to the visible model queu
  45. renderObjectQueue = currentScene->getVisiblemodels();
  46. }
  47. bool RenderManager::initSoftwareRenderer(){
  48. int w = DisplayManager::SCREEN_WIDTH;
  49. int h = DisplayManager::SCREEN_HEIGHT;
  50. return renderInstance.startUp(w,h);
  51. }