Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: 1 [2]
31  Java Game APIs & Engines / Java 2D / Re: About multiple buffers when using BufferStrate on: 2002-11-06 18:53:34
thanks chet,

that pretty much takes care of my doubts. Although, as you said yourself, there are some holes in the API, it's pretty workable as it is, I just needed to know how it worked, there isn't that much documentation on this.

Seb.

PD: I still miss interrupts!
32  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-11-06 00:23:33
I disabled the matrox, I still get bad performance if Java2D uses Direct3D.

I have to add though that I didn't reboot the computer with the Matrox disabled, that could conceivably modify the operating environment and fix the problem. I'll try this at a later time when this machine can be taken offline.

Seb
33  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-11-02 06:07:45
I found what was causing the bad performance on my pentium 3/geForce2mx/w2k configuration. As I commented before I am getting 128 fps on another system while I got 10fps in this one.

The problem was due to Direct3D use in Java2D. I turned it off with -Dsun.java2d.d3d=false and immediatelly got 25fps on the geForce. Not a great improvement but the redraws are a lot smoother now.

It's also interesting to note, this system has another PCI display adapter (Matrox Millenium II - no 3D acceleration) besides the primary AGP. I got a frame rate improvemnt on both adapters after turning off direct3D.

Seb.
34  Java Game APIs & Engines / Java 2D / Re: About multiple buffers when using BufferStrate on: 2002-11-02 04:45:16
Allright, I just found Jeff's article on image types in java posted on this site thanks to google.

In there he does state that show() is scan synchronized, which is the only place where I found this documented, but I'm left wondering how the synching works.
1. Does it return immediattely or does it return after the retrace?
3. If it returns immediately, what happens to subsequent .getDrawGraphics() calls before the retrace? Do they return the same back buffer?

