wggl
Version:
A friendly interface to shaders
53 lines (52 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var attr_1 = require("./attr");
var uniform_1 = require("./uniform");
var texture_1 = require("./texture");
var buffer_1 = require("./buffer");
var wggl_1 = require("./wggl");
// Convenience function for creating attrs
function attr(size, stride, offset, normalize) {
if (size === void 0) { size = 1; }
if (stride === void 0) { stride = 0; }
if (offset === void 0) { offset = 0; }
if (normalize === void 0) { normalize = false; }
return new attr_1.Attr(size, stride, offset, normalize);
}
exports.attr = attr;
// Convenience function for creating uniforms
function uniform(length, type) {
if (length === void 0) { length = 1; }
if (type === void 0) { type = uniform_1.UniformType.float; }
return new uniform_1.Uniform(length, type);
}
exports.uniform = uniform;
// Creates a partially applied Texture factory
function texture(width, height, pixels, props) {
return function (canvas) { return new texture_1.Texture(canvas, width, height, pixels, props); };
}
exports.texture = texture;
// Creates a partially applied Buffer factory
function buffer(canvas, attachment, level) {
if (attachment === void 0) { attachment = buffer_1.BufferAttachment.COLOR_ATTACHMENT0; }
if (level === void 0) { level = 0; }
var gl = canvas.getContext("webgl");
if (!gl) {
console.warn("No WebGL support");
return function () { };
}
var buffer = gl.createFramebuffer();
return function (texture, target, customAttachment, customLevel) {
if (target === void 0) { target = buffer_1.TexturePointer.TEXTURE_2D; }
return new buffer_1.Buffer(gl, texture, target, buffer, customAttachment || attachment, customLevel || level);
};
}
exports.buffer = buffer;
// Convenience function for constructing a Wggl instance
exports.default = (function (canvas, vertShader, fragShader) {
return new wggl_1.Wggl(canvas, vertShader, fragShader);
});
exports.QUAD2 = [-1, -1, 1, -1, -1, 1, 1, 1];
var shader_1 = require("./shader");
exports.vs = shader_1.vs;
exports.fs = shader_1.fs;