Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLStencilManager.m
41159 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "MTLStencilManager.h"26//#include "MTLContext.h"27//#include "sun_java2d_SunGraphics2D.h"28//#import "common.h"2930@implementation MTLStencilManager {31id<MTLDepthStencilState> _stencilState;32id<MTLDepthStencilState> _genStencilState;33}3435@synthesize stencilState = _stencilState;36@synthesize genStencilState = _genStencilState;3738- (id _Nonnull)initWithDevice:(id<MTLDevice>) device {39self = [super init];40if (self) {41MTLDepthStencilDescriptor* stencilDescriptor;42stencilDescriptor = [[MTLDepthStencilDescriptor new] autorelease];43stencilDescriptor.frontFaceStencil.stencilCompareFunction = MTLCompareFunctionEqual;44stencilDescriptor.frontFaceStencil.stencilFailureOperation = MTLStencilOperationKeep;4546// TODO : backFaceStencil can be set to nil if all primitives are drawn as front-facing primitives47// currently, fill parallelogram uses back-facing primitive drawing - that needs to be changed.48// Once that part is changed, set backFaceStencil to nil49//stencilDescriptor.backFaceStencil = nil;5051stencilDescriptor.backFaceStencil.stencilCompareFunction = MTLCompareFunctionEqual;52stencilDescriptor.backFaceStencil.stencilFailureOperation = MTLStencilOperationKeep;53_stencilState = [device newDepthStencilStateWithDescriptor:stencilDescriptor];5455MTLDepthStencilDescriptor* genStencilDescriptor;56genStencilDescriptor = [[MTLDepthStencilDescriptor new] autorelease];57genStencilDescriptor.backFaceStencil.stencilCompareFunction = MTLCompareFunctionAlways;58genStencilDescriptor.backFaceStencil.depthStencilPassOperation = MTLStencilOperationReplace;59genStencilDescriptor.frontFaceStencil.stencilCompareFunction = MTLCompareFunctionAlways;60genStencilDescriptor.frontFaceStencil.depthStencilPassOperation = MTLStencilOperationReplace;61_genStencilState = [device newDepthStencilStateWithDescriptor:genStencilDescriptor];62}63return self;64}6566- (void)dealloc {67[_stencilState release];68[super dealloc];69}7071@end727374