@awayjs/stage
Version:
Stage for AwayJS
145 lines (127 loc) • 5.42 kB
text/typescript
import { ContextGLDrawMode } from '../base/ContextGLDrawMode';
import { ContextGLBlendEquation, ContextGLBlendFactor } from '../base/ContextGLBlendFactor';
import { ContextGLCompareMode } from '../base/ContextGLCompareMode';
import { ContextGLMipFilter } from '../base/ContextGLMipFilter';
import { ContextGLStencilAction } from '../base/ContextGLStencilAction';
import { ContextGLTextureFilter } from '../base/ContextGLTextureFilter';
import { ContextGLVertexBufferFormat } from '../base/ContextGLVertexBufferFormat';
import { ContextGLWrapMode } from '../base/ContextGLWrapMode';
/**
* AWAYJS to WebGL constants mapping
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
*/
export const TEXTURE = {
'texture2d': 0x0DE1,// gl.TEXTURE_2D
'textureCube': 0x8513 // gl.TEXTURE_CUBE_MAP
};
export const WRAP = {
[]: 0x2901,// gl.REPEAT,
[]: 0x812F // gl.CLAMP_TO_EDGE
};
export const FILTER = {
[]: 0x2601, // gl.LINEAR,
[]:0x2600, // gl.NEAREST
};
export const MIP_FILTER = {
[]: {
[]:0x2701, // gl.LINEAR_MIPMAP_NEAREST,
[]: 0x2703, // gl.LINEAR_MIPMAP_LINEAR,
[]: 0x2601 // gl.LINEAR
},
[]: {
[]:0x2700, // gl.NEAREST_MIPMAP_NEAREST,
[]: 0x2702, // gl.NEAREST_MIPMAP_LINEAR,
[]: 0x2600 // gl.NEAREST
}
};
/* eslint-disable */
//setup shortcut dictionaries
const BF = ContextGLBlendFactor;
const BE = ContextGLBlendEquation;
export const BLEND_OP = {
[]: 0x1, // gl.ONE,
[]: 0x0304, // gl.DST_ALPHA,
[]: 0x0306, // gl.DST_COLOR,
[]: 0x0305, // gl.ONE_MINUS_DST_ALPHA,
[]: 0x0307, // gl.ONE_MINUS_DST_COLOR,
[]: 0x0303, // gl.ONE_MINUS_SRC_ALPHA,
[]: 0x0301, // gl.ONE_MINUS_SRC_COLOR,
[]: 0x0302, //gl.SRC_ALPHA,
[]: 0x0300, // gl.SRC_COLOR,
[]: 0x0 // gl.ZERO
};
export const BLEND_EQ = {
[]: 0x8006,
[]: 0x800A,
[]: 0x800B,
[]: 0x8007,
[]: 0x8008
}
export const DRAW_MODE = {
[]: 0x0001, // gl.LINES,
[]: 0x0004, //gl.TRIANGLES
};
const CM = ContextGLCompareMode;
export const COMPARE_OP = {
[]: 0x0207, // gl.ALWAYS,
[]: 0x0202, // gl.EQUAL,
[]: 0x0204, // gl.GREATER,
[]: 0x0206, // gl.GEQUAL,
[]: 0x0201, // gl.LESS,
[]: 0x0203, // gl.LEQUAL,
[]: 0x0200, // gl.NEVER,
[]: 0x0205, // gl.NOTEQUAL
};
const SA = ContextGLStencilAction;
export const STENCIL_ACTION = {
[]: 0x1E00, //gl.KEEP,
[]: 0x1E01, //gl.REPLACE,
[]: 0x1E02, //gl.INCR,
[]: 0x1E03, // gl.DECR,
[]: 0x150A, // gl.INVERT,
[]: 0x8507, // gl.INCR_WRAP,
[]: 0x8508, // gl.DECR_WRAP,
[]: 0, // gl.ZERO
};
export interface IVertexBufferProperties {
size: number;
type: number;
normalized: boolean;
}
class VPropConstructor implements IVertexBufferProperties {
constructor(
public size: number,
public type: number,
public normalized: boolean
) {}
}
const enum DATA_TYPE {
BYTE = 0x1400, // gl.BYTE
UNSIGNED_BYTE = 0x1401, // gl.UNSIGNED_BYTE
SHORT = 0x1402, // gl.SHORT
UNSIGNED_SHORT = 0x1403, // gl.UNSIGNED_SHORT
FLOAT = 0x1406, // gl.FLOAT
}
const VBF = ContextGLVertexBufferFormat;
export const VERTEX_BUF_PROPS: Record<number, IVertexBufferProperties> = {
[]: new VPropConstructor(1, DATA_TYPE.FLOAT, false),
[]: new VPropConstructor(2, DATA_TYPE.FLOAT, false),
[]: new VPropConstructor(3, DATA_TYPE.FLOAT, false),
[]: new VPropConstructor(4, DATA_TYPE.FLOAT, false),
[]: new VPropConstructor(1, DATA_TYPE.BYTE, true),
[]: new VPropConstructor(2, DATA_TYPE.BYTE, true),
[]: new VPropConstructor(3, DATA_TYPE.BYTE, true),
[]: new VPropConstructor(4, DATA_TYPE.BYTE, true),
[]: new VPropConstructor(1, DATA_TYPE.UNSIGNED_BYTE, true),
[]: new VPropConstructor(2, DATA_TYPE.UNSIGNED_BYTE, true),
[]: new VPropConstructor(3, DATA_TYPE.UNSIGNED_BYTE, true),
[]: new VPropConstructor(4, DATA_TYPE.UNSIGNED_BYTE, true),
[]: new VPropConstructor(1, DATA_TYPE.SHORT, false),
[]: new VPropConstructor(2, DATA_TYPE.SHORT, false),
[]: new VPropConstructor(3, DATA_TYPE.SHORT, false),
[]: new VPropConstructor(4, DATA_TYPE.SHORT, false),
[]: new VPropConstructor(1, DATA_TYPE.UNSIGNED_SHORT, false),
[]: new VPropConstructor(2, DATA_TYPE.UNSIGNED_SHORT, false),
[]: new VPropConstructor(3, DATA_TYPE.UNSIGNED_SHORT, false),
[]: new VPropConstructor(4, DATA_TYPE.UNSIGNED_SHORT, false)
}