Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  "2D blocks game" water falling  (Read 625 times)
0 Members and 1 Guest are viewing this topic.
Offline Doubstract
« Posted 2014-02-28 17:33:40 »

I am making 2D blocks game, everything is ok, but i cant make water falling correct. Water falling is working, but it takes too much FPS.
My water blocks extends class Blocks. To render blocks i am using VBOs (one chunk - one VBO). Right now i am updating chunk VBO, when water block moves. I am doing it like that:

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  
for(int cx = 0;cx < sizex;cx++){
            for(int cy = 0;cy < sizey;cy++){
               for(int bx = 0;bx < 16;bx++){
                  for(int by = 0;by < 16;by++){
                     if(cy == sizex-1 && by == 15){
                     }else{
                     if(chunks[cx][cy].blocks[bx][by].isWater){
                                 if(by == 15){
                                    if(chunks[cx][cy+1].blocks[bx][0].id == IDS.airBlockID){
                                         chunks[cx][cy+1].blocks[bx][0] = new WaterBlock(...);
                                         chunks[cx][cy].blocks[bx][by] = new AirBlock(...);
                                          chunks[cx][cy].updateVBOTextures();
                                          chunks[cx][cy+1].updateVBOTextures();
                                    }
                                 }else{
                                    if(chunks[cx][cy].blocks[bx][by+1].id == IDS.airBlockID){
                                         chunks[cx][cy].blocks[bx][by+1] = new WaterBlock(...);
                                        chunks[cx][cy].blocks[bx][by] = new AirBlock(...);
                                         chunks[cx][cy].updateVBOTextures();
                                    }
                                 }
                              }
                           }
                  }
               }
            }
         }


My main FPS problem here is this line:
1  
  chunks[...][...].updateVBOTextures();

I am updating VBOs every tick, and it takes too much FPS. I want to ask, how i can avoid this VBOs updating every tick, and still get similar result (i want to see how water falling).
Offline The Lion King
« Reply #1 - Posted 2014-02-28 17:50:04 »

how are you updating your vbo?

can i see your shaders and updateVBOTextures method

also what version of openGL are you using for the most part and what is your limit?

"You have to want it more than you want to breath, then you will be successful"
Offline Longarmx
« Reply #2 - Posted 2014-02-28 18:18:32 »

Are you using GL_STREAM_DRAW instead of GL_STATIC_DRAW?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline The Lion King
« Reply #3 - Posted 2014-02-28 18:24:14 »

Are you using GL_STREAM_DRAW instead of GL_STATIC_DRAW?

if he is changing data he should be using GL_DYNAMIC_DRAW, not static, also all this does is tell openGL how to put the buffer in memory and shouldn't cause huge drops in FPS with what is probably a small amount of data anyway

"You have to want it more than you want to breath, then you will be successful"
Offline saucymeatman
« Reply #4 - Posted 2014-03-01 00:09:58 »

Dynamic Draw is for multiple updates pre-render and GL_STREAM_DRAW is intended for when you know you will need to update once per frame or less, but your right, I dont think it would cause a frame rate drop in a simple 2d game.

I could be wrong.

Offline Longarmx
« Reply #5 - Posted 2014-03-01 01:59:39 »

What is in your updateVBOTextures method?

Offline The Lion King
« Reply #6 - Posted 2014-03-01 02:00:25 »

Dynamic Draw is for multiple updates pre-render and GL_STREAM_DRAW is intended for when you know you will need to update once per frame or less, but your right, I dont think it would cause a frame rate drop in a simple 2d game.

I could be wrong.



You are mistaken. Dynamic is multiple changes in the lifetime of the BO and used frequently. Static is no changes once set and used frequently. Steam is set once and not used often.

"You have to want it more than you want to breath, then you will be successful"
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2014-03-01 02:35:58 »

The way I understand it is:

STATIC_DRAW - 1:N
DYNAMIC_DRAW - M:N
STREAM_DRAW - 1:1

Where the ratio is Uploads:Drawings.

So static is upload once, draw any amount of times.
Dynamic is upload any amount of times, and drawn any amount of times per upload.
Stream is upload any amount of times, and draw once per upload.

Of course, these are just hints to the GPU, which lets it store the buffer in a way that makes it fastest for that sort of operation. You can draw STREAM_DRAW buffers as much as you like, but it would be more optimised to use dynamic.

Offline Doubstract
« Reply #8 - Posted 2014-03-01 09:47:32 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void updateVBOTextures(){
      for(int xb = 0;xb < 16;xb++){
         for(int yb = 0;yb < 16;yb++){
            changeTextureVBO((xb*16)+yb,blocks[xb][yb].textureX,blocks[xb][yb].textureY);
         }
      }
      glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
      glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) BufferUtils.createFloatBuffer(data.length).put(data).flip() , GL_STATIC_DRAW);
     
   }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public void changeTextureVBO(int target,float textureX, float textureY){
      target = target * 32;
      data[target+2] = textureX;
      data[target+3] = textureY;
     
      data[target+2+8] = textureX + texSize;
      data[target+3+8] = textureY;
     
      data[target+10+8] = textureX + texSize;
      data[target+11+8] = textureY + texSize;
     
      data[target+18+8] = textureX ;
      data[target+19+8] = textureY + texSize;
     
      target = 0;
     
   }


I am using static draw. I am not using any shaders.
Offline The Lion King
« Reply #9 - Posted 2014-03-01 09:59:14 »

Use dynamic draw, use glBufferSubData (or glMapBuffers if you wanna be more modern). Instead of remaking the float buffer, flip it again and use .put(float[], offset, size). Will be way faster Smiley

"You have to want it more than you want to breath, then you will be successful"
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!