Skip to content

a through stream that reads from a GLSL token object stream and writes back a stream of GLSL token strings

License

Notifications You must be signed in to change notification settings

json2d/glsl-detokenizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glsl-detokenizer

A through stream that reads from a GLSL token object stream and writes back a stream of GLSL token strings

Works with token object stream created by stackgl/glsl-tokenizer

// Streaming API:
var tokenizer = require('glsl-tokenizer/stream')
var detokenizer = require('glsl-detokenizer/stream')
var fs = require('fs')

const glslIn = fs.createReadStream('some.glsl')
const glslOut = fs.createReadStream('some-modded.glsl')

glslIn
  .pipe(tokenizer())
  .on('data', function(token) {
      if(token.type == 'float') {
          token.data = '1.0'; // change all float literals to 1.0
      }
  })
  .pipe(detokenizer())
  .pipe(glslOut)


// Synchronously:
var tokenizer = require('glsl-tokenizer/string')
var detokenizer = require('glsl-detokenizer/string')
var fs = require('fs')

const tokens = tokenizerString(fs.readFileSync('some.glsl'))
tokens.forEach( token => {
    if(token.type == 'float') {
        token.data = '1.0'; // change all float literals to 1.0
    }    
})
fs.writeFileSync('some-modded.glsl',detokenizerString(tokens))

License

MIT, see LICENSE.md for further information.

About

a through stream that reads from a GLSL token object stream and writes back a stream of GLSL token strings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published