= 9 anni fa
parent
commit
5927654fce

+ 18 - 3
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -338,10 +338,19 @@
             }
         }
 
+        /**
+         * Overrides the default sort function applied in the renderging group to prepare the meshes.
+         * This allowed control for front to back rendering or reversly depending of the special needs.
+         * 
+         * @param renderingGroupId The rendering group id corresponding to its index
+         * @param opaqueSortCompareFn The opaque queue comparison function use to sort.
+         * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.
+         * @param transparentSortCompareFn The transparent queue comparison function use to sort.
+         */
         public setRenderingOrder(renderingGroupId: number,
             opaqueSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
             alphaTestSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
-            transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number = null) {
+            transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number = null): void {
             
             this._renderingManager.setRenderingOrder(renderingGroupId,
                 opaqueSortCompareFn,
@@ -349,8 +358,14 @@
                 transparentSortCompareFn);
         }
 
-        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClear: boolean) {            
-            this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClear);
+        /**
+         * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.
+         * 
+         * @param renderingGroupId The rendering group id corresponding to its index
+         * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
+         */
+        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {            
+            this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);
         }
 
         public clone(): RenderTargetTexture {

+ 80 - 3
src/Rendering/babylon.renderingGroup.ts

@@ -16,6 +16,10 @@
 
         public onBeforeTransparentRendering: () => void;
 
+        /**
+         * Set the opaque sort comparison function.
+         * If null the sub meshes will be render in the order they were created 
+         */
         public set opaqueSortCompareFn(value: (a: SubMesh, b: SubMesh) => number) {
             this._opaqueSortCompareFn = value;
             if (value) {
@@ -26,6 +30,10 @@
             }
         }
 
+        /**
+         * Set the alpha test sort comparison function.
+         * If null the sub meshes will be render in the order they were created 
+         */
         public set alphaTestSortCompareFn(value: (a: SubMesh, b: SubMesh) => number) {
             this._alphaTestSortCompareFn = value;
             if (value) {
@@ -36,6 +44,10 @@
             }
         }
 
+        /**
+         * Set the transparent sort comparison function.
+         * If null the sub meshes will be render in the order they were created 
+         */
         public set transparentSortCompareFn(value: (a: SubMesh, b: SubMesh) => number) {
             this._transparentSortCompareFn = value;
             if (value) {
@@ -46,6 +58,13 @@
             }
         }
 
+        /**
+         * Creates a new rendering group.
+         * @param index The rendering group index
+         * @param opaqueSortCompareFn The opaque sort comparison function. If null no order is applied
+         * @param alphaTestSortCompareFn The alpha test sort comparison function. If null no order is applied
+         * @param transparentSortCompareFn The transparent sort comparison function. If null back to front + alpha index sort is applied
+         */
         constructor(public index: number, scene: Scene,
             opaqueSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
             alphaTestSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
@@ -57,6 +76,11 @@
             this.transparentSortCompareFn = transparentSortCompareFn;            
         }
 
+        /**
+         * Render all the sub meshes contained in the group.
+         * @param customRenderFunction Used to override the default render behaviour of the group.
+         * @returns true if rendered some submeshes.
+         */
         public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>) => void): boolean {
             if (customRenderFunction) {
                 customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes);
@@ -88,18 +112,36 @@
             return true;
         }
 
+        /**
+         * Renders the opaque submeshes in the order from the opaqueSortCompareFn.
+         * @param subMeshes The submeshes to render
+         */
         private renderOpaqueSorted(subMeshes: SmartArray<SubMesh>): void {
-            return RenderingGroup.renderSorted(subMeshes, this.opaqueSortCompareFn, this._scene.activeCamera.globalPosition);
+            return RenderingGroup.renderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera.globalPosition);
         }
 
+        /**
+         * Renders the opaque submeshes in the order from the alphatestSortCompareFn.
+         * @param subMeshes The submeshes to render
+         */
         private renderAlphaTestSorted(subMeshes: SmartArray<SubMesh>): void {
-            return RenderingGroup.renderSorted(subMeshes, this.alphaTestSortCompareFn, this._scene.activeCamera.globalPosition);
+            return RenderingGroup.renderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera.globalPosition);
         }
 
+        /**
+         * Renders the opaque submeshes in the order from the transparentSortCompareFn.
+         * @param subMeshes The submeshes to render
+         */
         private renderTransparentSorted(subMeshes: SmartArray<SubMesh>): void {
-            return RenderingGroup.renderSorted(subMeshes, this.transparentSortCompareFn, this._scene.activeCamera.globalPosition);
+            return RenderingGroup.renderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera.globalPosition);
         }
 
+        /**
+         * Renders the submeshes in a specified order.
+         * @param subMeshes The submeshes to sort before render
+         * @param sortCompareFn The comparison function use to sort
+         * @param cameraPosition The camera position use to preprocess the submeshes to help sorting
+         */
         private static renderSorted(subMeshes: SmartArray<SubMesh>, sortCompareFn: (a: SubMesh, b: SubMesh) => number, cameraPosition: Vector3): void {
             let subIndex = 0;
             let subMesh;
@@ -118,6 +160,10 @@
             }
         }
 
