| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 140 | 140 | 
| 141 // Creates the vertex struct resource on the service side. It will only set the | 141 // Creates the vertex struct resource on the service side. It will only set the | 
| 142 // vertex inputs if they represent semantics and types we know about. The | 142 // vertex inputs if they represent semantics and types we know about. The | 
| 143 // command buffer API will not draw with an incomplete vertex struct. | 143 // command buffer API will not draw with an incomplete vertex struct. | 
| 144 // This function will get called on Draw, after any change to the vertex inputs | 144 // This function will get called on Draw, after any change to the vertex inputs | 
| 145 // has occurred. | 145 // has occurred. | 
| 146 void StreamBankCB::CreateVertexStruct() { | 146 void StreamBankCB::CreateVertexStruct() { | 
| 147   DCHECK_EQ(kInvalidResource, vertex_struct_id_); | 147   DCHECK_EQ(kInvalidResource, vertex_struct_id_); | 
| 148   vertex_struct_id_ = renderer_->vertex_structs_ids().AllocateID(); | 148   vertex_struct_id_ = renderer_->vertex_structs_ids().AllocateID(); | 
| 149   CommandBufferHelper *helper = renderer_->helper(); | 149   CommandBufferHelper *helper = renderer_->helper(); | 
| 150   CommandBufferEntry args[5]; | 150   helper->CreateVertexStruct(vertex_struct_id_, vertex_stream_params_.size()); | 
| 151   args[0].value_uint32 = vertex_struct_id_; |  | 
| 152   args[1].value_uint32 = vertex_stream_params_.size(); |  | 
| 153   helper->AddCommand(command_buffer::CREATE_VERTEX_STRUCT, 2, args); |  | 
| 154   for (unsigned int i = 0; i < vertex_stream_params_.size(); ++i) { | 151   for (unsigned int i = 0; i < vertex_stream_params_.size(); ++i) { | 
| 155     const Stream &stream = vertex_stream_params_[i]->stream(); | 152     const Stream &stream = vertex_stream_params_[i]->stream(); | 
| 156     vertex_struct::Semantic cb_semantic; | 153     vertex_struct::Semantic cb_semantic; | 
| 157     unsigned int cb_semantic_index; | 154     unsigned int cb_semantic_index; | 
| 158     if (!GetCBSemantic(stream.semantic(), stream.semantic_index(), &cb_semantic, | 155     if (!GetCBSemantic(stream.semantic(), stream.semantic_index(), &cb_semantic, | 
| 159                        &cb_semantic_index)) { | 156                        &cb_semantic_index)) { | 
| 160       DLOG(INFO) << "Unknown semantic (" << stream.semantic() << ", " | 157       DLOG(INFO) << "Unknown semantic (" << stream.semantic() << ", " | 
| 161                  << stream.semantic_index() << ") - ignoring stream."; | 158                  << stream.semantic_index() << ") - ignoring stream."; | 
| 162       continue; | 159       continue; | 
| 163     } | 160     } | 
| 164     vertex_struct::Type cb_type = GetCBType(stream.field()); | 161     vertex_struct::Type cb_type = GetCBType(stream.field()); | 
| 165     if (cb_type == vertex_struct::NUM_TYPES) { | 162     if (cb_type == vertex_struct::NUM_TYPES) { | 
| 166       DLOG(INFO) << "Invalid type (" << stream.field().num_components() | 163       DLOG(INFO) << "Invalid type (" << stream.field().num_components() | 
| 167                  << ") - ignoring stream."; | 164                  << ") - ignoring stream."; | 
| 168       continue; | 165       continue; | 
| 169     } | 166     } | 
| 170 | 167 | 
| 171     namespace cmd = command_buffer::set_vertex_input_cmd; |  | 
| 172     VertexBufferCB *vertex_buffer = | 168     VertexBufferCB *vertex_buffer = | 
| 173         static_cast<VertexBufferCB *>(stream.field().buffer()); | 169         static_cast<VertexBufferCB *>(stream.field().buffer()); | 
| 174     args[0].value_uint32 = vertex_struct_id_; | 170     helper->SetVertexInput( | 
| 175     args[1].value_uint32 = i; | 171         vertex_struct_id_, i, | 
| 176     args[2].value_uint32 = vertex_buffer->resource_id(); | 172         vertex_buffer->resource_id(), | 
| 177     args[3].value_uint32 = stream.field().offset(); | 173         stream.field().offset(), | 
| 178     args[4].value_uint32 = | 174         cb_semantic, | 
| 179         cmd::SemanticIndex::MakeValue(cb_semantic_index) | | 175         cb_semantic_index, | 
| 180         cmd::Semantic::MakeValue(cb_semantic) | | 176         cb_type, | 
| 181         cmd::Type::MakeValue(cb_type) | | 177         vertex_buffer->stride()); | 
| 182         cmd::Stride::MakeValue(vertex_buffer->stride()); |  | 
| 183     helper->AddCommand(command_buffer::SET_VERTEX_INPUT, 5, args); |  | 
| 184   } | 178   } | 
| 185 } | 179 } | 
| 186 | 180 | 
| 187 // Destroys the vertex struct resource on the service side. | 181 // Destroys the vertex struct resource on the service side. | 
| 188 void StreamBankCB::DestroyVertexStruct() { | 182 void StreamBankCB::DestroyVertexStruct() { | 
| 189   if (vertex_struct_id_ != kInvalidResource) { | 183   if (vertex_struct_id_ != kInvalidResource) { | 
| 190     CommandBufferHelper *helper = renderer_->helper(); | 184     CommandBufferHelper *helper = renderer_->helper(); | 
| 191     CommandBufferEntry args[1]; | 185     helper->DestroyVertexStruct(vertex_struct_id_); | 
| 192     args[0].value_uint32 = vertex_struct_id_; |  | 
| 193     helper->AddCommand(command_buffer::DESTROY_VERTEX_STRUCT, 1, args); |  | 
| 194     renderer_->vertex_structs_ids().FreeID(vertex_struct_id_); | 186     renderer_->vertex_structs_ids().FreeID(vertex_struct_id_); | 
| 195     vertex_struct_id_ = kInvalidResource; | 187     vertex_struct_id_ = kInvalidResource; | 
| 196   } | 188   } | 
| 197 } | 189 } | 
| 198 | 190 | 
| 199 void StreamBankCB::BindStreamsForRendering() { | 191 void StreamBankCB::BindStreamsForRendering() { | 
| 200   if (vertex_struct_id_ == kInvalidResource) | 192   if (vertex_struct_id_ == kInvalidResource) | 
| 201     CreateVertexStruct(); | 193     CreateVertexStruct(); | 
| 202   CommandBufferHelper *helper = renderer_->helper(); | 194   CommandBufferHelper *helper = renderer_->helper(); | 
| 203   CommandBufferEntry args[6]; | 195   helper->SetVertexStruct(vertex_struct_id_); | 
| 204   // Sets current vertex struct. |  | 
| 205   args[0].value_uint32 = vertex_struct_id_; |  | 
| 206   helper->AddCommand(command_buffer::SET_VERTEX_STRUCT, 1, args); |  | 
| 207 } | 196 } | 
| 208 | 197 | 
| 209 }  // namespace o3d | 198 }  // namespace o3d | 
| OLD | NEW | 
|---|