@@ -2006,7 +2006,9 @@ -(void)updateCanvas:(BOOL)animated {
20062006 // Metal updates drawable size automatically via CAMetalLayer
20072007 int framebufferWidth = (int )([[self metalView ] drawableSize ].width );
20082008 int framebufferHeight = (int )([[self metalView ] drawableSize ].height );
2009- CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2009+ if (framebufferWidth > 0 && framebufferHeight > 0 ) {
2010+ CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2011+ }
20102012#else
20112013 [[self eaglView ] updateFrameBufferSize: (int )self .view.bounds.size.width h: (int )self .view.bounds.size.height];
20122014#endif
@@ -2177,9 +2179,17 @@ -(void)setScissorRect:(MTLScissorRect)rect enabled:(BOOL)enabled {
21772179 view.scissorRect = rect;
21782180 view.scissorEnabled = enabled;
21792181
2180- // Apply scissor to the current encoder if it exists
2181- // Note: The iOSPort version doesn't use currentEncoder, so we'll store the state
2182- // and it will be applied when the next encoder is created
2182+ // If there's a current encoder, apply scissor immediately
2183+ if (view.currentEncoder != nil ) {
2184+ if (enabled) {
2185+ [view.currentEncoder setScissorRect: rect];
2186+ } else {
2187+ // Disable scissor by setting it to full drawable size
2188+ CGSize drawableSize = [view drawableSize ];
2189+ MTLScissorRect fullRect = {0 , 0 , (NSUInteger )drawableSize.width , (NSUInteger )drawableSize.height };
2190+ [view.currentEncoder setScissorRect: fullRect];
2191+ }
2192+ }
21832193}
21842194#else
21852195EAGLView* lastFoundEaglView;
@@ -2236,9 +2246,12 @@ - (void)awakeFromNib
22362246
22372247 // Initialize Metal matrices
22382248 METALView *metalView = [self metalView ];
2239- int framebufferWidth = (int )metalView.drawableSize .width ;
2240- int framebufferHeight = (int )metalView.drawableSize .height ;
2241- CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2249+ CAMetalLayer *layer = (CAMetalLayer *)metalView.layer ;
2250+ int framebufferWidth = (int )layer.drawableSize .width ;
2251+ int framebufferHeight = (int )layer.drawableSize .height ;
2252+ if (framebufferWidth > 0 && framebufferHeight > 0 ) {
2253+ CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2254+ }
22422255#else
22432256#ifdef USE_ES2
22442257 if (!cn1CompareMatrices (GLKMatrix4Identity, CN1transformMatrix)) {
@@ -2818,7 +2831,9 @@ -(void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coor
28182831 // Metal updates drawable size automatically
28192832 int framebufferWidth = (int )([[self metalView ] drawableSize ].width );
28202833 int framebufferHeight = (int )([[self metalView ] drawableSize ].height );
2821- CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2834+ if (framebufferWidth > 0 && framebufferHeight > 0 ) {
2835+ CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2836+ }
28222837#else
28232838 [[self eaglView ] updateFrameBufferSize: (int )size.width h: (int )size.height];
28242839 [[self eaglView ] deleteFramebuffer ];
@@ -2865,7 +2880,9 @@ -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOr
28652880 // Metal updates drawable size automatically
28662881 int framebufferWidth = (int )([[self metalView ] drawableSize ].width );
28672882 int framebufferHeight = (int )([[self metalView ] drawableSize ].height );
2868- CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2883+ if (framebufferWidth > 0 && framebufferHeight > 0 ) {
2884+ CN1_Metal_InitMatrices (framebufferWidth, framebufferHeight);
2885+ }
28692886#else
28702887 [[self eaglView ] updateFrameBufferSize: (int )self .view.bounds.size.width h: (int )self .view.bounds.size.height];
28712888 [[self eaglView ] deleteFramebuffer ];
@@ -3031,7 +3048,6 @@ - (void)drawFrame:(CGRect)rect
30313048 }
30323049 }
30333050#ifdef CN1_USE_METAL
3034- METALView *metalView = [self metalView ];
30353051 [metalView presentFramebuffer ];
30363052#else
30373053 GLErrorLog;
@@ -3135,6 +3151,7 @@ - (BOOL)validateProgram:(GLuint)prog
31353151 return TRUE ;
31363152}
31373153
3154+ #ifndef CN1_USE_METAL
31383155- (BOOL )loadShaders
31393156{
31403157 GLuint vertShader, fragShader;
@@ -3202,9 +3219,10 @@ - (BOOL)loadShaders
32023219 glDeleteShader (vertShader);
32033220 if (fragShader)
32043221 glDeleteShader (fragShader);
3205-
3222+
32063223 return TRUE ;
32073224}
3225+ #endif // CN1_USE_METAL
32083226
32093227
32103228-(BOOL )isPaintFinished {
0 commit comments