_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3 values | text stringlengths 52 373k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q23700 | TokenRequest | train | function TokenRequest(callContext, authenticationContext, clientId, resource, redirectUri) {
this._log = new Logger('TokenRequest', callContext._logContext);
this._callContext = callContext;
this._authenticationContext = authenticationContext;
this._resource = resource;
this._clientId = clientId;
this._redirectUri = redirectUri;
// This should be set at the beginning of getToken
// functions that have a userId.
this._userId = null;
this._userRealm = null;
this._pollingClient = {};
} | javascript | {
"resource": ""
} |
q23701 | UserRealm | train | function UserRealm(callContext, userPrinciple, authority) {
this._log = new Logger('UserRealm', callContext._logContext);
this._callContext = callContext;
this._apiVersion = '1.0';
this._federationProtocol = null;
this._accountType = null;
this._federationMetadataUrl = null;
this._federationActiveAuthUrl = null;
this._userPrinciple = userPrinciple;
this._authority = authority;
} | javascript | {
"resource": ""
} |
q23702 | WSTrustRequest | train | function WSTrustRequest(callContext, wstrustEndpointUrl, appliesTo, wstrustEndpointVersion) {
this._log = new Logger('WSTrustRequest', callContext._logContext);
this._callContext = callContext;
this._wstrustEndpointUrl = wstrustEndpointUrl;
this._appliesTo = appliesTo;
this._wstrustEndpointVersion = wstrustEndpointVersion;
} | javascript | {
"resource": ""
} |
q23703 | _datePlusMinutes | train | function _datePlusMinutes(date, minutes) {
var minutesInMilliSeconds = minutes * 60 * 1000;
var epochTime = date.getTime() + minutesInMilliSeconds;
return new Date(epochTime);
} | javascript | {
"resource": ""
} |
q23704 | createRequestOptions | train | function createRequestOptions(self, options) {
var defaultOptions = {}; //{ strictSSL : true };
var mergedOptions = defaultOptions;
if (options) {
_.extend(mergedOptions, options);
}
if (self._callContext.options && self._callContext.options.http) {
_.extend(mergedOptions, self._callContext.options.http);
}
addDefaultRequestHeaders(self, mergedOptions);
return mergedOptions;
} | javascript | {
"resource": ""
} |
q23705 | scrubRSTRLogMessage | train | function scrubRSTRLogMessage(RSTR) {
var scrubbedRSTR = null;
var singleLineRSTR = RSTR.replace(/(\r\n|\n|\r)/gm,'');
var matchResult = assertionRegEx.exec(singleLineRSTR);
if (null === matchResult) {
// No Assertion was matched so just return the RSTR as is.
scrubbedRSTR = singleLineRSTR;
} else {
var samlAssertion = matchResult[1];
var samlAssertionStartTag = matchResult[2];
scrubbedRSTR = singleLineRSTR.replace(samlAssertion, samlAssertionStartTag + 'ASSERTION CONTENTS REDACTED</saml:Assertion>');
}
return 'RSTR Response: ' + scrubbedRSTR;
} | javascript | {
"resource": ""
} |
q23706 | WSTrustResponse | train | function WSTrustResponse(callContext, response, wstrustVersion) {
this._log = new Logger('WSTrustResponse', callContext._logContext);
this._callContext = callContext;
this._response = response;
this._dom = null;
this._errorCode = null;
this._faultMessage = null;
this._tokenType = null;
this._token = null;
this._wstrustVersion = wstrustVersion;
this._log.verbose(function(){return scrubRSTRLogMessage(response);});
} | javascript | {
"resource": ""
} |
q23707 | CodeRequest | train | function CodeRequest(callContext, authenticationContext, clientId, resource) {
this._log = new Logger('DeviceCodeRequest', callContext._logContext);
this._callContext = callContext;
this._authenticationContext = authenticationContext;
this._resource = resource;
this._clientId = clientId;
// This should be set at the beginning of getToken
// functions that have a userId.
this._userId = null;
} | javascript | {
"resource": ""
} |
q23708 | Mex | train | function Mex(callContext, url) {
this._log = new Logger('MEX', callContext._logContext);
this._callContext = callContext;
this._url = url;
this._dom = null;
this._mexDoc = null;
this._usernamePasswordPolicy = {};
this._log.verbose('Mex created');
this._log.verbose('Mex created with url: ' + url, true);
} | javascript | {
"resource": ""
} |
q23709 | train | function(data, escapeHeaderValues) {
const onFrame = jasmine.createSpy('onFrame');
const onIncomingPing = jasmine.createSpy('onIncomingPing');
const parser = new StompJs.Parser(onFrame, onIncomingPing);
parser.parseChunk(data);
const rawFrame = onFrame.calls.first().args[0];
return StompJs.FrameImpl.fromRawFrame(rawFrame, escapeHeaderValues);
} | javascript | {
"resource": ""
} | |
q23710 | trap | train | function trap(opts) {
const { isTrapped: wasTrapped, restoreTrap } = this;
const isTrapped = this.isTrapped = this.state.open;
const isFirstRender = (opts && opts.firstRender);
const wasToggled = isTrapped !== wasTrapped;
const focusEl = (this.state.focus && document.getElementById(this.state.focus)) || this.closeEl;
if (restoreTrap || (isTrapped && !wasTrapped)) {
screenReaderTrap.trap(this.windowEl);
keyboardTrap.trap(this.windowEl);
}
// Ensure focus is set and body scroll prevented on initial render.
if (isFirstRender && isTrapped) {
focusEl.focus();
bodyScroll.prevent();
}
if (wasToggled) {
cancelAsync.call(this);
const onFinishTransition = () => {
this.cancelTransition = undefined;
if (isTrapped) {
focusEl.focus();
emitAndFire(this, 'dialog-show');
} else {
bodyScroll.restore();
emitAndFire(this, 'dialog-close');
// Reset dialog scroll position lazily to avoid jank.
// Note since the dialog is not in the dom at this point none of the scroll methods will work.
this.cancelScrollReset = setTimeout(() => {
this.dialogEl.parentNode.replaceChild(this.dialogEl, this.dialogEl);
this.cancelScrollReset = undefined;
}, 20);
}
};
if (isTrapped) {
if (!isFirstRender) {
bodyScroll.prevent();
this.cancelTransition = transition({
el: this.dialogEl,
className: 'dialog--show',
waitFor: this.transitionEls
}, onFinishTransition);
}
this.dialogEl.removeAttribute('hidden');
} else {
if (!isFirstRender) {
this.cancelTransition = transition({
el: this.dialogEl,
className: 'dialog--hide',
waitFor: this.transitionEls
}, onFinishTransition);
}
this.dialogEl.setAttribute('hidden', '');
}
}
} | javascript | {
"resource": ""
} |
q23711 | release | train | function release() {
if (this.isTrapped) {
this.restoreTrap = this.state.open;
screenReaderTrap.untrap(this.windowEl);
keyboardTrap.untrap(this.windowEl);
} else {
this.restoreTrap = false;
}
} | javascript | {
"resource": ""
} |
q23712 | handlePageClick | train | function handlePageClick(originalEvent) {
const target = originalEvent.target;
emitAndFire(this, 'pagination-select', {
originalEvent,
el: target,
value: target.innerText
});
} | javascript | {
"resource": ""
} |
q23713 | cancel | train | function cancel() {
if (ended) {
return;
}
ended = true;
for (let i = ran; i < pending; i++) {
const child = waitFor[i];
child.removeEventListener(TRANSITION_END, listener);
}
if (cancelFrame) {
cancelFrame();
classList.remove(initClass);
} else {
classList.remove(className);
}
} | javascript | {
"resource": ""
} |
q23714 | listener | train | function listener({ target }) {
target.removeEventListener(TRANSITION_END, listener);
if (++ran === pending) {
ended = true;
classList.remove(className);
if (cb) {
cb();
}
}
} | javascript | {
"resource": ""
} |
q23715 | nextFrame | train | function nextFrame(fn) {
let frame;
let cancelFrame;
if (window.requestAnimationFrame) {
frame = requestAnimationFrame(() => {
frame = requestAnimationFrame(fn);
});
cancelFrame = cancelAnimationFrame;
} else {
frame = setTimeout(fn, 26); // 16ms to simulate RAF, 10ms to ensure called after the frame.
cancelFrame = clearTimeout;
}
return () => {
if (frame) {
cancelFrame(frame);
frame = undefined;
}
};
} | javascript | {
"resource": ""
} |
q23716 | processHtmlAttributes | train | function processHtmlAttributes(input = {}) {
const attributes = {};
const htmlAttributes = input.htmlAttributes;
const wildcardAttributes = input['*'];
let obj = htmlAttributes || wildcardAttributes;
if (htmlAttributes && wildcardAttributes) {
obj = Object.assign(wildcardAttributes, htmlAttributes);
}
if (obj) {
Object.keys(obj).forEach((key) => {
attributes[camelToKebab(key)] = obj[key];
});
}
return attributes;
} | javascript | {
"resource": ""
} |
q23717 | emitAndFire | train | function emitAndFire(widget, eventName, eventArg) {
const originalEmit = widget.emit;
let event;
if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
event = new CustomEvent(eventName, { detail: eventArg });
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, true, true, eventArg);
}
widget.el.dispatchEvent(event);
originalEmit.call(widget, eventName, eventArg);
} | javascript | {
"resource": ""
} |
q23718 | processStateChange | train | function processStateChange(index) {
if (index >= 0 && index < this.state.headings.length && index !== this.state.index) {
this.setState('index', index);
emitAndFire(this, 'tab-select', { index });
}
} | javascript | {
"resource": ""
} |
q23719 | getHeadingEl | train | function getHeadingEl(e, isFake) {
let headingEl = e.target;
const headingClass = prefix(isFake, 'tabs__item');
while (!headingEl.classList.contains(headingClass)) {
headingEl = headingEl.parentNode;
}
return headingEl;
} | javascript | {
"resource": ""
} |
q23720 | getElementIndex | train | function getElementIndex(headingEl) {
return Array.prototype.slice.call(headingEl.parentNode.children).indexOf(headingEl);
} | javascript | {
"resource": ""
} |
q23721 | handleItemClick | train | function handleItemClick(e) {
let itemEl = e.target;
const parentEl = itemEl.closest('.menu__item, .fake-menu__item');
if (parentEl) { // nested click inside menu_item
itemEl = parentEl;
}
this.setCheckedItem(getItemElementIndex(itemEl), true);
} | javascript | {
"resource": ""
} |
q23722 | setCheckedItem | train | function setCheckedItem(itemIndex, toggle) {
const item = this.state.items[itemIndex];
if (item) {
if (this.state.isCheckbox && !toggle) {
item.checked = true;
} else if (this.state.isCheckbox && toggle) {
item.checked = !item.checked;
} else if (this.state.isRadio) {
this.state.items[itemIndex].checked = true;
}
if (this.state.isCheckbox || this.state.isRadio) {
this.setStateDirty('items');
}
if (this.state.isRadio || toggle) {
this.processAfterStateChange([itemIndex]);
}
}
} | javascript | {
"resource": ""
} |
q23723 | setCheckedList | train | function setCheckedList(indexArray) {
if (indexArray) {
this.state.items.forEach((item) => {
item.checked = false;
});
indexArray.forEach((index) => {
this.setCheckedItem(index);
});
this.processAfterStateChange(indexArray);
}
} | javascript | {
"resource": ""
} |
q23724 | transform | train | function transform(el, context) {
// Only runs on top level ebay ui templates (skips demos).
const isEbayUIComponentFile = COMPONENT_FILES.indexOf(context.filename) !== -1;
if (isEbayUIComponentFile && el.hasAttribute('w-bind')) {
el.setAttributeValue('data-ebayui', context.builder.literal(true));
}
} | javascript | {
"resource": ""
} |
q23725 | handleMove | train | function handleMove(originalEvent, target) {
if (this.isMoving) {
return;
}
const { state } = this;
const direction = parseInt(target.getAttribute('data-direction'), 10);
const nextIndex = this.move(direction);
const slide = getSlide(state, nextIndex);
emitAndFire(this, 'carousel-slide', { slide: slide + 1, originalEvent });
emitAndFire(this, `carousel-${direction === 1 ? 'next' : 'previous'}`, { originalEvent });
} | javascript | {
"resource": ""
} |
q23726 | handleDotClick | train | function handleDotClick(originalEvent, target) {
if (this.isMoving) {
return;
}
const { state: { config, itemsPerSlide } } = this;
const slide = parseInt(target.getAttribute('data-slide'), 10);
config.preserveItems = true;
this.setState('index', slide * itemsPerSlide);
emitAndFire(this, 'carousel-slide', { slide: slide + 1, originalEvent });
} | javascript | {
"resource": ""
} |
q23727 | togglePlay | train | function togglePlay(originalEvent) {
const { state: { config, paused } } = this;
config.preserveItems = true;
this.setState('paused', !paused);
if (paused && !this.isMoving) {
this.move(RIGHT);
}
emitAndFire(this, `carousel-${paused ? 'play' : 'pause'}`, { originalEvent });
} | javascript | {
"resource": ""
} |
q23728 | handleScroll | train | function handleScroll(scrollLeft) {
const { state } = this;
const { config, items, gap } = state;
let closest;
if (scrollLeft >= getMaxOffset(state) - gap) {
closest = items.length - 1;
} else {
// Find the closest item using a binary search on each carousel slide.
const itemsPerSlide = state.itemsPerSlide || 1;
const totalItems = items.length;
let low = 0;
let high = Math.ceil(totalItems / itemsPerSlide) - 1;
while (high - low > 1) {
const mid = Math.floor((low + high) / 2);
if (scrollLeft > items[mid * itemsPerSlide].left) {
low = mid;
} else {
high = mid;
}
}
const deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
const deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
closest = normalizeIndex(state, (deltaLow > deltaHigh ? high : low) * itemsPerSlide);
}
if (state.index !== closest) {
config.skipScrolling = true;
config.preserveItems = true;
this.setState('index', closest);
emitAndFire(this, 'carousel-scroll', { index: closest });
}
} | javascript | {
"resource": ""
} |
q23729 | move | train | function move(delta) {
const { state } = this;
const { index, items, itemsPerSlide, autoplayInterval, slideWidth, gap, peek, config } = state;
const nextIndex = getNextIndex(state, delta);
let offsetOverride;
config.preserveItems = true;
this.isMoving = true;
// When we are in autoplay mode we overshoot the desired index to land on a clone
// of one of the ends. Then after the transition is over we update to the proper position.
if (autoplayInterval) {
if (delta === RIGHT && nextIndex < index) {
// Transitions to one slide before the beginning.
offsetOverride = -slideWidth - gap;
// Move the items in the last slide to be before the first slide.
for (let i = Math.ceil(itemsPerSlide + peek); i--;) {
const item = items[items.length - i - 1];
item.transform = `translateX(${(getMaxOffset(state) + slideWidth + gap) * -1}px)`;
}
} else if (delta === LEFT && nextIndex > index) {
// Transitions one slide past the end.
offsetOverride = getMaxOffset(state) + slideWidth + gap;
// Moves the items in the first slide to be after the last slide.
for (let i = Math.ceil(itemsPerSlide + peek); i--;) {
const item = items[i];
item.transform = `translateX(${(getMaxOffset(state) + slideWidth + gap)}px)`;
}
}
config.offsetOverride = offsetOverride;
}
this.setState('index', nextIndex);
this.once('carousel-update', () => {
this.isMoving = false;
if (offsetOverride !== undefined) {
// If we are in autoplay mode and went outside of the normal offset
// We make sure to restore all of the items that got moved around.
items.forEach(item => { item.transform = undefined; });
}
});
return nextIndex;
} | javascript | {
"resource": ""
} |
q23730 | getOffset | train | function getOffset(state) {
const { items, index } = state;
if (!items.length) {
return 0;
}
return Math.min(items[index].left, getMaxOffset(state)) || 0;
} | javascript | {
"resource": ""
} |
q23731 | getMaxOffset | train | function getMaxOffset({ items, slideWidth }) {
if (!items.length) {
return 0;
}
return Math.max(items[items.length - 1].right - slideWidth, 0) || 0;
} | javascript | {
"resource": ""
} |
q23732 | getSlide | train | function getSlide({ index, itemsPerSlide }, i = index) {
if (!itemsPerSlide) {
return;
}
return Math.ceil(i / itemsPerSlide);
} | javascript | {
"resource": ""
} |
q23733 | normalizeIndex | train | function normalizeIndex({ items, itemsPerSlide }, index) {
let result = index;
result %= items.length || 1; // Ensure index is within bounds.
result -= result % (itemsPerSlide || 1); // Round index to the nearest valid slide index.
result = Math.abs(result); // Ensure positive value.
return result;
} | javascript | {
"resource": ""
} |
q23734 | getNextIndex | train | function getNextIndex(state, delta) {
const { index, items, slideWidth, itemsPerSlide } = state;
let i = index;
let item;
// If going backward from 0, we go to the end.
if (delta === LEFT && i === 0) {
i = items.length - 1;
} else {
// Find the index of the next item that is not fully in view.
do {
item = items[i += delta];
} while (item && item.fullyVisible);
if (delta === LEFT && !itemsPerSlide) {
// If going left without items per slide, go as far left as possible while keeping this item fully in view.
const targetOffset = item.right - slideWidth;
do {
item = items[--i];
} while (item && item.left >= targetOffset);
i += 1;
}
}
return normalizeIndex(state, i);
} | javascript | {
"resource": ""
} |
q23735 | forEls | train | function forEls(parent, fn) {
let i = 0;
let child = parent.firstElementChild;
while (child) {
fn(child, i++);
child = child.nextElementSibling;
}
} | javascript | {
"resource": ""
} |
q23736 | observeRoot | train | function observeRoot(widget, attributes, callback, skipSetState) {
attributes.forEach(attribute => {
Object.defineProperty(widget.el, attribute, {
get() {
return widget.state[attribute];
},
set(value) {
if (!skipSetState) {
widget.setState(attribute, value);
}
if (callback) {
callback(value);
}
}
});
});
} | javascript | {
"resource": ""
} |
q23737 | observeInner | train | function observeInner(widget, el, attribute, path, dirtyPath, callback) {
Object.defineProperty(el, attribute, {
get() {
return _get(widget.state, `${path}.${attribute}`);
},
set(value) {
_set(widget.state, `${path}.${attribute}`, value);
if (dirtyPath) {
widget.setStateDirty(dirtyPath);
}
callback(el);
}
});
} | javascript | {
"resource": ""
} |
q23738 | scroll | train | function scroll(el) {
if (!el) {
return;
}
const parentEl = el && el.parentElement;
const offsetBottom = el.offsetTop + el.offsetHeight;
const scrollBottom = parentEl.scrollTop + parentEl.offsetHeight;
if (el.offsetTop < parentEl.scrollTop) {
parentEl.scrollTop = el.offsetTop;
} else if (offsetBottom > scrollBottom) {
parentEl.scrollTop = offsetBottom - parentEl.offsetHeight;
}
} | javascript | {
"resource": ""
} |
q23739 | handleKeydown | train | function handleKeydown(keyCodes, e, callback) {
const keyCode = e.charCode || e.keyCode;
if (keyCodes.indexOf(keyCode) !== -1) {
callback();
}
} | javascript | {
"resource": ""
} |
q23740 | handleNotKeydown | train | function handleNotKeydown(keyCodes, e, callback) {
const keyCode = e.charCode || e.keyCode;
if (keyCodes.indexOf(keyCode) === -1) {
callback();
}
} | javascript | {
"resource": ""
} |
q23741 | isDirectory | train | function isDirectory(obj) {
return obj.sources.every(path => {
try {
return fs.lstatSync(path).isDirectory();
} catch (e) {
return false;
}
});
} | javascript | {
"resource": ""
} |
q23742 | handleOptionClick | train | function handleOptionClick(event) {
let el;
// find the element with the data
// start with the target element
if (event.target.dataset.optionValue) {
el = event.target;
// check up the tree one level (in case option text or status was clicked)
} else if (event.target.parentNode.dataset.optionValue) {
el = event.target.parentNode;
}
this.processAfterStateChange(el);
this.expander.collapse();
this.el.querySelector(comboboxHostSelector).focus();
} | javascript | {
"resource": ""
} |
q23743 | handleChannelConvertedEvent | train | function handleChannelConvertedEvent(msg) {
return (dispatch, getState) => {
const channelId = msg.data.channel_id;
if (channelId) {
const channel = getChannel(getState(), channelId);
if (channel) {
dispatch({
type: ChannelTypes.RECEIVED_CHANNEL,
data: {...channel, type: General.PRIVATE_CHANNEL},
});
}
}
};
} | javascript | {
"resource": ""
} |
q23744 | plural | train | function plural(ms, msAbs, n, name) {
var isPlural = msAbs >= n * 1.5;
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
} | javascript | {
"resource": ""
} |
q23745 | getNativeConstructorFromType | train | function getNativeConstructorFromType(type) {
return {
string: String,
boolean: Boolean,
array: Array,
function: Function,
int: Number,
serverapi: Object,
object: Object
}[type];
} | javascript | {
"resource": ""
} |
q23746 | copyExistingProperties | train | function copyExistingProperties(src, dst) {
Object.keys(dst).forEach(function(key) {
if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
dst[key] = src[key];
}
});
} | javascript | {
"resource": ""
} |
q23747 | setDefaults | train | function setDefaults(newDefaults) {
helper.copyExistingProperties(newDefaults, defaults);
attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line
textures.setTextureDefaults_(newDefaults); // eslint-disable-line
} | javascript | {
"resource": ""
} |
q23748 | addExtensionsToContext | train | function addExtensionsToContext(gl) {
for (let ii = 0; ii < supportedExtensions.length; ++ii) {
addExtensionToContext(gl, supportedExtensions[ii]);
}
} | javascript | {
"resource": ""
} |
q23749 | createContext | train | function createContext(canvas, opt_attribs) {
const names = ["webgl2", "webgl", "experimental-webgl"];
let context = null;
for (let ii = 0; ii < names.length; ++ii) {
context = canvas.getContext(names[ii], opt_attribs);
if (context) {
if (defaults.addExtensionsToContext) {
addExtensionsToContext(context);
}
break;
}
}
return context;
} | javascript | {
"resource": ""
} |
q23750 | drawBufferInfo | train | function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
type = type === undefined ? gl.TRIANGLES : type;
const indices = bufferInfo.indices;
const elementType = bufferInfo.elementType;
const numElements = count === undefined ? bufferInfo.numElements : count;
offset = offset === undefined ? 0 : offset;
if (elementType || indices) {
if (instanceCount !== undefined) {
gl.drawElementsInstanced(type, numElements, elementType === undefined ? gl.UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
} else {
gl.drawElements(type, numElements, elementType === undefined ? gl.UNSIGNED_SHORT : bufferInfo.elementType, offset);
}
} else {
if (instanceCount !== undefined) {
gl.drawArraysInstanced(type, offset, numElements, instanceCount);
} else {
gl.drawArrays(type, offset, numElements);
}
}
} | javascript | {
"resource": ""
} |
q23751 | getGLTypeForTypedArray | train | function getGLTypeForTypedArray(typedArray) {
if (typedArray instanceof Int8Array) { return BYTE; } // eslint-disable-line
if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArray instanceof Int16Array) { return SHORT; } // eslint-disable-line
if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
if (typedArray instanceof Int32Array) { return INT; } // eslint-disable-line
if (typedArray instanceof Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
if (typedArray instanceof Float32Array) { return FLOAT; } // eslint-disable-line
throw "unsupported typed array type";
} | javascript | {
"resource": ""
} |
q23752 | getGLTypeForTypedArrayType | train | function getGLTypeForTypedArrayType(typedArrayType) {
if (typedArrayType === Int8Array) { return BYTE; } // eslint-disable-line
if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArrayType === Int16Array) { return SHORT; } // eslint-disable-line
if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
if (typedArrayType === Int32Array) { return INT; } // eslint-disable-line
if (typedArrayType === Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
if (typedArrayType === Float32Array) { return FLOAT; } // eslint-disable-line
throw "unsupported typed array type";
} | javascript | {
"resource": ""
} |
q23753 | negate | train | function negate(m, dst) {
dst = dst || new MatType(16);
dst[ 0] = -m[ 0];
dst[ 1] = -m[ 1];
dst[ 2] = -m[ 2];
dst[ 3] = -m[ 3];
dst[ 4] = -m[ 4];
dst[ 5] = -m[ 5];
dst[ 6] = -m[ 6];
dst[ 7] = -m[ 7];
dst[ 8] = -m[ 8];
dst[ 9] = -m[ 9];
dst[10] = -m[10];
dst[11] = -m[11];
dst[12] = -m[12];
dst[13] = -m[13];
dst[14] = -m[14];
dst[15] = -m[15];
return dst;
} | javascript | {
"resource": ""
} |
q23754 | copy | train | function copy(m, dst) {
dst = dst || new MatType(16);
dst[ 0] = m[ 0];
dst[ 1] = m[ 1];
dst[ 2] = m[ 2];
dst[ 3] = m[ 3];
dst[ 4] = m[ 4];
dst[ 5] = m[ 5];
dst[ 6] = m[ 6];
dst[ 7] = m[ 7];
dst[ 8] = m[ 8];
dst[ 9] = m[ 9];
dst[10] = m[10];
dst[11] = m[11];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
return dst;
} | javascript | {
"resource": ""
} |
q23755 | identity | train | function identity(dst) {
dst = dst || new MatType(16);
dst[ 0] = 1;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 1;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23756 | transpose | train | function transpose(m, dst) {
dst = dst || new MatType(16);
if (dst === m) {
let t;
t = m[1];
m[1] = m[4];
m[4] = t;
t = m[2];
m[2] = m[8];
m[8] = t;
t = m[3];
m[3] = m[12];
m[12] = t;
t = m[6];
m[6] = m[9];
m[9] = t;
t = m[7];
m[7] = m[13];
m[13] = t;
t = m[11];
m[11] = m[14];
m[14] = t;
return dst;
}
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const m30 = m[3 * 4 + 0];
const m31 = m[3 * 4 + 1];
const m32 = m[3 * 4 + 2];
const m33 = m[3 * 4 + 3];
dst[ 0] = m00;
dst[ 1] = m10;
dst[ 2] = m20;
dst[ 3] = m30;
dst[ 4] = m01;
dst[ 5] = m11;
dst[ 6] = m21;
dst[ 7] = m31;
dst[ 8] = m02;
dst[ 9] = m12;
dst[10] = m22;
dst[11] = m32;
dst[12] = m03;
dst[13] = m13;
dst[14] = m23;
dst[15] = m33;
return dst;
} | javascript | {
"resource": ""
} |
q23757 | setTranslation | train | function setTranslation(a, v, dst) {
dst = dst || identity();
if (a !== dst) {
dst[ 0] = a[ 0];
dst[ 1] = a[ 1];
dst[ 2] = a[ 2];
dst[ 3] = a[ 3];
dst[ 4] = a[ 4];
dst[ 5] = a[ 5];
dst[ 6] = a[ 6];
dst[ 7] = a[ 7];
dst[ 8] = a[ 8];
dst[ 9] = a[ 9];
dst[10] = a[10];
dst[11] = a[11];
}
dst[12] = v[0];
dst[13] = v[1];
dst[14] = v[2];
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23758 | getTranslation | train | function getTranslation(m, dst) {
dst = dst || v3.create();
dst[0] = m[12];
dst[1] = m[13];
dst[2] = m[14];
return dst;
} | javascript | {
"resource": ""
} |
q23759 | getAxis | train | function getAxis(m, axis, dst) {
dst = dst || v3.create();
const off = axis * 4;
dst[0] = m[off + 0];
dst[1] = m[off + 1];
dst[2] = m[off + 2];
return dst;
} | javascript | {
"resource": ""
} |
q23760 | setAxis | train | function setAxis(a, v, axis, dst) {
if (dst !== a) {
dst = copy(a, dst);
}
const off = axis * 4;
dst[off + 0] = v[0];
dst[off + 1] = v[1];
dst[off + 2] = v[2];
return dst;
} | javascript | {
"resource": ""
} |
q23761 | perspective | train | function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {
dst = dst || new MatType(16);
const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);
const rangeInv = 1.0 / (zNear - zFar);
dst[0] = f / aspect;
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
dst[4] = 0;
dst[5] = f;
dst[6] = 0;
dst[7] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = (zNear + zFar) * rangeInv;
dst[11] = -1;
dst[12] = 0;
dst[13] = 0;
dst[14] = zNear * zFar * rangeInv * 2;
dst[15] = 0;
return dst;
} | javascript | {
"resource": ""
} |
q23762 | ortho | train | function ortho(left, right, bottom, top, near, far, dst) {
dst = dst || new MatType(16);
dst[0] = 2 / (right - left);
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
dst[4] = 0;
dst[5] = 2 / (top - bottom);
dst[6] = 0;
dst[7] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 2 / (near - far);
dst[11] = 0;
dst[12] = (right + left) / (left - right);
dst[13] = (top + bottom) / (bottom - top);
dst[14] = (far + near) / (near - far);
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23763 | frustum | train | function frustum(left, right, bottom, top, near, far, dst) {
dst = dst || new MatType(16);
const dx = (right - left);
const dy = (top - bottom);
const dz = (near - far);
dst[ 0] = 2 * near / dx;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 2 * near / dy;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = (left + right) / dx;
dst[ 9] = (top + bottom) / dy;
dst[10] = far / dz;
dst[11] = -1;
dst[12] = 0;
dst[13] = 0;
dst[14] = near * far / dz;
dst[15] = 0;
return dst;
} | javascript | {
"resource": ""
} |
q23764 | lookAt | train | function lookAt(eye, target, up, dst) {
dst = dst || new MatType(16);
const xAxis = tempV3a;
const yAxis = tempV3b;
const zAxis = tempV3c;
v3.normalize(
v3.subtract(eye, target, zAxis), zAxis);
v3.normalize(v3.cross(up, zAxis, xAxis), xAxis);
v3.normalize(v3.cross(zAxis, xAxis, yAxis), yAxis);
dst[ 0] = xAxis[0];
dst[ 1] = xAxis[1];
dst[ 2] = xAxis[2];
dst[ 3] = 0;
dst[ 4] = yAxis[0];
dst[ 5] = yAxis[1];
dst[ 6] = yAxis[2];
dst[ 7] = 0;
dst[ 8] = zAxis[0];
dst[ 9] = zAxis[1];
dst[10] = zAxis[2];
dst[11] = 0;
dst[12] = eye[0];
dst[13] = eye[1];
dst[14] = eye[2];
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23765 | translation | train | function translation(v, dst) {
dst = dst || new MatType(16);
dst[ 0] = 1;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 1;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = v[0];
dst[13] = v[1];
dst[14] = v[2];
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23766 | translate | train | function translate(m, v, dst) {
dst = dst || new MatType(16);
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
const m00 = m[0];
const m01 = m[1];
const m02 = m[2];
const m03 = m[3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const m30 = m[3 * 4 + 0];
const m31 = m[3 * 4 + 1];
const m32 = m[3 * 4 + 2];
const m33 = m[3 * 4 + 3];
if (m !== dst) {
dst[ 0] = m00;
dst[ 1] = m01;
dst[ 2] = m02;
dst[ 3] = m03;
dst[ 4] = m10;
dst[ 5] = m11;
dst[ 6] = m12;
dst[ 7] = m13;
dst[ 8] = m20;
dst[ 9] = m21;
dst[10] = m22;
dst[11] = m23;
}
dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;
dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;
dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;
dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;
return dst;
} | javascript | {
"resource": ""
} |
q23767 | rotateX | train | function rotateX(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m10 = m[4];
const m11 = m[5];
const m12 = m[6];
const m13 = m[7];
const m20 = m[8];
const m21 = m[9];
const m22 = m[10];
const m23 = m[11];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[4] = c * m10 + s * m20;
dst[5] = c * m11 + s * m21;
dst[6] = c * m12 + s * m22;
dst[7] = c * m13 + s * m23;
dst[8] = c * m20 - s * m10;
dst[9] = c * m21 - s * m11;
dst[10] = c * m22 - s * m12;
dst[11] = c * m23 - s * m13;
if (m !== dst) {
dst[ 0] = m[ 0];
dst[ 1] = m[ 1];
dst[ 2] = m[ 2];
dst[ 3] = m[ 3];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | {
"resource": ""
} |
q23768 | rotateY | train | function rotateY(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c * m00 - s * m20;
dst[ 1] = c * m01 - s * m21;
dst[ 2] = c * m02 - s * m22;
dst[ 3] = c * m03 - s * m23;
dst[ 8] = c * m20 + s * m00;
dst[ 9] = c * m21 + s * m01;
dst[10] = c * m22 + s * m02;
dst[11] = c * m23 + s * m03;
if (m !== dst) {
dst[ 4] = m[ 4];
dst[ 5] = m[ 5];
dst[ 6] = m[ 6];
dst[ 7] = m[ 7];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | {
"resource": ""
} |
q23769 | rotationZ | train | function rotationZ(angleInRadians, dst) {
dst = dst || new MatType(16);
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c;
dst[ 1] = s;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = -s;
dst[ 5] = c;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23770 | rotateZ | train | function rotateZ(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c * m00 + s * m10;
dst[ 1] = c * m01 + s * m11;
dst[ 2] = c * m02 + s * m12;
dst[ 3] = c * m03 + s * m13;
dst[ 4] = c * m10 - s * m00;
dst[ 5] = c * m11 - s * m01;
dst[ 6] = c * m12 - s * m02;
dst[ 7] = c * m13 - s * m03;
if (m !== dst) {
dst[ 8] = m[ 8];
dst[ 9] = m[ 9];
dst[10] = m[10];
dst[11] = m[11];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | {
"resource": ""
} |
q23771 | axisRotation | train | function axisRotation(axis, angleInRadians, dst) {
dst = dst || new MatType(16);
let x = axis[0];
let y = axis[1];
let z = axis[2];
const n = Math.sqrt(x * x + y * y + z * z);
x /= n;
y /= n;
z /= n;
const xx = x * x;
const yy = y * y;
const zz = z * z;
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
const oneMinusCosine = 1 - c;
dst[ 0] = xx + (1 - xx) * c;
dst[ 1] = x * y * oneMinusCosine + z * s;
dst[ 2] = x * z * oneMinusCosine - y * s;
dst[ 3] = 0;
dst[ 4] = x * y * oneMinusCosine - z * s;
dst[ 5] = yy + (1 - yy) * c;
dst[ 6] = y * z * oneMinusCosine + x * s;
dst[ 7] = 0;
dst[ 8] = x * z * oneMinusCosine + y * s;
dst[ 9] = y * z * oneMinusCosine - x * s;
dst[10] = zz + (1 - zz) * c;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23772 | scaling | train | function scaling(v, dst) {
dst = dst || new MatType(16);
dst[ 0] = v[0];
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = v[1];
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = v[2];
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | {
"resource": ""
} |
q23773 | scale | train | function scale(m, v, dst) {
dst = dst || new MatType(16);
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
dst[ 0] = v0 * m[0 * 4 + 0];
dst[ 1] = v0 * m[0 * 4 + 1];
dst[ 2] = v0 * m[0 * 4 + 2];
dst[ 3] = v0 * m[0 * 4 + 3];
dst[ 4] = v1 * m[1 * 4 + 0];
dst[ 5] = v1 * m[1 * 4 + 1];
dst[ 6] = v1 * m[1 * 4 + 2];
dst[ 7] = v1 * m[1 * 4 + 3];
dst[ 8] = v2 * m[2 * 4 + 0];
dst[ 9] = v2 * m[2 * 4 + 1];
dst[10] = v2 * m[2 * 4 + 2];
dst[11] = v2 * m[2 * 4 + 3];
if (m !== dst) {
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | {
"resource": ""
} |
q23774 | transformPoint | train | function transformPoint(m, v, dst) {
dst = dst || v3.create();
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
const d = v0 * m[0 * 4 + 3] + v1 * m[1 * 4 + 3] + v2 * m[2 * 4 + 3] + m[3 * 4 + 3];
dst[0] = (v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0] + m[3 * 4 + 0]) / d;
dst[1] = (v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1] + m[3 * 4 + 1]) / d;
dst[2] = (v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2] + m[3 * 4 + 2]) / d;
return dst;
} | javascript | {
"resource": ""
} |
q23775 | transformDirection | train | function transformDirection(m, v, dst) {
dst = dst || v3.create();
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];
dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];
dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];
return dst;
} | javascript | {
"resource": ""
} |
q23776 | createBufferFromTypedArray | train | function createBufferFromTypedArray(gl, typedArray, type, drawType) {
if (helper.isBuffer(gl, typedArray)) {
return typedArray;
}
type = type || gl.ARRAY_BUFFER;
const buffer = gl.createBuffer();
setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
return buffer;
} | javascript | {
"resource": ""
} |
q23777 | setAttribInfoBufferFromArray | train | function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
array = makeTypedArray(array);
if (offset !== undefined) {
gl.bindBuffer(gl.ARRAY_BUFFER, attribInfo.buffer);
gl.bufferSubData(gl.ARRAY_BUFFER, offset, array);
} else {
setBufferFromTypedArray(gl, gl.ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
}
} | javascript | {
"resource": ""
} |
q23778 | createBufferFromArray | train | function createBufferFromArray(gl, array, arrayName) {
const type = arrayName === "indices" ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
const typedArray = makeTypedArray(array, arrayName);
return createBufferFromTypedArray(gl, typedArray, type);
} | javascript | {
"resource": ""
} |
q23779 | createBuffersFromArrays | train | function createBuffersFromArrays(gl, arrays) {
const buffers = { };
Object.keys(arrays).forEach(function(key) {
buffers[key] = createBufferFromArray(gl, arrays[key], key);
});
// Ugh!
if (arrays.indices) {
buffers.numElements = arrays.indices.length;
buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');
} else {
buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
}
return buffers;
} | javascript | {
"resource": ""
} |
q23780 | addLineNumbers | train | function addLineNumbers(src, lineOffset) {
lineOffset = lineOffset || 0;
++lineOffset;
return src.split("\n").map(function(line, ndx) {
return (ndx + lineOffset) + ": " + line;
}).join("\n");
} | javascript | {
"resource": ""
} |
q23781 | loadShader | train | function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
const errFn = opt_errorCallback || error;
// Create the shader object
const shader = gl.createShader(shaderType);
// Remove the first end of line because WebGL 2.0 requires
// #version 300 es
// as the first line. No whitespace allowed before that line
// so
//
// <script>
// #version 300 es
// </script>
//
// Has one line before it which is invalid according to GLSL ES 3.00
//
let lineOffset = 0;
if (spaceRE.test(shaderSource)) {
lineOffset = 1;
shaderSource = shaderSource.replace(spaceRE, '');
}
// Load the shader source
gl.shaderSource(shader, shaderSource);
// Compile the shader
gl.compileShader(shader);
// Check the compile status
const compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
if (!compiled) {
// Something went wrong during compilation; get the error
const lastError = gl.getShaderInfoLog(shader);
errFn(addLineNumbers(shaderSource, lineOffset) + "\n*** Error compiling shader: " + lastError);
gl.deleteShader(shader);
return null;
}
return shader;
} | javascript | {
"resource": ""
} |
q23782 | createUniformSetters | train | function createUniformSetters(gl, program) {
let textureUnit = 0;
/**
* Creates a setter for a uniform of the given program with it's
* location embedded in the setter.
* @param {WebGLProgram} program
* @param {WebGLUniformInfo} uniformInfo
* @returns {function} the created setter.
*/
function createUniformSetter(program, uniformInfo) {
const location = gl.getUniformLocation(program, uniformInfo.name);
const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]");
const type = uniformInfo.type;
const typeInfo = typeMap[type];
if (!typeInfo) {
throw ("unknown type: 0x" + type.toString(16)); // we should never get here.
}
let setter;
if (typeInfo.bindPoint) {
// it's a sampler
const unit = textureUnit;
textureUnit += uniformInfo.size;
if (isArray) {
setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
} else {
setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
}
} else {
if (typeInfo.arraySetter && isArray) {
setter = typeInfo.arraySetter(gl, location);
} else {
setter = typeInfo.setter(gl, location);
}
}
setter.location = location;
return setter;
}
const uniformSetters = { };
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
for (let ii = 0; ii < numUniforms; ++ii) {
const uniformInfo = gl.getActiveUniform(program, ii);
if (isBuiltIn(uniformInfo)) {
continue;
}
let name = uniformInfo.name;
// remove the array suffix.
if (name.substr(-3) === "[0]") {
name = name.substr(0, name.length - 3);
}
const setter = createUniformSetter(program, uniformInfo);
uniformSetters[name] = setter;
}
return uniformSetters;
} | javascript | {
"resource": ""
} |
q23783 | createUniformSetter | train | function createUniformSetter(program, uniformInfo) {
const location = gl.getUniformLocation(program, uniformInfo.name);
const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]");
const type = uniformInfo.type;
const typeInfo = typeMap[type];
if (!typeInfo) {
throw ("unknown type: 0x" + type.toString(16)); // we should never get here.
}
let setter;
if (typeInfo.bindPoint) {
// it's a sampler
const unit = textureUnit;
textureUnit += uniformInfo.size;
if (isArray) {
setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
} else {
setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
}
} else {
if (typeInfo.arraySetter && isArray) {
setter = typeInfo.arraySetter(gl, location);
} else {
setter = typeInfo.setter(gl, location);
}
}
setter.location = location;
return setter;
} | javascript | {
"resource": ""
} |
q23784 | bindTransformFeedbackInfo | train | function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
if (transformFeedbackInfo.transformFeedbackInfo) {
transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;
}
if (bufferInfo.attribs) {
bufferInfo = bufferInfo.attribs;
}
for (const name in bufferInfo) {
const varying = transformFeedbackInfo[name];
if (varying) {
const buf = bufferInfo[name];
if (buf.offset) {
gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);
} else {
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer);
}
}
}
} | javascript | {
"resource": ""
} |
q23785 | createTransformFeedback | train | function createTransformFeedback(gl, programInfo, bufferInfo) {
const tf = gl.createTransformFeedback();
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf);
gl.useProgram(programInfo.program);
bindTransformFeedbackInfo(gl, programInfo, bufferInfo);
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
return tf;
} | javascript | {
"resource": ""
} |
q23786 | createUniformBlockSpecFromProgram | train | function createUniformBlockSpecFromProgram(gl, program) {
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
const uniformData = [];
const uniformIndices = [];
for (let ii = 0; ii < numUniforms; ++ii) {
uniformIndices.push(ii);
uniformData.push({});
const uniformInfo = gl.getActiveUniform(program, ii);
if (isBuiltIn(uniformInfo)) {
break;
}
// REMOVE [0]?
uniformData[ii].name = uniformInfo.name;
}
[
[ "UNIFORM_TYPE", "type" ],
[ "UNIFORM_SIZE", "size" ], // num elements
[ "UNIFORM_BLOCK_INDEX", "blockNdx" ],
[ "UNIFORM_OFFSET", "offset", ],
].forEach(function(pair) {
const pname = pair[0];
const key = pair[1];
gl.getActiveUniforms(program, uniformIndices, gl[pname]).forEach(function(value, ndx) {
uniformData[ndx][key] = value;
});
});
const blockSpecs = {};
const numUniformBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
for (let ii = 0; ii < numUniformBlocks; ++ii) {
const name = gl.getActiveUniformBlockName(program, ii);
const blockSpec = {
index: ii,
usedByVertexShader: gl.getActiveUniformBlockParameter(program, ii, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
usedByFragmentShader: gl.getActiveUniformBlockParameter(program, ii, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
size: gl.getActiveUniformBlockParameter(program, ii, gl.UNIFORM_BLOCK_DATA_SIZE),
uniformIndices: gl.getActiveUniformBlockParameter(program, ii, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),
};
blockSpec.used = blockSpec.usedByVertexSahder || blockSpec.usedByFragmentShader;
blockSpecs[name] = blockSpec;
}
return {
blockSpecs: blockSpecs,
uniformData: uniformData,
};
} | javascript | {
"resource": ""
} |
q23787 | createUniformBlockInfoFromProgram | train | function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
const blockSpecs = uniformBlockSpec.blockSpecs;
const uniformData = uniformBlockSpec.uniformData;
const blockSpec = blockSpecs[blockName];
if (!blockSpec) {
warn("no uniform block object named:", blockName);
return {
name: blockName,
uniforms: {},
};
}
const array = new ArrayBuffer(blockSpec.size);
const buffer = gl.createBuffer();
const uniformBufferIndex = blockSpec.index;
gl.bindBuffer(gl.UNIFORM_BUFFER, buffer);
gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
let prefix = blockName + ".";
if (arraySuffixRE.test(prefix)) {
prefix = prefix.replace(arraySuffixRE, ".");
}
const uniforms = {};
blockSpec.uniformIndices.forEach(function(uniformNdx) {
const data = uniformData[uniformNdx];
const typeInfo = typeMap[data.type];
const Type = typeInfo.Type;
const length = data.size * typeInfo.size;
let name = data.name;
if (name.substr(0, prefix.length) === prefix) {
name = name.substr(prefix.length);
}
uniforms[name] = new Type(array, data.offset, length / Type.BYTES_PER_ELEMENT);
});
return {
name: blockName,
array: array,
asFloat: new Float32Array(array), // for debugging
buffer: buffer,
uniforms: uniforms,
};
} | javascript | {
"resource": ""
} |
q23788 | createUniformBlockInfo | train | function createUniformBlockInfo(gl, programInfo, blockName) {
return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
} | javascript | {
"resource": ""
} |
q23789 | bindUniformBlock | train | function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
const uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
const blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
if (blockSpec) {
const bufferBindIndex = blockSpec.index;
gl.bindBufferRange(gl.UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
return true;
}
return false;
} | javascript | {
"resource": ""
} |
q23790 | setUniformBlock | train | function setUniformBlock(gl, programInfo, uniformBlockInfo) {
if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
gl.bufferData(gl.UNIFORM_BUFFER, uniformBlockInfo.array, gl.DYNAMIC_DRAW);
}
} | javascript | {
"resource": ""
} |
q23791 | setBlockUniforms | train | function setBlockUniforms(uniformBlockInfo, values) {
const uniforms = uniformBlockInfo.uniforms;
for (const name in values) {
const array = uniforms[name];
if (array) {
const value = values[name];
if (value.length) {
array.set(value);
} else {
array[0] = value;
}
}
}
} | javascript | {
"resource": ""
} |
q23792 | createProgramInfo | train | function createProgramInfo(
gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
let good = true;
shaderSources = shaderSources.map(function(source) {
// Lets assume if there is no \n it's an id
if (source.indexOf("\n") < 0) {
const script = getElementById(source);
if (!script) {
progOptions.errorCallback("no element with id: " + source);
good = false;
} else {
source = script.text;
}
}
return source;
});
if (!good) {
return null;
}
const program = createProgramFromSources(gl, shaderSources, progOptions);
if (!program) {
return null;
}
return createProgramInfoFromProgram(gl, program);
} | javascript | {
"resource": ""
} |
q23793 | canGenerateMipmap | train | function canGenerateMipmap(gl, width, height, internalFormat /*, type */) {
if (!utils.isWebGL2(gl)) {
return isPowerOf2(width) && isPowerOf2(height);
}
const info = textureInternalFormatInfo[internalFormat];
if (!info) {
throw "unknown internal format";
}
return info.colorRenderable && info.textureFilterable;
} | javascript | {
"resource": ""
} |
q23794 | getTextureTypeForArrayType | train | function getTextureTypeForArrayType(gl, src, defaultType) {
if (isArrayBuffer(src)) {
return typedArrays.getGLTypeForTypedArray(src);
}
return defaultType || gl.UNSIGNED_BYTE;
} | javascript | {
"resource": ""
} |
q23795 | savePackState | train | function savePackState(gl, options) {
if (options.colorspaceConversion !== undefined) {
lastPackState.colorspaceConversion = gl.getParameter(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL);
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
}
if (options.premultiplyAlpha !== undefined) {
lastPackState.premultiplyAlpha = gl.getParameter(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
}
if (options.flipY !== undefined) {
lastPackState.flipY = gl.getParameter(gl.UNPACK_FLIP_Y_WEBGL);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, options.flipY);
}
} | javascript | {
"resource": ""
} |
q23796 | restorePackState | train | function restorePackState(gl, options) {
if (options.colorspaceConversion !== undefined) {
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, lastPackState.colorspaceConversion);
}
if (options.premultiplyAlpha !== undefined) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, lastPackState.premultiplyAlpha);
}
if (options.flipY !== undefined) {
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, lastPackState.flipY);
}
} | javascript | {
"resource": ""
} |
q23797 | saveSkipState | train | function saveSkipState(gl) {
lastPackState.unpackAlignment = gl.getParameter(gl.UNPACK_ALIGNMENT);
if (utils.isWebGL2(gl)) {
lastPackState.unpackRowLength = gl.getParameter(gl.UNPACK_ROW_LENGTH);
lastPackState.unpackImageHeight = gl.getParameter(gl.UNPACK_IMAGE_HEIGHT);
lastPackState.unpackSkipPixels = gl.getParameter(gl.UNPACK_SKIP_PIXELS);
lastPackState.unpackSkipRows = gl.getParameter(gl.UNPACK_SKIP_ROWS);
lastPackState.unpackSkipImages = gl.getParameter(gl.UNPACK_SKIP_IMAGES);
}
} | javascript | {
"resource": ""
} |
q23798 | setTextureSamplerParameters | train | function setTextureSamplerParameters(gl, target, parameteriFn, options) {
if (options.minMag) {
parameteriFn.call(gl, target, gl.TEXTURE_MIN_FILTER, options.minMag);
parameteriFn.call(gl, target, gl.TEXTURE_MAG_FILTER, options.minMag);
}
if (options.min) {
parameteriFn.call(gl, target, gl.TEXTURE_MIN_FILTER, options.min);
}
if (options.mag) {
parameteriFn.call(gl, target, gl.TEXTURE_MAG_FILTER, options.mag);
}
if (options.wrap) {
parameteriFn.call(gl, target, gl.TEXTURE_WRAP_S, options.wrap);
parameteriFn.call(gl, target, gl.TEXTURE_WRAP_T, options.wrap);
if (target === gl.TEXTURE_3D || helper.isSampler(gl, target)) {
parameteriFn.call(gl, target, gl.TEXTURE_WRAP_R, options.wrap);
}
}
if (options.wrapR) {
parameteriFn.call(gl, target, gl.TEXTURE_WRAP_R, options.wrapR);
}
if (options.wrapS) {
parameteriFn.call(gl, target, gl.TEXTURE_WRAP_S, options.wrapS);
}
if (options.wrapT) {
parameteriFn.call(gl, target, gl.TEXTURE_WRAP_T, options.wrapT);
}
if (options.minLod) {
parameteriFn.call(gl, target, gl.TEXTURE_MIN_LOD, options.minLod);
}
if (options.maxLod) {
parameteriFn.call(gl, target, gl.TEXTURE_MAX_LOD, options.maxLod);
}
if (options.baseLevel) {
parameteriFn.call(gl, target, gl.TEXTURE_BASE_LEVEL, options.baseLevel);
}
if (options.maxLevel) {
parameteriFn.call(gl, target, gl.TEXTURE_MAX_LEVEL, options.maxLevel);
}
} | javascript | {
"resource": ""
} |
q23799 | setTextureParameters | train | function setTextureParameters(gl, tex, options) {
const target = options.target || gl.TEXTURE_2D;
gl.bindTexture(target, tex);
setTextureSamplerParameters(gl, target, gl.texParameteri, options);
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.