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.