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 28 matching lines...) Expand all Loading... |
39 #include "core/cross/command_buffer/buffer_cb.h" | 39 #include "core/cross/command_buffer/buffer_cb.h" |
40 #include "core/cross/command_buffer/effect_cb.h" | 40 #include "core/cross/command_buffer/effect_cb.h" |
41 #include "core/cross/command_buffer/stream_bank_cb.h" | 41 #include "core/cross/command_buffer/stream_bank_cb.h" |
42 #include "command_buffer/common/cross/gapi_interface.h" | 42 #include "command_buffer/common/cross/gapi_interface.h" |
43 #include "command_buffer/client/cross/cmd_buffer_helper.h" | 43 #include "command_buffer/client/cross/cmd_buffer_helper.h" |
44 | 44 |
45 // TODO: add unit tests. | 45 // TODO: add unit tests. |
46 | 46 |
47 namespace o3d { | 47 namespace o3d { |
48 | 48 |
49 using command_buffer::ResourceID; | 49 using command_buffer::ResourceId; |
50 using command_buffer::CommandBufferHelper; | 50 using command_buffer::CommandBufferHelper; |
51 using command_buffer::CommandBufferEntry; | 51 using command_buffer::CommandBufferEntry; |
52 using command_buffer::GAPIInterface; | 52 using command_buffer::GAPIInterface; |
53 using command_buffer::kInvalidResource; | 53 using command_buffer::kInvalidResource; |
54 namespace vertex_struct = command_buffer::vertex_struct; | 54 namespace vertex_struct = command_buffer::vertex_struct; |
55 | 55 |
56 StreamBankCB::StreamBankCB(ServiceLocator* service_locator, | 56 StreamBankCB::StreamBankCB(ServiceLocator* service_locator, |
57 RendererCB *renderer) | 57 RendererCB *renderer) |
58 : StreamBank(service_locator), | 58 : StreamBank(service_locator), |
59 renderer_(renderer), | 59 renderer_(renderer), |
(...skipping 10 matching lines...) Expand all Loading... |
70 Stream::Semantic semantic, | 70 Stream::Semantic semantic, |
71 unsigned int semantic_index, | 71 unsigned int semantic_index, |
72 vertex_struct::Semantic *out_semantic, | 72 vertex_struct::Semantic *out_semantic, |
73 unsigned int *out_semantic_index) { | 73 unsigned int *out_semantic_index) { |
74 // TODO: what meaning do we really want to put to our semantics ? How | 74 // TODO: what meaning do we really want to put to our semantics ? How |
75 // do they match the semantics that are set in the effect ? What combination | 75 // do they match the semantics that are set in the effect ? What combination |
76 // of (semantic, index) are supposed to work ? | 76 // of (semantic, index) are supposed to work ? |
77 switch (semantic) { | 77 switch (semantic) { |
78 case Stream::POSITION: | 78 case Stream::POSITION: |
79 if (semantic_index != 0) return false; | 79 if (semantic_index != 0) return false; |
80 *out_semantic = vertex_struct::POSITION; | 80 *out_semantic = vertex_struct::kPosition; |
81 *out_semantic_index = 0; | 81 *out_semantic_index = 0; |
82 return true; | 82 return true; |
83 case Stream::NORMAL: | 83 case Stream::NORMAL: |
84 if (semantic_index != 0) return false; | 84 if (semantic_index != 0) return false; |
85 *out_semantic = vertex_struct::NORMAL; | 85 *out_semantic = vertex_struct::kNormal; |
86 *out_semantic_index = 0; | 86 *out_semantic_index = 0; |
87 return true; | 87 return true; |
88 case Stream::TANGENT: | 88 case Stream::TANGENT: |
89 if (semantic_index != 0) return false; | 89 if (semantic_index != 0) return false; |
90 *out_semantic = vertex_struct::TEX_COORD; | 90 *out_semantic = vertex_struct::kTexCoord; |
91 *out_semantic_index = 6; | 91 *out_semantic_index = 6; |
92 return true; | 92 return true; |
93 case Stream::BINORMAL: | 93 case Stream::BINORMAL: |
94 if (semantic_index != 0) return false; | 94 if (semantic_index != 0) return false; |
95 *out_semantic = vertex_struct::TEX_COORD; | 95 *out_semantic = vertex_struct::kTexCoord; |
96 *out_semantic_index = 7; | 96 *out_semantic_index = 7; |
97 return true; | 97 return true; |
98 case Stream::COLOR: | 98 case Stream::COLOR: |
99 if (semantic_index > 1) return false; | 99 if (semantic_index > 1) return false; |
100 *out_semantic = vertex_struct::COLOR; | 100 *out_semantic = vertex_struct::kColor; |
101 *out_semantic_index = semantic_index; | 101 *out_semantic_index = semantic_index; |
102 return true; | 102 return true; |
103 case Stream::TEXCOORD: | 103 case Stream::TEXCOORD: |
104 *out_semantic = vertex_struct::TEX_COORD; | 104 *out_semantic = vertex_struct::kTexCoord; |
105 *out_semantic_index = semantic_index; | 105 *out_semantic_index = semantic_index; |
106 return true; | 106 return true; |
107 default: | 107 default: |
108 return false; | 108 return false; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 // Converts a data type from O3D enum values to command-buffer enum values. | 112 // Converts a data type from O3D enum values to command-buffer enum values. |
113 static vertex_struct::Type GetCBType(const Field& field) { | 113 static vertex_struct::Type GetCBType(const Field& field) { |
114 if (field.IsA(FloatField::GetApparentClass())) { | 114 if (field.IsA(FloatField::GetApparentClass())) { |
115 switch (field.num_components()) { | 115 switch (field.num_components()) { |
116 case 1: | 116 case 1: |
117 return vertex_struct::FLOAT1; | 117 return vertex_struct::kFloat1; |
118 case 2: | 118 case 2: |
119 return vertex_struct::FLOAT2; | 119 return vertex_struct::kFloat3; |
120 case 3: | 120 case 3: |
121 return vertex_struct::FLOAT3; | 121 return vertex_struct::kFloat3; |
122 case 4: | 122 case 4: |
123 return vertex_struct::FLOAT4; | 123 return vertex_struct::kFloat4; |
124 } | 124 } |
125 } else if (field.IsA(UByteNField::GetApparentClass())) { | 125 } else if (field.IsA(UByteNField::GetApparentClass())) { |
126 switch (field.num_components()) { | 126 switch (field.num_components()) { |
127 case 4: | 127 case 4: |
128 return vertex_struct::UCHAR4N; | 128 return vertex_struct::kUChar4N; |
129 } | 129 } |
130 } | 130 } |
131 DLOG(ERROR) << "Unknown Stream DataType"; | 131 DLOG(ERROR) << "Unknown Stream DataType"; |
132 return vertex_struct::NUM_TYPES; | 132 return vertex_struct::kNumTypes; |
133 } | 133 } |
134 | 134 |
135 // This function is overridden so that we can invalidate the vertex struct any | 135 // This function is overridden so that we can invalidate the vertex struct any |
136 // time the streams change. | 136 // time the streams change. |
137 void StreamBankCB::OnUpdateStreams() { | 137 void StreamBankCB::OnUpdateStreams() { |
138 DestroyVertexStruct(); | 138 DestroyVertexStruct(); |
139 } | 139 } |
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 helper->CreateVertexStruct(vertex_struct_id_, vertex_stream_params_.size()); | 150 helper->CreateVertexStruct(vertex_struct_id_, vertex_stream_params_.size()); |
151 for (unsigned int i = 0; i < vertex_stream_params_.size(); ++i) { | 151 for (unsigned int i = 0; i < vertex_stream_params_.size(); ++i) { |
152 const Stream &stream = vertex_stream_params_[i]->stream(); | 152 const Stream &stream = vertex_stream_params_[i]->stream(); |
153 vertex_struct::Semantic cb_semantic; | 153 vertex_struct::Semantic cb_semantic; |
154 unsigned int cb_semantic_index; | 154 unsigned int cb_semantic_index; |
155 if (!GetCBSemantic(stream.semantic(), stream.semantic_index(), &cb_semantic, | 155 if (!GetCBSemantic(stream.semantic(), stream.semantic_index(), &cb_semantic, |
156 &cb_semantic_index)) { | 156 &cb_semantic_index)) { |
157 DLOG(INFO) << "Unknown semantic (" << stream.semantic() << ", " | 157 DLOG(INFO) << "Unknown semantic (" << stream.semantic() << ", " |
158 << stream.semantic_index() << ") - ignoring stream."; | 158 << stream.semantic_index() << ") - ignoring stream."; |
159 continue; | 159 continue; |
160 } | 160 } |
161 vertex_struct::Type cb_type = GetCBType(stream.field()); | 161 vertex_struct::Type cb_type = GetCBType(stream.field()); |
162 if (cb_type == vertex_struct::NUM_TYPES) { | 162 if (cb_type == vertex_struct::kNumTypes) { |
163 DLOG(INFO) << "Invalid type (" << stream.field().num_components() | 163 DLOG(INFO) << "Invalid type (" << stream.field().num_components() |
164 << ") - ignoring stream."; | 164 << ") - ignoring stream."; |
165 continue; | 165 continue; |
166 } | 166 } |
167 | 167 |
168 VertexBufferCB *vertex_buffer = | 168 VertexBufferCB *vertex_buffer = |
169 static_cast<VertexBufferCB *>(stream.field().buffer()); | 169 static_cast<VertexBufferCB *>(stream.field().buffer()); |
170 helper->SetVertexInput( | 170 helper->SetVertexInput( |
171 vertex_struct_id_, i, | 171 vertex_struct_id_, i, |
172 vertex_buffer->resource_id(), | 172 vertex_buffer->resource_id(), |
(...skipping 16 matching lines...) Expand all Loading... |
189 } | 189 } |
190 | 190 |
191 void StreamBankCB::BindStreamsForRendering() { | 191 void StreamBankCB::BindStreamsForRendering() { |
192 if (vertex_struct_id_ == kInvalidResource) | 192 if (vertex_struct_id_ == kInvalidResource) |
193 CreateVertexStruct(); | 193 CreateVertexStruct(); |
194 CommandBufferHelper *helper = renderer_->helper(); | 194 CommandBufferHelper *helper = renderer_->helper(); |
195 helper->SetVertexStruct(vertex_struct_id_); | 195 helper->SetVertexStruct(vertex_struct_id_); |
196 } | 196 } |
197 | 197 |
198 } // namespace o3d | 198 } // namespace o3d |
OLD | NEW |