@@ -166,18 +166,6 @@ impl SpecializedRenderPipeline for PolylinePipeline {
166
166
type Key = PolylinePipelineKey ;
167
167
168
168
fn specialize ( & self , key : Self :: Key ) -> RenderPipelineDescriptor {
169
- let vertex_attributes = vec ! [
170
- VertexAttribute {
171
- format: VertexFormat :: Float32x3 ,
172
- offset: 0 ,
173
- shader_location: 0 ,
174
- } ,
175
- VertexAttribute {
176
- format: VertexFormat :: Float32x3 ,
177
- offset: 12 ,
178
- shader_location: 1 ,
179
- } ,
180
- ] ;
181
169
let shader_defs = Vec :: new ( ) ;
182
170
let ( label, blend, depth_write_enabled) ;
183
171
@@ -208,15 +196,24 @@ impl SpecializedRenderPipeline for PolylinePipeline {
208
196
false => TextureFormat :: bevy_default ( ) ,
209
197
} ;
210
198
199
+ let mut vertex_layout = VertexBufferLayout {
200
+ step_mode : VertexStepMode :: Instance ,
201
+ array_stride : VertexFormat :: Float32x3 . size ( ) ,
202
+ attributes : vec ! [ VertexAttribute {
203
+ format: VertexFormat :: Float32x3 ,
204
+ offset: 0 ,
205
+ shader_location: 0 ,
206
+ } ] ,
207
+ } ;
208
+
211
209
RenderPipelineDescriptor {
212
210
vertex : VertexState {
213
211
shader : self . shader . clone ( ) ,
214
212
entry_point : "vertex" . into ( ) ,
215
213
shader_defs : shader_defs. clone ( ) ,
216
- buffers : vec ! [ VertexBufferLayout {
217
- array_stride: 12 ,
218
- step_mode: VertexStepMode :: Instance ,
219
- attributes: vertex_attributes,
214
+ buffers : vec ! [ vertex_layout. clone( ) , {
215
+ vertex_layout. attributes[ 0 ] . shader_location = 1 ;
216
+ vertex_layout
220
217
} ] ,
221
218
} ,
222
219
fragment : Some ( FragmentState {
@@ -388,9 +385,18 @@ impl<P: PhaseItem> RenderCommand<P> for DrawPolyline {
388
385
pass : & mut TrackedRenderPass < ' w > ,
389
386
) -> RenderCommandResult {
390
387
if let Some ( gpu_polyline) = polylines. into_inner ( ) . get ( pl_handle. unwrap ( ) ) {
391
- pass. set_vertex_buffer ( 0 , gpu_polyline. vertex_buffer . slice ( ..) ) ;
388
+ if gpu_polyline. vertex_count < 2 {
389
+ return RenderCommandResult :: Success ;
390
+ }
391
+
392
+ let item_size = VertexFormat :: Float32x3 . size ( ) ;
393
+ let buffer_size = gpu_polyline. vertex_buffer . size ( ) - item_size;
394
+ pass. set_vertex_buffer ( 0 , gpu_polyline. vertex_buffer . slice ( ..buffer_size) ) ;
395
+ pass. set_vertex_buffer ( 1 , gpu_polyline. vertex_buffer . slice ( item_size..) ) ;
396
+
392
397
let num_instances = gpu_polyline. vertex_count . max ( 1 ) - 1 ;
393
398
pass. draw ( 0 ..6 , 0 ..num_instances) ;
399
+
394
400
RenderCommandResult :: Success
395
401
} else {
396
402
RenderCommandResult :: Failure
0 commit comments