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
package min3d.core;

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

import min3d.vos.Uv;


public class UvBufferList 
{
	public static final int PROPERTIES_PER_ELEMENT = 2;
	public static final int BYTES_PER_PROPERTY = 4;

	private FloatBuffer _b;
	private int _numElements = 0;
	
	public UvBufferList(FloatBuffer $b, int $size)
	{
		ByteBuffer bb = ByteBuffer.allocateDirect($b.limit() * BYTES_PER_PROPERTY); 
		bb.order(ByteOrder.nativeOrder());
		_b = bb.asFloatBuffer();
		_b.put($b);
		_numElements = $size;
	}
	
	public UvBufferList(int $maxElements)
	{
		int numBytes = $maxElements * PROPERTIES_PER_ELEMENT * BYTES_PER_PROPERTY;
		ByteBuffer bb = ByteBuffer.allocateDirect(numBytes); 
		bb.order(ByteOrder.nativeOrder());
		
		_b  = bb.asFloatBuffer();
	}
	
	/**
	 * 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 Uv getAsUv(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		return new Uv( _b.get(), _b.get() );
	}
	
	public void putInUv(int $index, Uv $uv)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		$uv.u = _b.get();
		$uv.v = _b.get();
	}

	public float getPropertyU(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		return _b.get();
	}
	public float getPropertyV(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 1);
		return _b.get();
	}
	
	//
	
	public void add(Uv $uv)
	{
		set( _numElements, $uv );
		_numElements++;
	}
	
	public void add(float $u, float $v)
	{
		set(_numElements, $u, $v);
		_numElements++;
	}
	
	public void set(int $index, Uv $uv)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put($uv.u);
		_b.put($uv.v);
	}

	public void set(int $index, float $u, float $v)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put($u);
		_b.put($v);
	}
	
	public void setPropertyU(int $index, float $u)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put($u);
	}
	public void setPropertyV(int $index, float $v)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 1);
		_b.put($v);
	}
	
	//
	
	public FloatBuffer buffer()
	{
		return _b;
	}
	
	public UvBufferList clone()
	{
		_b.position(0);
		UvBufferList c = new UvBufferList(_b, size());
		return c;
	}
}

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

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