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 29 matching lines...) Expand all Loading... |
40 #include "command_buffer/common/cross/buffer_sync_api.h" | 40 #include "command_buffer/common/cross/buffer_sync_api.h" |
41 #include "command_buffer/common/cross/cmd_buffer_format.h" | 41 #include "command_buffer/common/cross/cmd_buffer_format.h" |
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 namespace vertex_struct = command_buffer::vertex_struct; |
53 | 53 |
54 EffectCB::EffectCB(ServiceLocator *service_locator, RendererCB *renderer) | 54 EffectCB::EffectCB(ServiceLocator *service_locator, RendererCB *renderer) |
55 : Effect(service_locator), | 55 : Effect(service_locator), |
56 resource_id_(command_buffer::kInvalidResource), | 56 resource_id_(command_buffer::kInvalidResource), |
57 generation_(0), | 57 generation_(0), |
58 renderer_(renderer) { | 58 renderer_(renderer) { |
59 } | 59 } |
60 | 60 |
(...skipping 21 matching lines...) Expand all Loading... |
82 << " bytes to load the effect."; | 82 << " bytes to load the effect."; |
83 return false; | 83 return false; |
84 } | 84 } |
85 memcpy(buffer_data, vp_main.data(), vp_main.size()); | 85 memcpy(buffer_data, vp_main.data(), vp_main.size()); |
86 buffer_data[vp_main.size()] = 0; | 86 buffer_data[vp_main.size()] = 0; |
87 memcpy(buffer_data + vp_main.size() + 1, fp_main.data(), fp_main.size()); | 87 memcpy(buffer_data + vp_main.size() + 1, fp_main.data(), fp_main.size()); |
88 buffer_data[vp_main.size() + 1 + fp_main.size()] = 0; | 88 buffer_data[vp_main.size() + 1 + fp_main.size()] = 0; |
89 memcpy(buffer_data + vp_main.size() + 1 + fp_main.size() + 1, | 89 memcpy(buffer_data + vp_main.size() + 1 + fp_main.size() + 1, |
90 source.data(), source.size()); | 90 source.data(), source.size()); |
91 | 91 |
92 ResourceID resource_id = renderer_->effect_ids().AllocateID(); | 92 ResourceId resource_id = renderer_->effect_ids().AllocateID(); |
93 | 93 |
94 CommandBufferHelper *helper = renderer_->helper(); | 94 CommandBufferHelper *helper = renderer_->helper(); |
95 helper->CreateEffect( | 95 helper->CreateEffect( |
96 resource_id, source_size, | 96 resource_id, source_size, |
97 renderer_->transfer_shm_id(), | 97 renderer_->transfer_shm_id(), |
98 renderer_->allocator()->GetOffset(buffer_data)); | 98 renderer_->allocator()->GetOffset(buffer_data)); |
99 renderer_->allocator()->FreePendingToken(buffer_data, helper->InsertToken()); | 99 renderer_->allocator()->FreePendingToken(buffer_data, helper->InsertToken()); |
100 | 100 |
101 // NOTE: we're calling Finish to check the command result, to see if | 101 // NOTE: we're calling Finish to check the command result, to see if |
102 // the effect has succesfully compiled. | 102 // the effect has succesfully compiled. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 renderer_->transfer_shm_id(), | 147 renderer_->transfer_shm_id(), |
148 &renderer_->effect_param_ids()); | 148 &renderer_->effect_param_ids()); |
149 effect_helper.DestroyEffectParameters(param_descs_); | 149 effect_helper.DestroyEffectParameters(param_descs_); |
150 param_descs_.clear(); | 150 param_descs_.clear(); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 static const ObjectBase::Class* CBTypeToParamType( | 154 static const ObjectBase::Class* CBTypeToParamType( |
155 effect_param::DataType type) { | 155 effect_param::DataType type) { |
156 switch (type) { | 156 switch (type) { |
157 case effect_param::FLOAT1: | 157 case effect_param::kFloat1: |
158 return ParamFloat::GetApparentClass(); | 158 return ParamFloat::GetApparentClass(); |
159 case effect_param::FLOAT2: | 159 case effect_param::kFloat2: |
160 return ParamFloat2::GetApparentClass(); | 160 return ParamFloat2::GetApparentClass(); |
161 case effect_param::FLOAT3: | 161 case effect_param::kFloat3: |
162 return ParamFloat3::GetApparentClass(); | 162 return ParamFloat3::GetApparentClass(); |
163 case effect_param::FLOAT4: | 163 case effect_param::kFloat4: |
164 return ParamFloat4::GetApparentClass(); | 164 return ParamFloat4::GetApparentClass(); |
165 case effect_param::INT: | 165 case effect_param::kInt: |
166 return ParamInteger::GetApparentClass(); | 166 return ParamInteger::GetApparentClass(); |
167 case effect_param::MATRIX4: | 167 case effect_param::kMatrix4: |
168 return ParamMatrix4::GetApparentClass(); | 168 return ParamMatrix4::GetApparentClass(); |
169 case effect_param::SAMPLER: | 169 case effect_param::kSampler: |
170 return ParamSampler::GetApparentClass(); | 170 return ParamSampler::GetApparentClass(); |
171 case effect_param::TEXTURE: | 171 case effect_param::kTexture: |
172 return ParamTexture::GetApparentClass(); | 172 return ParamTexture::GetApparentClass(); |
173 default : { | 173 default : { |
174 DLOG(ERROR) << "Cannot convert command buffer type " | 174 DLOG(ERROR) << "Cannot convert command buffer type " |
175 << type | 175 << type |
176 << " to a Param type."; | 176 << " to a Param type."; |
177 return NULL; | 177 return NULL; |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
(...skipping 20 matching lines...) Expand all Loading... |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 | 205 |
206 static bool CBSemanticToO3DSemantic( | 206 static bool CBSemanticToO3DSemantic( |
207 vertex_struct::Semantic semantic, | 207 vertex_struct::Semantic semantic, |
208 unsigned int semantic_index, | 208 unsigned int semantic_index, |
209 Stream::Semantic *out_semantic, | 209 Stream::Semantic *out_semantic, |
210 unsigned int *out_semantic_index) { | 210 unsigned int *out_semantic_index) { |
211 switch (semantic) { | 211 switch (semantic) { |
212 case vertex_struct::POSITION: | 212 case vertex_struct::kPosition: |
213 if (semantic_index != 0) return false; | 213 if (semantic_index != 0) return false; |
214 *out_semantic = Stream::POSITION; | 214 *out_semantic = Stream::POSITION; |
215 *out_semantic_index = 0; | 215 *out_semantic_index = 0; |
216 return true; | 216 return true; |
217 case vertex_struct::NORMAL: | 217 case vertex_struct::kNormal: |
218 if (semantic_index != 0) return false; | 218 if (semantic_index != 0) return false; |
219 *out_semantic = Stream::NORMAL; | 219 *out_semantic = Stream::NORMAL; |
220 *out_semantic_index = 0; | 220 *out_semantic_index = 0; |
221 return true; | 221 return true; |
222 case vertex_struct::COLOR: | 222 case vertex_struct::kColor: |
223 if (semantic_index > 1) return false; | 223 if (semantic_index > 1) return false; |
224 *out_semantic = Stream::COLOR; | 224 *out_semantic = Stream::COLOR; |
225 *out_semantic_index = semantic_index; | 225 *out_semantic_index = semantic_index; |
226 return true; | 226 return true; |
227 case vertex_struct::TEX_COORD: | 227 case vertex_struct::kTexCoord: |
228 if (semantic_index == 6) { | 228 if (semantic_index == 6) { |
229 *out_semantic = Stream::TANGENT; | 229 *out_semantic = Stream::TANGENT; |
230 *out_semantic_index = 0; | 230 *out_semantic_index = 0; |
231 return true; | 231 return true; |
232 } else if (semantic_index == 7) { | 232 } else if (semantic_index == 7) { |
233 *out_semantic = Stream::BINORMAL; | 233 *out_semantic = Stream::BINORMAL; |
234 *out_semantic_index = 0; | 234 *out_semantic_index = 0; |
235 return true; | 235 return true; |
236 } else { | 236 } else { |
237 *out_semantic = Stream::TEXCOORD; | 237 *out_semantic = Stream::TEXCOORD; |
(...skipping 13 matching lines...) Expand all Loading... |
251 if (CBSemanticToO3DSemantic(stream_descs_[i].semantic, | 251 if (CBSemanticToO3DSemantic(stream_descs_[i].semantic, |
252 stream_descs_[i].semantic_index, | 252 stream_descs_[i].semantic_index, |
253 &semantic, | 253 &semantic, |
254 &semantic_index)) { | 254 &semantic_index)) { |
255 array->push_back(EffectStreamInfo(semantic, semantic_index)); | 255 array->push_back(EffectStreamInfo(semantic, semantic_index)); |
256 } | 256 } |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 } // namespace o3d | 260 } // namespace o3d |
OLD | NEW |