2
0

GLNode.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.GLNode = function( type ) {
  5. this.uuid = THREE.Math.generateUUID();
  6. this.allow = {};
  7. this.requestUpdate = false;
  8. this.type = type;
  9. };
  10. THREE.GLNode.prototype.verify = function( builder, cache, requires ) {
  11. builder.isVerify = true;
  12. var material = builder.material;
  13. this.build( builder.addCache( cache, requires ), 'v4' );
  14. material.clearVertexNode();
  15. material.clearFragmentNode();
  16. builder.removeCache();
  17. builder.isVerify = false;
  18. };
  19. THREE.GLNode.prototype.verifyAndBuildCode = function( builder, output, cache, requires ) {
  20. this.verify( builder, cache, requires );
  21. return this.buildCode( builder, output, cache, requires );
  22. };
  23. THREE.GLNode.prototype.buildCode = function( builder, output, cache, requires ) {
  24. var material = builder.material;
  25. var data = { result : this.build( builder.addCache( cache, requires ), output ) };
  26. if ( builder.isShader( 'vertex' ) ) data.code = material.clearVertexNode();
  27. else data.code = material.clearFragmentNode();
  28. builder.removeCache();
  29. return data;
  30. };
  31. THREE.GLNode.prototype.verifyDepsNode = function( builder, data, output ) {
  32. data.deps = ( data.deps || 0 ) + 1;
  33. var outputLen = builder.getFormatLength( output );
  34. if ( outputLen > data.outputMax || this.getType( builder ) ) {
  35. data.outputMax = outputLen;
  36. data.output = output;
  37. }
  38. };
  39. THREE.GLNode.prototype.build = function( builder, output, uuid ) {
  40. var material = builder.material;
  41. var data = material.getDataNode( uuid || this.uuid );
  42. if ( builder.isShader( 'verify' ) ) this.verifyDepsNode( builder, data, output );
  43. if ( this.allow[ builder.shader ] === false ) {
  44. throw new Error( 'Shader ' + shader + ' is not compatible with this node.' );
  45. }
  46. if ( this.requestUpdate && ! data.requestUpdate ) {
  47. material.requestUpdate.push( this );
  48. data.requestUpdate = true;
  49. }
  50. return this.generate( builder, output, uuid );
  51. };
  52. THREE.GLNode.prototype.getType = function( builder ) {
  53. return this.type;
  54. };