Subversion Repositories AndroidProjects

Rev

Rev 185 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
176 chris 1
package com.gebauz.Bauzoid.graphics.model;
2
 
3
import java.nio.ByteBuffer;
4
import java.nio.ByteOrder;
5
import java.nio.ShortBuffer;
6
 
7
import com.gebauz.Bauzoid.app.Consts;
185 chris 8
import com.gebauz.Bauzoid.graphics.Graphics;
9
import com.gebauz.Bauzoid.graphics.GraphicsObject;
176 chris 10
 
11
import android.opengl.GLES20;
12
 
13
/** Index stream. */
185 chris 14
public class IndexStream extends GraphicsObject
176 chris 15
{
16
        private int mIndexCount = 0;
17
        private ShortBuffer mData;
18
 
19
        private int mBufferID = 0;
20
        private static int[] BUFFERID = new int[1];
21
 
22
        /** Constructor. */
185 chris 23
        public IndexStream(Graphics graphics, int indexCount, byte[] data)
176 chris 24
        {
185 chris 25
                super(graphics);
176 chris 26
                mIndexCount = indexCount;
27
 
179 chris 28
                ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length);
176 chris 29
                byteBuffer.order(ByteOrder.nativeOrder());
179 chris 30
                byteBuffer.put(data);
176 chris 31
                byteBuffer.position(0);
180 chris 32
                mData = byteBuffer.asShortBuffer();
176 chris 33
        }
34
 
35
        /** Upload indices to hardware. */
36
        public final void upload()
37
        {
38
                GLES20.glGenBuffers(1, BUFFERID, 0);
39
                mBufferID = BUFFERID[0];
40
 
41
                GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mBufferID);
42
                GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, mData.capacity() * Consts.SIZEOF_SHORT, mData, GLES20.GL_STATIC_DRAW);
43
                GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
44
        }
45
 
46
        /** Unload indices from hardware. */
47
        public final void unload()
48
        {
49
                BUFFERID[0] = mBufferID;
50
                GLES20.glDeleteBuffers(1, BUFFERID, 0);
51
                mBufferID = 0;
52
        }
53
 
54
        /** Activate index stream. */
55
        public final void activate()
56
        {
57
                // TODO: state tracking
58
                GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mBufferID);
59
        }
60
 
61
        /** Deactivate index stream. */
62
        public final void deactivate()
63
        {
64
                // TODO: state tracking
65
                GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
66
        }
67
 
68
}