簡體   English   中英

集成圖形上的慢Java2D繪圖

[英]Slow Java2D Drawing on Integrated Graphics

我正在開發一個簡單的2D游戲,通過Java2D API渲染。 我注意到,當我嘗試在集成顯卡上繪圖時性能崩潰。

我已經在我的主鑽機上測試了這款游戲,其中包括更新的ATI Radeon和我5歲的筆記本電腦,它還有一個(令人難以置信的過時)Radeon。 兩者都得到了很好的FPS,但是當我嘗試使用我的Intel i5的板載HD 4000顯卡時,它的速度大約是20 FPS。

我正在使用全屏獨占模式。

在任何特定時刻,我一次渲染大約1000張圖像。

令人討厭的是,當我嘗試getAvailableAcceleratedMemory()時,它只返回-1這張卡,它似乎拒絕加速任何圖像。

有沒有人有任何想法如何解決這個問題?

渲染代碼:

    Graphics g = bufferStrategy.getDrawGraphics();
    g.drawImage(img, x, y, img.getWidth(), img.getHeight(), null)
    g.dispose();
    bufferStrategy.show();

圖片加載代碼:

    BufferedImage I = null;
    I = ImageIO.read(new File(currentFolder+imgPath));
    imgMap.put(imgIdentifier, I);

圖像存儲在由字符串標識的BufferedImages的散列圖中,因此當實體需要繪制並對其進行成像時,只需將其從散列映射中取出並繪制它。 在當前情況下,實體主要是地板和牆磚,因此它們永遠不會改變(因此不必從第一次以外的哈希圖中獲取圖像)。

編輯 - 我已經合並了MadProgrammer的方法,但它沒有改變我的FPS。

這是將圖像轉換為兼容圖像的示例......本身並不是答案

這是我使用的一些庫代碼...

public static BufferedImage createCompatibleImage(BufferedImage image) {
    BufferedImage target = createCompatibleImage(image, image.getWidth(), image.getHeight());
    Graphics2D g2d = target.createGraphics();
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();
    return target;
}

public static BufferedImage createCompatibleImage(BufferedImage image,
        int width, int height) {
    return getGraphicsConfiguration().createCompatibleImage(width, height, image.getTransparency());
}

public static GraphicsConfiguration getGraphicsConfiguration() {
    return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}

我會做點像......

I = createCompatibleImage(ImageIO.read(new File(currentFolder+imgPath)));
imgMap.put(imgIdentifier, I);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM