Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  Improving Texture Loading  (Read 1189 times)
0 Members and 1 Guest are viewing this topic.
Offline CopyableCougar4
« Posted 2014-08-01 17:37:59 »

Hi

In my project I have to load a texture that is a spritesheet used for a
Theme
for my GUI controls. The theme loads fine, but it takes about 30ms (only 1ms for theme creation, 29ms for texture loading) so I would like to speed up my texture loading. As of now I load many of my textures through serialized objects where the png data is in a byte array. However the process still takes too long. I was hoping someone on JGO could help me find some ways to speed up the efficiency of my code.

Here is the pastebin for my Texture class, my ObjectLoading class, and my SerializableBufferWrapper class: http://pastebin.java-gaming.org/f3717614b0e19

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Online BurntPizza

« JGO Bitwise Duke »


Medals: 291
Exp: 5 years



« Reply #1 - Posted 2014-08-01 18:04:24 »

First question: why is that too slow? 30ms is a 33rd of a second. That seems pretty quick to me for what sounds like a 1-time operation.
Offline CopyableCougar4
« Reply #2 - Posted 2014-08-01 18:07:36 »

It's too slow because it happens before anything is rendered but after the display is created. I will live with it if there aren't ways to speed it up, but it would be nice to speed it up.

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pitbuller
« Reply #3 - Posted 2014-08-01 18:08:54 »

Use smaller texture or stream it.
Offline CopyableCougar4
« Reply #4 - Posted 2014-08-01 18:10:24 »

If by streaming it you mean using a FileInputStream, I am because of the deserialization, but if you mean something else then please clarify.

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Online BurntPizza

« JGO Bitwise Duke »


Medals: 291
Exp: 5 years



« Reply #5 - Posted 2014-08-01 18:12:29 »

If it's really that noticeable then surely you can read the files in on a separate thread before or while the display is being created.

Otherwise first thing is if your'e using serialization make sure to wrap the FileInputStream in a BufferedInputStream and then the ObjectInputStream, should be considerably faster.
Offline CopyableCougar4
« Reply #6 - Posted 2014-08-01 18:19:52 »

Wrapping the File streams in Buffered streams shaved about 5-10ms off the process so far Smiley

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Online BurntPizza

« JGO Bitwise Duke »


Medals: 291
Exp: 5 years



« Reply #7 - Posted 2014-08-01 18:25:32 »

Really the fastest way would be to store the raw buffers in files and read them in with an NIO FileChannel. No serialization or anything.
Offline CopyableCougar4
« Reply #8 - Posted 2014-08-01 18:34:44 »

How would I store the dimensions of the texture? Would I just write those to the same buffer?

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Online BurntPizza

« JGO Bitwise Duke »


Medals: 291
Exp: 5 years



« Reply #9 - Posted 2014-08-01 18:37:10 »

You could dedicate the first X bytes to header information like that, read it in any way you like, and then read the rest into the buffer, or use a separate properties file.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #10 - Posted 2014-08-02 07:41:50 »

Hello

Maybe you should display something (a message with a progress bar for example) that doesn't need any resource stored in a file while loading a few files when the end user launches your game. You can still improve texture loading but imagine that you have to load a lot more images, you'll need to indicate that you're loading something instead of just showing a black screen.

Offline trollwarrior1
« Reply #11 - Posted 2014-08-02 07:47:58 »

Unless you need to load more than 10 of these images, I don't see any problem.. Loading takes 33ms? You would load 33 images in 1 second. How is that slow? A lot of games take at least 10 seconds to load at the start of the game and they keep reloading stuff when already playing, which takes more time. I bet you don't have more than 5 images..
Offline theagentd

« JGO Bitwise Duke »


Medals: 366
Projects: 2
Exp: 8 years



« Reply #12 - Posted 2014-08-02 07:59:30 »

Maybe this could be useful: http://www.java-gaming.org/topics/tutorial-stutter-free-texture-streaming-with-lwjgl/32571/view.html

Myomyomyo.
Offline Longarmx
« Reply #13 - Posted 2014-08-02 15:48:29 »

It's too slow because it happens before anything is rendered but after the display is created.

Simple fix: Draw a loading screen BEFORE you load your images.

Offline gouessej
« Reply #14 - Posted 2014-08-02 16:03:43 »

@Longarmx That's a bit what I suggested.

@theagentd Nice tutorial but it works with OpenGL drivers reliable enough to manage multi-threading.

Edit.: Sven does something similar in the JOGL media player:
http://forum.jogamp.org/transfer-images-from-TextureData-to-a-Texture-off-of-the-EDT-in-JOGL-tp4032678p4032694.html

Offline Sickan

Senior Devvie


Medals: 9



« Reply #15 - Posted 2014-08-02 16:07:59 »

Hello

Maybe you should display something (a message with a progress bar for example) that doesn't need any resource stored in a file while loading a few files when the end user launches your game. You can still improve texture loading but imagine that you have to load a lot more images, you'll need to indicate that you're loading something instead of just showing a black screen.

I fully agree. Even if he got texture loading down to a few ms, he'd eventually reach a point where loading all his textures takes noticeable time. Unless of course his game consisted of a dozen or so images total. So a loading screen is more or less inevitable no matter how fast you load your textures.
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-23 03:34:11

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!