/** Virtual function called when the plunger hits something. * The plunger is special in that it is not deleted when hitting an object. * Instead it stays around (though not as a graphical or physical object) * till the rubber band expires. * \param kart Pointer to the kart hit (NULL if not a kart). * \param obj Pointer to PhysicalObject object if hit (NULL otherwise). */ void Plunger::hit(Kart *kart, PhysicalObject *obj) { if(isOwnerImmunity(kart)) return; RaceGUIBase* gui = World::getWorld()->getRaceGUI(); irr::core::stringw hit_message; // pulling back makes no sense in battle mode, since this mode is not a race. // so in battle mode, always hide view if( m_reverse_mode || race_manager->isBattleMode() ) { if(kart) { kart->blockViewWithPlunger(); hit_message += StringUtils::insertValues(getPlungerInFaceString(), kart->getName().c_str(), m_owner->getName().c_str() ).c_str(); gui->addMessage(hit_message, NULL, 3.0f, 40, video::SColor(255, 255, 255, 255), false); } m_keep_alive = 0; // Make this object invisible by placing it faaar down. Note that if this // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. getNode()->setVisible(false); World::getWorld()->getPhysics()->removeBody(getBody()); } else { m_keep_alive = m_owner->getKartProperties()->getRubberBandDuration(); // Make this object invisible by placing it faaar down. Not that if this // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. scene::ISceneNode *node = getNode(); if(node) { node->setVisible(false); } World::getWorld()->getPhysics()->removeBody(getBody()); if(kart) { m_rubber_band->hit(kart); return; } else if(obj) { Vec3 pos(obj->getBody()->getWorldTransform().getOrigin()); m_rubber_band->hit(NULL, &pos); } else { m_rubber_band->hit(NULL, &(getXYZ())); } } } // hit
void IrrDriver::renderFixed(float dt) { World *world = World::getWorld(); // Never NULL. m_video_driver->beginScene(/*backBuffer clear*/ true, /*zBuffer*/ true, world->getClearColor()); irr_driver->getVideoDriver()->enableMaterial2D(); RaceGUIBase *rg = world->getRaceGUI(); if (rg) rg->update(dt); for(unsigned int i=0; i<Camera::getNumCameras(); i++) { Camera *camera = Camera::getCamera(i); std::ostringstream oss; oss << "drawAll() for kart " << i; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), (i+1)*60, 0x00, 0x00); camera->activate(); rg->preRenderCallback(camera); // adjusts start referee m_renderpass = ~0; m_scene_manager->drawAll(); PROFILER_POP_CPU_MARKER(); // Note that drawAll must be called before rendering // the bullet debug view, since otherwise the camera // is not set up properly. This is only used for // the bullet debug view. if (UserConfigParams::m_artist_debug_mode) World::getWorld()->getPhysics()->draw(); } // for i<world->getNumKarts() // Set the viewport back to the full screen for race gui m_video_driver->setViewPort(core::recti(0, 0, UserConfigParams::m_width, UserConfigParams::m_height)); for(unsigned int i=0; i<Camera::getNumCameras(); i++) { Camera *camera = Camera::getCamera(i); std::ostringstream oss; oss << "renderPlayerView() for kart " << i; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), 0x00, 0x00, (i+1)*60); rg->renderPlayerView(camera, dt); PROFILER_POP_CPU_MARKER(); } // for i<getNumKarts // Either render the gui, or the global elements of the race gui. GUIEngine::render(dt); // Render the profiler if(UserConfigParams::m_profiler_enabled) { PROFILER_DRAW(); } #ifdef DEBUG drawDebugMeshes(); #endif m_video_driver->endScene(); }
void IrrDriver::renderGLSL(float dt) { BoundingBoxes.clear(); World *world = World::getWorld(); // Never NULL. Track *track = world->getTrack(); for (unsigned i = 0; i < PowerupManager::POWERUP_MAX; i++) { scene::IMesh *mesh = powerup_manager->m_all_meshes[i]; if (!mesh) continue; for (unsigned j = 0; j < mesh->getMeshBufferCount(); j++) { scene::IMeshBuffer *mb = mesh->getMeshBuffer(j); if (!mb) continue; for (unsigned k = 0; k < 4; k++) { video::ITexture *tex = mb->getMaterial().getTexture(k); if (!tex) continue; compressTexture(tex, true); } } } // Overrides video::SOverrideMaterial &overridemat = m_video_driver->getOverrideMaterial(); overridemat.EnablePasses = scene::ESNRP_SOLID | scene::ESNRP_TRANSPARENT; overridemat.EnableFlags = 0; if (m_wireframe) { overridemat.Material.Wireframe = 1; overridemat.EnableFlags |= video::EMF_WIREFRAME; } if (m_mipviz) { overridemat.Material.MaterialType = m_shaders->getShader(ES_MIPVIZ); overridemat.EnableFlags |= video::EMF_MATERIAL_TYPE; overridemat.EnablePasses = scene::ESNRP_SOLID; } // Get a list of all glowing things. The driver's list contains the static ones, // here we add items, as they may disappear each frame. std::vector<GlowData> glows = m_glowing; ItemManager * const items = ItemManager::get(); const u32 itemcount = items->getNumberOfItems(); u32 i; for (i = 0; i < itemcount; i++) { Item * const item = items->getItem(i); if (!item) continue; const Item::ItemType type = item->getType(); if (type != Item::ITEM_NITRO_BIG && type != Item::ITEM_NITRO_SMALL && type != Item::ITEM_BONUS_BOX && type != Item::ITEM_BANANA && type != Item::ITEM_BUBBLEGUM) continue; LODNode * const lod = (LODNode *) item->getSceneNode(); if (!lod->isVisible()) continue; const int level = lod->getLevel(); if (level < 0) continue; scene::ISceneNode * const node = lod->getAllNodes()[level]; node->updateAbsolutePosition(); GlowData dat; dat.node = node; dat.r = 1.0f; dat.g = 1.0f; dat.b = 1.0f; const video::SColorf &c = ItemManager::getGlowColor(type); dat.r = c.getRed(); dat.g = c.getGreen(); dat.b = c.getBlue(); glows.push_back(dat); } // Start the RTT for post-processing. // We do this before beginScene() because we want to capture the glClear() // because of tracks that do not have skyboxes (generally add-on tracks) m_post_processing->begin(); RaceGUIBase *rg = world->getRaceGUI(); if (rg) rg->update(dt); if (!CVS->isDefferedEnabled()) { SColor clearColor(0, 150, 150, 150); if (World::getWorld() != NULL) clearColor = World::getWorld()->getClearColor(); glClear(GL_COLOR_BUFFER_BIT); glDepthMask(GL_TRUE); glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } for(unsigned int cam = 0; cam < Camera::getNumCameras(); cam++) { Camera * const camera = Camera::getCamera(cam); scene::ICameraSceneNode * const camnode = camera->getCameraSceneNode(); std::ostringstream oss; oss << "drawAll() for kart " << cam; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), (cam+1)*60, 0x00, 0x00); camera->activate(!CVS->isDefferedEnabled()); rg->preRenderCallback(camera); // adjusts start referee m_scene_manager->setActiveCamera(camnode); const core::recti &viewport = camera->getViewport(); if (World::getWorld() && World::getWorld()->getTrack()->hasShadows() && !SphericalHarmonicsTextures.empty()) irr_driver->getSceneManager()->setAmbientLight(SColor(0, 0, 0, 0)); // TODO: put this outside of the rendering loop if (!m_skybox_ready) { prepareSkybox(); m_skybox_ready = true; } if (!CVS->isDefferedEnabled()) glEnable(GL_FRAMEBUFFER_SRGB); PROFILER_PUSH_CPU_MARKER("Update Light Info", 0xFF, 0x0, 0x0); unsigned plc = UpdateLightsInfo(camnode, dt); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("UBO upload", 0x0, 0xFF, 0x0); computeMatrixesAndCameras(camnode, viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); uploadLightingData(); PROFILER_POP_CPU_MARKER(); renderScene(camnode, plc, glows, dt, track->hasShadows(), false); // Render bounding boxes if (irr_driver->getBoundingBoxesViz()) { glUseProgram(UtilShader::ColoredLine::getInstance()->Program); glBindVertexArray(UtilShader::ColoredLine::getInstance()->vao); glBindBuffer(GL_ARRAY_BUFFER, UtilShader::ColoredLine::getInstance()->vbo); UtilShader::ColoredLine::getInstance()->setUniforms(SColor(255, 255, 0, 0)); const float *tmp = BoundingBoxes.data(); for (unsigned int i = 0; i < BoundingBoxes.size(); i += 1024 * 6) { unsigned count = MIN2((int)BoundingBoxes.size() - i, 1024 * 6); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]); glDrawArrays(GL_LINES, 0, count / 3); } } // Debug physic // Note that drawAll must be called before rendering // the bullet debug view, since otherwise the camera // is not set up properly. This is only used for // the bullet debug view. if (UserConfigParams::m_artist_debug_mode) World::getWorld()->getPhysics()->draw(); if (world != NULL && world->getPhysics() != NULL) { IrrDebugDrawer* debug_drawer = world->getPhysics()->getDebugDrawer(); if (debug_drawer != NULL && debug_drawer->debugEnabled()) { const std::map<video::SColor, std::vector<float> >& lines = debug_drawer->getLines(); std::map<video::SColor, std::vector<float> >::const_iterator it; glUseProgram(UtilShader::ColoredLine::getInstance()->Program); glBindVertexArray(UtilShader::ColoredLine::getInstance()->vao); glBindBuffer(GL_ARRAY_BUFFER, UtilShader::ColoredLine::getInstance()->vbo); for (it = lines.begin(); it != lines.end(); it++) { UtilShader::ColoredLine::getInstance()->setUniforms(it->first); const std::vector<float> &vertex = it->second; const float *tmp = vertex.data(); for (unsigned int i = 0; i < vertex.size(); i += 1024 * 6) { unsigned count = MIN2((int)vertex.size() - i, 1024 * 6); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]); glDrawArrays(GL_LINES, 0, count / 3); } } glUseProgram(0); glBindVertexArray(0); } } // Render the post-processed scene if (CVS->isDefferedEnabled()) { bool isRace = StateManager::get()->getGameState() == GUIEngine::GAME; FrameBuffer *fbo = m_post_processing->render(camnode, isRace); if (irr_driver->getNormals()) irr_driver->getFBO(FBO_NORMAL_AND_DEPTHS).BlitToDefault(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); else if (irr_driver->getSSAOViz()) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); m_post_processing->renderPassThrough(m_rtts->getFBO(FBO_HALF1_R).getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); } else if (irr_driver->getRSM()) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y); m_post_processing->renderPassThrough(m_rtts->getRSM().getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); } else if (irr_driver->getShadowViz()) { renderShadowsDebug(); } else { glEnable(GL_FRAMEBUFFER_SRGB); glBindFramebuffer(GL_FRAMEBUFFER, 0); if (CVS->isDefferedEnabled()) camera->activate(); m_post_processing->renderPassThrough(fbo->getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); glDisable(GL_FRAMEBUFFER_SRGB); } } // Save projection-view matrix for the next frame camera->setPreviousPVMatrix(m_ProjViewMatrix); PROFILER_POP_CPU_MARKER(); } // for i<world->getNumKarts() // Use full screen size float tmp[2]; tmp[0] = float(m_actual_screen_size.Width); tmp[1] = float(m_actual_screen_size.Height); glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO); glBufferSubData(GL_UNIFORM_BUFFER, (16 * 9) * sizeof(float), 2 * sizeof(float), tmp); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glUseProgram(0); // Set the viewport back to the full screen for race gui m_video_driver->setViewPort(core::recti(0, 0, irr_driver->getActualScreenSize().Width, irr_driver->getActualScreenSize().Height)); for(unsigned int i=0; i<Camera::getNumCameras(); i++) { Camera *camera = Camera::getCamera(i); std::ostringstream oss; oss << "renderPlayerView() for kart " << i; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), 0x00, 0x00, (i+1)*60); rg->renderPlayerView(camera, dt); PROFILER_POP_CPU_MARKER(); } // for i<getNumKarts { ScopedGPUTimer Timer(getGPUTimer(Q_GUI)); PROFILER_PUSH_CPU_MARKER("GUIEngine", 0x75, 0x75, 0x75); // Either render the gui, or the global elements of the race gui. GUIEngine::render(dt); PROFILER_POP_CPU_MARKER(); } // Render the profiler if(UserConfigParams::m_profiler_enabled) { PROFILER_DRAW(); } #ifdef DEBUG drawDebugMeshes(); #endif PROFILER_PUSH_CPU_MARKER("EndSccene", 0x45, 0x75, 0x45); m_video_driver->endScene(); PROFILER_POP_CPU_MARKER(); getPostProcessing()->update(dt); }
void render(float elapsed_time) { GUIEngine::dt = elapsed_time; // Not yet initialized, or already cleaned up if (g_skin == NULL) return; // ---- menu drawing // draw background image and sections const GameState gamestate = g_state_manager->getGameState(); if (gamestate == MENU && GUIEngine::getCurrentScreen() != NULL && !GUIEngine::getCurrentScreen()->needs3D()) { g_skin->drawBgImage(); } else if (gamestate == INGAME_MENU) { g_skin->drawBGFadeColor(); } g_driver->enableMaterial2D(); if (gamestate == MENU || gamestate == INGAME_MENU) { g_skin->renderSections(); } // let irrLicht do the rest (the Skin object will be called for // further render) g_env->drawAll(); // ---- some menus may need updating if (gamestate != GAME) { if (ModalDialog::isADialogActive()) ModalDialog::getCurrent()->onUpdate(dt); else getCurrentScreen()->onUpdate(elapsed_time, g_driver); } else { if (ModalDialog::isADialogActive()) { ModalDialog::getCurrent()->onUpdate(dt); } else { RaceGUIBase* rg = World::getWorld()->getRaceGUI(); if (rg != NULL) rg->renderGlobal(elapsed_time); } } if (gamestate == MENU || gamestate == INGAME_MENU) { g_skin->drawTooltips(); } if (gamestate != GAME && !gui_messages.empty()) { core::dimension2d<u32> screen_size = irr_driver->getFrameSize(); const int text_height = getFontHeight() + 20; const int y_from = screen_size.Height - text_height; int count = 0; std::vector<MenuMessage>::iterator it; for (it=gui_messages.begin(); it != gui_messages.end();) { if ((*it).m_time > 0.0f) { (*it).m_time -= dt; core::rect<s32> msgRect(core::position2d<s32>(0, y_from - count*text_height), core::dimension2d<s32>(screen_size.Width, text_height) ); Private::g_driver->draw2DRectangle(SColor(255,252,248,230), msgRect); Private::g_font->draw((*it).m_message.c_str(), msgRect, video::SColor(255, 255, 0, 0), true /* hcenter */, true /* vcenter */); count++; it++; } else { it = gui_messages.erase(it); } } } // draw FPS if enabled if ( UserConfigParams::m_display_fps ) irr_driver->displayFPS(); g_driver->enableMaterial2D(false); if (gamestate == MENU) { if (DemoWorld::updateIdleTimeAndStartDemo(elapsed_time)) { return; } } else { DemoWorld::resetIdleTime(); } } // render
/** This function is called after instanciating. This can't be moved to the * contructor as child classes must be instanciated, otherwise polymorphism * will fail and the results will be incorrect . Also in init() functions * can be called that use World::getWorld(). */ void World::init() { race_state = new RaceState(); m_faster_music_active = false; m_fastest_kart = 0; m_eliminated_karts = 0; m_eliminated_players = 0; m_num_players = 0; // Create the race gui before anything else is attached to the scene node // (which happens when the track is loaded). This allows the race gui to // do any rendering on texture. createRaceGUI(); // Grab the track file m_track = track_manager->getTrack(race_manager->getTrackName()); if(!m_track) { std::ostringstream msg; msg << "Track '" << race_manager->getTrackName() << "' not found.\n"; throw std::runtime_error(msg.str()); } // Create the physics m_physics = new Physics(); unsigned int num_karts = race_manager->getNumberOfKarts(); //assert(num_karts > 0); // Load the track models - this must be done before the karts so that the // karts can be positioned properly on (and not in) the tracks. m_track->loadTrackModel(this, race_manager->getReverseTrack()); for(unsigned int i=0; i<num_karts; i++) { std::string kart_ident = history->replayHistory() ? history->getKartIdent(i) : race_manager->getKartIdent(i); int local_player_id = race_manager->getKartLocalPlayerId(i); int global_player_id = race_manager->getKartGlobalPlayerId(i); AbstractKart* newkart = createKart(kart_ident, i, local_player_id, global_player_id, race_manager->getKartType(i)); m_karts.push_back(newkart); m_track->adjustForFog(newkart->getNode()); } // for i if(ReplayPlay::get()) ReplayPlay::get()->Load(); resetAllKarts(); // Note: track reset must be called after all karts exist, since check // objects need to allocate data structures depending on the number // of karts. m_track->reset(); if(!history->replayHistory()) history->initRecording(); if(ReplayRecorder::get()) ReplayRecorder::get()->init(); network_manager->worldLoaded(); powerup_manager->updateWeightsForRace(num_karts); // erase messages left over RaceGUIBase* rg = getRaceGUI(); if (rg) { rg->init(); rg->clearAllMessages(); } } // init
void IrrDriver::renderGLSL(float dt) { World *world = World::getWorld(); // Never NULL. // Overrides video::SOverrideMaterial &overridemat = m_video_driver->getOverrideMaterial(); overridemat.EnablePasses = scene::ESNRP_SOLID | scene::ESNRP_TRANSPARENT; overridemat.EnableFlags = 0; if (m_wireframe) { overridemat.Material.Wireframe = 1; overridemat.EnableFlags |= video::EMF_WIREFRAME; } if (m_mipviz) { overridemat.Material.MaterialType = m_shaders->getShader(ES_MIPVIZ); overridemat.EnableFlags |= video::EMF_MATERIAL_TYPE; overridemat.EnablePasses = scene::ESNRP_SOLID; } // Get a list of all glowing things. The driver's list contains the static ones, // here we add items, as they may disappear each frame. std::vector<GlowData> glows = m_glowing; std::vector<GlowNode *> transparent_glow_nodes; ItemManager * const items = ItemManager::get(); const u32 itemcount = items->getNumberOfItems(); u32 i; // For each static node, give it a glow representation const u32 staticglows = glows.size(); for (i = 0; i < staticglows; i++) { scene::ISceneNode * const node = glows[i].node; const float radius = (node->getBoundingBox().getExtent().getLength() / 2) * 2.0f; GlowNode * const repnode = new GlowNode(irr_driver->getSceneManager(), radius); repnode->setPosition(node->getTransformedBoundingBox().getCenter()); transparent_glow_nodes.push_back(repnode); } for (i = 0; i < itemcount; i++) { Item * const item = items->getItem(i); if (!item) continue; const Item::ItemType type = item->getType(); if (type != Item::ITEM_NITRO_BIG && type != Item::ITEM_NITRO_SMALL && type != Item::ITEM_BONUS_BOX && type != Item::ITEM_BANANA && type != Item::ITEM_BUBBLEGUM) continue; LODNode * const lod = (LODNode *) item->getSceneNode(); if (!lod->isVisible()) continue; const int level = lod->getLevel(); if (level < 0) continue; scene::ISceneNode * const node = lod->getAllNodes()[level]; node->updateAbsolutePosition(); GlowData dat; dat.node = node; dat.r = 1.0f; dat.g = 1.0f; dat.b = 1.0f; const video::SColorf &c = ItemManager::getGlowColor(type); dat.r = c.getRed(); dat.g = c.getGreen(); dat.b = c.getBlue(); glows.push_back(dat); // Push back its representation too const float radius = (node->getBoundingBox().getExtent().getLength() / 2) * 2.0f; GlowNode * const repnode = new GlowNode(irr_driver->getSceneManager(), radius); repnode->setPosition(node->getTransformedBoundingBox().getCenter()); transparent_glow_nodes.push_back(repnode); } // Start the RTT for post-processing. // We do this before beginScene() because we want to capture the glClear() // because of tracks that do not have skyboxes (generally add-on tracks) m_post_processing->begin(); m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false); m_video_driver->beginScene(/*backBuffer clear*/ true, /*zBuffer*/ true, world->getClearColor()); // Clear normal and depth to zero m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_NORMAL_AND_DEPTH), true, false, video::SColor(0,0,0,0)); // Clear specular map to zero m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_SPECULARMAP), true, false, video::SColor(0,0,0,0)); irr_driver->getVideoDriver()->enableMaterial2D(); RaceGUIBase *rg = world->getRaceGUI(); if (rg) rg->update(dt); for(unsigned int cam = 0; cam < Camera::getNumCameras(); cam++) { Camera * const camera = Camera::getCamera(cam); scene::ICameraSceneNode * const camnode = camera->getCameraSceneNode(); #ifdef ENABLE_PROFILER std::ostringstream oss; oss << "drawAll() for kart " << cam << std::flush; PROFILER_PUSH_CPU_MARKER(oss.str().c_str(), (cam+1)*60, 0x00, 0x00); #endif camera->activate(); rg->preRenderCallback(camera); // adjusts start referee const u32 bgnodes = m_background.size(); /* if (bgnodes) { // If there are background nodes (3d skybox), draw them now. m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false); m_renderpass = scene::ESNRP_SKY_BOX; m_scene_manager->drawAll(m_renderpass); const video::SOverrideMaterial prev = overridemat; overridemat.Enabled = 1; overridemat.EnableFlags = video::EMF_MATERIAL_TYPE; overridemat.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; for (i = 0; i < bgnodes; i++) { m_background[i]->setPosition(camnode->getPosition() * 0.97f); m_background[i]->updateAbsolutePosition(); m_background[i]->render(); } overridemat = prev; m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, true); }*/ // Fire up the MRT irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH), false, false); PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00); m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_SOLID; glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDepthMask(GL_TRUE); glDisable(GL_BLEND); irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS); m_scene_manager->drawAll(m_renderpass); irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION)); irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW)); irr_driver->genProjViewMatrix(); PROFILER_POP_CPU_MARKER(); // Todo : reenable glow and shadows //ShadowImportanceProvider * const sicb = (ShadowImportanceProvider *) // irr_driver->getCallback(ES_SHADOW_IMPORTANCE); //sicb->updateIPVMatrix(); // Used to cull glowing items & lights const core::aabbox3df cambox = camnode->getViewFrustum()->getBoundingBox(); PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90); // Shadows if (!m_mipviz && !m_wireframe && UserConfigParams::m_shadows) //&& World::getWorld()->getTrack()->hasShadows()) { renderShadows(camnode, camera); } PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00); // Lights renderLights(cambox, camnode, overridemat, cam, dt); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Solid Pass 2", 0x00, 0x00, 0xFF); irr_driver->setPhase(SOLID_LIT_PASS); glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDepthMask(GL_FALSE); glDisable(GL_BLEND); m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_SOLID; m_scene_manager->drawAll(m_renderpass); PROFILER_POP_CPU_MARKER(); if (World::getWorld()->getTrack()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00); m_post_processing->renderFog(irr_driver->getInvProjMatrix()); PROFILER_POP_CPU_MARKER(); } PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0xFF, 0x00); // Render anything glowing. if (!m_mipviz && !m_wireframe) { irr_driver->setPhase(GLOW_PASS); renderGlow(overridemat, glows, cambox, cam); } // end glow PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF); renderSkybox(); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Lensflare/godray", 0x00, 0xFF, 0xFF); // Is the lens flare enabled & visible? Check last frame's query. const bool hasflare = World::getWorld()->getTrack()->hasLensFlare(); const bool hasgodrays = World::getWorld()->getTrack()->hasGodRays(); if (true)//hasflare || hasgodrays) { irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver(); GLuint res = 0; if (m_query_issued) gl_driver->extGlGetQueryObjectuiv(m_lensflare_query, GL_QUERY_RESULT, &res); m_post_processing->setSunPixels(res); // Prepare the query for the next frame. glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); gl_driver->extGlBeginQuery(GL_SAMPLES_PASSED_ARB, m_lensflare_query); m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); m_scene_manager->drawAll(scene::ESNRP_CAMERA); irr_driver->setPhase(GLOW_PASS); m_sun_interposer->render(); gl_driver->extGlEndQuery(GL_SAMPLES_PASSED_ARB); m_query_issued = true; m_lensflare->setStrength(res / 4000.0f); if (hasflare) m_lensflare->OnRegisterSceneNode(); // Make sure the color mask is reset glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } PROFILER_POP_CPU_MARKER(); // We need to re-render camera due to the per-cam-node hack. PROFILER_PUSH_CPU_MARKER("- Transparent Pass", 0xFF, 0x00, 0x00); irr_driver->setPhase(TRANSPARENT_PASS); m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_TRANSPARENT; glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); m_scene_manager->drawAll(m_renderpass); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Particles", 0xFF, 0xFF, 0x00); m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_TRANSPARENT_EFFECT; glDepthMask(GL_FALSE); glDisable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); m_scene_manager->drawAll(m_renderpass); PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Displacement", 0x00, 0x00, 0xFF); // Handle displacing nodes, if any const u32 displacingcount = m_displacing.size(); if (displacingcount) { renderDisplacement(overridemat, cam); } PROFILER_POP_CPU_MARKER(); // Drawing for this cam done, cleanup const u32 glowrepcount = transparent_glow_nodes.size(); for (i = 0; i < glowrepcount; i++) { transparent_glow_nodes[i]->remove(); transparent_glow_nodes[i]->drop(); } PROFILER_POP_CPU_MARKER(); // Note that drawAll must be called before rendering // the bullet debug view, since otherwise the camera // is not set up properly. This is only used for // the bullet debug view. if (UserConfigParams::m_artist_debug_mode) World::getWorld()->getPhysics()->draw(); } // for i<world->getNumKarts() PROFILER_PUSH_CPU_MARKER("Postprocessing", 0xFF, 0xFF, 0x00); // Render the post-processed scene m_post_processing->render(); PROFILER_POP_CPU_MARKER(); // Set the viewport back to the full screen for race gui m_video_driver->setViewPort(core::recti(0, 0, UserConfigParams::m_width, UserConfigParams::m_height)); for(unsigned int i=0; i<Camera::getNumCameras(); i++) { Camera *camera = Camera::getCamera(i); char marker_name[100]; sprintf(marker_name, "renderPlayerView() for kart %d", i); PROFILER_PUSH_CPU_MARKER(marker_name, 0x00, 0x00, (i+1)*60); rg->renderPlayerView(camera, dt); PROFILER_POP_CPU_MARKER(); } // for i<getNumKarts PROFILER_PUSH_CPU_MARKER("GUIEngine", 0x75, 0x75, 0x75); // Either render the gui, or the global elements of the race gui. GUIEngine::render(dt); PROFILER_POP_CPU_MARKER(); // Render the profiler if(UserConfigParams::m_profiler_enabled) { PROFILER_DRAW(); } #ifdef DEBUG drawDebugMeshes(); #endif PROFILER_PUSH_CPU_MARKER("EndSccene", 0x45, 0x75, 0x45); m_video_driver->endScene(); PROFILER_POP_CPU_MARKER(); getPostProcessing()->update(dt); }