add primitive api docs (#4595)

This commit is contained in:
Weiliang Wang
2019-06-12 09:36:58 +08:00
committed by GitHub
parent 00eac3b237
commit 0ba1ba2d4e
16 changed files with 838 additions and 13 deletions
+26
View File
@@ -2,42 +2,68 @@ import { Vec3 } from '../../core/value-types';
import { vec3 } from '../../core/vmath';
import { IGeometry, IGeometryOptions } from './define';
/**
* @zh
* 立方体参数选项
*/
interface IBoxOptions extends RecursivePartial<IGeometryOptions> {
/**
* @en
* Box extent on X-axis.
* @zh
* 立方体宽度
*/
width?: number;
/**
* @en
* Box extent on Y-axis.
* @zh
* 立方体高度
*/
height?: number;
/**
* @en
* Box extent on Z-axis.
* @zh
* 立方体长度
*/
length?: number;
/**
* @en
* Segment count on X-axis.
* @zh
* 宽度线段数
*/
widthSegments?: number;
/**
* @en
* Segment count on Y-axis.
* @zh
* 高度线段数
*/
heightSegments?: number;
/**
* @en
* Segment count on Z-axis.
* @zh
* 长度线段数
*/
lengthSegments?: number;
}
/**
* @en
* This function generates a box with specified extents and centered at origin,
* but may be repositioned through `center` option).
* @param options Options.
* @zh
* 生成一个立方体,其大小是定义的范围且中心在原点
* @param options 参数选项.
*/
export default function box (options?: IBoxOptions): IGeometry {
options = options || {};
+11
View File
@@ -1,5 +1,9 @@
import { vec3 } from '../../core/vmath';
/**
* @zh
* 胶囊体参数选项
*/
export interface ICapsuteOptions {
sides: number;
heightSegments: number;
@@ -10,6 +14,13 @@ export interface ICapsuteOptions {
const temp1 = vec3.create(0, 0, 0);
const temp2 = vec3.create(0, 0, 0);
/**
* @zh
* 生成一个胶囊体
* @param radiusTop 顶部半径
* @param radiusBottom 底部半径
* @param opts 胶囊体参数选项
*/
export default function (radiusTop = 0.5, radiusBottom = 0.5, height = 2, opts: RecursivePartial<ICapsuteOptions> = {}) {
const torsoHeight = height - radiusTop - radiusBottom;
const sides = opts.sides || 32;
+12
View File
@@ -1,11 +1,20 @@
import { GFXPrimitiveMode } from '../../gfx/define';
import { applyDefaultGeometryOptions, IGeometry, IGeometryOptions } from './define';
/**
* @zh
* 圆形参数选项
*/
interface ICircleOptions extends IGeometryOptions {
// The segments. Default to 64.
segments: number;
}
/**
* @zh
* 应用默认圆参数
* @param options 圆参数
*/
function applyDefaultCircleOptions (options?: RecursivePartial<ICircleOptions>): ICircleOptions {
options = applyDefaultGeometryOptions<ICircleOptions>(options);
options.segments = 64;
@@ -15,6 +24,9 @@ function applyDefaultCircleOptions (options?: RecursivePartial<ICircleOptions>):
/**
* Generate a circle with radius 1, centered at origin.
* @param options Options.
* @zh
* 生成一个圆,其半径是单位1,中心点在原点
* @param options 参数选项
*/
export default function circle (options?: RecursivePartial<ICircleOptions> | ICircleOptions): IGeometry {
const normalizedOptions = applyDefaultCircleOptions(options);
+7
View File
@@ -4,6 +4,13 @@ import cylinder, { ICylinderOptions } from './cylinder';
type IConeOptions = ICylinderOptions;
/**
* @zh
* 生成一个圆锥
* @param radius 圆锥半径
* @param height 圆锥高度
* @param opts 圆锥参数选项
*/
export default function (radius = 0.5, height = 1, opts: RecursivePartial<IConeOptions> = {}) {
return cylinder(0, radius, height, opts);
}
+11
View File
@@ -1,6 +1,10 @@
import { vec3 } from '../../core/vmath';
import { IGeometry, IGeometryOptions } from './define';
/**
* @zh
* 圆柱参数选项
*/
export interface ICylinderOptions extends IGeometryOptions {
radialSegments: number;
heightSegments: number;
@@ -11,6 +15,13 @@ export interface ICylinderOptions extends IGeometryOptions {
const temp1 = vec3.create(0, 0, 0);
const temp2 = vec3.create(0, 0, 0);
/**
* @zh
* 生成一个圆柱
* @param radiusTop 顶部半径
* @param radiusBottom 底部半径
* @param opts 圆柱参数选项
*/
export default function (radiusTop = 0.5, radiusBottom = 0.5, height = 2, opts: RecursivePartial<ICylinderOptions> = {}): IGeometry {
const halfHeight = height * 0.5;
const radialSegments = opts.radialSegments || 32;
+52 -1
View File
@@ -1,18 +1,32 @@
import { GFXPrimitiveMode } from '../../gfx/define';
import { IGFXAttribute } from '../../gfx/input-assembler';
/**
* @zh
* 几何体参数选项
*/
export interface IGeometryOptions {
/**
* @en
* Whether to include normal. Default to true.
* @zh
* 是否包含法线。默认为true
*/
includeNormal: boolean;
/**
* @en
* Whether to include uv. Default to true.
* @zh
* 是否包含UV.默认为true
*/
includeUV: boolean;
}
/**
* @zh
* 应用默认的几何参数选项
*/
export function applyDefaultGeometryOptions<GeometryOptions = IGeometryOptions> (
options?: RecursivePartial<IGeometryOptions>): GeometryOptions {
options = options || {};
@@ -25,29 +39,48 @@ export function applyDefaultGeometryOptions<GeometryOptions = IGeometryOptions>
return options as GeometryOptions;
}
/**
* @zh
* 几何体信息
*/
export interface IGeometry {
/**
* @en
* Vertex positions.
* @zh
* 顶点位置
*/
positions: number[];
/**
* @en
* Vertex normals.
* @zh
* 顶点法线
*/
normals?: number[];
/**
* @en
* Texture coordinates.
* @zh
* 纹理坐标
*/
uvs?: number[];
/**
* @en
* Vertex colors.
* @zh
* 顶点颜色
*/
colors?: number[];
/**
* @en
* specify vertex attributes, use (positions|normals|uvs|colors) as keys
* @zh
* 顶点属性
*/
attributes?: IGFXAttribute[];
@@ -57,12 +90,18 @@ export interface IGeometry {
}>;
/**
* @en
* Bounding sphere radius.
* @zh
* 包围球半径
*/
boundingRadius?: number;
/**
* @en
* Min position.
* @zh
* 最小位置
*/
minPos?: {
x: number;
@@ -71,7 +110,10 @@ export interface IGeometry {
};
/**
* @en
* Max position.
* @zh
* 最大位置
*/
maxPos?: {
x: number;
@@ -80,17 +122,26 @@ export interface IGeometry {
};
/**
* Gemetry indices, if one needs indexed-draw.
* @en
* Geometry indices, if one needs indexed-draw.
* @zh
* 几何索引,当使用索引绘制时
*/
indices?: number[];
/**
* @en
* Topology of the geometry vertices. Default is TRIANGLE_LIST.
* @zh
* 几何顶点的拓扑图元。默认值是TRIANGLE_LIST
*/
primitiveMode?: GFXPrimitiveMode;
/**
* @en
* whether rays casting from the back face of this geometry could collide with it
* @zh
* 是否是双面,用于判断来自于几何体背面的射线检测
*/
doubleSided?: boolean;
}
+16
View File
@@ -2,6 +2,13 @@ import { Vec3 } from '../../core/value-types';
import { vec3 } from '../../core/vmath';
import { applyDefaultGeometryOptions, IGeometry, IGeometryOptions } from './define';
/**
* @zh
* 生成一个圆锥
* @param radius 圆锥半径
* @param height 圆锥高度
* @param opts 圆锥参数选项
*/
interface IPlaneOptions extends RecursivePartial<IGeometryOptions> {
/**
* Plane extent on X-axis.
@@ -24,6 +31,11 @@ interface IPlaneOptions extends RecursivePartial<IGeometryOptions> {
lengthSegments: number;
}
/**
* @zh
* 应用默认的平面参数选项
* @param options 平面参数选项
*/
function applyDefaultPlaneOptions (options?: RecursivePartial<IPlaneOptions>): IPlaneOptions {
options = applyDefaultGeometryOptions<IPlaneOptions>(options);
options.width = options.width || 10;
@@ -42,8 +54,12 @@ const c10 = vec3.create(0, 0, 0);
const c01 = vec3.create(0, 0, 0);
/**
* @en
* This function generates a plane on XOZ plane with positive Y direction.
* @param options Options.
* @zh
* 生成一个平面,其位于XOZ平面,方向为Y轴正方向
* @param options 平面参数选项
*/
export default function (options?: IPlaneOptions): IGeometry {
const normalizedOptions = applyDefaultPlaneOptions(options);
+4
View File
@@ -3,8 +3,12 @@
import { applyDefaultGeometryOptions, IGeometry, IGeometryOptions } from './define';
/**
* @en
* Generate a quad with width and height both to 1, centered at origin.
* @param options Options.
* @zh
* 生成一个四边形,宽高都为1,中心在原点
* @param options 参数选项
*/
export default function quad (options?: IGeometryOptions): IGeometry {
const normalizedOptions = applyDefaultGeometryOptions(options);
+10
View File
@@ -1,10 +1,20 @@
import { vec3 } from '../../core/vmath';
import { IGeometry, IGeometryOptions } from './define';
/**
* @zh
* 球参数选项
*/
interface ISphereOptions extends IGeometryOptions {
segments: number;
}
/**
* @zh
* 生成一个球
* @param radius 球半径
* @param options 参数选项
*/
export default function (radius = 0.5, opts: RecursivePartial<ISphereOptions> = {}): IGeometry {
const segments = opts.segments !== undefined ? opts.segments : 32;
+11
View File
@@ -1,12 +1,23 @@
import { vec3 } from '../../core/vmath';
import { IGeometryOptions } from './define';
/**
* @zh
* 环面参数选项
*/
interface ITorusOptions extends IGeometryOptions {
radialSegments: number;
tubularSegments: number;
arc: number;
}
/**
* @zh
* 生成一个环面
* @param radius 环面半径
* @param tube 管形大小
* @param opts 参数选项
*/
export default function (radius = 0.4, tube = 0.1, opts: RecursivePartial<ITorusOptions> = {}) {
const radialSegments = opts.radialSegments || 32;
const tubularSegments = opts.tubularSegments || 32;
+17
View File
@@ -1,6 +1,12 @@
import { GFXPrimitiveMode } from '../../gfx/define';
import { IGeometry } from './define';
/**
* @zh
* 平移几何体
* @param geometry 几何体信息
* @param offset 偏移量
*/
export function translate (geometry: IGeometry, offset: { x?: number; y?: number; z?: number; }) {
const x = offset.x || 0;
const y = offset.y || 0;
@@ -27,6 +33,12 @@ export function translate (geometry: IGeometry, offset: { x?: number; y?: number
return geometry;
}
/**
* @zh
* 缩放几何体
* @param geometry 几何体信息
* @param value 缩放量
*/
export function scale (geometry: IGeometry, value: { x?: number; y?: number; z?: number }) {
const x = value.x || 0;
const y = value.y || 0;
@@ -54,6 +66,11 @@ export function scale (geometry: IGeometry, value: { x?: number; y?: number; z?:
return geometry;
}
/**
* @zh
* 将几何体转换为线框模式,仅支持三角形拓扑的几何体
* @param geometry 几何体信息
*/
export function wireframed (geometry: IGeometry) {
const { indices } = geometry;
if (!indices) {
+1 -1
View File
@@ -105,7 +105,7 @@ export abstract class GFXCommandBuffer extends GFXObject {
/**
* @zh
* GFX命令缓冲分配器
* GFX命令分配器
*/
protected _allocator: GFXCommandAllocator | null = null;
+224 -4
View File
@@ -3,6 +3,10 @@ export const GFX_MAX_TEXTURE_UNITS: number = 16;
export const GFX_MAX_ATTACHMENTS: number = 4;
export const GFX_MAX_BUFFER_BINDINGS: number = 24;
/**
* @zh
* GFX对象类型
*/
export enum GFXObjectType {
UNKNOWN,
BUFFER,
@@ -22,12 +26,20 @@ export enum GFXObjectType {
WINDOW,
}
/**
* @zh
* GFX状态
*/
export enum GFXStatus {
UNREADY,
FAILED,
SUCCESS,
}
/**
* @zh
* GFX对象
*/
export class GFXObject {
public get gfxType (): GFXObjectType {
@@ -38,14 +50,32 @@ export class GFXObject {
return this._status;
}
/**
* @zh
* 对象类型
*/
protected _gfxType = GFXObjectType.UNKNOWN;
/**
* @zh
* 对象状态
*/
protected _status = GFXStatus.UNREADY;
/**
* @zh
* 构造函数
* @param gfxType GFX对象类型
*/
constructor (gfxType: GFXObjectType) {
this._gfxType = gfxType;
}
}
/**
* @zh
* GFX顶点属性名
*/
export enum GFXAttributeName {
ATTR_POSITION = 'a_position',
ATTR_NORMAL = 'a_normal',
@@ -69,6 +99,10 @@ export enum GFXAttributeName {
ATTR_BATCH_UV = 'a_batch_uv',
}
/**
* @zh
* GFX数据类型
*/
export enum GFXType {
UNKNOWN,
// vectors
@@ -107,6 +141,10 @@ export enum GFXType {
COUNT,
}
/**
* @zh
* GFX格式
*/
export enum GFXFormat {
UNKNOWN,
@@ -229,6 +267,10 @@ export enum GFXFormat {
PVRTC2_4BPP,
}
/**
* @zh
* GFX缓冲使用方式标识位
*/
export enum GFXBufferUsageBit {
NONE = 0,
TRANSFER_SRC = 0x1,
@@ -242,6 +284,10 @@ export enum GFXBufferUsageBit {
export type GFXBufferUsage = GFXBufferUsageBit;
/**
* @zh
* GFX内存使用方式标识位
*/
export enum GFXMemoryUsageBit {
NONE = 0,
DEVICE = 0x1,
@@ -250,6 +296,10 @@ export enum GFXMemoryUsageBit {
export type GFXMemoryUsage = GFXMemoryUsageBit;
/**
* @zh
* GFX缓冲访问标识位
*/
export enum GFXBufferAccessBit {
NONE = 0,
READ = 0x1,
@@ -258,6 +308,10 @@ export enum GFXBufferAccessBit {
export type GFXBufferAccess = GFXBufferAccessBit;
/**
* @zh
* GFX图元模式标识位
*/
export enum GFXPrimitiveMode {
POINT_LIST,
LINE_LIST,
@@ -276,23 +330,39 @@ export enum GFXPrimitiveMode {
QUAD_PATCH_LIST,
}
/**
* @zh
* GFX三角形填充模式
*/
export enum GFXPolygonMode {
FILL,
POINT,
LINE,
}
/**
* @zh
* GFX着色模式
*/
export enum GFXShadeModel {
GOURAND,
FLAT,
}
/**
* @zh
* GFX裁剪模式
*/
export enum GFXCullMode {
NONE,
FRONT,
BACK,
}
/**
* @zh
* GFX比较函数
*/
export enum GFXComparisonFunc {
NEVER,
LESS,
@@ -304,6 +374,10 @@ export enum GFXComparisonFunc {
ALWAYS,
}
/**
* @zh
* GFX模板操作
*/
export enum GFXStencilOp {
ZERO,
KEEP,
@@ -315,6 +389,10 @@ export enum GFXStencilOp {
DECR_WRAP,
}
/**
* @zh
* GFX混合操作
*/
export enum GFXBlendOp {
ADD,
SUB,
@@ -323,6 +401,10 @@ export enum GFXBlendOp {
MAX,
}
/**
* @zh
* GFX混合因子
*/
export enum GFXBlendFactor {
ZERO,
ONE,
@@ -341,6 +423,10 @@ export enum GFXBlendFactor {
ONE_MINUS_CONSTANT_ALPHA,
}
/**
* @zh
* GFX颜色掩码
*/
export enum GFXColorMask {
NONE = 0x0,
R = 0x1,
@@ -350,6 +436,10 @@ export enum GFXColorMask {
ALL = R | G | B | A,
}
/**
* @zh
* GFX过滤模式
*/
export enum GFXFilter {
NONE,
POINT,
@@ -357,6 +447,10 @@ export enum GFXFilter {
ANISOTROPIC,
}
/**
* @zh
* GFX寻址模式
*/
export enum GFXAddress {
WRAP,
MIRROR,
@@ -364,12 +458,20 @@ export enum GFXAddress {
BORDER,
}
/**
* @zh
* GFX纹理类型
*/
export enum GFXTextureType {
TEX1D,
TEX2D,
TEX3D,
}
/**
* @zh
* GFX纹理使用方式标识位
*/
export enum GFXTextureUsageBit {
NONE = 0,
TRANSFER_SRC = 0x1,
@@ -384,6 +486,10 @@ export enum GFXTextureUsageBit {
export type GFXTextureUsage = GFXTextureUsageBit;
/**
* @zh
* GFX采样数量
*/
export enum GFXSampleCount {
X1,
X2,
@@ -394,6 +500,10 @@ export enum GFXSampleCount {
X64,
}
/**
* @zh
* GFX纹理标识位
*/
export enum GFXTextureFlagBit {
NONE = 0,
GEN_MIPMAP = 0x1,
@@ -403,6 +513,10 @@ export enum GFXTextureFlagBit {
export type GFXTextureFlags = GFXTextureFlagBit;
/**
* @zh
* GFX纹理视图类型
*/
export enum GFXTextureViewType {
TV1D,
TV2D,
@@ -412,6 +526,10 @@ export enum GFXTextureViewType {
TV2D_ARRAY,
}
/**
* @zh
* GFX Shader类型
*/
export enum GFXShaderType {
VERTEX,
HULL,
@@ -422,6 +540,10 @@ export enum GFXShaderType {
COUNT,
}
/**
* @zh
* GFX绑定类型
*/
export enum GFXBindingType {
UNKNOWN,
UNIFORM_BUFFER,
@@ -429,24 +551,38 @@ export enum GFXBindingType {
STORAGE_BUFFER,
}
/**
* @zh
* GFX命令缓冲类型
*/
export enum GFXCommandBufferType {
PRIMARY,
SECONDARY,
}
// Enumeration all possible values of operations to be performed on initially Loading a Framebuffer Object.
/**
* @zh
* 初始载入帧缓冲时的内存操作
*/
export enum GFXLoadOp {
LOAD, // Load the contents from the fbo from previous
CLEAR, // Clear the fbo
DISCARD, // Ignore writing to the fbo and keep old data
}
// Enumerates all possible values of operations to be performed when Storing to a Framebuffer Object.
/**
* @zh
* 存储到帧缓冲时的内存操作
*/
export enum GFXStoreOp {
STORE, // Write the source to the destination
DISCARD, // Don't write the source to the destination
}
/**
* @zh
* GFX纹理布局
*/
export enum GFXTextureLayout {
UNDEFINED,
GENERAL,
@@ -460,12 +596,20 @@ export enum GFXTextureLayout {
PRESENT_SRC,
}
/**
* @zh
* GFX管线绑定点
*/
export enum GFXPipelineBindPoint {
GRAPHICS,
COMPUTE,
RAY_TRACING,
}
/**
* @zh
* GFX动态状态
*/
export enum GFXDynamicState {
VIEWPORT,
SCISSOR,
@@ -477,20 +621,30 @@ export enum GFXDynamicState {
STENCIL_COMPARE_MASK,
}
/**
* @zh
* GFX模板操作面朝向
*/
export enum GFXStencilFace {
FRONT,
BACK,
ALL,
}
/**
* @zh
* GFX队列类型
*/
export enum GFXQueueType {
GRAPHICS,
COMPUTE,
TRANSFER,
}
// Interfaces
/**
* @zh
* GFX矩形
*/
export interface IGFXRect {
x: number;
y: number;
@@ -498,6 +652,10 @@ export interface IGFXRect {
height: number;
}
/**
* @zh
* GFX视口
*/
export interface IGFXViewport {
left: number;
top: number;
@@ -507,6 +665,10 @@ export interface IGFXViewport {
maxDepth: number;
}
/**
* @zh
* GFX颜色
*/
export interface IGFXColor {
r: number;
g: number;
@@ -514,6 +676,10 @@ export interface IGFXColor {
a: number;
}
/**
* @zh
* GFX清空标识
*/
export enum GFXClearFlag {
NONE = 0,
COLOR = 1,
@@ -523,18 +689,30 @@ export enum GFXClearFlag {
ALL = COLOR | DEPTH | STENCIL,
}
/**
* @zh
* GFX偏移量
*/
export interface IGFXOffset {
x: number;
y: number;
z: number;
}
/**
* @zh
* GFX范围
*/
export interface IGFXExtent {
width: number;
height: number;
depth: number;
}
/**
* @zh
* GFX纹理子资源信息
*/
export class GFXTextureSubres {
public baseMipLevel: number = 0;
public levelCount: number = 1;
@@ -542,6 +720,10 @@ export class GFXTextureSubres {
public layerCount: number = 1;
}
/**
* @zh
* GFX纹理拷贝信息
*/
export class GFXTextureCopy {
public srcSubres: GFXTextureSubres = new GFXTextureSubres();
public srcOffset: IGFXOffset = { x: 0, y: 0, z: 0 };
@@ -550,6 +732,10 @@ export class GFXTextureCopy {
public extent: IGFXExtent = { width: 0, height: 0, depth: 0 };
}
/**
* @zh
* GFX缓冲纹理拷贝信息
*/
export class GFXBufferTextureCopy {
public buffOffset: number = 0;
public buffStride: number = 0;
@@ -559,6 +745,10 @@ export class GFXBufferTextureCopy {
public texSubres: GFXTextureSubres = new GFXTextureSubres();
}
/**
* @zh
* GFX格式数据类型
*/
export enum GFXFormatType {
NONE,
UNORM,
@@ -569,6 +759,10 @@ export enum GFXFormatType {
FLOAT,
}
/**
* @zh
* GFX格式信息
*/
export interface IGFXFormatInfo {
readonly name: string;
readonly size: number;
@@ -580,6 +774,10 @@ export interface IGFXFormatInfo {
readonly isCompressed: boolean;
}
/**
* @zh
* GFX格式信息数组
*/
// tslint:disable: max-line-length
export const GFXFormatInfos: IGFXFormatInfo[] = [
@@ -688,6 +886,14 @@ export const GFXFormatInfos: IGFXFormatInfo[] = [
];
// tslint:enable: max-line-length
/**
* @zh
* GFX格式内存大小
* @param format GFX格式
* @param width 像素宽度
* @param height 像素高度
* @param depth 像素深度
*/
export function GFXFormatSize (format: GFXFormat, width: number, height: number, depth: number): number {
if (!GFXFormatInfos[format].isCompressed) {
@@ -742,6 +948,15 @@ export function GFXFormatSize (format: GFXFormat, width: number, height: number,
}
}
/**
* @zh
* GFX格式表面内存大小
* @param format GFX格式
* @param width 像素宽度
* @param height 像素高度
* @param depth 像素深度
* @param mips mip层数
*/
export function GFXFormatSurfaceSize (
format: GFXFormat, width: number, height: number,
depth: number, mips: number): number {
@@ -758,6 +973,11 @@ export function GFXFormatSurfaceSize (
return size;
}
/**
* @zh
* 得到GFX数据类型的大小
* @param type GFX数据类型
*/
export function GFXGetTypeSize (type: GFXType): number {
switch (type) {
case GFXType.BOOL:
+325 -5
View File
@@ -18,12 +18,20 @@ import { GFXWindow, IGFXWindowInfo } from './window';
ccenum(GFXFormat);
/**
* @zh
* GFX API
*/
export enum GFXAPI {
UNKNOWN,
WEBGL,
WEBGL2,
}
/**
* @zh
* GFX特性
*/
export enum GFXFeature {
COLOR_FLOAT,
COLOR_HALF_FLOAT,
@@ -41,6 +49,10 @@ export enum GFXFeature {
COUNT,
}
/**
* @zh
* GFX设备描述信息
*/
export interface IGFXDeviceInfo {
canvasElm: HTMLElement;
isAntialias?: boolean;
@@ -51,6 +63,10 @@ export interface IGFXDeviceInfo {
nativeHeight?: number;
}
/**
* @zh
* GFX设备
*/
// tslint:disable: max-line-length
export abstract class GFXDevice {
@@ -134,10 +150,6 @@ export abstract class GFXDevice {
return this._maxUniformBlockSize;
}
public get maxCombinedUniformBlocks (): number {
return this._maxCombinedUniformBlocks;
}
public get depthBits (): number {
return this._depthBits;
}
@@ -166,72 +178,380 @@ export abstract class GFXDevice {
return this._numTris;
}
/**
* @zh
* HTML画布
*/
protected _canvas: HTMLCanvasElement | null = null;
/**
* @zh
* 用于2D绘制的HTML画布
*/
protected _canvas2D: HTMLCanvasElement | null = null;
/**
* @zh
* GFX API
*/
protected _gfxAPI: GFXAPI = GFXAPI.UNKNOWN;
protected _deviceName: string = '';
/**
* @zh
* 渲染器描述
*/
protected _renderer: string = '';
/**
* @zh
* 厂商描述
*/
protected _vendor: string = '';
/**
* @zh
* 驱动版本
*/
protected _version: string = '';
/**
* @zh
* 特性数组
*/
protected _features: boolean[] = new Array<boolean>(GFXFeature.COUNT);
/**
* @zh
* GFX队列
*/
protected _queue: GFXQueue | null = null;
/**
* @zh
* DPR 设备像素比
*/
protected _devicePixelRatio: number = 1.0;
/**
* @zh
* 设备像素宽度
*/
protected _width: number = 0;
/**
* @zh
* 设备像素高度
*/
protected _height: number = 0;
/**
* @zh
* 设备原生的像素宽度
*/
protected _nativeWidth: number = 0;
/**
* @zh
* 设备原生的像素高度
*/
protected _nativeHeight: number = 0;
/**
* @zh
* 设备主窗口
*/
protected _mainWindow: GFXWindow | null = null;
/**
* @zh
* 命令分配器
*/
protected _cmdAllocator: GFXCommandAllocator | null = null;
/**
* @zh
* 最大顶点属性数量
*/
protected _maxVertexAttributes: number = 0;
/**
* @zh
* 最大顶点Uniform向量数
*/
protected _maxVertexUniformVectors: number = 0;
/**
* @zh
* 最大片段Uniform向量数
*/
protected _maxFragmentUniformVectors: number = 0;
/**
* @zh
* 最大纹理单元数量
*/
protected _maxTextureUnits: number = 0;
/**
* @zh
* 最大顶点纹理单元数量
*/
protected _maxVertexTextureUnits: number = 0;
/**
* @zh
* 最大UniformBuffer绑定数量
*/
protected _maxUniformBufferBindings: number = GFX_MAX_BUFFER_BINDINGS;
/**
* @zh
* 最大Uniform块大小
*/
protected _maxUniformBlockSize: number = 0;
protected _maxCombinedUniformBlocks: number = GFX_MAX_BUFFER_BINDINGS;
/**
* @zh
* 深度位数
*/
protected _depthBits: number = 0;
/**
* @zh
* 模板位数
*/
protected _stencilBits: number = 0;
/**
* @zh
* 颜色格式
*/
protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN;
/**
* @zh
* 深度模板格式
*/
protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN;
/**
* @zh
* Shader ID 生成标识
*/
protected _shaderIdGen: number = 0;
/**
* @zh
* 系统宏定义
*/
protected _macros: Map<string, string> = new Map();
/**
* @zh
* 绘制调用次数
*/
protected _numDrawCalls: number = 0;
/**
* @zh
* 渲染三角形数量
*/
protected _numTris: number = 0;
/**
* @zh
* 初始化函数
* @param info GFX设备描述信息
*/
public abstract initialize (info: IGFXDeviceInfo): boolean;
/**
* @zh
* 销毁函数
*/
public abstract destroy (): void;
/**
* @zh
* 重置设备大小
* @param width 设备宽度
* @param height 设备高度
*/
public abstract resize (width: number, height: number);
/**
* @zh
* 创建缓冲
* @param info GFX缓冲描述信息
*/
public abstract createBuffer (info: IGFXBufferInfo): GFXBuffer;
/**
* @zh
* 创建纹理
* @param info GFX纹理描述信息
*/
public abstract createTexture (info: IGFXTextureInfo): GFXTexture;
/**
* @zh
* 创建纹理视图
* @param info GFX纹理视图描述信息
*/
public abstract createTextureView (info: IGFXTextureViewInfo): GFXTextureView;
/**
* @zh
* 创建采样器
* @param info GFX采样器描述信息
*/
public abstract createSampler (info: IGFXSamplerInfo): GFXSampler;
/**
* @zh
* 创建绑定布局
* @param info GFX绑定布局描述信息
*/
public abstract createBindingLayout (info: IGFXBindingLayoutInfo): GFXBindingLayout;
/**
* @zh
* 创建着色器
* @param info GFX着色器描述信息
*/
public abstract createShader (info: IGFXShaderInfo): GFXShader;
/**
* @zh
* 创建纹理
* @param info GFX纹理描述信息
*/
public abstract createInputAssembler (info: IGFXInputAssemblerInfo): GFXInputAssembler;
/**
* @zh
* 创建渲染过程
* @param info GFX渲染过程描述信息
*/
public abstract createRenderPass (info: IGFXRenderPassInfo): GFXRenderPass;
/**
* @zh
* 创建帧缓冲
* @param info GFX帧缓冲描述信息
*/
public abstract createFramebuffer (info: IGFXFramebufferInfo): GFXFramebuffer;
/**
* @zh
* 创建管线布局
* @param info GFX管线布局描述信息
*/
public abstract createPipelineLayout (info: IGFXPipelineLayoutInfo): GFXPipelineLayout;
/**
* @zh
* 创建管线状态
* @param info GFX管线状态描述信息
*/
public abstract createPipelineState (info: IGFXPipelineStateInfo): GFXPipelineState;
/**
* @zh
* 创建命令分配器
* @param info GFX命令分配器描述信息
*/
public abstract createCommandAllocator (info: IGFXCommandAllocatorInfo): GFXCommandAllocator;
/**
* @zh
* 创建命令缓冲
* @param info GFX命令缓冲描述信息
*/
public abstract createCommandBuffer (info: IGFXCommandBufferInfo): GFXCommandBuffer;
/**
* @zh
* 创建队列
* @param info GFX队列描述信息
*/
public abstract createQueue (info: IGFXQueueInfo): GFXQueue;
/**
* @zh
* 创建窗口
* @param info GFX窗口描述信息
*/
public abstract createWindow (info: IGFXWindowInfo): GFXWindow;
/**
* @zh
* 呈现当前帧
*/
public abstract present ();
/**
* @zh
* 拷贝缓冲到纹理
* @param buffers 缓冲数组
* @param texture GFX纹理
* @param regions GFX缓冲纹理拷贝区域信息
*/
public abstract copyBuffersToTexture (buffers: ArrayBuffer[], texture: GFXTexture, regions: GFXBufferTextureCopy[]);
/**
* @zh
* 拷贝图像到纹理
* @param texImages 图像数据源
* @param texture GFX纹理
* @param regions GFX缓冲纹理拷贝区域信息
*/
public abstract copyTexImagesToTexture (texImages: TexImageSource[], texture: GFXTexture, regions: GFXBufferTextureCopy[]);
/**
* @zh
* 拷贝帧缓冲到缓冲
* @param srcFramebuffer 源帧缓冲
* @param dstBuffer 目的缓冲
* @param regions GFX缓冲纹理拷贝区域信息
*/
public abstract copyFramebufferToBuffer (srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]);
/**
* @zh
* 填充帧缓冲
* @param src 源帧缓冲
* @param dst 目的帧缓冲
* @param srcRect 源矩形区域
* @param dstRect 目的矩形区域
* @param filter 过滤模式
*/
public abstract blitFramebuffer (src: GFXFramebuffer, dst: GFXFramebuffer, srcRect: IGFXRect, dstRect: IGFXRect, filter: GFXFilter);
/**
* @zh
* 是否具备特性
* @param feature GFX特性
*/
public hasFeature (feature: GFXFeature): boolean {
return this._features[feature];
}
/**
* @zh
* 生成 Shader ID
*/
public genShaderId (): number {
return this._shaderIdGen++;
}
/**
* @zh
* 定义宏
* @param macro 宏
* @param value 值
*/
public defineMacro (macro: string, value?: string) {
const val = (value !== undefined ? value : '');
this._macros.set(macro, val);
+111
View File
@@ -3,6 +3,10 @@ import { GFXBuffer, GFXBufferSource, IGFXDrawInfo } from './buffer';
import { GFXFormat, GFXFormatInfos, GFXObject, GFXObjectType } from './define';
import { GFXDevice } from './device';
/**
* @zh
* GFX顶点属性
*/
export interface IGFXAttribute {
name: string;
format: GFXFormat;
@@ -11,6 +15,10 @@ export interface IGFXAttribute {
isInstanced?: boolean;
}
/**
* @zh
* GFX输入汇集器描述信息
*/
export interface IGFXInputAssemblerInfo {
attributes: IGFXAttribute[];
vertexBuffers: GFXBuffer[];
@@ -18,6 +26,10 @@ export interface IGFXInputAssemblerInfo {
indirectBuffer?: GFXBuffer;
}
/**
* @zh
* GFX输入汇集器
*/
export abstract class GFXInputAssembler extends GFXObject {
public get vertexBuffers (): GFXBuffer[] {
@@ -96,28 +108,112 @@ export abstract class GFXInputAssembler extends GFXObject {
return this._indirectBuffer;
}
/**
* @zh
* GFX设备
*/
protected _device: GFXDevice;
/**
* @zh
* 顶点属性数组
*/
protected _attributes: IGFXAttribute[] = [];
/**
* @zh
* 顶点缓冲数组
*/
protected _vertexBuffers: GFXBuffer[] = [];
/**
* @zh
* 索引缓冲
*/
protected _indexBuffer: GFXBuffer | null = null;
/**
* @zh
* 顶点数量
*/
protected _vertexCount: number = 0;
/**
* @zh
* 起始顶点
*/
protected _firstVertex: number = 0;
/**
* @zh
* 索引数量
*/
protected _indexCount: number = 0;
/**
* @zh
* 起始索引
*/
protected _firstIndex: number = 0;
/**
* @zh
* 顶点偏移量
*/
protected _vertexOffset: number = 0;
/**
* @zh
* 实例数量
*/
protected _instanceCount: number = 0;
/**
* @zh
* 起始实例
*/
protected _firstInstance: number = 0;
/**
* @zh
* 是否间接绘制
*/
protected _isIndirect: boolean = false;
/**
* @zh
* 间接绘制缓冲
*/
protected _indirectBuffer: GFXBuffer | null = null;
/**
* @zh
* 构造函数
* @param device GFX设备
*/
constructor (device: GFXDevice) {
super(GFXObjectType.INPUT_ASSEMBLER);
this._device = device;
}
/**
* @zh
* 初始化函数
* @param info GFX汇集器描述信息
*/
public abstract initialize (info: IGFXInputAssemblerInfo): boolean;
/**
* @zh
* 销毁函数
*/
public abstract destroy (): void;
/**
* @zh
* 得到顶点缓冲
* @param stream 顶点流索引
*/
public getVertexBuffer (stream: number = 0): GFXBuffer | null {
if (stream < this._vertexBuffers.length) {
return this._vertexBuffers[stream];
@@ -126,6 +222,11 @@ export abstract class GFXInputAssembler extends GFXObject {
}
}
/**
* @zh
* 提取绘制信息
* @param drawInfo 绘制信息
*/
public extractDrawInfo (drawInfo: IGFXDrawInfo) {
drawInfo.vertexCount = this._vertexCount;
drawInfo.firstVertex = this._firstVertex;
@@ -137,6 +238,7 @@ export abstract class GFXInputAssembler extends GFXObject {
}
/**
* @en
* update VB data on the fly.
* @param vbuffer - an ArrayBuffer containing the full VB
* @param attr - name of the attribute to update (default names are specified in GFXAttributeName)
@@ -148,6 +250,11 @@ export abstract class GFXInputAssembler extends GFXObject {
* const submodel = someModelComponent.model.getSubModel(0);
* // say the new positions is stored in 'data' as a plain array
* submodel.inputAssembler.updateVertexBuffer(vbuffer, cc.GFXAttributeName.ATTR_POSITION, data);
* @zh
* 根据顶点属性名称更新顶点缓冲数据
* @param vbuffer 缓冲数据源
* @param attr 属性名
* @param data 更新数据
*/
public updateVertexAttr (vbuffer: GFXBufferSource, attr: string, data: number[]) {
let offset = 0;
@@ -174,6 +281,10 @@ export abstract class GFXInputAssembler extends GFXObject {
* const submodel = someModelComponent.model.getSubModel(0);
* submodel.inputAssembler.updateIndexBuffer(ibuffer, [0, 1, 2]);
* submodel.updateCommandBuffer(); // index count changed
* @zh
* 更新索引缓冲数据
* @param ibuffer 缓冲数据源
* @param data 更新数据
*/
public updateIndexBuffer (ibuffer: GFXBufferSource, data: number[]) {
const count = this._indexCount;
-2
View File
@@ -182,7 +182,6 @@ export class WebGL2GFXDevice extends GFXDevice {
this._maxVertexTextureUnits = gl.getParameter(WebGL2RenderingContext.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
this._maxUniformBufferBindings = gl.getParameter(WebGL2RenderingContext.MAX_UNIFORM_BUFFER_BINDINGS);
this._maxUniformBlockSize = gl.getParameter(WebGL2RenderingContext.MAX_UNIFORM_BLOCK_SIZE);
this._maxCombinedUniformBlocks = gl.getParameter(WebGL2RenderingContext.MAX_COMBINED_UNIFORM_BLOCKS);
this._depthBits = gl.getParameter(WebGL2RenderingContext.DEPTH_BITS);
this._stencilBits = gl.getParameter(WebGL2RenderingContext.STENCIL_BITS);
// let maxVertexUniformBlocks = gl.getParameter(WebGL2RenderingContext.MAX_VERTEX_UNIFORM_BLOCKS);
@@ -299,7 +298,6 @@ export class WebGL2GFXDevice extends GFXDevice {
// console.info('MAX_VERTEX_TEXTURE_IMAGE_UNITS: ' + this._maxVertexTextureUnits);
console.info('MAX_UNIFORM_BUFFER_BINDINGS: ' + this._maxUniformBufferBindings);
// console.info('MAX_UNIFORM_BLOCK_SIZE: ' + this._maxUniformBlockSize);
// console.info('MAX_COMBINED_UNIFORM_BLOCKS: ' + this._maxCombinedUniformBlocks);
console.info('DEPTH_BITS: ' + this._depthBits);
console.info('STENCIL_BITS: ' + this._stencilBits);
// console.info('UNIFORM_BUFFER_OFFSET_ALIGNMENT: ' + uboOffsetAlignment);