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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CommandBufferEntry args[4]; | 95 helper->CreateEffect( |
96 args[0].value_uint32 = resource_id; | 96 resource_id, source_size, |
97 args[1].value_uint32 = source_size; | 97 renderer_->transfer_shm_id(), |
98 args[2].value_uint32 = renderer_->transfer_shm_id(); | 98 renderer_->allocator()->GetOffset(buffer_data)); |
99 args[3].value_uint32 = renderer_->allocator()->GetOffset(buffer_data); | |
100 helper->AddCommand(command_buffer::CREATE_EFFECT, 4, args); | |
101 renderer_->allocator()->FreePendingToken(buffer_data, helper->InsertToken()); | 99 renderer_->allocator()->FreePendingToken(buffer_data, helper->InsertToken()); |
102 | 100 |
103 // 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 |
104 // the effect has succesfully compiled. | 102 // the effect has succesfully compiled. |
105 helper->Finish(); | 103 helper->Finish(); |
106 if (renderer_->sync_interface()->GetParseError() != | 104 if (renderer_->sync_interface()->GetParseError() != |
107 BufferSyncInterface::PARSE_NO_ERROR) { | 105 BufferSyncInterface::kParseNoError) { |
108 O3D_ERROR(service_locator()) << "Effect failed to compile."; | 106 O3D_ERROR(service_locator()) << "Effect failed to compile."; |
109 renderer_->effect_ids().FreeID(resource_id); | 107 renderer_->effect_ids().FreeID(resource_id); |
110 return false; | 108 return false; |
111 } | 109 } |
112 resource_id_ = resource_id; | 110 resource_id_ = resource_id; |
113 EffectHelper effect_helper(helper, renderer_->allocator(), | 111 EffectHelper effect_helper(helper, renderer_->allocator(), |
114 renderer_->transfer_shm_id(), | 112 renderer_->transfer_shm_id(), |
115 &renderer_->effect_param_ids()); | 113 &renderer_->effect_param_ids()); |
116 if (!effect_helper.CreateEffectParameters(resource_id, ¶m_descs_)) { | 114 if (!effect_helper.CreateEffectParameters(resource_id, ¶m_descs_)) { |
117 O3D_ERROR(service_locator()) << "Failed to create effect parameters."; | 115 O3D_ERROR(service_locator()) << "Failed to create effect parameters."; |
(...skipping 15 matching lines...) Expand all Loading... |
133 } | 131 } |
134 set_source(source); | 132 set_source(source); |
135 return true; | 133 return true; |
136 } | 134 } |
137 | 135 |
138 void EffectCB::Destroy() { | 136 void EffectCB::Destroy() { |
139 set_source(""); | 137 set_source(""); |
140 ++generation_; | 138 ++generation_; |
141 if (resource_id_ != command_buffer::kInvalidResource) { | 139 if (resource_id_ != command_buffer::kInvalidResource) { |
142 CommandBufferHelper *helper = renderer_->helper(); | 140 CommandBufferHelper *helper = renderer_->helper(); |
143 CommandBufferEntry args[1]; | 141 helper->DestroyEffect(resource_id_); |
144 args[0].value_uint32 = resource_id_; | |
145 helper->AddCommand(command_buffer::DESTROY_EFFECT, 1, args); | |
146 renderer_->effect_ids().FreeID(resource_id_); | 142 renderer_->effect_ids().FreeID(resource_id_); |
147 resource_id_ = command_buffer::kInvalidResource; | 143 resource_id_ = command_buffer::kInvalidResource; |
148 } | 144 } |
149 if (param_descs_.size() > 0) { | 145 if (param_descs_.size() > 0) { |
150 EffectHelper effect_helper(renderer_->helper(), renderer_->allocator(), | 146 EffectHelper effect_helper(renderer_->helper(), renderer_->allocator(), |
151 renderer_->transfer_shm_id(), | 147 renderer_->transfer_shm_id(), |
152 &renderer_->effect_param_ids()); | 148 &renderer_->effect_param_ids()); |
153 effect_helper.DestroyEffectParameters(param_descs_); | 149 effect_helper.DestroyEffectParameters(param_descs_); |
154 param_descs_.clear(); | 150 param_descs_.clear(); |
155 } | 151 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (CBSemanticToO3DSemantic(stream_descs_[i].semantic, | 251 if (CBSemanticToO3DSemantic(stream_descs_[i].semantic, |
256 stream_descs_[i].semantic_index, | 252 stream_descs_[i].semantic_index, |
257 &semantic, | 253 &semantic, |
258 &semantic_index)) { | 254 &semantic_index)) { |
259 array->push_back(EffectStreamInfo(semantic, semantic_index)); | 255 array->push_back(EffectStreamInfo(semantic, semantic_index)); |
260 } | 256 } |
261 } | 257 } |
262 } | 258 } |
263 | 259 |
264 } // namespace o3d | 260 } // namespace o3d |
OLD | NEW |