Java2D:在Ubuntu上不加速BufferedImage [英] Java2D: BufferedImage not accelerated on Ubuntu

查看:50
本文介绍了Java2D:在Ubuntu上不加速BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在使用Java2D API开发Java游戏,并且在Ubuntu环境中运行游戏时会遇到一些奇怪的性能问题.

We are currently developing a game in Java using the Java2D API and are experiencing some strange performance issues when running it in an Ubuntu environment.

我们的帧速率从Windows和Mac系统上的平均62fps下降到Ubuntu上的大约10fps.经过数小时的调试和测试各种JVM标志后,看来似乎没有在Ubuntu下加速使用位掩码的BufferedImages,因为

Our frame rate drops from an average of 62fps on Windows and Mac systems to about 10fps on Ubuntu. After some hours of debugging and testing various JVM flags it seems to be that BufferedImages using a bitmask are not being accelerated under Ubuntu because

System.out.println(img.getCapabilities(config).isAccelerated());

打印为假.

当前我们正在通过以下方式加载图像

Currently we are loading our images via

img = ImageIO.read(url);

,然后使用以下方法创建与设备兼容的BufferedImage:

and are then creating a device compatible BufferedImage using the following method:

private static BufferedImage createCompatibleImage(BufferedImage img) {

    // Get default graphics device
    GraphicsDeviceService graphicsDevice = ServiceProvider
            .getService(GraphicsDeviceService.class);
    GraphicsConfiguration config = graphicsDevice
            .getGraphicsConfiguration();

    // Get desired transparency mode
    int transparency = img.getColorModel().hasAlpha() ? Transparency.BITMASK
            : Transparency.OPAQUE;

    // Create device compatible buffered image
    BufferedImage ret = config.createCompatibleImage(img.getWidth(),
            img.getHeight(), transparency);

    // Draw old image onto new compatible image
    Graphics2D graphics = ret.createGraphics();
    graphics.drawImage(img, 0, 0, null);
    graphics.dispose();

    // Return compatible image
    return ret;
}

使用Transparency.OPAQUE创建兼容的BufferedImages时,将上面代码的第一行标记为true,这表明图像现在已加速并且帧频似乎恢复正常.

When creating compatible BufferedImages using the Transparency.OPAQUE, flag the first line of code above prints out true, which indicates that the image is now accelerated and the frame rate seems to be back at normal.

但是,这当然不是我们想要的解决方案,因为绘制的图像根本没有任何透明度,而是具有丑陋的黑色背景.

However this is of course not our desired solution since the images get drawn without any transparency at all and instead have ugly black backgrounds.

那么,有人知道这个问题的解决方案吗?

So, does anyone know a solution to this problem?

推荐答案

我相信问题在于,您在硬件加速环境中使用BITMASK.

I believe the trouble is in the fact that you use BITMASK in a hardware accelerated environment.

我不清楚限制在哪里.

  • 只有VolatileImage吗?还是也适用于BITMASK BufferedImage实例?
  • 它同时适用于OpenGL和Direct3D管道吗? (不谨慎使用此线程; OpenGL是Linux上唯一可用的线程)

无论如何,解决方案"是仅在软件渲染的环境中使用BITMASK图像;在硬件加速的环境中,您需要使用TRANSLUCENT图像.除了较旧的javagaming.org线程之外,我很难为我的主张找到有效的来源,所以我唯一能说的就是尝试一下.

In any case the "solution" is to use BITMASK images only in software rendered environments; in hardware accelerated environments you need to use TRANSLUCENT images in stead. Its hard for me to find a valid source for my claim other than an older javagaming.org thread, so the only thing I can say is to try it out.

http://www.java-gaming.org/index.php? topic = 19561.5

这篇关于Java2D:在Ubuntu上不加速BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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