@@ -111,23 +111,23 @@ impl<'a, T: ShaderParam> Batch for (&'a mesh::Mesh<back::GlResources>, mesh::Sli
111
111
}
112
112
113
113
/// Owned batch - self-contained, but has heap-allocated data
114
- pub struct OwnedBatch < T : ShaderParam > {
115
- mesh : mesh:: Mesh < back :: GlResources > ,
114
+ pub struct OwnedBatch < T : ShaderParam , R : Resources > {
115
+ mesh : mesh:: Mesh < R > ,
116
116
mesh_link : mesh:: Link ,
117
117
/// Mesh slice
118
- pub slice : mesh:: Slice < back :: GlResources > ,
118
+ pub slice : mesh:: Slice < R > ,
119
119
/// Parameter data.
120
120
pub param : T ,
121
- program : ProgramHandle < back :: GlResources > ,
121
+ program : ProgramHandle < R > ,
122
122
param_link : T :: Link ,
123
123
/// Draw state
124
124
pub state : DrawState ,
125
125
}
126
126
127
- impl < T : ShaderParam > OwnedBatch < T > {
127
+ impl < T : ShaderParam , R : Resources > OwnedBatch < T , R > {
128
128
/// Create a new owned batch
129
- pub fn new ( mesh : mesh:: Mesh < back :: GlResources > , program : ProgramHandle < back :: GlResources > , param : T )
130
- -> Result < OwnedBatch < T > , BatchError > {
129
+ pub fn new ( mesh : mesh:: Mesh < R > , program : ProgramHandle < R > , param : T )
130
+ -> Result < OwnedBatch < T , R > , BatchError > {
131
131
let slice = mesh. to_slice ( PrimitiveType :: TriangleList ) ;
132
132
let mesh_link = match link_mesh ( & mesh, program. get_info ( ) ) {
133
133
Ok ( l) => l,
@@ -149,7 +149,7 @@ impl<T: ShaderParam> OwnedBatch<T> {
149
149
}
150
150
}
151
151
152
- impl < T : ShaderParam > Batch for OwnedBatch < T > {
152
+ impl < T : ShaderParam > Batch for OwnedBatch < T , back :: GlResources > {
153
153
type Resources = back:: GlResources ;
154
154
type Error = ( ) ;
155
155
@@ -250,73 +250,73 @@ impl<T: Clone + PartialEq> Array<T> {
250
250
/// Ref batch - copyable and smaller, but depends on the `Context`.
251
251
/// It has references to the resources (mesh, program, state), that are held
252
252
/// by the context that created the batch, so these have to be used together.
253
- pub struct RefBatch < T : ShaderParam > {
254
- mesh_id : Id < mesh:: Mesh < back :: GlResources > > ,
253
+ pub struct RefBatch < T : ShaderParam , R : Resources > {
254
+ mesh_id : Id < mesh:: Mesh < R > > ,
255
255
mesh_link : mesh:: Link ,
256
256
/// Mesh slice
257
- pub slice : mesh:: Slice < back :: GlResources > ,
258
- program_id : Id < ProgramHandle < back :: GlResources > > ,
257
+ pub slice : mesh:: Slice < R > ,
258
+ program_id : Id < ProgramHandle < R > > ,
259
259
param_link : T :: Link ,
260
260
state_id : Id < DrawState > ,
261
261
}
262
262
263
- impl < T : ShaderParam > Copy for RefBatch < T > where T :: Link : Copy { }
263
+ impl < T : ShaderParam , R : Resources > Copy for RefBatch < T , R > where T :: Link : Copy { }
264
264
265
- impl < T : ShaderParam > fmt:: Debug for RefBatch < T > {
265
+ impl < T : ShaderParam , R : Resources > fmt:: Debug for RefBatch < T , R > {
266
266
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
267
267
write ! ( f, "RefBatch(mesh: {:?}, slice: {:?}, program: {:?}, state: {:?})" ,
268
268
self . mesh_id, self . slice, self . program_id, self . state_id)
269
269
}
270
270
}
271
271
272
- impl < T : ShaderParam > PartialEq for RefBatch < T > {
273
- fn eq ( & self , other : & RefBatch < T > ) -> bool {
272
+ impl < T : ShaderParam , R : Resources > PartialEq for RefBatch < T , R > {
273
+ fn eq ( & self , other : & RefBatch < T , R > ) -> bool {
274
274
self . program_id == other. program_id &&
275
275
self . state_id == other. state_id &&
276
276
self . mesh_id == other. mesh_id
277
277
}
278
278
}
279
279
280
- impl < T : ShaderParam > Eq for RefBatch < T > { }
280
+ impl < T : ShaderParam , R : Resources > Eq for RefBatch < T , R > { }
281
281
282
- impl < T : ShaderParam > PartialOrd for RefBatch < T > {
283
- fn partial_cmp ( & self , other : & RefBatch < T > ) -> Option < Ordering > {
282
+ impl < T : ShaderParam , R : Resources > PartialOrd for RefBatch < T , R > {
283
+ fn partial_cmp ( & self , other : & RefBatch < T , R > ) -> Option < Ordering > {
284
284
Some ( self . cmp ( other) )
285
285
}
286
286
}
287
287
288
- impl < T : ShaderParam > Ord for RefBatch < T > {
289
- fn cmp ( & self , other : & RefBatch < T > ) -> Ordering {
288
+ impl < T : ShaderParam , R : Resources > Ord for RefBatch < T , R > {
289
+ fn cmp ( & self , other : & RefBatch < T , R > ) -> Ordering {
290
290
( & self . program_id , & self . state_id , & self . mesh_id ) . cmp (
291
291
& ( & other. program_id , & other. state_id , & other. mesh_id ) )
292
292
}
293
293
}
294
294
295
- impl < T : ShaderParam > RefBatch < T > {
295
+ impl < T : ShaderParam , R : Resources > RefBatch < T , R > {
296
296
/// Compare meshes by Id
297
- pub fn cmp_mesh ( & self , other : & RefBatch < T > ) -> Ordering {
297
+ pub fn cmp_mesh ( & self , other : & RefBatch < T , R > ) -> Ordering {
298
298
self . mesh_id . cmp ( & other. mesh_id )
299
299
}
300
300
/// Compare programs by Id
301
- pub fn cmp_program ( & self , other : & RefBatch < T > ) -> Ordering {
301
+ pub fn cmp_program ( & self , other : & RefBatch < T , R > ) -> Ordering {
302
302
self . program_id . cmp ( & other. program_id )
303
303
}
304
304
/// Compare draw states by Id
305
- pub fn cmp_state ( & self , other : & RefBatch < T > ) -> Ordering {
305
+ pub fn cmp_state ( & self , other : & RefBatch < T , R > ) -> Ordering {
306
306
self . state_id . cmp ( & other. state_id )
307
307
}
308
308
}
309
309
310
310
/// Factory of ref batches, required to always be used with them.
311
- pub struct Context {
312
- meshes : Array < mesh:: Mesh < back :: GlResources > > ,
313
- programs : Array < ProgramHandle < back :: GlResources > > ,
311
+ pub struct Context < R : Resources > {
312
+ meshes : Array < mesh:: Mesh < R > > ,
313
+ programs : Array < ProgramHandle < R > > ,
314
314
states : Array < DrawState > ,
315
315
}
316
316
317
- impl Context {
317
+ impl < R : Resources > Context < R > {
318
318
/// Create a new empty `Context`
319
- pub fn new ( ) -> Context {
319
+ pub fn new ( ) -> Context < R > {
320
320
Context {
321
321
meshes : Array :: new ( ) ,
322
322
programs : Array :: new ( ) ,
@@ -325,14 +325,14 @@ impl Context {
325
325
}
326
326
}
327
327
328
- impl Context {
328
+ impl < R : Resources > Context < R > {
329
329
/// Produce a new ref batch
330
330
pub fn make_batch < T : ShaderParam > ( & mut self ,
331
- program : & ProgramHandle < back :: GlResources > ,
332
- mesh : & mesh:: Mesh < back :: GlResources > ,
333
- slice : mesh:: Slice < back :: GlResources > ,
331
+ program : & ProgramHandle < R > ,
332
+ mesh : & mesh:: Mesh < R > ,
333
+ slice : mesh:: Slice < R > ,
334
334
state : & DrawState )
335
- -> Result < RefBatch < T > , BatchError > {
335
+ -> Result < RefBatch < T , R > , BatchError > {
336
336
let mesh_link = match link_mesh ( mesh, program. get_info ( ) ) {
337
337
Ok ( l) => l,
338
338
Err ( e) => return Err ( BatchError :: Mesh ( e) ) ,
@@ -365,7 +365,7 @@ impl Context {
365
365
}
366
366
}
367
367
368
- impl < ' a , T : ShaderParam > Batch for ( & ' a RefBatch < T > , & ' a T , & ' a Context ) {
368
+ impl < ' a , T : ShaderParam > Batch for ( & ' a RefBatch < T , back :: GlResources > , & ' a T , & ' a Context < back :: GlResources > ) {
369
369
type Resources = back:: GlResources ;
370
370
type Error = OutOfBounds ;
371
371
0 commit comments