Skip to content

Commit

Permalink
feat(webgl): add ALIAS_TEXTURE GLSL macro
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 10, 2019
1 parent d7679d6 commit 4640ce4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/webgl/src/glsl/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ ${ok}${fail ? `\n#else\n${fail}` : ""}
#endif`;
};

export const ALIAS_TEXTURE = VERSION_CHECK(
300,
"",
"#define texture texture2D"
);

/**
* GLSL version specific fragment shader output. If `__VERSION__ >= 300`
* assigns `body` to `out`, else to `gl_FragColor`.
Expand Down
7 changes: 4 additions & 3 deletions packages/webgl/src/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GLSL, ShaderSpec } from "./api";
import { VERSION_CHECK } from "./glsl/syntax";
import { ALIAS_TEXTURE } from "./glsl/syntax";

export const PASSTHROUGH_VS =
"void main(){v_uv=a_uv;gl_Position=vec4(a_position,0.0,1.0);}";
Expand All @@ -9,9 +9,10 @@ export const PASSTHROUGH_FS = "void main(){o_fragColor=texture(u_tex,v_uv);}";
export const FX_SHADER_SPEC: ShaderSpec = {
vs: PASSTHROUGH_VS,
fs: PASSTHROUGH_FS,
pre: VERSION_CHECK(300, "", "#define texture texture2D"),
pre: ALIAS_TEXTURE,
attribs: { position: GLSL.vec2, uv: GLSL.vec2 },
varying: { uv: GLSL.vec2 },
uniforms: { tex: GLSL.sampler2D },
state: { depth: false }
state: { depth: false },
ext: {}
};
4 changes: 2 additions & 2 deletions packages/webgl/src/shaders/lambert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../api";
import { defglslA } from "../glsl/assemble";
import { lambert } from "../glsl/lighting";
import { VERSION_CHECK } from "../glsl/syntax";
import { ALIAS_TEXTURE } from "../glsl/syntax";
import { mvp, surfaceNormal } from "../glsl/vertex";
import { defMaterial } from "../material";
import { autoNormalMatrix2 } from "../normal-mat";
Expand Down Expand Up @@ -36,7 +36,7 @@ export const LAMBERT = (opts: Partial<LambertOpts> = {}): ShaderSpec => ({
}`,
[lambert]
),
pre: VERSION_CHECK(300, "", "#define texture texture2D"),
pre: ALIAS_TEXTURE,
attribs: {
position: GLSL.vec3,
normal: GLSL.vec3,
Expand Down

0 comments on commit 4640ce4

Please sign in to comment.