Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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  
  Accelerated translucency in 1.4.2....  (Read 2826 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Posted 2003-10-09 13:16:47 »

It appears acceleration it only applied when drawing onto the back buffers of a BufferStrategy.  Sad

Which skuppered my plans for a cool blending effect for particle weapons/explosions and other fx :-/

I foolishly thought that because BufferStrategy uses VolatileImages for its back buffers, the accelerated translucency would be applied to all VolatileImage usage.

It turns out that isn't the case - Accelerated translucency is only applied when the source image is a Transparency.Translucent Image, AND the destination is a BufferStrategy back buffer.

1  
2  
3  
4  
5  
         VolatileImage blurBuffer = gc.createCompatibleVolatileImage(SCREEN_WIDTH,SCREEN_HEIGHT);
         BufferedImage blackImage = gc.createCompatibleImage(SCREEN_WIDTH,SCREEN_HEIGHT,Transparency.TRANSLUCENT);
         g = blackImage.createGraphics();
         g.setColor(new Color(0x55000000,true));
         g.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);


and then in the render loop :-

1  
2  
3  
4  
5  
6  
7  
8  
Graphics2D blurGraphics = blurBuffer.createGraphics();
blurGraphics.drawImage(blackImage,0,0,null); // <<this 1 line takes the fps from 150, down to 10 :-/

//misc effects drawing using blurGraphics

Graphics2D bufferGraphics = bufferStrategy.getDrawGraphics();
bufferGraphics.drawImage(blurBuffer,0,0,null);
//other misc non-blurred drawing


bahhhhhhh, thats annoying Sad


Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline MGodehardt

Junior Member




why does the chicken cross the road?


« Reply #1 - Posted 2003-10-09 13:54:06 »

Translusent Images are NOT accelerated in 1.4.2, u can enable a BUGGY version of transluscent acceleration, but i do not recommend this and sun does it also not recommend.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #2 - Posted 2003-10-09 14:02:00 »

Quote
u can enable a BUGGY version of transluscent acceleration, but i do not recommend this and sun does it also not recommend.


Thats what I was refering to.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #3 - Posted 2003-10-09 14:05:15 »

What is the switch to do so?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #4 - Posted 2003-10-09 14:12:31 »

1  
System.setProperty("sun.java2d.translaccel", "true");


it must be set before any awt stuff initialises.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline MGodehardt

Junior Member




why does the chicken cross the road?


« Reply #5 - Posted 2003-10-09 15:46:55 »

But be careful, when enabled some strange things can happen, for e.g. when enabled some diagonal lines will not be drawn until proper Alpha channel settings are set.

I recommend, wait until sun releases 1.5, a customer is much more upset when your game crashes 1000 times, he will quit and i can not pay my bills, bad. Better give him a 98% bullet proof program with less features.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #6 - Posted 2003-10-09 15:58:51 »

Im well aware of all the bugs and limitations in it.

The purpose of this Thread was to highlight 1 such limiation Grin

I've got tired of waiting for 1.5, and to find that 1.5 won't include accelerated transforms on Windows??? sigh

What good is having

a) the image in vram
b) the backbuffer in vram
c) the composite operation done on the gfx card

if the transform has to be done by the cpu in main memory Huh

It will result in so much reading back from vram, the end application will be 10times *slower* than the software only version Huh

Oh well, im not gonna rant about it again, I promise :-/

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline MGodehardt

Junior Member




why does the chicken cross the road?


« Reply #7 - Posted 2003-10-10 07:35:04 »

Oh sometimes the performance is 100 times worse with software rendering enabled, depends on your system.

I agree with you Abuse, hw accelerated transformations are a must for good games, isometric worls are not plain, i need some hills and without hw accelerated transformations, its impossible for me to implement this.

Ever played UO ? it uses military isometric and it was the first online game using this technic with success.

