claygl-next
Advanced tools
Comparing version 2.0.0-alpha.32 to 2.0.0-alpha.33
@@ -138,3 +138,5 @@ import { GLEnum } from '../core/type'; | ||
*/ | ||
render(list: GLRenderableObject[], renderHooks?: GLRenderHooks): boolean; | ||
render(list: GLRenderableObject[], renderHooks?: GLRenderHooks, opts?: { | ||
waitForAllShadersCompiled?: boolean; | ||
}): boolean; | ||
private _updatePrograms; | ||
@@ -141,0 +143,0 @@ isAllProgramCompiled(): boolean; |
@@ -96,2 +96,4 @@ import Notifier from './core/Notifier'; | ||
* If use parallel shader compile. | ||
* We still need to set shader.parallelCompile to true | ||
* to enable the specified shader manually | ||
*/ | ||
@@ -231,2 +233,7 @@ parallelShaderCompile: boolean; | ||
filter?: (renderable: Renderable) => boolean; | ||
/** | ||
* If waiting for all shaders compiled. Available when parallelShaderCompile is true. | ||
* Default to be false, it will render the meshes that has finishing compiling shader eargerly. | ||
*/ | ||
waitForAllShadersCompiled?: boolean; | ||
}): boolean | undefined; | ||
@@ -240,3 +247,5 @@ /** | ||
*/ | ||
renderPass(list: GLRenderableObject<Material>[], camera?: Camera, frameBuffer?: FrameBuffer, renderHooks?: RenderHooks, scene?: Scene): boolean; | ||
renderPass(list: GLRenderableObject<Material>[], camera?: Camera, frameBuffer?: FrameBuffer, renderHooks?: RenderHooks, scene?: Scene, opts?: { | ||
waitForAllShadersCompiled?: boolean; | ||
}): boolean; | ||
/** | ||
@@ -251,3 +260,5 @@ * Bind frame buffer manually. | ||
setMaxJointNumber(val: number): void; | ||
renderPreZ(list: GLRenderableObject<Material>[], camera: Camera, frameBuffer?: FrameBuffer): void; | ||
renderPreZ(list: GLRenderableObject<Material>[], camera: Camera, frameBuffer?: FrameBuffer, opts?: { | ||
waitForAllShadersCompiled?: boolean; | ||
}): void; | ||
/** | ||
@@ -254,0 +265,0 @@ * Dispose given scene, including all geometris, textures and shaders in the scene |
@@ -227,2 +227,7 @@ import { Dict, UnionToIntersection } from './core/type'; | ||
private readonly _shaderID; | ||
/** | ||
* If enable parallel compile. | ||
* Only available when renderer#parallelShaderCompile is true. | ||
*/ | ||
parallelCompile?: boolean; | ||
version: 3; | ||
@@ -229,0 +234,0 @@ get shaderID(): string; |
import { COLOR_ATTACHMENT0, HALF_FLOAT, UNSIGNED_BYTE, UNSIGNED_INT_24_8 } from '../../core/constants'; | ||
import { assign, isFunction, keys, optional } from '../../core/util'; | ||
import Texture2D from '../../Texture2D'; | ||
import FilterCompositeNode from '../FilterNode'; | ||
import { texturePropList } from '../TexturePool'; | ||
@@ -50,3 +51,3 @@ class RenderGraphNode { | ||
const derivedParams = this._deriveTextureParams(renderer) || {}; | ||
const outputInfo = this._compositeNode.outputs[outputName] || {}; | ||
const outputInfo = this._getOutputInfo(outputName) || {}; | ||
const width = isFunction(outputInfo.width) ? outputInfo.width(renderer) : outputInfo.width; | ||
@@ -127,3 +128,3 @@ const height = isFunction(outputInfo.height) | ||
getOutputTexture(renderer, outputPin, usePrevFrame) { | ||
const outputInfo = this._compositeNode.outputs[outputPin]; | ||
const outputInfo = this._getOutputInfo(outputPin); | ||
const prevOutputTextures = this._prevOutputTextures; | ||
@@ -193,3 +194,3 @@ const outputTextures = this._outputTextures; | ||
outputNames.forEach((outputName, idx) => { | ||
const outputInfo = compositeNode.outputs[outputName]; | ||
const outputInfo = this._getOutputInfo(outputName); | ||
const parameters = this.getTextureParams(outputName, renderer); | ||
@@ -207,5 +208,17 @@ const persistedTextures = this._persistedTextures; | ||
} | ||
const attachment = outputInfo.attachment || COLOR_ATTACHMENT0 + idx; | ||
outputTextures[outputName] = texture; | ||
MRTOutputTextures[outputName] = texture; | ||
}); | ||
// The MRTOutputTextures follows the order of assigning node.outputs. It's easily to get wrong with the order of frag.outputs. | ||
// Align them | ||
(compositeNode instanceof FilterCompositeNode && outputNames.length > 0 | ||
? compositeNode.pass.material.shader.outputs | ||
: outputNames).forEach((outputName, idx) => { | ||
const outputInfo = this._getOutputInfo(outputName); | ||
if (!outputInfo) { | ||
// When outputName is from compositeNode.pass.material.shader.outputs | ||
return; | ||
} | ||
const texture = MRTOutputTextures[outputName]; | ||
const attachment = outputInfo.attachment || COLOR_ATTACHMENT0 + idx; | ||
// FIXME attachment changes in different nodes | ||
@@ -226,3 +239,3 @@ sharedFrameBuffer.attach(texture, +attachment); | ||
const texture = MRTOutputTextures[outputName]; | ||
const outputInfo = compositeNode.outputs[outputName]; | ||
const outputInfo = this._getOutputInfo(outputName); | ||
if (!outputLinks[outputName].length && !outputInfo.persist) { | ||
@@ -283,3 +296,3 @@ texturePool.release(texture); | ||
const outputTexture = this._outputTextures[outputName]; | ||
const outputInfo = this._compositeNode.outputs[outputName]; | ||
const outputInfo = this._getOutputInfo(outputName); | ||
if (this._needsKeepPrevFrame[outputName]) { | ||
@@ -299,3 +312,3 @@ this._prevOutputTextures[outputName] = outputTexture; | ||
if (refCount[outputName] <= 0) { | ||
const outputInfo = this._compositeNode.outputs[outputName]; | ||
const outputInfo = this._getOutputInfo(outputName); | ||
if (!outputInfo.persist && (link.prevFrame || !this._needsKeepPrevFrame[outputName])) { | ||
@@ -302,0 +315,0 @@ texturePool.release(texture); |
@@ -138,3 +138,5 @@ import { GLEnum } from '../core/type'; | ||
*/ | ||
render(list: GLRenderableObject[], renderHooks?: GLRenderHooks): boolean; | ||
render(list: GLRenderableObject[], renderHooks?: GLRenderHooks, opts?: { | ||
waitForAllShadersCompiled?: boolean; | ||
}): boolean; | ||
private _updatePrograms; | ||
@@ -141,0 +143,0 @@ isAllProgramCompiled(): boolean; |
@@ -42,6 +42,5 @@ import GLExtension from './GLExtension'; | ||
this.throwError = optional(opts.throwError, true); | ||
if (opts.parallelShaderCompile) { | ||
this._parallelShaderCompile = this._glext.getExtension('KHR_parallel_shader_compile'); | ||
} | ||
this._programMgr = new ProgramManager(this, this._parallelShaderCompile || false); | ||
this._programMgr = new ProgramManager(this, opts.parallelShaderCompile | ||
? this._glext.getExtension('KHR_parallel_shader_compile') | ||
: undefined); | ||
} | ||
@@ -95,4 +94,5 @@ setViewport(x, y, width, height, dpr) { | ||
*/ | ||
render(list, renderHooks) { | ||
render(list, renderHooks, opts) { | ||
renderHooks = renderHooks || {}; | ||
opts = opts || {}; | ||
renderHooks.getMaterial = renderHooks.getMaterial || defaultGetMaterial; | ||
@@ -106,3 +106,6 @@ renderHooks.getMaterialUniform = renderHooks.getMaterialUniform || defaultGetUniform; | ||
const isBoundToFramebuffer = this._framebuffer; | ||
this._updatePrograms(list, renderHooks); | ||
const hasProgramCompiling = this._updatePrograms(list, renderHooks); | ||
if (hasProgramCompiling && opts.waitForAllShadersCompiled) { | ||
return true; | ||
} | ||
if (renderHooks.sortCompare) { | ||
@@ -124,3 +127,2 @@ list.sort(renderHooks.sortCompare); | ||
let drawBuffersCount = 0; | ||
let unfinished = false; | ||
for (let i = 0; i < list.length; i++) { | ||
@@ -135,6 +137,2 @@ const renderable = list[i]; | ||
let program = renderable.__program; | ||
if (program.isCompiling()) { | ||
unfinished = true; | ||
continue; | ||
} | ||
// If has error in shader and program is invalid | ||
@@ -241,6 +239,7 @@ if (!program.isValid()) { | ||
} | ||
return unfinished; | ||
return hasProgramCompiling; | ||
} | ||
_updatePrograms(list, renderHooks) { | ||
const getMaterial = renderHooks.getMaterial || defaultGetMaterial; | ||
let hasProgramCompiling = false; | ||
for (let i = 0; i < list.length; i++) { | ||
@@ -266,3 +265,7 @@ const renderable = list[i]; | ||
renderable.__program = program; | ||
if (program.isCompiling()) { | ||
hasProgramCompiling = true; | ||
} | ||
} | ||
return hasProgramCompiling; | ||
} | ||
@@ -269,0 +272,0 @@ isAllProgramCompiled() { |
@@ -179,3 +179,3 @@ import { keys } from '../core/util'; | ||
program.buildProgram(_gl, shader, finalVertexCode, finalFragmentCode); | ||
if (parallelExt) { | ||
if (parallelExt && shader.parallelCompile) { | ||
program.__compiling = true; | ||
@@ -182,0 +182,0 @@ } |
@@ -96,2 +96,4 @@ import Notifier from './core/Notifier'; | ||
* If use parallel shader compile. | ||
* We still need to set shader.parallelCompile to true | ||
* to enable the specified shader manually | ||
*/ | ||
@@ -231,2 +233,7 @@ parallelShaderCompile: boolean; | ||
filter?: (renderable: Renderable) => boolean; | ||
/** | ||
* If waiting for all shaders compiled. Available when parallelShaderCompile is true. | ||
* Default to be false, it will render the meshes that has finishing compiling shader eargerly. | ||
*/ | ||
waitForAllShadersCompiled?: boolean; | ||
}): boolean | undefined; | ||
@@ -240,3 +247,5 @@ /** | ||
*/ | ||
renderPass(list: GLRenderableObject<Material>[], camera?: Camera, frameBuffer?: FrameBuffer, renderHooks?: RenderHooks, scene?: Scene): boolean; | ||
renderPass(list: GLRenderableObject<Material>[], camera?: Camera, frameBuffer?: FrameBuffer, renderHooks?: RenderHooks, scene?: Scene, opts?: { | ||
waitForAllShadersCompiled?: boolean; | ||
}): boolean; | ||
/** | ||
@@ -251,3 +260,5 @@ * Bind frame buffer manually. | ||
setMaxJointNumber(val: number): void; | ||
renderPreZ(list: GLRenderableObject<Material>[], camera: Camera, frameBuffer?: FrameBuffer): void; | ||
renderPreZ(list: GLRenderableObject<Material>[], camera: Camera, frameBuffer?: FrameBuffer, opts?: { | ||
waitForAllShadersCompiled?: boolean; | ||
}): void; | ||
/** | ||
@@ -254,0 +265,0 @@ * Dispose given scene, including all geometris, textures and shaders in the scene |
@@ -238,4 +238,7 @@ // TODO Resources like shader, texture, geometry reference management | ||
const globalMaterial = opts.globalMaterial || scene.material; | ||
const passOpts = { | ||
waitForAllShadersCompiled: opts.waitForAllShadersCompiled | ||
}; | ||
// Render pre z | ||
preZ && this.renderPreZ(opaqueList, camera, frameBuffer); | ||
preZ && this.renderPreZ(opaqueList, camera, frameBuffer, passOpts); | ||
gl.depthFunc(preZ ? constants.LEQUAL : constants.LESS); | ||
@@ -268,3 +271,3 @@ // Update the depth of transparent list. | ||
filter: opts.filter | ||
}, scene); | ||
}, scene, passOpts); | ||
unfinished = | ||
@@ -276,3 +279,3 @@ unfinished || | ||
filter: opts.filter | ||
}, scene); | ||
}, scene, passOpts); | ||
return unfinished; | ||
@@ -287,5 +290,5 @@ } | ||
*/ | ||
renderPass(list, camera, frameBuffer, renderHooks, scene) { | ||
renderPass(list, camera, frameBuffer, renderHooks, scene, opts) { | ||
this._bindFrameBuffer(frameBuffer); | ||
return this._renderPass(list, camera, frameBuffer, renderHooks, scene); | ||
return this._renderPass(list, camera, frameBuffer, renderHooks, scene, opts); | ||
} | ||
@@ -305,3 +308,3 @@ /** | ||
} | ||
_renderPass(list, camera, frameBuffer, renderHooks, scene) { | ||
_renderPass(list, camera, frameBuffer, renderHooks, scene, opts) { | ||
let worldM; | ||
@@ -426,3 +429,3 @@ const viewport = this._glPipeline.getViewport(); | ||
renderHooks && renderHooks.prepare && renderHooks.prepare(gl); | ||
const unfinished = this._glPipeline.render(list, assign(renderHooksForScene, renderHooks)); | ||
const unfinished = this._glPipeline.render(list, assign(renderHooksForScene, renderHooks), opts); | ||
renderHooks && renderHooks.cleanup && renderHooks.cleanup(gl); | ||
@@ -437,3 +440,3 @@ return unfinished; | ||
} | ||
renderPreZ(list, camera, frameBuffer) { | ||
renderPreZ(list, camera, frameBuffer, opts) { | ||
const _gl = this.gl; | ||
@@ -481,3 +484,3 @@ const preZPassMaterial = this._prezMaterial || new Material(new Shader(preZVertex, preZFragment)); | ||
sortCompare: Renderer.opaqueSortCompare | ||
}); | ||
}, undefined, opts); | ||
_gl.colorMask(true, true, true, true); | ||
@@ -484,0 +487,0 @@ _gl.depthMask(true); |
@@ -227,2 +227,7 @@ import { Dict, UnionToIntersection } from './core/type'; | ||
private readonly _shaderID; | ||
/** | ||
* If enable parallel compile. | ||
* Only available when renderer#parallelShaderCompile is true. | ||
*/ | ||
parallelCompile?: boolean; | ||
version: 3; | ||
@@ -229,0 +234,0 @@ get shaderID(): string; |
{ | ||
"name": "claygl-next", | ||
"version": "2.0.0-alpha.32", | ||
"version": "2.0.0-alpha.33", | ||
"description": "A 3D graphic library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
7136438
121954