Skip to content

Commit 6f2811d

Browse files
committed
CCGraphicsBufferBindingMetal implemented.
1 parent ddbc34e commit 6f2811d

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

cocos2d/Platforms/iOS/CCMetalSupport.m

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,33 @@ -(void)commit; {}
150150
@end
151151

152152

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+
153180
@implementation CCRenderCommandDrawMetal
154181

155182
static const MTLPrimitiveType MetalDrawModes[] = {
@@ -161,14 +188,12 @@ -(void)invokeOnRenderer:(CCRenderer *)renderer
161188
{
162189
CCMetalContext *context = [CCMetalContext currentContext];
163190
id<MTLRenderCommandEncoder> renderEncoder = context.currentRenderCommandEncoder;
164-
165-
id<MTLBuffer> vertexBuffer = ((CCGraphicsBufferMetal *)renderer->_vertexBuffer)->_buffer;
166191
id<MTLBuffer> indexBuffer = ((CCGraphicsBufferMetal *)renderer->_elementBuffer)->_buffer;
167192

168193
[renderEncoder pushDebugGroup:@"CCRendererCommandDraw: Invoke"];
194+
[renderer bindBuffers:YES];
169195
// [renderer setRenderState:_renderState];
170196
[renderEncoder setRenderPipelineState:context->_tempPiplelineState];
171-
[renderEncoder setVertexBuffer:vertexBuffer offset:0 atIndex:0];
172197
[renderEncoder drawIndexedPrimitives:MetalDrawModes[_mode] indexCount:_count indexType:MTLIndexTypeUInt16 indexBuffer:indexBuffer indexBufferOffset:2*_first];
173198
[renderEncoder popDebugGroup];
174199
}

0 commit comments

Comments
 (0)