-
Notifications
You must be signed in to change notification settings - Fork 563
8373232: Set default filters and addressing modes for 3D metal textures #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1f6e24a
a8ed468
64ddd46
80fdcc8
7fb54da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,8 @@ - (id) createContext:(dispatch_data_t)shaderLibData | |
| linearSamplerDict = [[NSMutableDictionary alloc] init]; | ||
| nonLinearSamplerDict = [[NSMutableDictionary alloc] init]; | ||
| compositeMode = com_sun_prism_mtl_MTLContext_MTL_COMPMODE_SRCOVER; //default | ||
| nonMipmappedSamplerState = nil; | ||
| mipmappedSamplerState = nil; | ||
|
|
||
| currentBufferIndex = 0; | ||
| commandQueue = [device newCommandQueue]; | ||
|
|
@@ -235,6 +237,35 @@ - (MetalRingBuffer*) getDataRingBuffer | |
| return sampler; | ||
| } | ||
|
|
||
| - (void) create3DSamplerStates | ||
| { | ||
jayathirthrao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (mipmappedSamplerState == nil || | ||
| nonMipmappedSamplerState == nil) { | ||
| MTLSamplerDescriptor *samplerDescriptor = [MTLSamplerDescriptor new]; | ||
| samplerDescriptor.minFilter = MTLSamplerMinMagFilterLinear; | ||
| samplerDescriptor.magFilter = MTLSamplerMinMagFilterLinear; | ||
| samplerDescriptor.rAddressMode = MTLSamplerAddressModeRepeat; | ||
| samplerDescriptor.sAddressMode = MTLSamplerAddressModeRepeat; | ||
| samplerDescriptor.tAddressMode = MTLSamplerAddressModeRepeat; | ||
| samplerDescriptor.mipFilter = MTLSamplerMipFilterNotMipmapped; | ||
| nonMipmappedSamplerState = [[self getDevice] newSamplerStateWithDescriptor:samplerDescriptor]; | ||
|
|
||
| samplerDescriptor.mipFilter = MTLSamplerMipFilterLinear; | ||
| mipmappedSamplerState = [[self getDevice] newSamplerStateWithDescriptor:samplerDescriptor]; | ||
|
|
||
| [samplerDescriptor release]; | ||
| } | ||
| } | ||
|
|
||
| - (id<MTLSamplerState>) get3DSamplerState:(bool)mipmapped | ||
| { | ||
| if (mipmapped) { | ||
| return mipmappedSamplerState; | ||
| } else { | ||
| return nonMipmappedSamplerState; | ||
| } | ||
| } | ||
|
|
||
| - (id<MTLDevice>) getDevice | ||
| { | ||
| return device; | ||
|
|
@@ -837,6 +868,16 @@ - (void) dealloc | |
| pixelBuffer = nil; | ||
| } | ||
|
|
||
| if (nonMipmappedSamplerState != nil) { | ||
| [nonMipmappedSamplerState release]; | ||
| nonMipmappedSamplerState = nil; | ||
| } | ||
|
|
||
| if (mipmappedSamplerState != nil) { | ||
| [mipmappedSamplerState release]; | ||
| mipmappedSamplerState = nil; | ||
| } | ||
|
|
||
| device = nil; | ||
|
|
||
| [super dealloc]; | ||
|
|
@@ -1109,6 +1150,18 @@ - (void) blit:(id<MTLTexture>)src srcX0:(int)srcX0 srcY0:(int)srcY0 srcX1:(int)s | |
| [mtlContext setWorldTransformIdentityMatrix]; | ||
| } | ||
|
|
||
| /* | ||
| * Class: com_sun_prism_mtl_MTLContext | ||
| * Method: nSetDeviceParametersFor3D | ||
| * Signature: (J)J | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor : |
||
| */ | ||
| JNIEXPORT void JNICALL Java_com_sun_prism_mtl_MTLContext_nSetDeviceParametersFor3D | ||
| (JNIEnv *env, jclass jClass, jlong ctx) | ||
| { | ||
| MetalContext *pCtx = (MetalContext*) jlong_to_ptr(ctx); | ||
| [pCtx create3DSamplerStates]; | ||
| } | ||
|
|
||
| /* | ||
| * Class: com_sun_prism_mtl_MTLContext | ||
| * Method: nCreateMTLMesh | ||
|
|
@@ -1290,12 +1343,12 @@ - (void) blit:(id<MTLTexture>)src srcX0:(int)srcX0 srcY0:(int)srcY0 srcX1:(int)s | |
| */ | ||
| JNIEXPORT void JNICALL Java_com_sun_prism_mtl_MTLContext_nSetMap | ||
| (JNIEnv *env, jclass jClass, jlong ctx, jlong nativePhongMaterial, | ||
| jint mapType, jlong nativeTexture) | ||
| jint mapType, jlong nativeTexture, jboolean useMipmap) | ||
| { | ||
| MetalPhongMaterial *phongMaterial = (MetalPhongMaterial *) jlong_to_ptr(nativePhongMaterial); | ||
| MetalTexture *texMap = (MetalTexture *) jlong_to_ptr(nativeTexture); | ||
|
|
||
| [phongMaterial setMap:mapType map:[texMap getTexture]]; | ||
| [phongMaterial setMap:mapType map:[texMap getTexture] useMipmap:useMipmap]; | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,12 +228,20 @@ - (void) render | |
| atIndex:0]; | ||
| [phongEncoder setFragmentTexture:[material getMap:DIFFUSE] | ||
| atIndex:0]; | ||
| [phongEncoder setFragmentSamplerState:[material getSamplerState:DIFFUSE] | ||
| atIndex:0]; | ||
| [phongEncoder setFragmentTexture:[material getMap:SPECULAR] | ||
| atIndex:1]; | ||
| [phongEncoder setFragmentSamplerState:[material getSamplerState:SPECULAR] | ||
| atIndex:0]; | ||
| [phongEncoder setFragmentTexture:[material getMap:BUMP] | ||
| atIndex:2]; | ||
| [phongEncoder setFragmentSamplerState:[material getSamplerState:BUMP] | ||
| atIndex:0]; | ||
| [phongEncoder setFragmentTexture:[material getMap:SELFILLUMINATION] | ||
| atIndex:3]; | ||
| [phongEncoder setFragmentSamplerState:[material getSamplerState:SELFILLUMINATION] | ||
| atIndex:0]; | ||
|
Comment on lines
+231
to
+244
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the observations @arapte . |
||
|
|
||
| [phongEncoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle | ||
| indexCount:[mesh getNumIndices] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use mipmapping only when
(!PlatformUtil.isEmbedded()) && (i == PhongMaterial.DIFFUSE || i == PhongMaterial.SELF_ILLUM);. We need to pass mipmap information, so that we can pick appropriate sampler state in native code.