glsl-token-descope

WebJar for glsl-token-descope

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

glsl-token-descope
Последняя версия

Последняя версия

1.0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

glsl-token-descope
WebJar for glsl-token-descope
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/glslify/glsl-token-descope

Скачать glsl-token-descope

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/glsl-token-descope/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>glsl-token-descope</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/glsl-token-descope/
implementation 'org.webjars.npm:glsl-token-descope:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/glsl-token-descope/
implementation ("org.webjars.npm:glsl-token-descope:1.0.2")
'org.webjars.npm:glsl-token-descope:jar:1.0.2'
<dependency org="org.webjars.npm" name="glsl-token-descope" rev="1.0.2">
  <artifact name="glsl-token-descope" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='glsl-token-descope', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "glsl-token-descope" % "1.0.2"
[org.webjars.npm/glsl-token-descope "1.0.2"]

Зависимости

compile (4)

Идентификатор библиотеки Тип Версия
org.webjars.npm : glsl-token-assignments jar [2.0.0,3)
org.webjars.npm : glsl-token-depth jar [1.1.0,2)
org.webjars.npm : glsl-token-properties jar [1.0.0,2)
org.webjars.npm : glsl-token-scope jar [1.1.0,2)

Модули Проекта

Данный проект не имеет модулей.

glsl-token-descope

experimental

"Descope" an array of GLSL tokens such that they can be safely inlined alongside within another shader without causing any global variable conflicts.

Useful for modularising GLSL source files, e.g. as is done in glslify, but should be useful in other tools too.

Written with WebGL's GLSL syntax in mind – all the same, pull requests to support other variants would be much appreciated :)

Usage

NPM

descope(tokens, [rename(name)])

Takes an array of GLSL tokens produced by glsl-tokenizer and renames variables to avoid global conflicts by modifying their "data" property in-place.

For example:

var tokenize  = require('glsl-tokenizer/string')
var descope   = require('glsl-token-descope')
var stringify = require('glsl-token-string')

var src = `
precision mediump float;

uniform mat4  top1;
uniform float top2;

void main() {
  float x = 1.0;
  gl_FragColor = vec4(vec3(x), top2);
}
`.trim()

var tokens = tokenize(src)

console.log(stringify(descope(tokens)))

Which should rename main, top1 and top2 to result in this output:

precision mediump float;

uniform mat4  top1_0;
uniform float top2_1;

void main_2() {
  float x = 1.0;
  gl_FragColor = vec4(vec3(x), top2_1);
}

Optionally, you may pass in a custom rename function as descope's second argument to choose how you rename your variables. For example, adding a custom rename function to the previous function:

descope(tokens, function(name) {
  return 'a_' + name
})

Would result in the following shader:

precision mediump float;

uniform mat4  a_top1;
uniform float a_top2;

void a_main() {
  float x = 1.0;
  gl_FragColor = vec4(vec3(x), a_top2);
}

See Also

License

MIT. See LICENSE.md for details.

org.webjars.npm

Версии библиотеки

Версия
1.0.2