I think I could figure out the third one experimenting a bit. My little scroller tilemap test (it's quite evolved now, I'll post a .jar somewhere when it's more useful) drops from 128 to 60 fps when I implement page flipping. This is what hinted me about the vertical retrace synching. It also seems that show() makes the thread sleep, and that's why I only get 60 fps now.

Jeff, can you expand on the inner workings of this a bit cause I'm just guessing.

Seb

35  Java Game APIs & Engines / Java 2D / About multiple buffers when using BufferStrategy on: 2002-11-01 20:52:31
I would like to know what reason there is to support more than a single back buffer when using a bufferstrategy.

As far as I know this has 2 uses, both of which are apparently not possible with the API as it stands.

The first use is, when using 3 buffers, to have the first buffer (the primary surface)  being displayed, the second buffer ready and waiting for the vertical retrace so that it can appear next, and the third buffer being drawn on.
This can't be done in Java since there's no way to intercept the retrace, and show() is not syncronized with the retrace either.

The second use is to draw on as many buffers as we can and optimally do PAGE FLIPPING between them, another impossibility since apparently we can only access one buffer at a time.

The last line of this tutorial: http://java.sun.com/docs/books/tutorial/extra/fullscreen/bufferstrategy.html, states that 'It may be end up being wasteful to use more than one back buffer. Multi-buffering is only useful when the drawing time exceeds the time spent to do a show. Profile your application.'

But that's no real use for multiple buffers. As it says in the tutorial, one should think about optimizing if it gets to that, specially for games.

I know there's a gaming API being developed by Sun, but they should think about adding this functionality to BufferStrategy since that's where it belongs.

Any comments on this? I'm mostly curious as to why they would add this functionality if it's mostly useless as it is. Maybe there's another use and I'm missing something.

Seb
36  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-10-29 20:09:22
Ok, after your comments I did some more testing. I ran both tests on different machines and you're right, direct handling of VolatileImages is apparently not necessary, at least on most machines.

On the one where I wrote the little test originally there is a performance difference between both implementations, as there is on the geForce 2 MX machine, but there is no difference in the machines with the SiS chipset.

So, there still is a difference on some machines, but having tested this, I would do the same thing your doing, use createComatibleImage() since it caused less problems on the geForce, although performance was only slighly better, around 12 fps, compared to 128 fps on the athlon/sis configuration! Shocked

Oh well, the problem might be related to the fact that I hardcode the DisplayMode, I don't get it from a list of available modes. I'll see.

Seb.
37  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-10-29 15:44:24
I just did. This is what I found:
Quote

For Beta 3, Shared Memory Extension is used on Solaris and Linux in the local display environment, resulting in better performance when rendering to the screen and to the images. When DGA is not available, toolkit images and images created with Component.createImage or GraphicsConfiguration.createCompatibleImage are stored in pixmaps instead of system memory, enabling faster copies to the screen using X protocol requests. You can override this behavior with the pmoffscreen runtime flag, described in the section Runtime Flag For Solaris and Linux .


It seems to me that this is referring only to the unix family of O. Systems, specifically Solaris and Linux.

Regarding creatImage images:
Quote

When creating an image whose data is copied to the screen, you should create the image with the same depth and type of the screen. This way, no pixel format conversion between the image and the screen is necessary before copying the image. To create such an image, use either Component.createImage or GraphicsConfiguration.createCompatibleImage, or use a BufferedImage created with the ColorModel of the screen. The pre-defined types of BufferedImage have their own color models.


This means to me that compatible image is faster than your average image only because there is no pixel transformation applied when copying. But it doesn't mention about storage in vRam.

I also found this, which is quite suggestive since it's rather odd that createImage would call createVolatileImage which would call createImage again. Of course its not impossible, just awkward:
Quote

-Dsun.java2d.ddoffscreen=false
Setting this flag to false turns off DirectDraw offscreen surfaces acceleration by forcing all createVolatileImage calls to become createImage calls, and disables hidden acceleration performed on surfaces created with createImage


And out of my own personal experience with the code I posted before, when method getTile is modified to return BufferedImages created with createCompatibleImage(...), the result is faster than using some generic image format, but not as fast as using VolatileImage.

Seb.
38  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-10-29 14:13:33
As far as Component.createImage(...) is concerned, I found no documentation indicating it returns VolatileImages. What's more, the only documented ways I found a developer can create an accelerated image is requesting one explicitly through the createCompatibleVolatileImage(...) methods.

Seb
39  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-10-29 13:57:37
Hello again,

Here are some performance numbers I got from running a modified version. In this version I use a direct rendering loop, and I call setIgnoreRepaint(true). This way I could get some timings.

All the tests were done at 640x480x32 full-screen.

I got around 78fps on a Duron 900 runing in a pc-chips 810 motherboard (this is a very low end motherboard with a SiS chipset and SiS integrated graphics sharing the RAM with the cpu, in otherwords, no dedicated vRam).

On an Athlon 1.3GHz (actual clock speed, not the model name) I get 128fps on the same motherboard.

Now there are still some issues I believe. I still have to check my code just in case I'm doing something wroung, but in my 600MHz P3 with a geForce 2 MX I must get something like 10 fps!! There might be some compatibility issues with the drivers, although as I said, it could be my fault. I have to check the code.

I also got around 35 fps on a toshiba 300Mhz laptop.

Seb.
40  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-10-29 01:24:10
I just wanted to add something. When drawing the tiles using VolatileImages always check if the Image is still valid, if not rerender it. (see my code. function getTile() )

This can happen on Windows when switching display modes.

Seb.
41  Java Game APIs & Engines / Java 2D / Re: Side Scrolling Problem on: 2002-10-27 08:35:12
Hi, I noticed you're using createCompatibleImage(), you should use createCompatibleVolatileImage(), only then can you be relatively assured the image is accelerated.

Here's a side scrolling thingy I wrote. Compare the speeds. In my tests there were definite performance improvements.

Some comments on this code. The display mode is hardcoded. It's not checking for available display modes before doing the switch, so you should know beforehand what's supported by your system. you can change it in the constructor, reference name 'fullScreenMode'. alt-enter to switch into full screen.

Don't take this code as the correct way to run a rendering loop though. I hacked it up today. The correct way should turn off paint events.

Well, hope it helps,
Seb


import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;

public class GraphicsTest2 extends Frame implements KeyListener {
final static int WIDTH = 640, HEIGHT = 480;
     Map map;
     int offset;
     String sync = "SEMAFORO";
     GraphicsEnvironment ge;
     GraphicsDevice gd;
     DisplayMode normalMode, fullScreenMode;
     boolean fullScreen;

     public GraphicsTest2() {
           ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
           gd = ge.getDefaultScreenDevice();
           normalMode = gd.getDisplayMode();
           fullScreenMode = new DisplayMode( WIDTH, HEIGHT, 32, DisplayMode.REFRESH_RATE_UNKNOWN );
           fullScreen = false;

           setUndecorated( true );

           map = new GraphicsTest2.Map();
//            map.setGraphicsConfiguration( gd.getDefaultConfiguration() );
           offset = 0;

           setBounds( 0, 0, WIDTH, HEIGHT );
           addKeyListener( this );
           setVisible( true );
     }

     public void paint( Graphics g ) {
           synchronized ( sync ) {
                 GraphicsConfiguration gc = ( (Graphics2D) g ).getDeviceConfiguration();
                 for ( int y = 0; y < (HEIGHT >> 4); y++ ) {
                       for (int x = 0; x < (WIDTH >> 4); x++ ) {
                             g.drawImage( map.getTile( gc, x, y ), ( (x<<4)+offset)%WIDTH, y<<4, null );
//                              g.drawImage( map.tiles[ map.bitmap
  • [y] ], ( (x<<4)+offset)%640, y<<4, null );
                           }
                     }
               }
         }
       public void update( Graphics g ) {
           paint(g);
       }

         public void setFullScreen( boolean yes ) {
               if ( yes && ! fullScreen ) {
                     gd.setFullScreenWindow( this );
                     gd.setDisplayMode( fullScreenMode );
                     fullScreen = true;
               } else if ( !yes && fullScreen ) {
                     gd.setDisplayMode( normalMode );
                     gd.setFullScreenWindow( null );
                     fullScreen = false;
               }
         }
         public boolean getFullScreen() {
               return fullScreen;
         }
         public void keyTyped( KeyEvent ke ) {
         }
         public void keyPressed( KeyEvent ke ) {
               if ( ke.getKeyCode() == KeyEvent.VK_ENTER && ke.isAltDown() ) {
                     setFullScreen( !getFullScreen() );
               }
               if ( ke.getKeyCode() == KeyEvent.VK_ESCAPE ) {
                     setFullScreen( false );
                     System.exit( 0 );
               }
         }
         public void keyReleased( KeyEvent ke ) {
         }

         public void setOffset( int i ) {
               synchronized ( sync ) {
                     offset = i;
               }
         }
         public Object getSync() {
               return sync;
         }

         public static void main( String[] args ) {
               GraphicsTest2 window = new GraphicsTest2();
               while( true ) {
                     for ( int j = 0; j< 640; j++ ) {
                           synchronized ( window.getSync() ) {
                                 window.setOffset( j );
                           }
                           window.repaint();
                     }
               }
         }

         class Map {
               static final int MAX_TILES = 128;
               byte[][] bitmap;
               Image[] tiles;
               VolatileImage[] volatiles;

               public Map() {
                     createTiles();
                     volatiles = new VolatileImage[MAX_TILES];
                     System.out.println( "Map constructor done." );
                     createMap();
               }
               public final Image getTile( GraphicsConfiguration gc, int x, int y ) {
                     int tileId = bitmap
  • [y];
                     VolatileImage img = volatiles[ tileId ];
                     if ( img == null ) {
                           volatiles[ tileId ] = img = gc.createCompatibleVolatileImage( 16, 16 );
                           renderVolatile( img, tiles[ tileId ] );
                     } else {
                           int returnCode = img.validate( gc );
                           if ( returnCode == VolatileImage.IMAGE_INCOMPATIBLE ) {
                                 img.flush();
                                 volatiles[ tileId ] = img = gc.createCompatibleVolatileImage( 16, 16 );
                                 renderVolatile( img, tiles[ tileId ] );
                           } else if ( returnCode == VolatileImage.IMAGE_RESTORED ) {
                                 renderVolatile( img, tiles[ tileId ] );
                           }
                     }
                     return img;
               }
               private final void renderVolatile( VolatileImage vImg, Image img ) {
                     Graphics2D g = vImg.createGraphics();
                     g.drawImage( img, 0, 0, null );
               }
               private void createMap() {
                     System.out.println( "Creating map bytemap..." );
                     bitmap = new byte[64][48];
                     for ( int y = 0; y < 48; y++ ) {
                           for (int x = 0; x < 64; x++ ) {
                                 bitmap
  • [y] = (byte) ( (x*y) % 128 );
                           }
                     }
               }
               private void createTiles() {
                     System.out.println( "Creating tiles..." );
                     tiles = new Image[MAX_TILES];
                     Font f = new Font( "SansSerif", Font.PLAIN, 16 );
                     for ( int i = 0; i < 128; i++ ) {
                           BufferedImage img = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
                           Graphics2D g = img.createGraphics();
                           g.drawString( Integer.toString( i, 16 ), 0, 14 );
                           tiles = img;
                     }
               }
         }
    }
    [/pre]
Pages: 1 [2]
 
Ecumene (145 views)
2017-09-30 02:57:34

theagentd (213 views)
2017-09-26 18:23:31

cybrmynd (294 views)
2017-08-02 12:28:51

cybrmynd (284 views)
2017-08-02 12:19:43

cybrmynd (294 views)
2017-08-02 12:18:09

Sralse (287 views)
2017-07-25 17:13:48

Archive (966 views)
2017-04-27 17:45:51

buddyBro (1092 views)
2017-04-05 03:38:00

CopyableCougar4 (1663 views)
2017-03-24 15:39:42

theagentd (1425 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!