void Scene::Render(Renderer *renderer) { if (m_Root && m_Camera) { m_Camera->CalculateViewMatrix(); // Update lighting parameters GetLightManager()->UpdateShader(this, ResourceManager::GetInstance()->GetShader("sprite")); GetLightManager()->UpdateShader(this, m_ParticleEmitter->GetShader()); m_Root->Render(this, renderer); m_ParticleEmitter->Render(renderer, m_Camera->GetView()); } }
bool Scene::AddChild(unsigned int ActorID, std::shared_ptr<ISceneNode> child) { m_ActorMap[ActorID] = child; // cast child into different node types and add to other managers if necessary (like if it is a light node, then add it to light manager) std::shared_ptr<LightNode> pLight = std::dynamic_pointer_cast<LightNode>(child); if (pLight) { // child is a LightNode; also add a reference to the LightManager GetLightManager()->AddLight(pLight); } // otherwise add it as child to Root node return m_Root->AddChild(child); }
bool Scene::RemoveChild(unsigned int ActorID) { std::shared_ptr<ISceneNode> kid = GetSceneNode(ActorID); // Check if it is any of the different node types (like light) and act accordingly) std::shared_ptr<LightNode> pLight = std::dynamic_pointer_cast<LightNode>(kid); if (pLight) { // child is a LightNode; also remove reference to the LightManager GetLightManager()->RemoveLight(pLight); } // Otherwise, erase as normal m_ActorMap.erase(ActorID); return m_Root->RemoveChild(ActorID); }
void RenderPipe_DLPre_opengl::renderByProgram( int type, const RenderEntityList& listToRender ) { glUseProgram(m_pipeProgramID[type]); glMatrixMode(GL_PROJECTION); glLoadMatrixf( (float *) &(GetProjectionMatrix())); CMatrix view_matrix = GetViewMatrix(); Light dirLight = GetLightManager().getDirLight(); CVector camPos = GetCamPos(); GLint reg = glGetUniformLocation(m_pipeProgramID[type], "u_light"); if (reg >= 0) glUniform4fv(reg, 4, (float *)&dirLight.dirLightData); reg = glGetUniformLocation(m_pipeProgramID[type], "u_textureSize"); if (reg >= 0) glUniform4fv(reg, 1, (float *)&m_vTextureSize); reg = glGetUniformLocation(m_pipeProgramID[type], "u_camPos"); if (reg >= 0) glUniform4fv(reg, 1, (float *)&camPos); reg = glGetUniformLocation(m_pipeProgramID[type], "u_shadowSampler"); if (reg >= 0) glUniform1i(reg, SHADOW_MAP_CHANNEL); reg = glGetUniformLocation(m_pipeProgramID[type], "u_diffuseSampler"); if (reg >= 0) glUniform1i(reg, DIFF0_MAP_CHANNEL); reg = glGetUniformLocation(m_pipeProgramID[type], "u_specSampler"); if (reg >= 0) glUniform1i(reg, SPEC_MAP_CHANNEL); reg = glGetUniformLocation(m_pipeProgramID[type], "u_normalSampler"); if (reg >= 0) glUniform1i(reg, NORMAL_MAP_CHANNEL); reg = glGetUniformLocation(m_pipeProgramID[type], "u_texoffset"); if (reg >= 0) glUniform4fv(reg, PCF_SAMPLES, (float *)m_PCFOffset); GLint regIsShadowed = glGetUniformLocation(m_pipeProgramID[type], "u_isShadowed"); GLint regCanBeLighted = glGetUniformLocation(m_pipeProgramID[type], "u_canBeLighted"); GLint regDiffScale = glGetUniformLocation(m_pipeProgramID[type], "u_diffScale"); for (RenderEntityList::const_iterator it=listToRender.begin(); it!=listToRender.end(); ++it) { if (regIsShadowed >= 0) glUniform1i(regIsShadowed, (*it)->canBeShadowed); if (regCanBeLighted >= 0) glUniform1i(regCanBeLighted, (*it)->canBeLighted); CMatrix worldMat = (*it)->getWorldMat(); CMatrix light_wvp_matrix = worldMat * m_light_vmat * m_zbias * m_light_pmat * m_remapmat; glMatrixMode(GL_TEXTURE); glActiveTexture(GL_TEXTURE0_ARB); glLoadMatrixf( (float *) &light_wvp_matrix ); glActiveTexture(GL_TEXTURE1_ARB); glLoadMatrixf( (float *) &worldMat); glActiveTexture(GL_TEXTURE0_ARB); glMatrixMode(GL_MODELVIEW); CMatrix worldlMatView = worldMat * view_matrix; glLoadMatrixf( (float *) &worldlMatView); if (regDiffScale >= 0) glUniform1f(regDiffScale, (*it)->getDiffuseMapScale(0)); (*it)->render(); } glUseProgram(0); }