Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Immediate Rendering callback #592

Merged
merged 1 commit into from

4 participants

@NINE78

Added "lower level" immediate rendering functionality. The existing mechanism requires modification of the WebGLRenderer for different objects. The new implementation leaves the current MarchingCubes immediate renderer intact but checks for existence of a immediateRenderCallback member function of the object. If found, that object is added to the scene.__webglObjectsImmediate array. The program, webgl context, and frustum are currently passed into the callback, putting al rendering responsibility at the implementing object. This may break the Three.js abstraction somewhat, but allows "power users" to do some funky webgl stuff while still relying on the Three.js framework for the rest of the scene...

@NINE78 NINE78 Added "lower level" immediate rendering functionality. The existing m…
…echanism requires modification of the WebGLRenderer for different objects. The new implementation leaves the current MarchingCubes immediate renderer intact but checks for existence of a immediateRenderCallback member function of the object. If found, that object is added to the scene.__webglObjectsImmediate array. The program, webgl context, and frustum are currently passed into the callback, putting al rendering responsibility at the implementing object. This may break the Three.js abstraction somewhat, but allows "power users" to do some funky webgl stuff while still relying on the Three.js framework for the rest of the scene...
c311a71
@pyrotechnick

FYI this should resolve both #548 and #586

@mrdoob
Owner

@alteredq: is it good to merge then? this goes a bit over my head right now :)

@alteredq

I guess so, this is still very early stage of such feature, we'll put it in and see where it'll go (usual procedure - collect enough use cases and keep refactoring).

@mrdoob mrdoob merged commit c311a71 into from
@mrdoob
Owner

Merged. Thanks @NINE78! :)

@NINE78

My pleasure; I hope others get some use out of this! I mainly use it to recursively traverse a LOD quadtree, and for another object to do some funky stencil buffer stuff...
The frustum is passed along to perform hierarchical frustum checking (first bounding sphere, and then bounding box). I'm considering doing some faster "frustum cone" checking as well.

As said before, I'm not quite sure this is the "cleanest" way of doing it, but since JS doesn't have any proper prototype/interface mechanism, it's the best I could come up with. But I do feel confident there is room in there for a "custom renderer pipeline" much like to ability to have custom shaders...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2011
  1. @NINE78

    Added "lower level" immediate rendering functionality. The existing m…

    NINE78 authored
    …echanism requires modification of the WebGLRenderer for different objects. The new implementation leaves the current MarchingCubes immediate renderer intact but checks for existence of a immediateRenderCallback member function of the object. If found, that object is added to the scene.__webglObjectsImmediate array. The program, webgl context, and frustum are currently passed into the callback, putting al rendering responsibility at the implementing object. This may break the Three.js abstraction somewhat, but allows "power users" to do some funky webgl stuff while still relying on the Three.js framework for the rest of the scene...
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 6 deletions.
  1. +26 −6 src/renderers/WebGLRenderer.js
View
32 src/renderers/WebGLRenderer.js
@@ -3636,7 +3636,12 @@ THREE.WebGLRenderer = function ( parameters ) {
setObjectFaces( object );
program = setProgram( _cameraLight, lights, fog, _depthMaterial, object );
- object.render( function( object ) { renderBufferImmediate( object, program, _depthMaterial.shading ); } );
+ if ( object.immediateRenderCallback ) {
+ object.immediateRenderCallback( program, _gl, _frustum );
+ }
+ else {
+ object.render( function( object ) { renderBufferImmediate( object, program, _depthMaterial.shading ); } );
+ }
}
@@ -3814,7 +3819,12 @@ THREE.WebGLRenderer = function ( parameters ) {
setObjectFaces( object );
program = setProgram( camera, lights, fog, scene.overrideMaterial, object );
- object.render( function( object ) { renderBufferImmediate( object, program, scene.overrideMaterial.shading ); } );
+ if ( object.immediateRenderCallback ) {
+ object.immediateRenderCallback( program, _gl, _frustum );
+ }
+ else {
+ object.render( function( object ) { renderBufferImmediate( object, program, _depthMaterial.shading ); } );
+ }
}
@@ -3876,7 +3886,12 @@ THREE.WebGLRenderer = function ( parameters ) {
setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
program = setProgram( camera, lights, fog, material, object );
- object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
+ if ( object.immediateRenderCallback ) {
+ object.immediateRenderCallback( program, _gl, _frustum );
+ }
+ else {
+ object.render( function( object ) { renderBufferImmediate( object, program, _depthMaterial.shading ); } );
+ }
}
@@ -3939,7 +3954,12 @@ THREE.WebGLRenderer = function ( parameters ) {
setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
program = setProgram( camera, lights, fog, material, object );
- object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
+ if ( object.immediateRenderCallback ) {
+ object.immediateRenderCallback( program, _gl, _frustum );
+ }
+ else {
+ object.render( function( object ) { renderBufferImmediate( object, program, _depthMaterial.shading ); } );
+ }
}
@@ -4275,7 +4295,7 @@ THREE.WebGLRenderer = function ( parameters ) {
geometry = object.geometry;
addBuffer( scene.__webglObjects, geometry, object );
- } else if ( THREE.MarchingCubes !== undefined && object instanceof THREE.MarchingCubes ) {
+ } else if ( THREE.MarchingCubes !== undefined && object instanceof THREE.MarchingCubes || object.immediateRenderCallback ) {
addBufferImmediate( scene.__webglObjectsImmediate, object );
@@ -4480,7 +4500,7 @@ THREE.WebGLRenderer = function ( parameters ) {
removeInstancesDirect( scene.__webglSprites, object );
- } else if ( object instanceof THREE.MarchingCubes ) {
+ } else if ( object instanceof THREE.MarchingCubes || object.immediateRenderCallback ) {
removeInstances( scene.__webglObjectsImmediate, object );
Something went wrong with that request. Please try again.