Results 1 to 2 of 2
  1. #1
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default Best Way To Render

    I am writing a Logic Analyzer host side software (for the logic), and rendering is taking too much resources. This is what the render looks like:

    (just the View Window): http://i.imgur.com/Zt70k.png

    I have tried:
    1) Rendering everything everytime - slow and memory intensive
    2) Layers with an alpha, and having 5 layers. 2 are always rendered, and the other 3 are rendered only if it changes, for example, the data layer only if zoom/pan changes. Also slow

    The second is my current one. When I profile it, the top 2 major users of time are methods not in my program. One of them is fillRect (which I use, but it is pointing to something else, in a Java SE class). I use this prior to every rendering to fill with transparency, so as to avoid "ghosting". This was changed from making a new BufferedImage everytime, which was even slower.

    The other major usage is something I am not familiar with, but was some sort of compositing. I am thinking that this is drawing the transparent BufferedImages to a common BufferedImage.

    Together, these 2 account for almost 100% of the rendering time. What can I do to speed it up? Here is the code. It is very messy, as I am slowly converting it, and has some extraneous code. The render method is what is called everytime.

    Complete Render Code: [Java] /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com

    Just the relevant bits: // // NOT COMPILABLE // public BufferedImage render(int w, int h, int xP, i - Pastebin.com

    I researched it a bit, I found some websites claiming that the Graphics API is one of the hardest to work with because it is so poorly documented in terms of behavior. The example I found was that it uses hardware acceleration, but as soon as you use the setRGB method, it stops.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Step -1: Render everything that is static to a BufferedImage, this is your background refresh image. (updated rarely)

    [Note: do all drawing to one master buffered image: lets call it buffer]

    Step 1: Draw background to buffer
    Step 2: Draw highlighted rectangle to buffer
    Step 3: Draw time tags to buffer
    Step 4: Draw lines for each channel to buffer
    Step 5: Draw buffer to screen (graphics object)

    Repeat 1-5 in a loop (make sure to put in a timer or Thread.sleep(...) as to not use all CPU)

    This will be fast.

    Another option is to encapsulate each of the channels in a panel, and do similar as above.

    Also. For performance use createCompatibleImage:

    Java Code:
    Graphics2D g2d = (Graphics2D)g;
    ...
    BufferedImage buffer = (g2d).getDeviceConfiguration().createCompatibleImage(
                dim.width, dim.height,java.awt.Transparency.OPAQUE);
    Last edited by mrmatt1111; 03-24-2011 at 07:27 PM.
    My Hobby Project: LegacyClone

Similar Threads

  1. Replies: 0
    Last Post: 01-31-2011, 10:08 AM
  2. Replies: 0
    Last Post: 10-21-2010, 12:09 PM
  3. Unable to render printing the complete JPanel
    By Y. Progammer in forum New To Java
    Replies: 6
    Last Post: 03-12-2010, 03:18 PM
  4. Why wont my object render properly
    By toecutter in forum AWT / Swing
    Replies: 3
    Last Post: 10-22-2009, 02:43 PM
  5. Loki Render 0.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-26-2007, 09:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •