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

import java.util.ArrayList;
import java.util.HashMap;

import min3d.Min3d;
import min3d.vos.Light;
import android.util.Log;

public class ManagedLightList 
{
	// List of Light objects
	private ArrayList<Light> _lights;

	// Map Light objects to GL_LIGHT indices
	private HashMap<Light, Integer> _lightToGlIndex;

	// 'Pool' of available GL_LIGHT id's
	private ArrayList<Integer> _availGlIndices;

	// Array of which GL_LIGHTS are enabled, where index corresponds to
	// GL_LIGHT[index]
	private boolean[] _glIndexEnabled;

	// Array of dirty flags, where index corresponds to GL_LIGHT[index]
	private boolean[] _glIndexEnabledDirty;

	// "GL index" here means an int from 0 to 8 that corresponds to
	// the int constants GL10.GL_LIGHT0 to GL10.GL_LIGHT7

	public ManagedLightList() 
	{
		reset();
	}

	public void reset() 
	{
		Log.i(Min3d.TAG, "ManagedLightList.reset()");

		_availGlIndices = new ArrayList<Integer>();
		for (int i = 0; i < Renderer.NUM_GLLIGHTS; i++) {
			_availGlIndices.add(i);
		}

		_lightToGlIndex = new HashMap<Light, Integer>();

		_glIndexEnabled = new boolean[Renderer.NUM_GLLIGHTS];
		_glIndexEnabledDirty = new boolean[Renderer.NUM_GLLIGHTS];
		for (int i = 0; i < Renderer.NUM_GLLIGHTS; i++) {
			_glIndexEnabled[i] = false;
			_glIndexEnabledDirty[i] = true;
		}

		_lights = new ArrayList<Light>();
	}

	public boolean add(Light $light) 
	{
		if (_lights.contains($light)) {
			return false;
		}

		if (_lights.size() > Renderer.NUM_GLLIGHTS)
			throw new Error("Exceeded maximum number of Lights");

		boolean result = _lights.add($light);

		int glIndex = _availGlIndices.remove(0);

		_lightToGlIndex.put($light, glIndex);

		_glIndexEnabled[glIndex] = true;
		_glIndexEnabledDirty[glIndex] = true;
		
		return result;
	}

	public void remove(Light $light) 
	{
		boolean result = _lights.remove($light);

		if (!result) return;

		int glIndex = _lightToGlIndex.get($light);
		
		_availGlIndices.add(glIndex);

		_glIndexEnabled[glIndex] = false;
		_glIndexEnabledDirty[glIndex] = true;
	}

	public void removeAll() 
	{
		reset();
	}

	public int size() 
	{
		return _lights.size();
	}

	public Light get(int $index) 
	{
		return _lights.get($index);
	}

	public Light[] toArray() {
		return (Light[]) _lights.toArray(new Light[_lights.size()]);
	}

	/**
	 * Used by Renderer
	 */
	int getGlIndexByLight(Light $light) /* package-private */
	{
		return _lightToGlIndex.get($light);
	}

	/**
	 * Used by Renderer
	 */
	Light getLightByGlIndex(int $glIndex) /* package-private */
	{
		for (int i = 0; i < _lights.size(); i++) 
		{
			Light light = _lights.get(i);
			if (_lightToGlIndex.get(light) == $glIndex)
				return light;
		}
		return null;
	}

	/**
	 * Used by Renderer
	 */
	boolean[] glIndexEnabledDirty() /* package-private */
	{
		return _glIndexEnabledDirty;
	}

	/**
	 * Used by Renderer
	 */
	boolean[] glIndexEnabled() /* package-private */
	{
		return _glIndexEnabled;
	}
}

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

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