Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Which methods from Graphics2D are HW-accelerated?  (Read 1338 times)
0 Members and 1 Guest are viewing this topic.
Offline DD.Jarod

Senior Newbie




Sry for my bad english :-)


« Posted 2003-12-28 19:33:21 »

Which methods from Graphics2D (got with createGraphics from a BufferedImage which was got with createCompatibleImage) are Hardwareaccelerated?
All of them or only drawImage(). And if only drawImage is accelerated, what happens if I call (e.g.) drawLine()?
Is the line drawn on the BufferedImage in the VRAM, or is the (BufferedImage in) VRAM copied to SystemRAM, the line drawn and the result copied back to VRAM?

And what happens if I call setRGB() from the BufferedImage?

And is there absolutely no HW acceleration for linux?
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #1 - Posted 2003-12-28 22:48:22 »

Simply put, none.

Managed images (those created with create/CompatibleImage) are cached in vram, but all the rendering goes to the surface in system memory (the 'master' copy), and, thus, is unaccelerated (rendering is performed by our software loops).

It's different for VolatileImages: they don't have a system memory copy, and the rendering happens to the surface in vram. Currently (as of 1.4.2) only a small number of rendering primitives is accelerated - drawlines, fillRects, etc (some through ddraw, some through GDI and some via d3d) and copying of other accelerated images to a VolatileImage (and, with a flag,  alpla blending of translucent managed images, using d3d).

The stuff said above is valid for windows. On unix it's different.
First, on unix opaque managed images don't have a system memory copy, they are stored in Pixmaps, and all rendering is done to them using X11 (except for the stuff X11 can't handle, of course). Whether this rendering is accelerated or not, and whether Pixmap is stored in vram, is driver/Xserver dependent.

1-bit transparent managed images, however,  do have  system memory copies, similar to the windows implementation,  and rendering  goes to the system memory copy.

There's tons of other details, you can take a look at this (somewhat outdated) paper

http://java.sun.com/products/java-media/2D/perf_graphics.html

Basically, the idea is that  one should use VolatileImage for images which are modified often (like a back-buffer), and use managed images for sprites and such.

Offline NexusOne

Junior Member




Java games rock!


« Reply #2 - Posted 2003-12-30 00:35:52 »

hmmm.. i guess you would be the one to ask... so if i'm just constantly updating an image and want to keep putting the newly-updated image on the screen, how do I work this? I would need to draw other images on the large image for each update, which would involve transparency, but the large image itself would end up totally opaque.. so should I use a volatile image for the large one? and draw bufferedImages onto it or regular images or other volatile images? if I use awt to draw the large image to a window will that slow it down or am I supposed to use awt? sorry for not understanding this very well but i've just been using regular Image objects with a Frame window and suffering through bad performance, and think it's time I improved my code. Just several lines of pseudocode would be really helpful, thanks.  Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DD.Jarod

Senior Newbie




Sry for my bad english :-)


« Reply #3 - Posted 2003-12-30 11:14:37 »

I don't know if it's correct, but this is the way I would do it (dirty pseucdocode):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
class Screen extends Frame implements Runnable
{
BufferStrategy BufferStrat;
VolitaleImage ImgBig;
Grpahics2D GrfxOnBig;
BufferedImage ImgSmall[];

public Screen()
{
System.setProperty("sun.java2d.translaccel", "true");       // for accelerated translucent  transperency
ImgBig = getGraphicsConfiguration().createCompatibleVolatileImage(Width, Height, true);     // the true for HW acceleration
GrfxOnBig = ImgBig.createGraphics();
ImgSmall = new BufferedImage[NumberOfSmallImgages];
for(int i = NumberOfSmallImgages-1; i >= 0; i--)
     {
     ImgSmall[i] = getGraphicsConfiguration().createCompatibleImage(ImgWidth,ImgHeight,Transparency.TRANSLUCENT);
     }
}

public void run()
{
Graphics2D GrfxScreen;
createBufferStrategy(2);     // to get accelerated screensurfaces
BufferStrat = this.getBufferStrategy();
GrfxScreen = (Graphics2D)BufferStrat.getDrawGraphics();

while(ProgRuns == true)
for(int i = NumberOfSmallImgages-1; i >= 0; i--)
     {
     YourMethodToDrawOnSmallImg(SmallImg[i]);
     GrfxBig.drawImage(posX, posY, SmallImg[i];
     }
GrfxScreen.drawImage(posX, posY, BigImg);     // draw on backbuffer
BufferStrat.show();      // flipp back- and frontbuffer
}

}


and then

1  
2  
Screen MyScreen = new Screen();
new Thread(MyScreen).start();


This is like I approximately made it.
I hope I haven't forgot some part you need.

The BufferedImage I just use because I haven't found a way to make VolitaleImages with Alphachannels.

Someone else some hints?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (22 views)
2014-09-07 01:11:22

Longarmx (21 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!