| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "command_buffer/client/cross/fenced_allocator.h" | 42 #include "command_buffer/client/cross/fenced_allocator.h" |
| 43 #include "command_buffer/client/cross/cmd_buffer_helper.h" | 43 #include "command_buffer/client/cross/cmd_buffer_helper.h" |
| 44 | 44 |
| 45 namespace o3d { | 45 namespace o3d { |
| 46 | 46 |
| 47 using command_buffer::BufferSyncInterface; | 47 using command_buffer::BufferSyncInterface; |
| 48 using command_buffer::CommandBufferEntry; | 48 using command_buffer::CommandBufferEntry; |
| 49 using command_buffer::CommandBufferHelper; | 49 using command_buffer::CommandBufferHelper; |
| 50 using command_buffer::ResourceID; | 50 using command_buffer::ResourceID; |
| 51 namespace effect_param = command_buffer::effect_param; | 51 namespace effect_param = command_buffer::effect_param; |
| 52 namespace vertex_struct = command_buffer::vertex_struct; |
| 52 | 53 |
| 53 EffectCB::EffectCB(ServiceLocator *service_locator, RendererCB *renderer) | 54 EffectCB::EffectCB(ServiceLocator *service_locator, RendererCB *renderer) |
| 54 : Effect(service_locator), | 55 : Effect(service_locator), |
| 55 resource_id_(command_buffer::kInvalidResource), | 56 resource_id_(command_buffer::kInvalidResource), |
| 56 generation_(0), | 57 generation_(0), |
| 57 renderer_(renderer) { | 58 renderer_(renderer) { |
| 58 } | 59 } |
| 59 | 60 |
| 60 EffectCB::~EffectCB() { | 61 EffectCB::~EffectCB() { |
| 61 Destroy(); | 62 Destroy(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return false; | 119 return false; |
| 119 } | 120 } |
| 120 for (unsigned int i = 0; i < param_descs_.size(); ++i) { | 121 for (unsigned int i = 0; i < param_descs_.size(); ++i) { |
| 121 if (!effect_helper.GetParamStrings(&(param_descs_[i]))) { | 122 if (!effect_helper.GetParamStrings(&(param_descs_[i]))) { |
| 122 O3D_ERROR(service_locator()) | 123 O3D_ERROR(service_locator()) |
| 123 << "Failed to create effect parameters strings."; | 124 << "Failed to create effect parameters strings."; |
| 124 Destroy(); | 125 Destroy(); |
| 125 return false; | 126 return false; |
| 126 } | 127 } |
| 127 } | 128 } |
| 129 if (!effect_helper.GetEffectStreams(resource_id, &stream_descs_)) { |
| 130 O3D_ERROR(service_locator()) << "Failed to get streams."; |
| 131 Destroy(); |
| 132 return false; |
| 133 } |
| 128 set_source(source); | 134 set_source(source); |
| 129 return true; | 135 return true; |
| 130 } | 136 } |
| 131 | 137 |
| 132 void EffectCB::Destroy() { | 138 void EffectCB::Destroy() { |
| 133 set_source(""); | 139 set_source(""); |
| 134 ++generation_; | 140 ++generation_; |
| 135 if (resource_id_ != command_buffer::kInvalidResource) { | 141 if (resource_id_ != command_buffer::kInvalidResource) { |
| 136 CommandBufferHelper *helper = renderer_->helper(); | 142 CommandBufferHelper *helper = renderer_->helper(); |
| 137 CommandBufferEntry args[1]; | 143 CommandBufferEntry args[1]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 sem_class = semantic_manager->LookupSemantic(desc.semantic); | 199 sem_class = semantic_manager->LookupSemantic(desc.semantic); |
| 194 } | 200 } |
| 195 array->push_back(EffectParameterInfo(desc.name, | 201 array->push_back(EffectParameterInfo(desc.name, |
| 196 param_class, | 202 param_class, |
| 197 0, | 203 0, |
| 198 desc.semantic, | 204 desc.semantic, |
| 199 sem_class)); | 205 sem_class)); |
| 200 } | 206 } |
| 201 } | 207 } |
| 202 | 208 |
| 209 |
| 210 static bool CBSemanticToO3DSemantic( |
| 211 vertex_struct::Semantic semantic, |
| 212 unsigned int semantic_index, |
| 213 Stream::Semantic *out_semantic, |
| 214 unsigned int *out_semantic_index) { |
| 215 switch (semantic) { |
| 216 case vertex_struct::POSITION: |
| 217 if (semantic_index != 0) return false; |
| 218 *out_semantic = Stream::POSITION; |
| 219 *out_semantic_index = 0; |
| 220 return true; |
| 221 case vertex_struct::NORMAL: |
| 222 if (semantic_index != 0) return false; |
| 223 *out_semantic = Stream::NORMAL; |
| 224 *out_semantic_index = 0; |
| 225 return true; |
| 226 case vertex_struct::COLOR: |
| 227 if (semantic_index > 1) return false; |
| 228 *out_semantic = Stream::COLOR; |
| 229 *out_semantic_index = semantic_index; |
| 230 return true; |
| 231 case vertex_struct::TEX_COORD: |
| 232 if (semantic_index == 6) { |
| 233 *out_semantic = Stream::TANGENT; |
| 234 *out_semantic_index = 0; |
| 235 return true; |
| 236 } else if (semantic_index == 7) { |
| 237 *out_semantic = Stream::BINORMAL; |
| 238 *out_semantic_index = 0; |
| 239 return true; |
| 240 } else { |
| 241 *out_semantic = Stream::TEXCOORD; |
| 242 *out_semantic_index = semantic_index; |
| 243 return true; |
| 244 } |
| 245 default: |
| 246 return false; |
| 247 } |
| 248 } |
| 203 void EffectCB::GetStreamInfo(EffectStreamInfoArray *array) { | 249 void EffectCB::GetStreamInfo(EffectStreamInfoArray *array) { |
| 204 // TODO(rlp) | 250 DCHECK(array); |
| 251 array->clear(); |
| 252 for (unsigned int i = 0; i < stream_descs_.size(); ++i) { |
| 253 Stream::Semantic semantic; |
| 254 unsigned int semantic_index; |
| 255 if (CBSemanticToO3DSemantic(stream_descs_[i].semantic, |
| 256 stream_descs_[i].semantic_index, |
| 257 &semantic, |
| 258 &semantic_index)) { |
| 259 array->push_back(EffectStreamInfo(semantic, semantic_index)); |
| 260 } |
| 261 } |
| 205 } | 262 } |
| 206 | 263 |
| 207 } // namespace o3d | 264 } // namespace o3d |
| OLD | NEW |