setCache()和CacheHint如何在JavaFX中协同工作? [英] How do setCache() and CacheHint work together in JavaFX?

查看:302
本文介绍了setCache()和CacheHint如何在JavaFX中协同工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于JavaFX,我有以下问题:

With regard to JavaFX, I have the following questions:


  1. 我是否需要在a上使用setCache(true)由setCacheHint()设置的缓存提示的节点实际上有什么效果?

  1. Do I need to use setCache(true) on a Node for a cache hint set by setCacheHint() to actually have any effect?

调用setCache实际上提高性能即帧率一些或大部分时间?当我使用setCache(true)并且我应用缩放和其他变换时,我无法观察到帧速率的任何变化。

Should calling setCache actually improve performance i.e. frame rate some or most of the time? I am unable to observe any change in frame rate when I use setCache(true) and I apply scaling and other transforms.


推荐答案


我是否需要在Node上使用setCache(true)来为setCacheHint()设置的缓存提示实际产生任何影响?

Do I need to use setCache(true) on a Node for a cache hint set by setCacheHint() to actually have any effect?

是。

cache 属性提示系统是否应该缓存节点渲染(作为内部图像)。

The cache property is a hint to the system whether the node rendering should be cached (as an internal image) at all or not.

cacheHint 属性是系统对节点上预期转换的提示,以便可以针对那些转换类型优化缓存操作(例如缓存提示旋转,缩放或速度等)。

The cacheHint property is a hint to the system of what transforms are expected on the node so that the caching operation can be optimized for those transform types, (e.g. the cache hints rotate, scale or speed, etc).

如果节点未设置为高速缓存,则cacheHint不可用t。

If the node is not set to be cached at all, the cacheHint is irrelevant.


调用setCache是​​否应该在某些时候或大部分时间内提高性能,即帧速率?

Should calling setCache actually improve performance i.e. frame rate some or most of the time?

不一定。 JavaFX的默认帧速率上限为60fps,因此如果性能足够好,即使没有任何缓存提示也能达到帧速率,您将看不到任何明显的差异。这是许多基本动画和变换的情况。

Not necessarily. JavaFX has a default frame rate cap of 60fps, so if performance is good enough that the frame rate is reached even without any cache hints, you won't see any visible difference. This is the case for many basic animations and transforms.

即使帧速率没有提高,缓存提示也可能使每个变换的执行效率更高,从而减少CPU或GPU密集度(通常通过视觉交易)质量)。

Even if frame rate is not improved, the cache hint may make each transform a bit more efficient to perform so that it is less CPU or GPU intensive (usually by trading visual quality).

可能还有其他因素会对您的帧速率产生更大的影响。这些事情可能与可缓存项目的渲染速度无关(例如,在游戏循环期间在JavaFX应用程序线程上执行的长时间运行操作或不断变化的节点内容)。

There may be other things which have a far greater impact on your frame rate. These things may have nothing to do with rendering speed of cacheable items (for example a long running operation executed on the JavaFX application thread during a game loop or constantly changing node content).

我使用了 setCache(true) setCacheHint(CacheHint.SPEED)的组合在我编写的小游戏中,其中包含多个同时动画节点,其中多个效果和半透明应用于节点。设置确实加快了速度(Mac OS X,Macbook Air 2012,Java FX 2.2)。

I have used a combination of setCache(true) and setCacheHint(CacheHint.SPEED) in small games I have written that featured multiple simultaneously animated nodes with multiple effects and translucency applied to the nodes. The settings did speed things up a lot (Mac OS X, Macbook Air 2012, Java FX 2.2).

而不是依赖于渲染系统的提示,您也可以手动获取快照节点树,并使用快照Image手动替换节点树。这种快照技术并不总是最好的方法,但如果提示在你的情况下效果不好,它确实给你一个替代方案。

Rather than relying on hints to the rendering system, you can also manually take a snapshot of a node tree and manually replace the node tree with the snapshot Image. This snapshot technique is not always the best way to go, but it does give you an alternative if the hints aren't working out well in your case.

这篇关于setCache()和CacheHint如何在JavaFX中协同工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