i use normal ( 30 degree ) isometric, but at the moment my world is flat, without transformations its impossible for me to transform a terrain tile into a hill, for e.g. one tile is at altitude 0 next is at altitude 10 ( 10 pixels above normal so the tile must be transformed to fill the complete hole between both.

i am using only standard jdk ( no jogl or similiar things ) and i will NEVER use anything not deployed from sun.
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #8 - Posted 2003-10-11 03:51:12 »

Hmm, there's something strange going on. Rendering (or compositing) translucent managed images to VolatileImage is  supposed to be accelerated (with the flag enabled, of course).

Try doing this in windowed mode, with bufferstrategy, it'll use VolatileImages as the buffers.

Also, disable any other rendering except that drawImage call and the vi to screen copy, and run the app with tracing (-Dsun.java2d.trace=log) and see what loop is being used.

Here's a version of what could be happening: the first copy to a vi will not be accelerated (we accelerate a managed image on the second copy), and the vi gets punted to system memory because we notice that it's being read from to do the compositing, and it never recovers from it. I'm not really sure why this is not happening with BB. May be it's because your Vi is smaller than BB, and we decide to punt an image to system memory surface based on percentage of the pixels we had to read from the image.

Try running the app with -Dsun.java2d.ddforcevram=true ,
or with -Dsun.java2d.accthreshold=0 (I think I explained sometime ago what these flags do)..
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #9 - Posted 2003-10-11 08:16:07 »

ah,
It appears to be accelerated in fullscreen, but not in windowed mode.

Then i set the flag :-

1  
System.setProperty("sun.java2d.accthreshold","0");


and it now works super fast in windowed mode as well ^_^

Seems there might be a bug with your acceleration threshold detection Tongue

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #10 - Posted 2003-10-13 03:22:12 »

So the ddforcevram flag didn't help?
I wrote a test, and any of these two flags helped.

And I think the cause of this problem is the one I've described. It doesn't happen in fs mode to backbuffer from BufferStrategy because we never punt those to system memory.
So, basically, it's not a bug but an implementation restriction =)

The test (what am I doing wrong? the formatting
just sucks):
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  
import java.awt.*;
import java.awt.image.*;

public class Test extends Frame {
    VolatileImage vimage;
    Image mimage;

    public Test() {
        pack();
        setSize(350, 360);
        vimage = createVolatileImage(300, 300);
        mimage =
            getGraphicsConfiguration().
               createCompatibleImage(300, 300,
                                     Transparency.TRANSLUCENT);
        Graphics g = mimage.getGraphics();
        g.setColor(Color.red);
        g.fillRect(0, 0, 300, 300);
    }

    public void paint(Graphics g) {
        Graphics vg = vimage.getGraphics();
        for (int i = 0; i < 100; i++) {
            vg.drawImage(mimage, 0, 0, null);
        }
        g.clearRect(0, 0, getWidth(), getHeight());
        g.drawImage(vimage, 5, 25, null);
        System.exit(0);
    }

    public static void main(String argv[]) {
        System.setProperty("sun.java2d.trace", "count");
        System.setProperty("sun.java2d.translaccel", "true");
        new Test().setVisible(true);
    }
}


And the output:
$ d:/devtools/java/j2sdk1.4.2/bin/java Test 2>&1 | grep D3D
$ d:/devtools/java/j2sdk1.4.2/bin/java -Dsun.java2d.ddforcevram=true Test 2>&1| grep D3D
98 calls to sun.awt.windows.D3DBlitLoops::Blit("Integer ARGB D3D with translucency", SrcOver, "Integer RGB DirectDraw")
$ d:/devtools/java/j2sdk1.4.2/bin/java -Dsun.java2d.accthreshold=0 Test 2>&1 | grep D3D
100 calls to sun.awt.windows.D3DBlitLoops::Blit("Integer ARGB D3D with translucency", SrcOver, "Integer RGB DirectDraw")
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #11 - Posted 2003-10-13 09:34:35 »

yup,

soz I should have said; sun.java2d.ddforcevram=true also fixes it =)

I was just so happy that sun.java2d.accthreshold=0 fixed it, i didn't bother trying the other 1 Wink

I'm gonna stick with the accthreshold=0 solution, cos it accelerates all the blits, (which avoids the ugly stutter you get with the forcevram solution, at the start of the app).

Setting the accthreshold flag also takes a few less bytes =) (its for a 4k app. im writing Tongue)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (60 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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!