diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-22 02:34:20 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-22 02:34:20 +0000 |
commit | 986b1d4ee068ca1888a46bea7280017ee99feceb (patch) | |
tree | e0c897b88dc09831df39a07ed4de9ec000ab06af /o3d | |
parent | 1da35175c66788af1312547ec24d6e36234a0aa5 (diff) | |
download | chromium_src-986b1d4ee068ca1888a46bea7280017ee99feceb.zip chromium_src-986b1d4ee068ca1888a46bea7280017ee99feceb.tar.gz chromium_src-986b1d4ee068ca1888a46bea7280017ee99feceb.tar.bz2 |
Changed the semantics of many fields throughout the o3d-webgl
implementation to be backed by Params using
o3d.ParamObject.setUpO3DParam_. This change was needed to maintain the
semantics of the plugin, where fetching a parameter of a certain name
and setting it is equivalent to setting the field against the object.
This change mandated moving all of the assignments of the form
"constructor.prototype.fieldName = defaultValue" into the constructor
function itself, so that the setter created by setUpO3DParam will be
properly called for those assignments. For all files touched by this
CL, moved all default field assignments, not just those associated
with Param-backed fields.
Incorporated petersont's setup of the dx_clipping uniform introduced
in amarinichev's cg_to_glsl converter. Commented out bogus
modification of projection matrix in o3d.Param.SAS.setProjection and
added TODO to modify all handwritten shaders. Fixed bug in
o3d.Buffer.prototype.resize where it needed to coerce the argument to
an integer, a bug in the type determination for arrays in param.js,
and a couple of other bugs.
Changed cg_to_glsl script to use the expected case for the SAS
matrices in the o3d-webgl backend. Hopefully this change will not
break the GLES2 backend.
Ran all o3d-webgl samples. All work except for shadow-map.html
(affected by https://bugs.webkit.org/show_bug.cgi?id=37963 ) and
helloworld.html, which now does not report any errors but also does
not display any output yet.
BUG=none
TEST=ran o3d-webgl samples
TBR=petersont,amarinichev
Review URL: http://codereview.chromium.org/1751006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
24 files changed, 782 insertions, 672 deletions
diff --git a/o3d/cg_to_glsl/convert.py b/o3d/cg_to_glsl/convert.py index 2ec61912..5e746c6 100755 --- a/o3d/cg_to_glsl/convert.py +++ b/o3d/cg_to_glsl/convert.py @@ -37,6 +37,38 @@ ATTRIBUTES_TO_SEMANTICS = dict( attr11 = 'tangent1', attr12 = 'binormal1') +MATRIX_UNIFORM_NAMES = [ + 'world', + 'view', + 'projection', + 'worldView', + 'worldViewProjection', + 'worldInverse', + 'viewInverse', + 'projectionInverse', + 'worldViewInverse', + 'viewProjectionInverse', + 'worldViewProjectionInverse', + 'worldTranspose', + 'viewTranspose', + 'projectionTranspose', + 'worldViewTranspose', + 'viewProjectionTranspose', + 'worldViewProjectionTranspose', + 'worldInverseTranspose', + 'viewInverseTranspose', + 'projectionInverseTranspose', + 'worldViewInverseTranspose', + 'viewProjectionInverseTranspose', + 'worldViewProjectionInverseTranspose' +] + +def correct_semantic_case(name): + lower_name = name.lower() + for current_name in MATRIX_UNIFORM_NAMES: + if lower_name == current_name.lower(): + return current_name + return lower_name def get_input_mapping(header): ret = dict() @@ -48,7 +80,7 @@ def get_input_mapping(header): new_name = new_name[:new_name.index('[')] if new_name.startswith('$'): new_name = new_name[1:] - ret[new_name] = (semantic.lower() if semantic + ret[new_name] = (correct_semantic_case(semantic) if semantic else old_name_and_type.split(' ')[2]) return ret diff --git a/o3d/samples/o3d-webgl-samples/helloworld.html b/o3d/samples/o3d-webgl-samples/helloworld.html index 654e975..a02a481 100644 --- a/o3d/samples/o3d-webgl-samples/helloworld.html +++ b/o3d/samples/o3d-webgl-samples/helloworld.html @@ -168,7 +168,7 @@ function initStep2(clientElements) { This tutorial shows how we load and display a scene in O3D. <br/> <!-- Start of O3D plugin --> -<div id="o3d" style="width: 600px; height: 600px;"></div> +<div id="o3d" width="600" height="600"></div> <!-- End of O3D plugin --> </body> </html> diff --git a/o3d/samples/o3d-webgl/bounding_box.js b/o3d/samples/o3d-webgl/bounding_box.js index ec92270..3492868d 100644 --- a/o3d/samples/o3d-webgl/bounding_box.js +++ b/o3d/samples/o3d-webgl/bounding_box.js @@ -32,15 +32,21 @@ /** * Creates BoundingBox from minExtent and maxExtent - * @param {!o3d.math.Point3} minExtent minimum extent of the box. - * @param {!o3d.math.Point3} maxExtent maximum extent of the box. + * @param {!o3d.math.Point3} opt_minExtent optional minimum extent of the box. + * @param {!o3d.math.Point3} opt_maxExtent optional maximum extent of the box. * @constructor */ o3d.BoundingBox = - function(minExtent, maxExtent) { + function(opt_minExtent, opt_maxExtent) { o3d.ParamObject.call(this); - this.minExtent = [minExtent[0], minExtent[1], minExtent[2]]; - this.minExtent = [maxExtent[0], maxExtent[1], maxExtent[2]]; + if (!opt_minExtent) { + opt_minExtent = [0, 0, 0]; + } + if (!opt_maxExtent) { + opt_maxExtent = [0, 0, 0]; + } + this.minExtent = [opt_minExtent[0], opt_minExtent[1], opt_minExtent[2]]; + this.maxExtent = [opt_maxExtent[0], opt_maxExtent[1], opt_maxExtent[2]]; }; o3d.inherit('BoundingBox', 'ParamObject'); diff --git a/o3d/samples/o3d-webgl/buffer.js b/o3d/samples/o3d-webgl/buffer.js index 2417b0a..8ef19e3 100644 --- a/o3d/samples/o3d-webgl/buffer.js +++ b/o3d/samples/o3d-webgl/buffer.js @@ -93,7 +93,9 @@ o3d.Buffer.prototype.allocateElements = */ o3d.Buffer.prototype.resize = function(numElements) { this.gl_buffer_ = this.gl.createBuffer(); - this.array_ = new this.ArrayType(numElements); + // Callers (in particular the deserializer) occasionally call this + // with floating-point numbers. + this.array_ = new this.ArrayType(Math.floor(numElements)); }; /** diff --git a/o3d/samples/o3d-webgl/clear_buffer.js b/o3d/samples/o3d-webgl/clear_buffer.js index fbc116a..ba4d36a 100644 --- a/o3d/samples/o3d-webgl/clear_buffer.js +++ b/o3d/samples/o3d-webgl/clear_buffer.js @@ -38,62 +38,57 @@ */ o3d.ClearBuffer = function() { o3d.RenderNode.call(this); + /** + * The color to clear the buffer in RGBA Float4 format. + * @type {!o3d.Float4} + */ this.clearColor = [0, 0, 0, 1]; + + /** + * true clears the current render target's color buffer to the clear color. + * false does not clear the color buffer. + * @type {boolean} + */ + this.clearColorFlag = true; + + /** + * The value to clear the depth buffer (0.0 - 1.0) + * @type {number} + */ + this.clearDepth = 1; + + /** + * true clears the current render target's depth buffer to the clear depth + * value. false does not clear the depth buffer. + * @type {boolean} + */ + this.clearDepthFlag = true; + + /** + * The value to clear the stencil buffer to (0 - 255). + * @type {number} + */ + this.clearStencil = 0; + + /** + * true clears the current render target's stencil buffer to the clear stencil + * value. false does not clear the stencil buffer + * @type {boolean} + */ + this.clearStencilFlag = true; }; o3d.inherit('ClearBuffer', 'RenderNode'); - - -/** - * The color to clear the buffer in RGBA Float4 format. - * @type {!o3d.Float4} - */ -o3d.ClearBuffer.prototype.clearColor = [0, 0, 0, 1]; - - - -/** - * true clears the current render target's color buffer to the clear color. - * false does not clear the color buffer. - * @type {boolean} - */ -o3d.ClearBuffer.prototype.clearColorFlag = true; - - - -/** - * The value to clear the depth buffer (0.0 - 1.0) - * @type {number} - */ -o3d.ClearBuffer.prototype.clearDepth = 1; - - - -/** - * true clears the current render target's depth buffer to the clear depth - * value. false does not clear the depth buffer. - * @type {boolean} - */ -o3d.ClearBuffer.prototype.clearDepthFlag = true; - - - -/** - * The value to clear the stencil buffer to (0 - 255). - * @type {number} - */ -o3d.ClearBuffer.prototype.clearStencil = 0; - - - -/** - * true clears the current render target's stencil buffer to the clear stencil - * value. false does not clear the stencil buffer - * @type {boolean} - */ -o3d.ClearBuffer.prototype.clearStencilFlag = true; - - +o3d.ParamObject.setUpO3DParam_(o3d.ClearBuffer, 'clearColor', 'ParamFloat4'); +o3d.ParamObject.setUpO3DParam_(o3d.ClearBuffer, + 'clearColorFlag', 'ParamBoolean'); +o3d.ParamObject.setUpO3DParam_(o3d.ClearBuffer, 'clearDepth', 'ParamFloat'); +o3d.ParamObject.setUpO3DParam_(o3d.ClearBuffer, + 'clearDepthFlag', 'ParamBoolean'); +o3d.ParamObject.setUpO3DParam_(o3d.ClearBuffer, + 'clearStencil', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.ClearBuffer, + 'clearStencilFlag', 'ParamBoolean'); /** * Function called in the render graph traversal before the children are diff --git a/o3d/samples/o3d-webgl/draw_context.js b/o3d/samples/o3d-webgl/draw_context.js index bf360cb..bd40a25 100644 --- a/o3d/samples/o3d-webgl/draw_context.js +++ b/o3d/samples/o3d-webgl/draw_context.js @@ -42,30 +42,27 @@ * @constructor */ o3d.DrawContext = function(opt_view, opt_projection) { - o3d.NamedObject.call(this); + o3d.ParamObject.call(this); + + /** + * The view matrix represents the viewing transformation, used to + * take vertices from world space to view space. + * @type {o3d.Matrix4} + */ this.view = opt_view || [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]; + + /** + * The projection matrix represents the projection transformation, + * used to take vertices from view space to screen space. This + * matrix is usually an orthographic or perspective transformation. + * @type {o3d.Matrix4} + */ this.projection = opt_projection || [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]; }; -o3d.inherit('DrawContext', 'NamedObject'); - - -/** - * The view matrix represents the viewing transformation, used to take vertices - * from world space to view space. - * @type {o3d.Matrix4} - */ -o3d.DrawContext.prototype.view = []; - - - -/** - * The projection matrix represents the projection transformation, used to take - * vertices from view space to screen space. This matrix is usually an - * orthographic or perspective transformation. - * @type {o3d.Matrix4} - */ -o3d.DrawContext.prototype.projection = []; +o3d.inherit('DrawContext', 'ParamObject'); +o3d.ParamObject.setUpO3DParam_(o3d.DrawContext, 'view', 'ParamMatrix4'); +o3d.ParamObject.setUpO3DParam_(o3d.DrawContext, 'projection', 'ParamMatrix4'); diff --git a/o3d/samples/o3d-webgl/draw_element.js b/o3d/samples/o3d-webgl/draw_element.js index d4f802e..aa31d51 100644 --- a/o3d/samples/o3d-webgl/draw_element.js +++ b/o3d/samples/o3d-webgl/draw_element.js @@ -40,30 +40,27 @@ */ o3d.DrawElement = function(opt_material) { o3d.ParamObject.call(this); + + /** + * The Material for this DrawElement. If it is null the material of + * owner will be used. + * @type {o3d.Material} + */ this.material = opt_material || null; + + /** + * The current owner of this Draw Element. Set to null to stop being owned. + * + * Note: DrawElements are referenced by the Pack they are created in + * and their owner. If the DrawElement is removed from its Pack then + * setting the owner to null will free the DrawElement. Or, visa + * versa, if you set the DrawElement's owner to null then removing + * it from its Pack will free the DrawElement. + * @type {o3d.Element} + */ + this.owner_ = null; }; o3d.inherit('DrawElement', 'ParamObject'); - -/** - * The Material for this DrawElement. If it is null the material of owner will - * be used. - * @type {o3d.Material} - */ -o3d.DrawElement.prototype.material = null; - - - -/** - * The current owner of this Draw Element. Set to null to stop being owned. - * - * Note: DrawElements are referenced by the Pack they are created in and their - * owner. If the DrawElement is removed from its Pack then setting the owner - * to null will free the DrawElement. Or, visa versa, if you set the - * DrawElement's owner to null then removing it from its Pack will free the - * DrawElement. - * @type {o3d.Element} - */ -o3d.DrawElement.prototype.owner_ = null; - +o3d.ParamObject.setUpO3DParam_(o3d.DrawElement, 'material', 'ParamMaterial'); diff --git a/o3d/samples/o3d-webgl/draw_list.js b/o3d/samples/o3d-webgl/draw_list.js index 3a39671..46ea458 100644 --- a/o3d/samples/o3d-webgl/draw_list.js +++ b/o3d/samples/o3d-webgl/draw_list.js @@ -98,7 +98,7 @@ o3d.DrawList.prototype.render = function() { o3d.Param.SAS ]; - material.effect.searchForParams_(paramObjects); + effect.searchForParams_(paramObjects); element.render(); } }; diff --git a/o3d/samples/o3d-webgl/draw_pass.js b/o3d/samples/o3d-webgl/draw_pass.js index 495e357..600f641 100644 --- a/o3d/samples/o3d-webgl/draw_pass.js +++ b/o3d/samples/o3d-webgl/draw_pass.js @@ -40,31 +40,29 @@ */ o3d.DrawPass = function(opt_drawList, opt_sortMethod) { o3d.RenderNode.call(this); - this.drawList = opt_drawList; + + /** + * The DrawList for this DrawPass. + * @type {o3d.DrawList} + */ + this.drawList = opt_drawList || null; + + /** + * The sort method for this DrawPass to draw the DrawList by. + * Default = BY_PERFORMANCE. + * @type {o3d.DrawList.SortMethod} + */ this.sortMethod = opt_sortMethod || o3d.DrawList.BY_PERFORMANCE; }; o3d.inherit('DrawPass', 'RenderNode'); - -/** - * The DrawList for this DrawPass. - * @type {o3d.DrawList} - */ -o3d.DrawPass.prototype.drawList = null; - - /** * @type {number} */ o3d.DrawPass.SortMethod = goog.typedef; - -/** - * The sort method for this DrawPass to draw the DrawList by. - * Default = BY_PERFORMANCE. - * @type {o3d.DrawList.SortMethod} - */ -o3d.DrawPass.prototype.sortMethod = o3d.DrawList.BY_PERFORMANCE; +o3d.ParamObject.setUpO3DParam_(o3d.DrawPass, 'drawList', 'ParamDrawList'); +o3d.ParamObject.setUpO3DParam_(o3d.DrawPass, 'sortMethod', 'ParamInteger'); /** * Called in rendergraph traversal before children are rendered. diff --git a/o3d/samples/o3d-webgl/effect.js b/o3d/samples/o3d-webgl/effect.js index b033a1c..50d02cf 100644 --- a/o3d/samples/o3d-webgl/effect.js +++ b/o3d/samples/o3d-webgl/effect.js @@ -129,6 +129,8 @@ o3d.Effect = function() { }; o3d.inherit('Effect', 'ParamObject'); +o3d.Effect.HELPER_CONSTANT_NAME = 'dx_clipping'; + /** * An object mapping the names of uniform variables to objects containing @@ -477,6 +479,10 @@ o3d.Effect.prototype.searchForParams_ = function(object_list) { } } + this.updateHelperConstants_(this.gl.displayInfo.width, + this.gl.displayInfo.height); + filled_map[o3d.Effect.HELPER_CONSTANT_NAME] = true; + for (name in this.uniforms_) { if (!filled_map[name]) { throw ('Uniform param not filled: '+name); @@ -486,6 +492,33 @@ o3d.Effect.prototype.searchForParams_ = function(object_list) { /** + * Updates certain parameters used to make the GLSL shaders have the + * same clipping semantics as D3D's. + * @param {number} width width of the viewport in pixels + * @param {number} height height of the viewport in pixels + * @private + */ +o3d.Effect.prototype.updateHelperConstants_ = function(width, height) { + var uniformInfo = this.uniforms_[o3d.Effect.HELPER_CONSTANT_NAME]; + var dx_clipping = [ 0.0, 0.0, 0.0, 0.0 ]; + if (uniformInfo) { + // currentRenderSurfaceSet is set in render_surface_set.js. + dx_clipping[0] = 1.0 / width; + dx_clipping[1] = -1.0 / height; + dx_clipping[2] = 2.0; + if (this.gl.currentRenderSurfaceSet) { + dx_clipping[3] = -1.0; + } else { + dx_clipping[3] = 1.0; + } + + this.gl.uniform4f(uniformInfo.location, + dx_clipping[0], dx_clipping[1], + dx_clipping[2], dx_clipping[3]); + } +}; + +/** * @type {number} */ o3d.Effect.MatrixLoadOrder = goog.typedef; diff --git a/o3d/samples/o3d-webgl/element.js b/o3d/samples/o3d-webgl/element.js index e42a788..92558b4 100644 --- a/o3d/samples/o3d-webgl/element.js +++ b/o3d/samples/o3d-webgl/element.js @@ -46,76 +46,87 @@ o3d.Element = function(opt_material, opt_boundingBox, opt_zSortPoint, opt_cull) { o3d.ParamObject.call(this); + + /** + * The Material for this element. + * @type {o3d.Material} + */ this.material = opt_material; + + /** + * The BoundingBox for this element. If culling is on this bounding + * box will be tested against the view frustum of any draw context + * used to render this Element. + * @type {o3d.BoundingBox} + */ this.boundingBox = opt_boundingBox || new o3d.BoundingBox([-1, -1, -1], [1, 1, 1]); + + /** + * The z sort point for this element. If this Element is drawn by a DrawPass + * that is set to sort by z order this value will be multiplied by the + * worldViewProjection matrix to compute a z value to sort by. + * @type {o3d.Point3} + */ this.zSortPoint = opt_zSortPoint || [0, 0, 0]; + + /** + * The priority for this element. Used to sort if this Element is drawn by a + * DrawPass that is set to sort by priority. + * @type {number} + */ + this.priority = 0; + + /** + * The cull settings for this element. If true this Element will be + * culled by the bounding box above compared to the view frustum it + * is being rendered with. + * + * @type {boolean} + */ this.cull = opt_cull || false; + + /** + * The current owner of this Draw Element. Pass in null to stop + * being owned. + * + * Note: Elements are referenced by the Pack they are created in and + * their owner. If the Element is removed from its Pack, then + * setting the owner to null will free the Element. Or, visa versa, + * if you set the Element's owner to null then removing it from its + * Pack will free the Element. + * + * @type {o3d.Element} + */ + this.owner_ = null; + + /** + * Gets all the DrawElements under this Element. + * + * Each access to this field gets the entire list so it is best to get it + * just once. For example: + * + * var drawElements = element.drawElements; + * for (var i = 0; i < drawElements.length; i++) { + * var drawElement = drawElements[i]; + * } + * + * + * Note that modifications to this array [e.g. push()] will not affect + * the underlying Element, while modifications to the members of the array. + * will affect them. + * + * @type {!Array.<!o3d.DrawElement>} + */ this.drawElements = []; }; o3d.inherit('Element', 'ParamObject'); - -/** - * The Material for this element. - * @type {o3d.Material} - */ -o3d.Element.prototype.material = null; - - - -/** - * The BoundingBox for this element. If culling is on this bounding box will be - * tested against the view frustum of any draw context used to render this - * Element. - * @type {o3d.BoundingBox} - */ -o3d.Element.prototype.boundingBox = null; - - - -/** - * The z sort point for this element. If this Element is drawn by a DrawPass - * that is set to sort by z order this value will be multiplied by the - * worldViewProjection matrix to compute a z value to sort by. - * @type {o3d.Point3} - */ -o3d.Element.prototype.zSortPoint = [0, 0, 0]; - - - -/** - * The priority for this element. Used to sort if this Element is drawn by a - * DrawPass that is set to sort by priority. - * @type {number} - */ -o3d.Element.prototype.priority = 0; - - - -/** - * The cull settings for this element. If true this Element will be culled - * by the bounding box above compared to the view frustum it is being rendered - * with. - * - * @type {boolean} - */ -o3d.Element.prototype.cull = false; - - - -/** - * The current owner of this Draw Element. Pass in null to stop being owned. - * - * Note: Elements are referenced by the Pack they are created in and their - * owner. If the Element is removed from its Pack, then setting the owner - * to null will free the Element. Or, visa versa, if you set the - * Element's owner to null then removing it from its Pack will free the - * Element. - * - * @type {o3d.Element} - */ -o3d.Element.prototype.owner_ = null; +o3d.ParamObject.setUpO3DParam_(o3d.Element, 'material', 'ParamMaterial'); +o3d.ParamObject.setUpO3DParam_(o3d.Element, 'boundingBox', 'ParamBoundingBox'); +o3d.ParamObject.setUpO3DParam_(o3d.Element, 'zSortPoint', 'ParamFloat3'); +o3d.ParamObject.setUpO3DParam_(o3d.Element, 'priority', 'ParamFloat'); +o3d.ParamObject.setUpO3DParam_(o3d.Element, 'cull', 'ParamBoolean'); o3d.Element.prototype.__defineSetter__('owner', function(o) { @@ -125,35 +136,11 @@ o3d.Element.prototype.__defineSetter__('owner', ); o3d.Element.prototype.__defineGetter__('owner', - function(o) { + function() { return this.owner_; } ); - - -/** - * Gets all the DrawElements under this Element. - * - * Each access to this field gets the entire list so it is best to get it - * just once. For example: - * - * var drawElements = element.drawElements; - * for (var i = 0; i < drawElements.length; i++) { - * var drawElement = drawElements[i]; - * } - * - * - * Note that modifications to this array [e.g. push()] will not affect - * the underlying Element, while modifications to the members of the array. - * will affect them. - * - * @type {!Array.<!o3d.DrawElement>} - */ -o3d.Element.prototype.drawElements = []; - - - /** * Creates a DrawElement for this Element. Note that unlike * Shape.createDrawElements and Transform.createDrawElements this one will diff --git a/o3d/samples/o3d-webgl/material.js b/o3d/samples/o3d-webgl/material.js index a7d6d3f..7dd1c8c 100644 --- a/o3d/samples/o3d-webgl/material.js +++ b/o3d/samples/o3d-webgl/material.js @@ -44,34 +44,27 @@ */ o3d.Material = function(opt_state, opt_effect, opt_draw_list) { o3d.ParamObject.call(this); - this.state = opt_state; - this.effect = opt_effect; - this.drawList = opt_draw_list; -}; -o3d.inherit('Material', 'ParamObject'); - + /** + * The State for this material. + * @type {o3d.State} + */ + this.state = opt_state || null; -/** - * The Effect for this material. - * @type {o3d.Effect} - */ -o3d.Material.prototype.effect = null; - - - -/** - * The State for this material. - * @type {o3d.State} - */ -o3d.Material.prototype.state = null; - - - -/** - * The DrawList this material will render on. - * @type {o3d.DrawList} - */ -o3d.Material.prototype.drawList = null; + /** + * The Effect for this material. + * @type {o3d.Effect} + */ + this.effect = opt_effect || null; + /** + * The DrawList this material will render on. + * @type {o3d.DrawList} + */ + this.drawList = opt_draw_list || null; +}; +o3d.inherit('Material', 'ParamObject'); +o3d.ParamObject.setUpO3DParam_(o3d.Material, 'effect', 'ParamEffect'); +o3d.ParamObject.setUpO3DParam_(o3d.Material, 'state', 'ParamState'); +o3d.ParamObject.setUpO3DParam_(o3d.Material, 'drawList', 'ParamDrawList'); diff --git a/o3d/samples/o3d-webgl/param.js b/o3d/samples/o3d-webgl/param.js index 3c0feee..a32d004 100644 --- a/o3d/samples/o3d-webgl/param.js +++ b/o3d/samples/o3d-webgl/param.js @@ -90,8 +90,8 @@ o3d.Param.prototype.__defineSetter__('value', } else { if (this.value_ != undefined && ( typeof this.value_ != typeof v || - (typeof this.value_ == 'Array' && v == 'Array' && - this.value_.length_ != v.length))) { + (this.value_.length_ !== undefined && + (this.value_.length_ != v.length)))) { this.gl.client.error_callback('Param type error.'); } this.value_ = v; @@ -181,6 +181,46 @@ o3d.ParamBoundingBox = function() { }; o3d.inherit('ParamBoundingBox', 'Param'); +// ParamBoundingBox requires a specialized setter because it must +// accept arrays of arrays and convert them into BoundingBoxes. It +// seems that if we define a setter against this prototype we must +// also define a getter -- it is not inherited. +o3d.ParamBoundingBox.prototype.__defineSetter__('value', + function(v) { + if (this.inputConnection) { + throw ('Tried to set bound parameter.'); + } else { + if (!v) { + v = new o3d.BoundingBox(); + } else if (v.length !== undefined) { + if (v.length == 0) { + v = new o3d.BoundingBox(); + } else if (v.length == 2) { + for (var ii = 0; ii < 2; ++ii) { + if (v[ii].length != 3) { + throw ('Expected sub-array of length 3 at index ' + ii + + ', got ' + v[ii].length); + } + } + v = new o3d.BoundingBox(v[0], v[1]); + } else { + throw 'Expected array of length 2'; + } + } + this.value_ = v; + } + } +); + +o3d.ParamBoundingBox.prototype.__defineGetter__('value', + function() { + if (this.inputConnection) { + return this.inputConnection.value; + } else { + return this.value_; + } + } +); /** * @constructor @@ -365,6 +405,16 @@ o3d.inherit('ParamState', 'Param'); /** * @constructor */ +o3d.ParamStreamBank = function() { + o3d.Param.call(this); + this.value = null; +}; +o3d.inherit('ParamStreamBank', 'Param'); + + +/** + * @constructor + */ o3d.ParamString = function() { o3d.Param.call(this); this.value = null; @@ -862,10 +912,15 @@ o3d.Param.SAS.setView = function(view) { * SAS parameters. */ o3d.Param.SAS.setProjection = function(projection) { + // TODO(petersont): this wasn't being used. Need to adjust all of + // the handwritten GLSL shaders to incorporate the modification of + // gl_Position based on dx_clipping. + /* var adjustedProjection = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 2, 0], [0, 0, -1, 1]]; o3d.Transform.compose( adjustedProjection, projection, adjustedProjection); + */ this['projection'] = projection; }; diff --git a/o3d/samples/o3d-webgl/param_object.js b/o3d/samples/o3d-webgl/param_object.js index f59f674..27b567e 100644 --- a/o3d/samples/o3d-webgl/param_object.js +++ b/o3d/samples/o3d-webgl/param_object.js @@ -41,6 +41,7 @@ o3d.ParamObject = function() { }; o3d.inherit('ParamObject', 'NamedObject'); +o3d.ParamObject.O3D_PREFIX_ = 'o3d.'; /** * Creates a Param with the given name and type on the ParamObject. @@ -121,7 +122,32 @@ o3d.ParamObject.prototype.createParam = */ o3d.ParamObject.prototype.getParam = function(param_name) { - return this.filterResult_(this.params_[param_name]); + var result = this.params_[param_name]; + var o3d_name; + if (!result) { + // Try again with O3D prefix. + o3d_name = o3d.ParamObject.O3D_PREFIX_ + param_name; + result = this.params_[o3d_name]; + } + + if (!result) { + // See if it's one of the params which needs to be created lazily. + // If it is, initialize it with the current value in the object. + var lazyParamMap = this.lazyParamMap_; + if (lazyParamMap) { + var name = param_name; + var param_type = this.lazyParamMap_[name]; + if (!param_type) { + name = o3d_name; + param_type = this.lazyParamMap_[name]; + } + if (param_type) { + result = this.createParam(name, param_type); + } + } + } + + return this.filterResult_(result); }; @@ -170,6 +196,7 @@ o3d.ParamObject.prototype.copyParams = o3d.notImplemented(); }; + /** * Filters results, turning 'undefined' into 'null'. * @private @@ -177,3 +204,38 @@ o3d.ParamObject.prototype.copyParams = o3d.ParamObject.prototype.filterResult_= function(result) { return (result ? result : null); }; + + +/** + * Sets up an o3d-scoped parameter against the given constructor + * function of the given type for the given field. + * @private + */ +o3d.ParamObject.setUpO3DParam_ = function(constructor, + fieldName, + paramType) { + var o3dParamName = o3d.ParamObject.O3D_PREFIX_ + fieldName; + + // The lazyParamMap primarily handles the case where getParam is + // called before the getter or setter below. It also simplifies the + // code below since it can simply call getParam and the param will + // be created on demand. + var lazyParamMap = constructor.prototype.lazyParamMap_; + if (!lazyParamMap) { + lazyParamMap = {}; + constructor.prototype.lazyParamMap_ = lazyParamMap; + } + lazyParamMap[o3dParamName] = paramType; + + constructor.prototype.__defineGetter__(fieldName, + function() { + var param = this.getParam(o3dParamName); + return param.value; + }); + constructor.prototype.__defineSetter__(fieldName, + function(v) { + var param = this.getParam(o3dParamName); + param.value = v; + }); +}; + diff --git a/o3d/samples/o3d-webgl/primitive.js b/o3d/samples/o3d-webgl/primitive.js index 7a757af..5d60f4b 100644 --- a/o3d/samples/o3d-webgl/primitive.js +++ b/o3d/samples/o3d-webgl/primitive.js @@ -40,7 +40,49 @@ */ o3d.Primitive = function(opt_streamBank) { o3d.Element.call(this); - this.streamBank = opt_streamBank; + /** + * The stream bank this primitive uses for vertices. + * @type {o3d.StreamBank} + */ + this.streamBank = opt_streamBank || null; + + /** + * The type of primitive the primitive is (i.e., POINTLIST, LINELIST, + * TRIANGLELIST, etc.) + * + * @type {o3d.Primitive.Type} + */ + this.primitiveType = o3d.Primitive.TRIANGLELIST; + + /** + * The number of vertices the primitive has. + * + * @type {number} + */ + this.numberVertices = 0; + + /** + * The number of rendering primitives (i.e., triangles, points, lines) the + * primitive has. + * + * @type {number} + */ + this.numberPrimitives = 0; + + /** + * The index of the first vertex to render. + * Default = 0. + * + * @type {number} + */ + this.startIndex = 0; + + /** + * The index buffer for the primitive. If null the primitive is non-indexed. + * @type {o3d.IndexBuffer} + */ + this.indexBuffer = null; + }; o3d.inherit('Primitive', 'Element'); @@ -60,62 +102,7 @@ o3d.Primitive.TRIANGLELIST = 4; o3d.Primitive.TRIANGLESTRIP = 5; o3d.Primitive.TRIANGLEFAN = 6; - - -/** - * The type of primitive the primitive is (i.e., POINTLIST, LINELIST, - * TRIANGLELIST, etc.) - * - * @type {o3d.Primitive.Type} - */ -o3d.Primitive.prototype.primitiveType = o3d.Primitive.TRIANGLELIST; - - - -/** - * The number of vertices the primitive has. - * - * @type {number} - */ -o3d.Primitive.prototype.numberVertices = 0; - - - -/** - * The number of rendering primitives (i.e., triangles, points, lines) the - * primitive has. - * - * @type {number} - */ -o3d.Primitive.prototype.numberPrimitives = 0; - - - -/** - * The index of the first vertex to render. - * Default = 0. - * - * @type {number} - */ -o3d.Primitive.prototype.startIndex = 0; - - - -/** - * The stream bank this primitive uses for vertices. - * @type {o3d.StreamBank} - */ -o3d.Primitive.prototype.streamBank = null; - - - -/** - * The index buffer for the primitive. If null the primitive is non-indexed. - * @type {number} - */ -o3d.Primitive.prototype.indexBuffer = null; - - +o3d.ParamObject.setUpO3DParam_(o3d.Primitive, 'streamBank', 'ParamStreamBank'); /** * Binds the vertex and index streams required to draw the shape. diff --git a/o3d/samples/o3d-webgl/render_node.js b/o3d/samples/o3d-webgl/render_node.js index 6bbbf36..0c2dc53 100644 --- a/o3d/samples/o3d-webgl/render_node.js +++ b/o3d/samples/o3d-webgl/render_node.js @@ -42,39 +42,55 @@ */ o3d.RenderNode = function(opt_priority, opt_active) { o3d.ParamObject.call(this); + + /** + * Sets the priority of this render node. lower priorities are + * rendered first. + * + * @type {number} + */ this.priority = opt_priority || 0; + + /** + * The immediate children of this RenderNode. + * + * Each access to this field gets the entire list so it is best to get it + * just once. For example: + * + * var children = renderNode.children; + * for (var i = 0; i < children.length; i++) { + * var child = children[i]; + * } + * + * Note that modifications to this array [e.g. push()] will not affect + * the underlying RenderNode, while modifications to the array's members + * will affect them. + * + * @type {!Array.<o3d.RenderNode>} + */ this.children = []; + + /** + * Setting false skips this render node. Setting true processes this render + * node. (ie, renders whatever it's supposed to render) + * + * @type {boolean} + */ + this.active = opt_active || true; + + /** + * Sets the parent of the node by re-parenting the node under parent_node. + * Setting parent_node to null removes the node and the entire subtree below + * it from the render graph. + * + * @type {o3d.RenderNode} + */ + this.parent = null; }; o3d.inherit('RenderNode','ParamObject'); - -/** - * Sets the priority of this render node. lower priorities are rendered first. - * - * @type {number} - */ -o3d.RenderNode.prototype.priority = 0; - - - -/** - * Setting false skips this render node. Setting true processes this render - * node. (ie, renders whatever it's supposed to render) - * - * @type {boolean} - */ -o3d.RenderNode.prototype.active = true; - - - -/** - * Sets the parent of the node by re-parenting the node under parent_node. - * Setting parent_node to null removes the node and the entire subtree below - * it from the render graph. - * - * @type {o3d.RenderNode} - */ -o3d.RenderNode.prototype.parent = null; +o3d.ParamObject.setUpO3DParam_(o3d.RenderNode, 'priority', 'ParamFloat'); +o3d.ParamObject.setUpO3DParam_(o3d.RenderNode, 'active', 'ParamBoolean'); o3d.RenderNode.prototype.__defineSetter__('parent', function(p) { @@ -116,27 +132,6 @@ o3d.RenderNode.prototype.removeChild = function(child) { /** - * The immediate children of this RenderNode. - * - * Each access to this field gets the entire list so it is best to get it - * just once. For example: - * - * var children = renderNode.children; - * for (var i = 0; i < children.length; i++) { - * var child = children[i]; - * } - * - * Note that modifications to this array [e.g. push()] will not affect - * the underlying RenderNode, while modifications to the array's members - * will affect them. - * - * @type {!Array.<o3d.RenderNode>} - */ -o3d.RenderNode.prototype.children = []; - - - -/** * Returns this render node and all its descendants. Note that this render node * might not be in the render graph. * diff --git a/o3d/samples/o3d-webgl/render_surface.js b/o3d/samples/o3d-webgl/render_surface.js index 8012bea..8ace573 100644 --- a/o3d/samples/o3d-webgl/render_surface.js +++ b/o3d/samples/o3d-webgl/render_surface.js @@ -41,27 +41,42 @@ */ o3d.RenderSurfaceBase = function(width, height, texture) { o3d.ParamObject.call(this); - this.width = width; - this.height = height; - this.texture = texture; -}; -o3d.inherit('RenderSurfaceBase', 'ParamObject'); - - -/** - * The width of the surface, in pixels. - * @type {number} - */ -o3d.RenderSurfaceBase.prototype.width = 0; - + /** + * The width of the surface, in pixels. + * @type {number} + */ + this.width = width || 0; + + /** + * The height of the surface, in pixels. + * @type {number} + */ + this.height = height || 0; + + /** + * The texture in which this surface is contained. + */ + this.texture = texture || null; + + /** + * The mip level targeted by this render surface. + * @type {number} + */ + this.level = 0; + + /** + * The underlying GL framebuffer object. + * @type {WebGLFramebuffer} + * @private + */ + this.framebuffer_ = null; -/** - * The height of the surface, in pixels. - * @type {number} - */ -o3d.RenderSurfaceBase.prototype.height = 0; +}; +o3d.inherit('RenderSurfaceBase', 'ParamObject'); +o3d.ParamObject.setUpO3DParam_(o3d.RenderSurfaceBase, 'width', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.RenderSurfaceBase, 'height', 'ParamInteger'); /** * A RenderSurface encapsulates the notion of a renderable surface. @@ -78,26 +93,6 @@ o3d.inherit('RenderSurface', 'RenderSurfaceBase'); /** - * The texture in which this surface is contained. - */ -o3d.RenderSurface.prototype.texture = null; - - -/** - * The mip level targeted by this render surface. - * @type {number} - */ -o3d.RenderSurface.level = 0; - - -/** - * The underlying GL framebuffer object. - * @type {WebGLFramebuffer} - * @private - */ -o3d.RenderSurfaceBase.prototype.framebuffer_ = null; - -/** * Initializes a render surface to render to the given texture. * @param {o3d.Texture2D} texture The texture. */ @@ -115,19 +110,18 @@ o3d.RenderSurface.prototype.initWithTexture = function(texture, level) { */ o3d.RenderDepthStencilSurface = function() { o3d.RenderSurfaceBase.call(this); + + /** + * The GL renderbuffer object for the depth / stencil buffer. + * @type {WebGLRenderbuffer} + * @private + */ + this.depth_stencil_buffer_ = null; }; o3d.inherit('RenderDepthStencilSurface', 'RenderSurfaceBase'); /** - * The GL renderbuffer object for the depth buffer. - * @type {WebGLRenderbuffer} - * @private - */ -o3d.RenderDepthStencilSurface.prototype.depth_stencil_buffer_ = null; - - -/** * Allocates depth and stnecil buffers of the given size. * @param {number} width * @param {number} height diff --git a/o3d/samples/o3d-webgl/render_surface_set.js b/o3d/samples/o3d-webgl/render_surface_set.js index 61692a5a..9484e9c 100644 --- a/o3d/samples/o3d-webgl/render_surface_set.js +++ b/o3d/samples/o3d-webgl/render_surface_set.js @@ -48,28 +48,30 @@ o3d.RenderSurfaceSet = function(opt_renderSurface, opt_renderDepthStencilSurface) { o3d.RenderNode.call(this); - o3d.RenderSurfaceSet.prototype.renderSurface = - opt_renderSurface; - o3d.RenderSurfaceSet.prototype.renderDepthStencilSurface = - opt_renderDepthStencilSurface; -}; -o3d.inherit('RenderSurfaceSet', 'RenderNode'); + /** + * The render surface to which the color contents of all RenderNode children + * should be drawn. + * @type {o3d.RenderSurface} + */ + this.renderSurface = opt_renderSurface || null; -/** - * The render surface to which the color contents of all RenderNode children - * should be drawn. - * @type {o3d.RenderSurface} - */ -o3d.RenderSurfaceSet.prototype.renderSurface = null; + /** + * The render depth stencil surface to which the depth contents of all + * RenderNode children should be drawn. + * @type {o3d.RenderDepthStencilSurface} + */ + this.renderDepthStencilSurface = opt_renderDepthStencilSurface || null; +}; +o3d.inherit('RenderSurfaceSet', 'RenderNode'); -/** - * The render depth stencil surface to which the depth contents of all - * RenderNode children should be drawn. - * @type {o3d.RenderDepthStencilSurface} - */ -o3d.RenderSurfaceSet.prototype.renderDepthStencilSurface = null; + +o3d.ParamObject.setUpO3DParam_(o3d.RenderSurfaceSet, + 'renderSurface', 'ParamRenderSurface'); +o3d.ParamObject.setUpO3DParam_(o3d.RenderSurfaceSet, + 'renderDepthStencilSurface', + 'ParamRenderDepthStencilSurface'); /** * Helper function to set the framebuffer back to the default one. @@ -147,8 +149,10 @@ o3d.RenderSurfaceSet.prototype.before = function() { this.installFramebufferObjects_(); this.previousHeight = this.gl.displayInfo.height; this.previousWidth = this.gl.displayInfo.width; + this.previousRenderSurfaceSet = this.gl.currentRenderSurfaceSet; this.gl.displayInfo.height = this.renderSurface.height; this.gl.displayInfo.width = this.renderSurface.width; + this.gl.currentRenderSurfaceSet = this; }; @@ -160,6 +164,8 @@ o3d.RenderSurfaceSet.prototype.after = function() { this.clearFramebufferObjects_(); this.gl.displayInfo.height = this.previousHeight; this.gl.displayInfo.width = this.previousWidth; + // This is consumed in effect.js. + this.gl.currentRenderSurfaceSet = this.previousRenderSurfaceSet; }; diff --git a/o3d/samples/o3d-webgl/sampler.js b/o3d/samples/o3d-webgl/sampler.js index 1748d83..f126385 100644 --- a/o3d/samples/o3d-webgl/sampler.js +++ b/o3d/samples/o3d-webgl/sampler.js @@ -48,7 +48,64 @@ */ o3d.Sampler = function() { o3d.ParamObject.call(this); + + /** + * The texture address mode for the u coordinate. + * @type {!o3d.Sampler.AddressMode} + */ + this.addressModeU = o3d.Sampler.WRAP; + + /** + * The texture address mode for the v coordinate. + * @type {!o3d.Sampler.AddressMode} + */ + this.addressModeV = o3d.Sampler.WRAP; + + /** + * The texture address mode for the w coordinate. + * @type {!o3d.Sampler.AddressMode} + */ + this.addressModeW = o3d.Sampler.WRAP; + + /** + * The magnification filter. Valid values for the mag filter are: + * POINT and LINEAR. Default = LINEAR. + * @type {!o3d.Sampler.FilterType} + */ + this.magFilter = o3d.Sampler.LINEAR; + + /** + * The minification filter. Valid values for the min filter are: + * POINT, LINEAR and ANISOTROPIC. Default = LINEAR. + * @type {!o3d.Sampler.FilterType} + */ + this.minFilter = o3d.Sampler.LINEAR; + + /** + * The mipmap filter used during minification. Valid values for the + * mip filter are: NONE, POINT and LINEAR. Default = LINEAR. + * @type {!o3d.Sampler.FilterType} + */ + this.mipFilter = o3d.Sampler.LINEAR; + + /** + * Color returned for texture coordinates outside the [0,1] range when the + * address mode is set to BORDER. + * @type {!Array.<number>} + */ this.borderColor = [0, 0, 0, 0]; + + /** + * Degree of anisotropy used when the ANISOTROPIC filter type is used. + * @type {number} + */ + this.maxAnisotropy = 1; + + /** + * The Texture object used by this Sampler. + * @type {o3d.Texture} + */ + this.texture = null; }; o3d.inherit('Sampler', 'ParamObject'); @@ -93,78 +150,13 @@ o3d.Sampler.LINEAR = 2; o3d.Sampler.ANISOTROPIC = 3; -/** - * The texture address mode for the u coordinate. - * @type {!o3d.Sampler.AddressMode} - */ -o3d.Sampler.prototype.addressModeU = o3d.Sampler.WRAP; - - - -/** - * The texture address mode for the v coordinate. - * @type {!o3d.Sampler.AddressMode} - */ -o3d.Sampler.prototype.addressModeV = o3d.Sampler.WRAP; - - - -/** - * The texture address mode for the w coordinate. - * @type {!o3d.Sampler.AddressMode} - */ -o3d.Sampler.prototype.addressModeW = o3d.Sampler.WRAP; - - - -/** - * The magnification filter. Valid values for the mag filter are: POINT and - * @type {!o3d.Sampler.FilterType} - */ -o3d.Sampler.prototype.magFilter = o3d.Sampler.LINEAR; - - - -/** - * The minification filter. Valid values for the min filter are: POINT, LINEAR - * and ANISOTROPIC. - * @type {!o3d.Sampler.FilterType} - */ -o3d.Sampler.prototype.minFilter = o3d.Sampler.LINEAR; - - - -/** - * The mipmap filter used during minification. Valid values for the mip filter - * are: NONE, POINT and LINEAR. - * @type {!o3d.Sampler.FilterType} - */ -o3d.Sampler.prototype.mipFilter = o3d.Sampler.LINEAR; - - - -/** - * Color returned for texture coordinates outside the [0,1] range when the - * address mode is set to BORDER. - * @type {!Array.<number>} - */ -o3d.Sampler.prototype.borderColor = [0, 0, 0, 0]; - - - -/** - * Degree of anisotropy used when the ANISOTROPIC filter type is used. - * @type {number} - */ -o3d.Sampler.prototype.maxAnisotropy = 1; - - - -/** - * The Texture object used by this Sampler. - * @type {o3d.Texture} - */ -o3d.Sampler.prototype.texture = null; - - +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'addressModeU', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'addressModeV', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'addressModeW', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'magFilter', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'minFilter', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'mipFilter', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'borderColor', 'ParamFloat4'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'maxAnisotropy', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Sampler, 'texture', 'ParamTexture'); diff --git a/o3d/samples/o3d-webgl/state_set.js b/o3d/samples/o3d-webgl/state_set.js index 054b5a8..e421622 100644 --- a/o3d/samples/o3d-webgl/state_set.js +++ b/o3d/samples/o3d-webgl/state_set.js @@ -40,16 +40,16 @@ */ o3d.StateSet = function(opt_state) { o3d.RenderNode.call(this); + + /** + * The State for this StateSet. + * @type {o3d.State} + */ this.state = opt_state || null; }; o3d.inherit('StateSet', 'RenderNode'); - -/** - * The State for this StateSet. - */ -o3d.StateSet.prototype.state = null; - +o3d.ParamObject.setUpO3DParam_(o3d.StateSet, 'state', 'ParamState'); /** * Sets the current state to the member state. @@ -59,4 +59,3 @@ o3d.StateSet.prototype.before = function() { this.state.set(); }; - diff --git a/o3d/samples/o3d-webgl/texture.js b/o3d/samples/o3d-webgl/texture.js index ce78349..53214d0 100644 --- a/o3d/samples/o3d-webgl/texture.js +++ b/o3d/samples/o3d-webgl/texture.js @@ -36,6 +36,33 @@ */ o3d.Texture = function() { o3d.ParamObject.call(this); + + /** + * The memory format used for storing the bitmap associated with the texture + * object. + * @type {o3d.Texture.Format} + */ + this.format = o3d.Texture.UNKNOWN_FORMAT; + + /** + * The number of mipmap levels used by the texture. + * @type {number} + */ + this.levels = 1; + + /** + * True if all the alpha values in the texture are 1.0 + * @type {boolean} + */ + this.alphaIsOne = true; + + /** + * The the associated gl texture. + * @type {WebGLTexture} + * @private + */ + this.texture_ = null; + }; o3d.inherit('Texture', 'ParamObject'); @@ -93,39 +120,6 @@ o3d.Texture.DXT3 = 7; o3d.Texture.DXT5 = 8; - -/** - * The memory format used for storing the bitmap associated with the texture - * object. - * @type {o3d.Texture.Format} - */ -o3d.Texture.prototype.format = o3d.Texture.UNKNOWN_FORMAT; - - - -/** - * The number of mipmap levels used by the texture. - * @type {number} - */ -o3d.Texture.prototype.levels = 1; - - - -/** - * True if all the alpha values in the texture are 1.0 - * @type {boolean} - */ -o3d.Texture.prototype.alphaIsOne = true; - - -/** - * The the associated gl texture. - * @type {WebGLTexture} - * @private - */ -o3d.Texture.prototype.texture_ = null; - - /** * Generates Mips. * @param {number} source_level the mip to use as the source. @@ -148,7 +142,17 @@ o3d.Texture.prototype.generateMips = */ o3d.Texture2D = function(opt_width, opt_height) { o3d.Texture.call(this); + + /** + * The width of the texture, in texels. + * @type {number} + */ this.width = opt_width || 0; + + /** + * The height of the texture, in texels. + * @type {number} + */ this.height = opt_height || 0; /** @@ -159,21 +163,8 @@ o3d.Texture2D = function(opt_width, opt_height) { }; o3d.inherit('Texture2D', 'Texture'); - -/** - * The width of the texture, in texels. - * @type {number} - */ -o3d.Texture2D.prototype.width = 0; - - - -/** - * The height of the texture, in texels. - * @type {number} - */ -o3d.Texture2D.prototype.height = 0; - +o3d.ParamObject.setUpO3DParam_(o3d.Texture2D, 'width', 'ParamInteger'); +o3d.ParamObject.setUpO3DParam_(o3d.Texture2D, 'height', 'ParamInteger'); /** * Returns a RenderSurface object associated with a mip_level of a texture. @@ -343,6 +334,12 @@ o3d.Texture2D.prototype.drawImage = */ o3d.TextureCUBE = function() { o3d.Texture.call(this); + + /** + * The length of each edge of the cube, in texels. + * @type {number} + */ + this.edgeLength = 0; }; o3d.inherit('TextureCUBE', 'Texture'); @@ -371,12 +368,7 @@ o3d.TextureCUBE.FACE_NEGATIVE_Y = 3; o3d.TextureCUBE.FACE_POSITIVE_Z = 4; o3d.TextureCUBE.FACE_NEGATIVE_Z = 5; - -/** - * The length of each edge of the cube, in texels. - * @type {number} - */ -o3d.TextureCUBE.prototype.edgeLength = 0; +o3d.ParamObject.setUpO3DParam_(o3d.TextureCUBE, 'edgeLength', 'ParamInteger'); /** diff --git a/o3d/samples/o3d-webgl/transform.js b/o3d/samples/o3d-webgl/transform.js index 6ed797b..1873c5d 100644 --- a/o3d/samples/o3d-webgl/transform.js +++ b/o3d/samples/o3d-webgl/transform.js @@ -52,41 +52,105 @@ o3d.Transform = function(opt_localMatrix, opt_worldMatrix, opt_visible, opt_boundingBox, opt_cull) { o3d.ParamObject.call(this); + + /** + * Local transformation matrix. + * Default = Identity. + */ this.localMatrix = opt_localMatrix || [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]; + + /** + * World (model) matrix as it was last computed. + */ this.worldMatrix = opt_worldMatrix || [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]; + + /** + * Sets the parent of the transform by re-parenting the transform under + * parent. Setting parent to null removes the transform and the + * entire subtree below it from the transform graph. + * If the operation would create a cycle it fails. + */ + this.parent = null; + + /** + * The Visibility for this transform. + * Default = true. + */ this.visible = opt_visible || true; + + /** + * The BoundingBox for this Transform. If culling is on this + * bounding box will be tested against the view frustum of any draw + * context used to with this Transform. + * @type {!o3d.BoundingBox} + */ this.boundingBox = opt_boundingBox || new o3d.BoundingBox([-1, -1, -1], [1, 1, 1]); + + /** + * The cull setting for this transform. If true this Transform will + * be culled by having its bounding box compared to the view frustum + * of any draw context it is used with. + * Default = false. + */ this.cull = opt_cull || false; + /** + * The immediate children of this Transform. + * + * Each access to this field gets the entire list, so it is best to get it + * just once. For example: + * + * var children = transform.children; + * for (var i = 0; i < children.length; i++) { + * var child = children[i]; + * } + * + * Note that modifications to this array [e.g. additions to it] will + * not affect the underlying Transform, while modifications to the + * members of the array will affect them. + */ this.children = []; + + /** + * Gets the shapes owned by this transform. + * + * Each access to this field gets the entire list so it is best to get it + * just once. For example: + * + * var shapes = transform.shapes; + * for (var i = 0; i < shapes.length; i++) { + * var shape = shapes[i]; + * } + * + * + * Note that modifications to this array [e.g. additions to it] will + * not affect the underlying Transform, while modifications to the + * members of the array will affect them. + */ this.shapes = []; }; o3d.inherit('Transform', 'ParamObject'); +o3d.ParamObject.setUpO3DParam_(o3d.Transform, 'visible', 'ParamBoolean'); +// TODO(petersont): need to better understand and possibly implement +// the semantics of SlaveParamMatrix4. +o3d.ParamObject.setUpO3DParam_(o3d.Transform, 'worldMatrix', 'ParamMatrix4'); +o3d.ParamObject.setUpO3DParam_(o3d.Transform, 'localMatrix', 'ParamMatrix4'); +o3d.ParamObject.setUpO3DParam_(o3d.Transform, 'cull', 'ParamBoolean'); +o3d.ParamObject.setUpO3DParam_(o3d.Transform, + 'boundingBox', 'ParamBoundingBox'); -/** - * The Visibility for this transform. - * Default = true. - */ -o3d.Transform.prototype.visible = true; - - - -/** - * Sets the parent of the transform by re-parenting the transform under - * parent. Setting parent to null removes the transform and the - * entire subtree below it from the transform graph. - * If the operation would create a cycle it fails. - */ -o3d.Transform.prototype.parent = null; o3d.Transform.prototype.__defineSetter__('parent', function(p) { + // TODO(petersont): handle removal from any old parent. this.parent_ = p; - p.addChild(this); + if (p) { + p.addChild(this); + } } ); @@ -96,25 +160,6 @@ o3d.Transform.prototype.__defineGetter__('parent', } ); - -/** - * The immediate children of this Transform. - * - * Each access to this field gets the entire list, so it is best to get it - * just once. For example: - * - * var children = transform.children; - * for (var i = 0; i < children.length; i++) { - * var child = children[i]; - * } - * - * Note that modifications to this array [e.g. additions to it] will not affect - * the underlying Transform, while modifications to the members of the array - * will affect them. - */ -o3d.Transform.prototype.children = []; - - /** * Adds a child transform. * @param {o3d.Transform} The new child. @@ -207,27 +252,6 @@ o3d.Transform.prototype.removeShape = /** - * Gets the shapes owned by this transform. - * - * Each access to this field gets the entire list so it is best to get it - * just once. For example: - * - * var shapes = transform.shapes; - * for (var i = 0; i < shapes.length; i++) { - * var shape = shapes[i]; - * } - * - * - * Note that modifications to this array [e.g. additions to it] will not affect - * the underlying Transform, while modifications to the members of the array - * will affect them. - */ -o3d.Transform.prototype.shapes = []; - - - - -/** * Walks the tree of transforms starting with this transform and creates * draw elements. If an Element already has a DrawElement that uses material a * new DrawElement will not be created. @@ -246,40 +270,6 @@ o3d.Transform.prototype.createDrawElements = /** - * World (model) matrix as it was last computed. - */ -o3d.Transform.prototype.worldMatrix = []; - - - -/** - * Local transformation matrix. - * Default = Identity. - */ -o3d.Transform.prototype.local_matrix = []; - - - -/** - * The cull setting for this transform. If true this Transform will be culled - * by having its bounding box compared to the view frustum of any draw context - * it is used with. - * Default = false. - */ -o3d.Transform.prototype.cull_ = false; - - - -/** - * The BoundingBox for this Transform. If culling is on this bounding box will - * be tested against the view frustum of any draw context used to with this - * Transform. - */ -o3d.Transform.prototype.boundingBox = null; - - - -/** * Sets the local matrix of this transform to the identity matrix. */ o3d.Transform.prototype.identity = function() { diff --git a/o3d/samples/o3d-webgl/tree_traversal.js b/o3d/samples/o3d-webgl/tree_traversal.js index 9eb84fe..149b25b 100644 --- a/o3d/samples/o3d-webgl/tree_traversal.js +++ b/o3d/samples/o3d-webgl/tree_traversal.js @@ -43,28 +43,28 @@ */ o3d.TreeTraversal = function(opt_transform) { o3d.RenderNode.call(this); - this.transform = opt_transform; + + /** + * The root Transform this TreeTraversal will start traversing from. + */ + this.transform = opt_transform || null; + + /** + * Private list of registered drawlists. + * @private + */ this.drawLists_ = []; + + /** + * Private list of drawlists to reset at render-time before traversal. + * @private + */ this.drawListsToReset_ = []; }; o3d.inherit('TreeTraversal', 'RenderNode'); - -/** - * The root Transform this TreeTraversal will start traversing from. - */ -o3d.TreeTraversal.prototype.transform = null; - - -/** - * Private list of registered drawlists. - */ -o3d.TreeTraversal.prototype.drawLists_ = []; - -/** - * Private list of drawlists to reset at render-time before traversal. - */ -o3d.TreeTraversal.prototype.drawListsToReset_ = []; +o3d.ParamObject.setUpO3DParam_(o3d.TreeTraversal, + 'transform', 'ParamTransform'); /** * Registers a DrawList with this TreeTraversal so that when this diff --git a/o3d/samples/o3d-webgl/viewport.js b/o3d/samples/o3d-webgl/viewport.js index 70e1386..a9ffebc 100644 --- a/o3d/samples/o3d-webgl/viewport.js +++ b/o3d/samples/o3d-webgl/viewport.js @@ -45,36 +45,34 @@ */ o3d.Viewport = function(opt_viewport, opt_depthRange) { o3d.RenderNode.call(this); + + /** + * The position and size to set the viewport in + * [left, top, width, height] format. + * + * Note: These values must describe a rectangle that is 100% inside + * the client area. In other words, [0.5, 0.0, 1.0, 1.0] would + * describe an area that is 1/2 off right side of the screen. That + * is an invalid value and will be clipped to [0.5, 0.0, 0.5, 1.0]. + * + * Default = [0.0, 0.0, 1.0, 1.0]. In other words, the full area. + * + * @type {!Array.<number>} + */ this.viewport = opt_viewport || [0.0, 0.0, 1.0, 1.0]; + + /** + * The min Z and max Z depth range in [min Z, max Z] format. + * Default = [0.0, 1.0]. + * + * @type {!Array.<number>} + */ this.depthRange = opt_depthRange || [0.0, 1.0]; }; o3d.inherit('Viewport', 'RenderNode'); - -/** - * The position and size to set the viewport in - * [left, top, width, height] format. - * - * Note: These values must describe a rectangle that is 100% inside the client - * area. In other words, [0.5, 0.0, 1.0, 1.0] would describe an area that is - * 1/2 off right side of the screen. That is an invalid value and will be - * clipped to [0.5, 0.0, 0.5, 1.0]. - * - * Default = [0.0, 0.0, 1.0, 1.0]. In other words, the full area. - * - * @type {!Array.<number>} - */ -o3d.Viewport.prototype.viewport = [0.0, 0.0, 1.0, 1.0]; - - -/** - * The min Z and max Z depth range in [min Z, max Z] format. - * Default = [0.0, 1.0]. - * - * @type {!Array.<number>} - */ -o3d.Viewport.prototype.depthRange = [0.0, 1.0]; - +o3d.ParamObject.setUpO3DParam_(o3d.Viewport, 'viewport', 'ParamFloat4'); +o3d.ParamObject.setUpO3DParam_(o3d.Viewport, 'depthRange', 'ParamFloat2'); /** * Called before the children are rendered. Sets up a viewport and |