") 100% no-repeat;padding-right:3rem}select:focus{background-image:url("data:image/svg+xml;utf8,")}select[multiple]{background:0 0;height:auto}textarea{min-height:6.5rem}label,legend{margin-bottom:.5rem;font-size:1.6rem;font-weight:700;display:block}fieldset{border-width:0;padding:0}input[type=checkbox],input[type=radio]{display:inline}.label-inline{margin-left:.5rem;font-weight:400;display:inline-block}.container{width:100%;max-width:112rem;margin:0 auto;padding:0 2rem;position:relative}.row{flex-direction:column;width:100%;padding:0;display:flex}.row.row-no-padding,.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{flex:auto;width:100%;max-width:100%;margin-left:0;display:block}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-40{margin-left:40%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-60{margin-left:60%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{align-self:center}@media (width>=40rem){.row{flex-direction:row;width:calc(100% + 2rem);margin-left:-1rem}.row .column{margin-bottom:inherit;padding:0 1rem}}a{color:#9b4dca;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{margin-top:0;padding-left:0;list-style:none}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{margin:1.5rem 0 1.5rem 3rem;font-size:90%}ol{list-style:inside decimal}ul{list-style:inside circle}.button,button,dd,dt,li{margin-bottom:1rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;text-align:left;width:100%;display:block;overflow-x:auto}td,th{border-bottom:.1rem solid #e1e1e1;padding:1.2rem 1.5rem}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}@media (width>=40rem){table{overflow-x:initial;display:table}}b,strong{font-weight:700}p{margin-top:0}h1,h2,h3,h4,h5,h6{letter-spacing:-.1rem;margin-top:0;margin-bottom:2rem;font-weight:300}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{letter-spacing:-.08rem;font-size:2.2rem;line-height:1.35}h5{letter-spacing:-.05rem;font-size:1.8rem;line-height:1.5}h6{letter-spacing:0;font-size:1.6rem;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:" ";display:table}.float-left{float:left}.float-right{float:right}html,body{background:#0000000d;min-width:calc(720px + 4em);margin:0;padding:0}main{background:#fff;min-width:720px;max-width:1280px;min-height:101vh;margin:auto;padding:0 2em;box-shadow:0 0 4px #0000004d}
Thin functional WebGL wrapper with strong typed GLSL DSL
Documentation
Installation
This library could be installed from npm repository
npm i --save webgl-dsl
Examples
Code sample
Here is a code you need to draw a triangle using WebGL-DSL
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
const width = canvas.width = canvas.clientWidth * devicePixelRatio;
const height = canvas.height = canvas.clientHeight * devicePixelRatio;
const gl = new Gl(canvas, { preserveDrawingBuffer: true });
const drawTriangles = gl.command(PrimitivesType.Triangles, {
uniforms: {},
attributes: {
aPosition: Type.Vector2,
aColor: Type.Vector4,
},
varyings: {
vColor: Type.Vector4,
},
vertex({ aPosition, aColor }) {
return {
gl_Position: val(aPosition.mul(0.75), 0, 1),
vColor: aColor,
};
},
fragment({ vColor }) {
return {
gl_FragColor: vColor.pow(val(1 / 2.2).vec4()),
};
},
});
drawTriangles.setAttributes([
{ aColor: [1, 0, 0, 1], aPosition: [0, 1] },
{ aColor: [0, 1, 0, 1], aPosition: [-1, -1] },
{ aColor: [0, 0, 1, 1], aPosition: [1, -1] },
]);
gl.settings()
.viewport(0, 0, width, height)
.clearColor(0, 0, 0, 1)
.apply(() => {
gl.cleanColorBuffer();
drawTriangles.draw();
});