+        /**
+         * Renders the submeshes in the order they were dispatched (no sort applied).
+         * @param subMeshes The submeshes to render
+         */
         private static renderUnsorted(subMeshes: SmartArray<SubMesh>): void {
             for (var subIndex = 0; subIndex < subMeshes.length; subIndex++) {
                 let submesh = subMeshes.data[subIndex];
@@ -125,6 +171,14 @@
             }
         }
 
+        /**
+         * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
+         * are rendered back to front if in the same alpha index.
+         * 
+         * @param a The first submesh
+         * @param b The second submesh
+         * @returns The result of the comparison
+         */
         public static defaultTransparentSortCompare(a: SubMesh, b:SubMesh) : number {
             // Alpha index first
             if (a._alphaIndex > b._alphaIndex) {
@@ -138,6 +192,14 @@
             return RenderingGroup.backToFrontSortCompare(a, b);
         }
 
+        /**
+         * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
+         * are rendered back to front.
+         * 
+         * @param a The first submesh
+         * @param b The second submesh
+         * @returns The result of the comparison
+         */
         public static backToFrontSortCompare(a: SubMesh, b:SubMesh) : number {
             // Then distance to camera
             if (a._distanceToCamera < b._distanceToCamera) {
@@ -150,6 +212,14 @@
             return 0;
         }
 
+        /**
+         * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
+         * are rendered front to back (prevent overdraw).
+         * 
+         * @param a The first submesh
+         * @param b The second submesh
+         * @returns The result of the comparison
+         */
         public static frontToBackSortCompare(a: SubMesh, b:SubMesh) : number {
             // Then distance to camera
             if (a._distanceToCamera < b._distanceToCamera) {
@@ -162,12 +232,19 @@
             return 0;
         }
 
+        /**
+         * Resets the different lists of submeshes to prepare a new frame.
+         */
         public prepare(): void {
             this._opaqueSubMeshes.reset();
             this._transparentSubMeshes.reset();
             this._alphaTestSubMeshes.reset();
         }
 
+        /**
+         * Inserts the submesh in its correct queue depending on its material.
+         * @param subMesh The submesh to dispatch
+         */
         public dispatch(subMesh: SubMesh): void {
             var material = subMesh.getMaterial();
             var mesh = subMesh.getMesh();

+ 24 - 2
src/Rendering/babylon.renderingManager.ts

@@ -1,6 +1,13 @@
 module BABYLON {
     export class RenderingManager {
+        /**
+         * The max id used for rendering groups (not included)
+         */
         public static MAX_RENDERINGGROUPS = 4;
+
+        /**
+         * The min id used for rendering groups (included)
+         */
         public static MIN_RENDERINGGROUPS = 0;
 
         private _scene: Scene;
@@ -153,6 +160,15 @@
             this._renderingGroups[renderingGroupId].dispatch(subMesh);
         }
 
+        /**
+         * Overrides the default sort function applied in the renderging group to prepare the meshes.
+         * This allowed control for front to back rendering or reversly depending of the special needs.
+         * 
+         * @param renderingGroupId The rendering group id corresponding to its index
+         * @param opaqueSortCompareFn The opaque queue comparison function use to sort.
+         * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.
+         * @param transparentSortCompareFn The transparent queue comparison function use to sort.
+         */
         public setRenderingOrder(renderingGroupId: number,
             opaqueSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
             alphaTestSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
@@ -170,8 +186,14 @@
             this._customTransparentSortCompareFn[renderingGroupId] = transparentSortCompareFn;
         }
 
-        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClear: boolean) {            
-            this._autoClearDepthStencil[renderingGroupId] = autoClear;
+        /**
+         * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.
+         * 
+         * @param renderingGroupId The rendering group id corresponding to its index
+         * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
+         */
+        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {            
+            this._autoClearDepthStencil[renderingGroupId] = autoClearDepthStencil;
         }
     }
 } 

+ 3 - 0
src/babylon.engine.ts

@@ -558,6 +558,9 @@
             return this._webGLVersion;
         }
 
+        /**
+         * Returns true if the stencil buffer has been enabled through the creation option of the context.
+         */
         public get isStencilEnable(): boolean {
             return this._isStencilEnable;
         }

+ 18 - 3
src/babylon.scene.ts

@@ -2922,10 +2922,19 @@
             return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         }
 
+        /**
+         * Overrides the default sort function applied in the renderging group to prepare the meshes.
+         * This allowed control for front to back rendering or reversly depending of the special needs.
+         * 
+         * @param renderingGroupId The rendering group id corresponding to its index
+         * @param opaqueSortCompareFn The opaque queue comparison function use to sort.
+         * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.
+         * @param transparentSortCompareFn The transparent queue comparison function use to sort.
+         */
         public setRenderingOrder(renderingGroupId: number,
             opaqueSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
             alphaTestSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
-            transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number = null) {
+            transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number = null): void {
             
             this._renderingManager.setRenderingOrder(renderingGroupId,
                 opaqueSortCompareFn,
@@ -2933,8 +2942,14 @@
                 transparentSortCompareFn);
         }
 
-        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClear: boolean) {            
-            this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClear);
+        /**
+         * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.
+         * 
+         * @param renderingGroupId The rendering group id corresponding to its index
+         * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
+         */
+        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {            
+            this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);
         }
     }
 }