• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.graphics.g3d.utils.shapebuilders;
18 
19 import com.badlogic.gdx.graphics.Color;
20 import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder;
21 import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo;
22 import com.badlogic.gdx.math.Matrix4;
23 import com.badlogic.gdx.math.Vector3;
24 import com.badlogic.gdx.utils.Array;
25 import com.badlogic.gdx.utils.FlushablePool;
26 import com.badlogic.gdx.utils.Pool;
27 import com.badlogic.gdx.utils.ShortArray;
28 
29 /** This class allows to reduce the static allocation needed for shape builders. It contains all the objects used internally by
30  * shape builders.
31  * @author realitix, xoppa */
32 public class BaseShapeBuilder {
33 	/* Color */
34 	protected static final Color tmpColor0 = new Color();
35 	protected static final Color tmpColor1 = new Color();
36 	protected static final Color tmpColor2 = new Color();
37 	protected static final Color tmpColor3 = new Color();
38 	protected static final Color tmpColor4 = new Color();
39 
40 	/* Vector3 */
41 	protected static final Vector3 tmpV0 = new Vector3();
42 	protected static final Vector3 tmpV1 = new Vector3();
43 	protected static final Vector3 tmpV2 = new Vector3();
44 	protected static final Vector3 tmpV3 = new Vector3();
45 	protected static final Vector3 tmpV4 = new Vector3();
46 	protected static final Vector3 tmpV5 = new Vector3();
47 	protected static final Vector3 tmpV6 = new Vector3();
48 	protected static final Vector3 tmpV7 = new Vector3();
49 
50 	/* VertexInfo */
51 	protected static final VertexInfo vertTmp0 = new VertexInfo();
52 	protected static final VertexInfo vertTmp1 = new VertexInfo();
53 	protected static final VertexInfo vertTmp2 = new VertexInfo();
54 	protected static final VertexInfo vertTmp3 = new VertexInfo();
55 	protected static final VertexInfo vertTmp4 = new VertexInfo();
56 	protected static final VertexInfo vertTmp5 = new VertexInfo();
57 	protected static final VertexInfo vertTmp6 = new VertexInfo();
58 	protected static final VertexInfo vertTmp7 = new VertexInfo();
59 	protected static final VertexInfo vertTmp8 = new VertexInfo();
60 
61 	/* Matrix4 */
62 	protected static final Matrix4 matTmp1 = new Matrix4();
63 
64 	private final static FlushablePool<Vector3> vectorPool = new FlushablePool<Vector3>() {
65 		@Override
66 		protected Vector3 newObject () {
67 			return new Vector3();
68 		}
69 	};
70 
71 	private final static FlushablePool<Matrix4> matrices4Pool = new FlushablePool<Matrix4>() {
72 		@Override
73 		protected Matrix4 newObject () {
74 			return new Matrix4();
75 		}
76 	};
77 
78 	/** Obtain a temporary {@link Vector3} object, must be free'd using {@link #freeAll()}. */
obtainV3()79 	protected static Vector3 obtainV3 () {
80 		return vectorPool.obtain();
81 	}
82 
83 	/** Obtain a temporary {@link Matrix4} object, must be free'd using {@link #freeAll()}. */
obtainM4()84 	protected static Matrix4 obtainM4 () {
85 		final Matrix4 result = matrices4Pool.obtain();
86 		return result;
87 	}
88 
89 	/** Free all objects obtained using one of the `obtainXX` methods. */
freeAll()90 	protected static void freeAll () {
91 		vectorPool.flush();
92 		matrices4Pool.flush();
93 	}
94 }
95