How do I reduce process that display TieMap?

Started by kureteRuby, June 18, 2016, 23:26:07

Previous topic - Next topic

kureteRuby

I made processing that display TieMap.However, This process is high capacity.

What should I do?

The part of Source Code.

class TileImage 
{
     
    protected static final int POSITION_INDEX = 0; // index of vertex attribute "in_Position"
    protected static final int COLOR_INDEX = 1; // index of vertex attribute "in_Color"
  
    protected static final int FLOAT_NUM_BYTES; // sizeof(float) in bytes
    protected static final int INT_NUM_BYTES; // sizeof(int) in bytes
    protected static final int VEC4_BYTES; // sizeof(vec4) in bytes
     
    static {
        FLOAT_NUM_BYTES = Float.SIZE / Byte.SIZE;
        INT_NUM_BYTES = Integer.SIZE / Byte.SIZE;
        VEC4_BYTES = 4 * FLOAT_NUM_BYTES;
    }
    //Texture Class
    protected Bitmap bitmap;
     
    protected int vboIndexId;
    protected int vboTexId;
     
    protected float[] indexesArray;
    protected float[] texturesArray;
     
    protected FloatBuffer textures;
 
    protected FloatBuffer indexes;
     
     
    public TileImage(Bitmap bitmap)
    {
        this.bitmap = bitmap;
    }
  public void dispose()
    {
        bitmap.dispose();
 
        glDisableVertexAttribArray(POSITION_INDEX);
  
        glDisableVertexAttribArray(COLOR_INDEX);
  
        glBindBuffer(GL_ARRAY_BUFFER, 0);
  
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  
        glDeleteBuffers(vboIndexId);
         
        glDeleteBuffers(vboTexId);
  
        glBindVertexArray(0);
    }
  public void draw()
    {
        if(!bitmap.getImagePath().equals(""))
        {
          GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
               
          bitmap.bind();
         
          glBindBuffer(GL_ARRAY_BUFFER, vboIndexId);
          GL11.glVertexPointer(3, GL_FLOAT, 0, 0l);
 
          glBindBuffer(GL_ARRAY_BUFFER, vboTexId);
          GL11.glTexCoordPointer(2, GL_FLOAT, 0, 0l);
 
          GL11.glDrawArrays(GL_QUADS, 0, indexesArray.length/3);
           
          GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
          GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
 
          glBindBuffer(GL_ARRAY_BUFFER, 0);
           
          bitmap.unBind();
        }
    }
 
    public void vBOSet()
    {
        textures = BufferUtils.createFloatBuffer(texturesArray.length);
        textures.put(texturesArray);
        textures.rewind(); 
         
        vboTexId = glGenBuffers();
         
        glBindBuffer(GL_ARRAY_BUFFER, vboTexId);
        glBufferData(GL_ARRAY_BUFFER, textures, GL_STATIC_DRAW);
         
        indexes = BufferUtils.createFloatBuffer(indexesArray.length);
        indexes.put(indexesArray);
        indexes.rewind();
  
        vboIndexId = glGenBuffers();
  
        glBindBuffer(GL_ARRAY_BUFFER, vboIndexId);
        glBufferData(GL_ARRAY_BUFFER, indexes, GL_STATIC_DRAW);
    }
}


Loadãâ,¬â,¬of CPU is nearlyãâ,¬â,¬25% when size of texturesArray is 1199872 and size of indexesArray is 1799808.

Environment is that OS is Windows7 and CPU is Core i5, GPU is inside Notebook.

I think that I rewrite source code Java to C++ andãâ,¬â,¬GLFW if way is none.

bobjob

Is the code 2D or 3D?
you want to make a call, only to the tiles that are currently displayed on the screen. If all tiles are displayed on the screen because you don't have a camera that moves, then you want to render them to a buffer/texture, instead of re rendering them every frame.

Cornix

I dont think you are going to win much in terms of performance if you switch to C++. You hardly use any java in your code, its just pure OpenGL calls. C++ is not going to magically make anything different.

kureteRuby

This program is 2D. However, the depth test is used at other parts.

There is a result used actually in the following picture.