6

I'm making a game in java and in used BufferedImages to render content to the screen. I had performance issues on low end machines where the game is supposed to run, so I switched to VolatileImage which are normally faster. Except they actually slow the whole thing down.

The images are created with GraphicsConfiguration.createCompatibleVolatileImage(...) and are drawn to the screen with Graphics.drawImage(...) (follow link to see which one specifically). They are drawn upon a Canvas using double buffering.

Does someone has an idea of what is going wrong here ?

Norswap
  • 11,740
  • 12
  • 47
  • 60
  • I have noticed the same. – Hardcoded Apr 21 '10 at 15:15
  • If you're short of memory on the graphics card, it obviously wont help. IIRC, `BufferedImage` has had some speedups, so the difference might not be as great as it once was. – Tom Hawtin - tackline Apr 21 '10 at 15:45
  • @Norswap: I really think that to find a great answer to this consist in finding top-notch Open Source Java games (there surely are some) or some great great Java demo (from the "demo scene") and try to understand what they've done. I used to program games and demos a long time ago on *very* exotic hardware (like the Amiga, SNES, mode 13x etc.) and I still don't know how to "push pixels" correctly in Java. This is once more a domain where Java has been "overengineered" and is unnecessarily complicated. I don't hold for my breath for someone here on SO to be able to really help you. – SyntaxT3rr0r Apr 21 '10 at 16:20
  • It's definitely not a problem of video memory (I only have 700kb worth of image to keep in memory). Also a friend of mine using VolatileImages in his own game (which he test on the same computers) said I saw a 10x speed improvement when switching from BufferedImages). – Norswap Apr 21 '10 at 16:26

1 Answers1

6

Most likely your code is mixing accelerated and unaccelerated operations.

This document is a must read. Section 3.2 in particular is essential for anyone working with accelerated Java graphics.

user1876190
  • 450
  • 4
  • 6
Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
  • Is it possible that scaling (in the sense of clipping, see link in the question) an image is such an unaccelerated operation ? Since I use sprite sheets, every draw must effectively select a part of the image to draw to the screen. – Norswap Apr 21 '10 at 16:08