void GraphicsGL2::DrawScenePassPost( const GraphicsConfigPass & pass, std::ostream & error_output) { assert(pass.draw.back() == "postprocess"); if (!pass.conditions.Satisfied(conditions)) return; shader_map_type::iterator si = shaders.find(pass.shader); if (si == shaders.end()) { ReportOnce(&pass, "Shader " + pass.shader + " couldn't be found", error_output); return; } postprocess.SetShader(&si->second); std::vector <TextureInterface*> input_textures; GetScenePassInputTextures(pass.inputs, input_textures); postprocess.SetTextures(glstate, input_textures, error_output); postprocess.SetColorMask(glstate, pass.write_color, pass.write_alpha); postprocess.SetDepthMode(glstate, DepthModeFromString(pass.depthtest), pass.write_depth); postprocess.SetBlendMode(glstate, BlendModeFromString(pass.blendmode)); render_output_map_type::iterator oi = render_outputs.find(pass.output); if (oi == render_outputs.end()) { ReportOnce(&pass, "Render output " + pass.output + " couldn't be found", error_output); return; } RenderOutput & output = oi->second; // setup camera, even though we don't use it directly for the post process // we want to have some info available std::string cameraname = pass.camera; camera_map_type::iterator ci = cameras.find(cameraname); if (ci == cameras.end()) { ReportOnce(&pass, "Camera " + cameraname + " couldn't be found", error_output); return; } postprocess.SetCamera(ci->second); output.Begin(glstate, error_output); CheckForOpenGLErrors("render output begin", error_output); postprocess.ClearOutput(glstate, pass.clear_color, pass.clear_depth); postprocess.Render(glstate, error_output); CheckForOpenGLErrors("render finish", error_output); output.End(glstate, error_output); CheckForOpenGLErrors("render output end", error_output); }
void GraphicsGL2::DrawScenePass( const GraphicsConfigPass & pass, std::map <std::string, PtrVector <Drawable> > & culled_static_drawlist, std::ostream & error_output) { // log failure here? if (!pass.conditions.Satisfied(conditions)) return; // setup shader shader_map_type::iterator si = shaders.find(pass.shader); if (si == shaders.end()) { ReportOnce(&pass, "Shader " + pass.shader + " couldn't be found", error_output); return; } renderscene.SetShader(&si->second); // setup textures std::vector <TextureInterface*> input_textures; GetScenePassInputTextures(pass.inputs, input_textures); renderscene.SetTextures(glstate, input_textures, error_output); // setup state renderscene.SetColorMask(glstate, pass.write_color, pass.write_alpha); renderscene.SetDepthMode(glstate, DepthModeFromString(pass.depthtest), pass.write_depth); renderscene.SetBlendMode(glstate, BlendModeFromString(pass.blendmode)); // setup output render_output_map_type::iterator oi = render_outputs.find(pass.output); if (oi == render_outputs.end()) { ReportOnce(&pass, "Render output " + pass.output + " couldn't be found", error_output); return; } RenderOutput & output = oi->second; // handle the cubemap case const bool cubemap = (output.IsFBO() && output.RenderToFBO().IsCubemap()); const int cubesides = cubemap ? 6 : 1; std::string cameraname = pass.camera; for (int cubeside = 0; cubeside < cubesides; cubeside++) { if (cubemap) { // build a name for the sub camera std::stringstream converter; converter << pass.camera << "_cubeside" << cubeside; cameraname = converter.str(); // attach the correct cube side on the render output AttachCubeSide(cubeside, output.RenderToFBO(), error_output); } // setup camera camera_map_type::iterator ci = cameras.find(cameraname); if (ci == cameras.end()) { ReportOnce(&pass, "Camera " + pass.camera + " couldn't be found", error_output); return; } renderscene.SetCamera(ci->second); // render pass draw layers output.Begin(glstate, error_output); renderscene.ClearOutput(glstate, pass.clear_color, pass.clear_depth); for (std::vector <std::string>::const_iterator d = pass.draw.begin(); d != pass.draw.end(); d++) { const std::string & layer = *d; // setup dynamic drawlist reseatable_reference <PtrVector <Drawable> > container_dynamic = dynamic_drawlist.GetByName(layer); if (!container_dynamic) { ReportOnce(&pass, "Drawable container " + layer + " couldn't be found", error_output); return; } // setup static drawlist const std::string drawlist_key = BuildKey(cameraname, layer); std::map <std::string, PtrVector <Drawable> >::const_iterator container_static = culled_static_drawlist.find(drawlist_key); if (container_static == culled_static_drawlist.end()) { ReportOnce(&pass, "Couldn't find culled static drawlist for camera/draw combination: " + drawlist_key, error_output); return; } if (!container_dynamic->empty() || !container_static->second.empty()) { renderscene.SetDrawLists(*container_dynamic, container_static->second); renderscene.Render(glstate, error_output); } } output.End(glstate, error_output); CheckForOpenGLErrors("render output end", error_output); } }
void GraphicsGL2::CullScenePass( const GraphicsConfigPass & pass, std::map <std::string, PtrVector <Drawable> > & culled_static_drawlist, std::ostream & error_output) { // for each pass, we have which camera and which draw layer to use // we want to do culling for each unique camera and draw layer combination // use camera/layer as the unique key assert(!pass.draw.empty()); if (pass.draw.back() == "postprocess" || !pass.conditions.Satisfied(conditions)) return; for (std::vector <std::string>::const_iterator d = pass.draw.begin(); d != pass.draw.end(); d++) { // determine if we're dealing with a cubemap render_output_map_type::iterator oi = render_outputs.find(pass.output); if (oi == render_outputs.end()) { ReportOnce(&pass, "Render output "+pass.output+" couldn't be found", error_output); return; } const bool cubemap = (oi->second.IsFBO() && oi->second.RenderToFBO().IsCubemap()); const int cubesides = cubemap ? 6 : 1; std::string cameraname = pass.camera; for (int cubeside = 0; cubeside < cubesides; cubeside++) { if (cubemap) { // build sub-camera // build a name for the sub camera { std::stringstream converter; converter << pass.camera << "_cubeside" << cubeside; cameraname = converter.str(); } // get the base camera camera_map_type::iterator bci = cameras.find(pass.camera); if (bci == cameras.end()) { ReportOnce(&pass, "Camera "+pass.camera+" couldn't be found", error_output); return; } // create our sub-camera GraphicsCamera & cam = cameras[cameraname]; cam = bci->second; // set the sub-camera's properties cam.rot = GetCubeSideOrientation(cubeside, cam.rot, error_output); cam.fov = 90; assert(oi->second.IsFBO()); const FrameBufferObject & fbo = oi->second.RenderToFBO(); cam.w = fbo.GetWidth(); cam.h = fbo.GetHeight(); } std::string key = BuildKey(cameraname, *d); if (pass.cull) { camera_map_type::iterator ci = cameras.find(cameraname); if (ci == cameras.end()) { ReportOnce(&pass, "Camera "+cameraname+" couldn't be found", error_output); return; } GraphicsCamera & cam = ci->second; if (culled_static_drawlist.find(key) == culled_static_drawlist.end()) { Frustum frustum; frustum.Extract(GetProjMatrix(cam).GetArray(), GetViewMatrix(cam).GetArray()); reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetDrawlist().GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container "+*d+" couldn't be found", error_output); return; } container->Query(frustum, culled_static_drawlist[key]); } } else { reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetDrawlist().GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container "+*d+" couldn't be found", error_output); return; } container->Query(Aabb<float>::IntersectAlways(), culled_static_drawlist[key]); } } } }
void GraphicsGL2::CullScenePass( const GraphicsConfigPass & pass, std::ostream & error_output) { // for each pass, we have which camera and which draw layer to use // we want to do culling for each unique camera and draw layer combination // use camera/layer as the unique key assert(!pass.draw.empty()); if (pass.draw.back() == "postprocess" || !pass.conditions.Satisfied(conditions)) return; for (std::vector <std::string>::const_iterator d = pass.draw.begin(); d != pass.draw.end(); d++) { // determine if we're dealing with a cubemap RenderOutputMap::iterator oi = render_outputs.find(pass.output); if (oi == render_outputs.end()) { ReportOnce(&pass, "Render output "+pass.output+" couldn't be found", error_output); return; } const bool cubemap = (oi->second.IsFBO() && oi->second.RenderToFBO().IsCubemap()); const int cubesides = cubemap ? 6 : 1; std::string cameraname = pass.camera; for (int cubeside = 0; cubeside < cubesides; cubeside++) { if (cubemap) { // build a name for the sub camera { std::ostringstream s; s << pass.camera << "_cubeside" << cubeside; cameraname = s.str(); } // get the base camera CameraMap::iterator bci = cameras.find(pass.camera); if (bci == cameras.end()) { ReportOnce(&pass, "Camera " + pass.camera + " couldn't be found", error_output); return; } // create our sub-camera GraphicsCamera & cam = cameras[cameraname]; cam = bci->second; // set the sub-camera's properties cam.rot = GetCubeSideOrientation(cubeside, cam.rot, error_output); cam.fov = 90; assert(oi->second.IsFBO()); const FrameBufferObject & fbo = oi->second.RenderToFBO(); cam.w = fbo.GetWidth(); cam.h = fbo.GetHeight(); } const std::string drawlist_name = BuildKey(cameraname, *d); CulledDrawList & drawlist = culled_drawlists[drawlist_name]; if (drawlist.valid) break; drawlist.valid = true; if (pass.cull) { // cull static drawlist reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } CameraMap::iterator ci = cameras.find(cameraname); if (ci == cameras.end()) { ReportOnce(&pass, "Camera " + cameraname + " couldn't be found", error_output); return; } const GraphicsCamera & cam = ci->second; Frustum frustum; frustum.Extract(GetProjMatrix(cam).GetArray(), GetViewMatrix(cam).GetArray()); container->Query(frustum, drawlist.drawables); // cull dynamic drawlist reseatable_reference <PtrVector <Drawable> > container_dynamic = dynamic_drawlist.GetByName(*d); if (!container_dynamic) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } for (size_t i = 0; i < container_dynamic->size(); ++i) { if (!Cull(frustum, *(*container_dynamic)[i])) drawlist.drawables.push_back((*container_dynamic)[i]); } } else { // copy static drawlist reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } container->Query(Aabb<float>::IntersectAlways(), drawlist.drawables); // copy dynamic drawlist reseatable_reference <PtrVector <Drawable> > container_dynamic = dynamic_drawlist.GetByName(*d); if (!container_dynamic) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } drawlist.drawables.insert( drawlist.drawables.end(), container_dynamic->begin(), container_dynamic->end()); } } } }