Subversion Repository Public Repository

Nextrek

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package min3d.core;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import min3d.vos.Color4;


public class Color4BufferList
{
	public static final int PROPERTIES_PER_ELEMENT = 4;
	public static final int BYTES_PER_PROPERTY = 1;

	private ByteBuffer _b;
	private int _numElements;
	
	public Color4BufferList(ByteBuffer $b, int $size)
	{
		_b = ByteBuffer.allocate($b.limit() * BYTES_PER_PROPERTY);
		_b.put($b);
		_numElements = $size;
	}
	
	public Color4BufferList(int $maxElements)
	{
		int numBytes = $maxElements * PROPERTIES_PER_ELEMENT * BYTES_PER_PROPERTY;
		_b = ByteBuffer.allocateDirect(numBytes); 
		_b.order(ByteOrder.nativeOrder());
	}
	
	/**
	 * The number of items in the list. 
	 */
	public int size()
	{
		return _numElements;
	}
	
	/**
	 * The _maximum_ number of items that the list can hold, as defined on instantiation.
	 * (Not to be confused with the Buffer's capacity)
	 */
	public int capacity()
	{
		return _b.capacity() / PROPERTIES_PER_ELEMENT;
	}
	
	/**
	 * Clear object in preparation for garbage collection
	 */
	public void clear()
	{
		_b.clear();
	}

	public Color4 getAsColor4(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		return new Color4( _b.get(), _b.get(), _b.get(), _b.get() );
	}
	
	public void putInColor4(int $index, Color4 $color4)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		$color4.r = (short)_b.get();
		$color4.g = (short)_b.get();
		$color4.b = (short)_b.get();
		$color4.a = (short)_b.get();
	}

	public short getPropertyR(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		return (short)_b.get();
	}
	public short getPropertyG(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 1);
		return (short)_b.get();
	}
	public float getPropertyB(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 2);
		return (short)_b.get();
	}
	public float getPropertyA(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 3);
		return (short)_b.get();
	}
	
	//
	
	public void add(Color4 $c)
	{
		set( _numElements, $c );
		_numElements++;
	}
	
	public void add(short $r, short $g, short $b, short $a)
	{
		set(_numElements, $r, $g, $b, $a);
		_numElements++;
	}
	
	public void set(int $index, Color4 $c)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put((byte)$c.r);
		_b.put((byte)$c.g);
		_b.put((byte)$c.b);
		_b.put((byte)$c.a);
		
		// Rem, OpenGL takes in color in this order: r,g,b,a -- _not_ a,r,g,b
	}

	public void set(int $index, short $r, short $g, short $b, short $a)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put((byte)$r);
		_b.put((byte)$g);
		_b.put((byte)$b);
		_b.put((byte)$a);
	}
	
	public void setPropertyR(int $index, short $r)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put((byte)$r);
	}
	public void setPropertyG(int $index, short $g)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 1);
		_b.put((byte)$g);
	}
	public void setPropertyB(int $index, short $b)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 2);
		_b.put((byte)$b);
	}
	public void setPropertyA(int $index, short $a)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 3);
		_b.put((byte)$a);
	}
	
	//
	
	public ByteBuffer buffer()
	{
		return _b;
	}
	
	public Color4BufferList clone()
	{
		_b.position(0);
		Color4BufferList c = new Color4BufferList(_b, size());
		return c;
	}
}

Commits for Nextrek/Android/LibrerieNextrek/src/min3d/core/Color4BufferList.java

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000