1 /*
  2 SpiderGL Computer Graphics Library
  3 Copyright (c) 2010, Marco Di Benedetto - Visual Computing Lab, ISTI - CNR
  4 All rights reserved.
  5 
  6 Redistribution and use in source and binary forms, with or without
  7 modification, are permitted provided that the following conditions are met:
  8     * Redistributions of source code must retain the above copyright
  9       notice, this list of conditions and the following disclaimer.
 10     * Redistributions in binary form must reproduce the above copyright
 11       notice, this list of conditions and the following disclaimer in the
 12       documentation and/or other materials provided with the distribution.
 13     * Neither the name of SpiderGL nor the
 14       names of its contributors may be used to endorse or promote products
 15       derived from this software without specific prior written permission.
 16 
 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20 DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY
 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 */
 28 
 29 /**
 30  * @fileOverview Core
 31  */
 32 
 33 /**
 34  * The SpiderGL.Core namespace.
 35  *
 36  * @namespace The SpiderGL.Core namespace.
 37  */
 38 SpiderGL.Core = { };
 39 
 40 /**
 41  * Default token.
 42  *
 43  * This constant can be used to set a parameter to its default value.
 44  *
 45  * @constant
 46  * @type object
 47  *
 48  * @example
 49  * texture.setSampler({
 50  *   wrapS : gl.REPEAT,
 51  *   wrapT : SpiderGL.Core.DEFAULT // set to the default value gl.CLAMP_TO_EDGE
 52  * });
 53  */
 54 SpiderGL.Core.DEFAULT = { };
 55 
 56 /**
 57  * Don't care token.
 58  *
 59  * This constant can be used to avoid setting policy/behavior parameter.
 60  *
 61  * @constant
 62  * @type object
 63  *
 64  * @example
 65  * texture.setImage({
 66  *   data  : image,
 67  *   flipY : SpiderGL.Core.DONT_CARE // overrides the texture automatic flipY policy and keeps current gl setting
 68  * });
 69  */
 70 SpiderGL.Core.DONT_CARE = { };
 71 
 72 /**
 73  * Alias for "".
 74  *
 75  * @constant
 76  * @type string
 77  */
 78 SpiderGL.Core.EMPTY_STRING = "";
 79 
 80 /**
 81  * Alias for { }.
 82  *
 83  * @constant
 84  * @type object
 85 */
 86 SpiderGL.Core.EMPTY_OBJECT = { };
 87 
 88 /**
 89  * Alias for [ ].
 90  *
 91  * @constant
 92  * @type array
 93 */
 94 SpiderGL.Core.EMPTY_ARRAY = [ ];
 95 
 96 /**
 97  * Alias for function () { }.
 98  *
 99  * It can be used as a function parameter or event handler to avoid checking whether the provided function is not null or undefined.
100  *
101  * @constant
102  * @type function
103  *
104  * @example
105  * // avoid test for null/undefined when invoking an event handler
106  * someObject.onSomeEvent = SpiderGL.Core.EMPTY_FUNCTION;
107  */
108 SpiderGL.Core.EMPTY_FUNCTION = function () { };
109 
110 /**
111  * Generates a unique id.
112  *
113  * @returns {number} A unique id.
114  */
115 SpiderGL.Core.generateUID = function () {
116 	SpiderGL.Core.generateUID._lastUID++;
117 	return SpiderGL.Core.generateUID._lastUID;
118 }
119 
120 SpiderGL.Core.generateUID._lastUID = 0;
121 
122 /**
123  * Creates a SpiderGL.Core.ObjectBase
124  *
125  * SpiderGL.Core.ObjectBase is the base class for all SpiderGL classes.
126  *
127  * @class The SpiderGL.Core.ObjectBase is the base class for all SpiderGL classes.
128  */
129 SpiderGL.Core.ObjectBase = function () {
130 	this._uid = SpiderGL.Core.generateUID();
131 };
132 
133 SpiderGL.Core.ObjectBase.prototype = {
134 	/**
135 	 * The object unique identifier.
136 	 *
137 	 * @type number
138 	 *
139 	 * @readonly
140 	 */
141 	get uid() {
142 		return this._uid;
143 	}
144 };
145