1- import { GLSLNodeParser , NodeBuilder , TextureNode , vectorComponents } from '../../../nodes/Nodes.js' ;
1+ import { GLSLNodeParser , NodeBuilder , TextureNode , vectorComponents , CodeNode } from '../../../nodes/Nodes.js' ;
22
33import NodeUniformBuffer from '../../common/nodes/NodeUniformBuffer.js' ;
44import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js' ;
@@ -9,13 +9,20 @@ import { NoColorSpace, ByteType, ShortType, RGBAIntegerFormat, RGBIntegerFormat,
99import { DataTexture } from '../../../textures/DataTexture.js' ;
1010import { error } from '../../../utils.js' ;
1111
12+ const glslPolyfills = {
13+ bitcast_int_uint : new CodeNode ( /* glsl */ 'uint tsl_bitcast_uint_to_int ( int x ) { return floatBitsToInt( uintBitsToFloat( x ) ); }' ) ,
14+ bitcast_uint_int : new CodeNode ( /* glsl */ 'uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }' )
15+ } ;
16+
1217const glslMethods = {
1318 textureDimensions : 'textureSize' ,
1419 equals : 'equal' ,
1520 bitcast_float_int : 'floatBitsToInt' ,
1621 bitcast_int_float : 'intBitsToFloat' ,
1722 bitcast_uint_float : 'uintBitsToFloat' ,
1823 bitcast_float_uint : 'floatBitsToUint' ,
24+ bitcast_uint_int : 'tsl_bitcast_uint_to_int' ,
25+ bitcast_int_uint : 'tsl_bitcast_int_to_uint'
1926} ;
2027
2128const precisionLib = {
@@ -127,6 +134,25 @@ class GLSLNodeBuilder extends NodeBuilder {
127134
128135 }
129136
137+ /**
138+ * Includes the given method name into the current
139+ * function node.
140+ *
141+ * @private
142+ * @param {string } name - The method name to include.
143+ * @return {CodeNode } The respective code node.
144+ */
145+ _include ( name ) {
146+
147+ const codeNode = glslPolyfills [ name ] ;
148+ codeNode . build ( this ) ;
149+
150+ this . addInclude ( codeNode ) ;
151+
152+ return codeNode ;
153+
154+ }
155+
130156 /**
131157 * Returns the native shader method name for a given generic name.
132158 *
@@ -135,6 +161,12 @@ class GLSLNodeBuilder extends NodeBuilder {
135161 */
136162 getMethod ( method ) {
137163
164+ if ( glslPolyfills [ method ] !== undefined ) {
165+
166+ this . _include ( method ) ;
167+
168+ }
169+
138170 return glslMethods [ method ] || method ;
139171
140172 }
@@ -148,7 +180,7 @@ class GLSLNodeBuilder extends NodeBuilder {
148180 */
149181 getBitcastMethod ( type , inputType ) {
150182
151- return glslMethods [ `bitcast_${ inputType } _${ type } ` ] ;
183+ return this . getMethod ( `bitcast_${ inputType } _${ type } ` ) ;
152184
153185 }
154186
0 commit comments