Merge pull request #121 from shrinktofit/skinning-model

fix webgl-debug
This commit is contained in:
Weiliang Wang
2019-01-24 18:48:10 +08:00
committed by GitHub
9 changed files with 59 additions and 48 deletions
@@ -27,7 +27,7 @@
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
import { mat4 } from '../../core/vmath';
import { GFXDevice, GFXFeature } from '../../gfx/device';
import { SkinningModel } from '../../renderer/models/skinning-model';
import { SkinningModel, __FORCE_USE_UNIFORM_STORAGE__ } from '../../renderer/models/skinning-model';
import { Node } from '../../scene-graph/node';
import { Material } from '../assets/material';
import Skeleton from '../assets/skeleton';
@@ -131,15 +131,16 @@ export default class SkinningModelComponent extends ModelComponent {
}
public _updateModelParams () {
super._updateModelParams();
// Should bind skeleton before super create pso
this._bindSkeleton();
super._updateModelParams();
}
protected _onMaterialModified (index: number, material: Material) {
super._onMaterialModified(index, material);
const device = _getGlobalDevice();
const useJointTexture = device !== null && device.hasFeature(GFXFeature.TEXTURE_FLOAT) && false;
const useJointTexture = !__FORCE_USE_UNIFORM_STORAGE__ && device !== null && device.hasFeature(GFXFeature.TEXTURE_FLOAT);
this.getMaterial(0, CC_EDITOR)!.setDefines({
CC_USE_SKINNING: true,
CC_USE_JOINTS_TEXTURE: useJointTexture,
-34
View File
@@ -1,44 +1,10 @@
import { GFXAttributeName, GFXPrimitiveMode } from '../../gfx/define';
export { default as find } from '../../scene-graph/find';
import { Texture2D } from '../../assets/texture-2d';
import { Filter, PixelFormat, WrapMode } from '../../assets/texture-base';
import { Vec3 } from '../../core/value-types';
import { AttributeBaseType, AttributeType,
IMeshStruct, IndexUnit, IPrimitive, IVertexAttribute, IVertexBundle, Mesh } from '../assets/mesh';
import { IGeometry } from '../primitive/define';
/**
*
*/
export function createJointsTexture (skinning: { joints: any[]; }) {
const jointCount = skinning.joints.length;
// Set jointsTexture.
// A squared texture with side length N(N > 1) multiples of 2 can store
// 2 ^ (2 * N - 2) matrices.
// We support most 1024 joints.
let size = 0;
if (jointCount > 1024) {
throw new Error('To many joints(more than 1024).');
} else if (jointCount > 256) {
size = 64;
} else if (jointCount > 64) {
size = 32;
} else if (jointCount > 16) {
size = 16;
} else if (jointCount > 4) {
size = 8;
} else {
size = 4;
}
const texture = new Texture2D();
texture.create(size, size, PixelFormat.RGBA32F);
texture.setFilters(Filter.NEAREST, Filter.NEAREST);
texture.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE);
return texture;
}
const copyAttribute = (attribute: IVertexAttribute) => Object.assign({}, attribute);
export function createMesh (geometry: IGeometry) {
// Collect attributes and calculate length of result vertex buffer.
+1 -3
View File
@@ -1,4 +1,4 @@
//import * as WebGLDeveloperTools from 'webgl-debug';
import * as WebGLDeveloperTools from 'webgl-debug';
import { GFXBindingLayout, GFXBindingUnit, IGFXBindingLayoutInfo } from '../binding-layout';
import { GFXBuffer, GFXBufferSource, IGFXBufferInfo, IGFXIndirectBuffer } from '../buffer';
import { GFXCommandAllocator, IGFXCommandAllocatorInfo } from '../command-allocator';
@@ -254,11 +254,9 @@ export class WebGLGFXDevice extends GFXDevice {
};
this._webGLRC = this._canvas.getContext('webgl', webGLCtxAttribs);
/*
if (this._webGLRC && info.debug) {
this._webGLRC = WebGLDeveloperTools.makeDebugContext(this._webGLRC, this._onWebGLError.bind(this));
}
*/
} catch (err) {
console.error(err);
return false;
+15 -2
View File
@@ -1,9 +1,9 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import { IBlockInfo, IBlockMember, IDefineInfo, IShaderInfo } from '../../3d/assets/effect-asset';
import { IBlockInfo, IBlockMember, IDefineInfo, IShaderInfo, ISamplerInfo } from '../../3d/assets/effect-asset';
import { GFXGetTypeSize, GFXShaderType } from '../../gfx/define';
import { GFXDevice } from '../../gfx/device';
import { GFXShader, GFXUniform, GFXUniformBlock } from '../../gfx/shader';
import { GFXShader, GFXUniform, GFXUniformBlock, GFXUniformSampler } from '../../gfx/shader';
import { UBOGlobal, UBOLocal } from '../../pipeline/render-pipeline';
import { SkinningUBO } from '../models/model-uniforms';
import { IDefineMap } from './effect';
@@ -87,6 +87,8 @@ class ProgramLib {
}
if (def.name === 'CC_USE_SKINNING') {
tmpl.blocks = tmpl.blocks.concat(skinning);
} else if (def.name === 'CC_USE_JOINTS_TEXTURE') {
tmpl.samplers = tmpl.samplers.concat(jointsTexture);
}
offset += cnt;
def._offset = offset;
@@ -151,6 +153,7 @@ class ProgramLib {
const globals = convertToBlockInfo(UBOGlobal.BLOCK);
const locals = convertToBlockInfo(UBOLocal.BLOCK);
const skinning = convertToBlockInfo(SkinningUBO.BLOCK);
const jointsTexture = convertToSamplerInfo(SkinningUBO.JOINT_TEXTURE);
function convertToUniformInfo (uniform: GFXUniform): IBlockMember {
return {
@@ -177,5 +180,15 @@ function convertToBlockInfo (block: GFXUniformBlock): IBlockInfo {
};
}
function convertToSamplerInfo (sampler: GFXUniformSampler): ISamplerInfo {
return {
name: sampler.name,
binding: sampler.binding,
defines: [],
type: sampler.type,
count: sampler.count
};
}
const programLib = cc.programLib = new ProgramLib();
export { programLib };
+1 -1
View File
@@ -15,6 +15,6 @@ export class SkinningUBO {
};
public static JOINT_TEXTURE: GFXUniformSampler = {
binding: 28, name: 'CCJointTexture', type: GFXType.SAMPLER2D, count: 1,
binding: 28, name: 'cc_jointsTexture', type: GFXType.SAMPLER2D, count: 1,
};
}
+34 -3
View File
@@ -1,7 +1,6 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import Skeleton from '../../3d/assets/skeleton';
import { createJointsTexture } from '../../3d/misc/utils';
import { Texture2D } from '../../assets/texture-2d';
import { mat4 } from '../../core/vmath';
import { GFXBuffer } from '../../gfx/buffer';
@@ -12,6 +11,7 @@ import { Node } from '../../scene-graph/node';
import { Model } from '../scene/model';
import { RenderScene } from '../scene/render-scene';
import { SkinningUBO } from './model-uniforms';
import { PixelFormat, Filter, WrapMode } from '../../assets/texture-base';
const textureSizeBuffer = new Float32Array(4);
@@ -34,6 +34,8 @@ function isUniformStorage (storage: JointStorage): storage is IJointUniformsStor
return !('texture' in storage);
}
export const __FORCE_USE_UNIFORM_STORAGE__ = false;
export class SkinningModel extends Model {
private _jointStorage: JointStorage | null = null;
private _skinningUBO: GFXBuffer;
@@ -52,8 +54,8 @@ export class SkinningModel extends Model {
public bindSkeleton (skeleton: Skeleton) {
this._destroyJointStorage();
if (this._device.hasFeature(GFXFeature.TEXTURE_FLOAT) && false) {
const jointsTexture = createJointsTexture(skeleton);
if (!__FORCE_USE_UNIFORM_STORAGE__ && this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
const jointsTexture = _createJointsTexture(skeleton);
textureSizeBuffer[0] = jointsTexture.width;
this._skinningUBO.update(
textureSizeBuffer, SkinningUBO.JOINTS_TEXTURE_SIZE_OFFSET, textureSizeBuffer.byteLength);
@@ -129,3 +131,32 @@ function _setJointMatrix (out: Float32Array, iMatrix: number, matrix: mat4) {
out[16 * iMatrix + 14] = matrix.m14;
out[16 * iMatrix + 15] = matrix.m15;
}
function _createJointsTexture (skinning: { joints: any[]; }) {
const jointCount = skinning.joints.length;
// Set jointsTexture.
// A squared texture with side length N(N > 1) multiples of 2 can store
// 2 ^ (2 * N - 2) matrices.
// We support most 1024 joints.
let size = 0;
if (jointCount > 1024) {
throw new Error('To many joints(more than 1024).');
} else if (jointCount > 256) {
size = 64;
} else if (jointCount > 64) {
size = 32;
} else if (jointCount > 16) {
size = 16;
} else if (jointCount > 4) {
size = 8;
} else {
size = 4;
}
const texture = new Texture2D();
texture.create(size, size, PixelFormat.RGBA32F);
texture.setFilters(Filter.NEAREST, Filter.NEAREST);
texture.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE);
return texture;
}
+1 -1
View File
@@ -77,7 +77,7 @@
"vinyl-buffer": "1.0.0",
"vinyl-source-stream": "1.0.0",
"watchify": "^3.7.0",
"webgl-debug": "github:cocos-creator/webgl-debug#5f9cbdd",
"webgl-debug": "github:cocos-creator/webgl-debug#4e535ed",
"yargs": "^12.0.5"
}
}
+1
View File
@@ -66,6 +66,7 @@ async function _doBundle (options: IBuildOptions) {
commonjs({
namedExports: {
cannon: ['CANNON', 'Shape'],
'webgl-debug': ['makeDebugContext', 'glEnumToString'],
},
}),
];
+2 -1
View File
@@ -60,7 +60,8 @@ export default {
commonjs({
namedExports: {
'cannon': ['CANNON']
'cannon': ['CANNON'],
'webgl-debug': ['makeDebugContext', 'glEnumToString']
}
}),
]