1 /***************************************************************************
3 * Copyright 2010,2011 BMW Car IT GmbH
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ****************************************************************************/
19 #include "ShaderDestroyCommand.h"
20 #include "ICommandExecutor.h"
23 #include "ShaderMap.h"
25 ExecutionResult ShaderDestroyCommand::execute(ICommandExecutor* executor)
27 Scene& scene = *(executor->getScene());
28 ExecutionResult result = ExecutionFailed;
30 // get shader by its ID
31 ShaderMapIterator iter = scene.m_shaderMap.find(m_id);
32 ShaderMapIterator iterEnd = scene.m_shaderMap.end();
37 LOG_ERROR("Layermanager", "shader ID " << m_id << " not found");
38 return ExecutionFailed;
41 Shader* shader = (*iter).second;
45 const SurfaceMap& surfaceMap = scene.getAllSurfaces();
46 result = removeShaderFromAllSurfaces(surfaceMap, shader) ? ExecutionSuccessRedraw : ExecutionSuccess;
48 const LayerMap& layerMap = scene.getAllLayers();
49 result = removeShaderFromAllLayers(layerMap, shader) ? ExecutionSuccessRedraw : result;
51 // remove shader from global shader list
52 scene.m_shaderMap.erase(iter);
61 /// detach shader from all surfaces
62 bool ShaderDestroyCommand::removeShaderFromAllSurfaces(const SurfaceMap & surfaceMap, Shader* shader)
65 SurfaceMapConstIterator iter = surfaceMap.begin();
66 SurfaceMapConstIterator iterEnd = surfaceMap.end();
67 for (; iter != iterEnd; ++iter)
69 GraphicalObject* obj = iter->second;
71 if (obj && obj->getShader() == shader)
81 bool ShaderDestroyCommand::removeShaderFromAllLayers(const LayerMap & layerMap, Shader *& shader)
84 LayerMapConstIterator iter = layerMap.begin();
85 LayerMapConstIterator iterEnd = layerMap.end();
86 for (; iter != iterEnd; ++iter)
88 GraphicalObject* obj = iter->second;
90 if (obj && obj->getShader()==shader)
100 unsigned int ShaderDestroyCommand::getShaderID() const
105 const std::string ShaderDestroyCommand::getString()
107 std::stringstream description;
108 description << "DestroyShaderCommand("
109 << "id=" << m_id << "(0x" << std::hex << m_id << ")" << std::dec
111 return description.str();