@@ -150,6 +150,33 @@ -(void)commit; {}
150
150
@end
151
151
152
152
153
+ @interface CCGraphicsBufferBindingsMetal : NSObject <CCGraphicsBufferBindings> @end
154
+ @implementation CCGraphicsBufferBindingsMetal {
155
+ CCGraphicsBufferMetal *_vertexBuffer;
156
+ CCGraphicsBufferMetal *_indexBuffer;
157
+ }
158
+
159
+ -(instancetype )initWithVertexBuffer : (CCGraphicsBufferMetal *)vertexBuffer indexBuffer : (CCGraphicsBufferMetal *)indexBuffer
160
+ {
161
+ if ((self = [super init ])){
162
+ _vertexBuffer = vertexBuffer;
163
+ _indexBuffer = indexBuffer;
164
+ }
165
+
166
+ return self;
167
+ }
168
+
169
+ -(void )bind : (BOOL )bind
170
+ {
171
+ id <MTLRenderCommandEncoder > renderEncoder = [CCMetalContext currentContext ].currentRenderCommandEncoder ;
172
+
173
+ [renderEncoder insertDebugSignpost: @" CCGraphicsBufferBindingsMetal: Bind vertex array." ];
174
+ [renderEncoder setVertexBuffer: _vertexBuffer->_buffer offset: 0 atIndex: 0 ];
175
+ }
176
+
177
+ @end
178
+
179
+
153
180
@implementation CCRenderCommandDrawMetal
154
181
155
182
static const MTLPrimitiveType MetalDrawModes[] = {
@@ -161,14 +188,12 @@ -(void)invokeOnRenderer:(CCRenderer *)renderer
161
188
{
162
189
CCMetalContext *context = [CCMetalContext currentContext ];
163
190
id <MTLRenderCommandEncoder > renderEncoder = context.currentRenderCommandEncoder ;
164
-
165
- id <MTLBuffer > vertexBuffer = ((CCGraphicsBufferMetal *)renderer->_vertexBuffer )->_buffer ;
166
191
id <MTLBuffer > indexBuffer = ((CCGraphicsBufferMetal *)renderer->_elementBuffer )->_buffer ;
167
192
168
193
[renderEncoder pushDebugGroup: @" CCRendererCommandDraw: Invoke" ];
194
+ [renderer bindBuffers: YES ];
169
195
// [renderer setRenderState:_renderState];
170
196
[renderEncoder setRenderPipelineState: context->_tempPiplelineState];
171
- [renderEncoder setVertexBuffer: vertexBuffer offset: 0 atIndex: 0 ];
172
197
[renderEncoder drawIndexedPrimitives: MetalDrawModes[_mode] indexCount: _count indexType: MTLIndexTypeUInt16 indexBuffer: indexBuffer indexBufferOffset: 2 *_first];
173
198
[renderEncoder popDebugGroup ];
174
199
}
0 commit comments