mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Merge pull request #2564 from cocos-creator/optimize
Merge optimizations into next
This commit is contained in:
+22
-13
@@ -30,6 +30,7 @@ const AutoReleaseUtils = require('./load-pipeline/auto-release-utils');
|
||||
const ComponentScheduler = require('./component-scheduler');
|
||||
const NodeActivator = require('./node-activator');
|
||||
const EventListeners = require('./event/event-listeners');
|
||||
const Obj = require('./platform/CCObject');
|
||||
const renderer = require('./renderer');
|
||||
const eventManager = require('./event-manager');
|
||||
|
||||
@@ -120,7 +121,7 @@ cc.Director = function () {
|
||||
|
||||
// FPS
|
||||
this._totalFrames = 0;
|
||||
this._lastUpdate = Date.now();
|
||||
this._lastUpdate = performance.now();
|
||||
this._deltaTime = 0.0;
|
||||
|
||||
// Scheduler for user registration update
|
||||
@@ -134,7 +135,7 @@ cc.Director = function () {
|
||||
|
||||
var self = this;
|
||||
cc.game.on(cc.game.EVENT_SHOW, function () {
|
||||
self._lastUpdate = Date.now();
|
||||
self._lastUpdate = performance.now();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -142,7 +143,7 @@ cc.Director.prototype = {
|
||||
constructor: cc.Director,
|
||||
init: function () {
|
||||
this._totalFrames = 0;
|
||||
this._lastUpdate = Date.now();
|
||||
this._lastUpdate = performance.now();
|
||||
this._paused = false;
|
||||
this._purgeDirectorInNextLoop = false;
|
||||
this._winSizeInPoints = cc.size(0, 0);
|
||||
@@ -211,7 +212,7 @@ cc.Director.prototype = {
|
||||
* calculates delta time since last time it was called
|
||||
*/
|
||||
calculateDeltaTime: function () {
|
||||
var now = Date.now();
|
||||
var now = performance.now();
|
||||
|
||||
this._deltaTime = (now - this._lastUpdate) / 1000;
|
||||
if ((cc.game.config[cc.game.CONFIG_KEY.debugMode] > 0) && (this._deltaTime > 1))
|
||||
@@ -440,7 +441,7 @@ cc.Director.prototype = {
|
||||
this._scene = null;
|
||||
|
||||
// purge destroyed nodes belongs to old scene
|
||||
cc.Object._deferredDestroy();
|
||||
Obj._deferredDestroy();
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('Destroy');
|
||||
|
||||
if (onBeforeLoadScene) {
|
||||
@@ -673,7 +674,7 @@ cc.Director.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
this._lastUpdate = Date.now();
|
||||
this._lastUpdate = performance.now();
|
||||
if (!this._lastUpdate) {
|
||||
cc.logID(1200);
|
||||
}
|
||||
@@ -899,7 +900,7 @@ cc.Director.prototype = {
|
||||
*/
|
||||
startAnimation: function () {
|
||||
this.invalid = false;
|
||||
this._lastUpdate = Date.now();
|
||||
this._lastUpdate = performance.now();
|
||||
},
|
||||
|
||||
/*
|
||||
@@ -913,6 +914,7 @@ cc.Director.prototype = {
|
||||
* Run main loop of director
|
||||
*/
|
||||
mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) {
|
||||
// Update
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
|
||||
@@ -928,12 +930,15 @@ cc.Director.prototype = {
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
}
|
||||
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
// Render
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
// After draw
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
this._totalFrames++;
|
||||
|
||||
} : function () {
|
||||
if (this._purgeDirectorInNextLoop) {
|
||||
this._purgeDirectorInNextLoop = false;
|
||||
@@ -943,6 +948,7 @@ cc.Director.prototype = {
|
||||
// calculate "global" dt
|
||||
this.calculateDeltaTime();
|
||||
|
||||
// Update
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Call start for new added components
|
||||
@@ -956,15 +962,18 @@ cc.Director.prototype = {
|
||||
// User can use this event to do things after update
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
Obj._deferredDestroy();
|
||||
}
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
|
||||
// Render
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
// After draw
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
|
||||
eventManager.frameUpdateListeners();
|
||||
this._totalFrames++;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+149
-62
@@ -43,7 +43,6 @@ const POSITION_CHANGED = 'position-changed';
|
||||
const SIZE_CHANGED = 'size-changed';
|
||||
const ANCHOR_CHANGED = 'anchor-changed';
|
||||
const ROTATION_CHANGED = 'rotation-changed';
|
||||
const WORLD_MATRIX_CHANGED = 'world-matrix-changed';
|
||||
const SCALE_CHANGED = 'scale-changed';
|
||||
const CHILD_REORDER = 'child-reorder';
|
||||
|
||||
@@ -55,8 +54,17 @@ var emptyFunc = function () {};
|
||||
var _mat4_temp = math.mat4.create();
|
||||
var _vec3_temp = math.vec3.create();
|
||||
var _quat_temp = math.quat.create();
|
||||
var _parents = [];
|
||||
var _globalOrderOfArrival = 1;
|
||||
|
||||
const POSITION_DIRTY_FLAG = 1 << 0;
|
||||
const SCALE_DIRTY_FLAG = 1 << 1;
|
||||
const ROTATION_DIRTY_FLAG = 1 << 2;
|
||||
const SKEW_DIRTY_FLAG = 1 << 3;
|
||||
// rotation transform dirty
|
||||
const RT_DIRTY_FLAG = SCALE_DIRTY_FLAG | ROTATION_DIRTY_FLAG | SKEW_DIRTY_FLAG;
|
||||
const ALL_DIRTY_FLAG = 0xffff;
|
||||
|
||||
/**
|
||||
* !#en The event type supported by Node
|
||||
* !#zh Node 支持的事件类型
|
||||
@@ -308,6 +316,16 @@ function _checkListeners (node, events) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function _syncWorldDirty (children) {
|
||||
for (let i = 0, l = children.length; i < l; i++) {
|
||||
let child = children[i];
|
||||
child._worldMatDirty = true;
|
||||
if (child._children.length > 0) {
|
||||
_syncWorldDirty(child._children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Class of all entities in Cocos Creator scenes.<br/>
|
||||
@@ -421,7 +439,7 @@ var Node = cc.Class({
|
||||
}
|
||||
|
||||
localPosition.x = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(POSITION_DIRTY_FLAG);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -464,7 +482,7 @@ var Node = cc.Class({
|
||||
}
|
||||
|
||||
localPosition.y = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(POSITION_DIRTY_FLAG);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -494,7 +512,7 @@ var Node = cc.Class({
|
||||
if (value !== localPosition.z) {
|
||||
if (!CC_EDITOR || isFinite(value)) {
|
||||
localPosition.z = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(POSITION_DIRTY_FLAG);
|
||||
}
|
||||
else {
|
||||
cc.error(ERR_INVALID_NUMBER, 'new z');
|
||||
@@ -524,7 +542,7 @@ var Node = cc.Class({
|
||||
this._rotationX = this._rotationY = value;
|
||||
// Update quaternion from rotation
|
||||
math.quat.fromEuler(this._quat, 0, 0, -value);
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(ROTATION_DIRTY_FLAG);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[ROTATION_CHANGED]) {
|
||||
@@ -557,7 +575,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
math.quat.fromEuler(this._quat, value, this._rotationY, 0);
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(ROTATION_DIRTY_FLAG);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[ROTATION_CHANGED]) {
|
||||
@@ -590,7 +608,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
math.quat.fromEuler(this._quat, this._rotationX, value, 0);
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(ROTATION_DIRTY_FLAG);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[ROTATION_CHANGED]) {
|
||||
@@ -625,7 +643,7 @@ var Node = cc.Class({
|
||||
set (value) {
|
||||
if (this._scale.x !== value) {
|
||||
this._scale.x = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(SCALE_DIRTY_FLAG);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[SCALE_CHANGED]) {
|
||||
@@ -651,7 +669,7 @@ var Node = cc.Class({
|
||||
set (value) {
|
||||
if (this._scale.y !== value) {
|
||||
this._scale.y = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(SCALE_DIRTY_FLAG);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[SCALE_CHANGED]) {
|
||||
@@ -676,7 +694,7 @@ var Node = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._skewX = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(SKEW_DIRTY_FLAG);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -695,7 +713,7 @@ var Node = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._skewY = value;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(SKEW_DIRTY_FLAG);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -908,8 +926,9 @@ var Node = cc.Class({
|
||||
|
||||
this._matrix = mathPools.mat4.get();
|
||||
this._worldMatrix = mathPools.mat4.get();
|
||||
this._localMatDirty = true;
|
||||
this._worldMatDirty = true;
|
||||
this._localMatDirty = 0;
|
||||
this._worldMatDirty = false;
|
||||
this.setLocalDirty(ALL_DIRTY_FLAG);
|
||||
|
||||
this._cullingMask = 1 << this.groupIndex;
|
||||
},
|
||||
@@ -983,6 +1002,7 @@ var Node = cc.Class({
|
||||
var actionManager = ActionManagerExist ? cc.director.getActionManager() : null;
|
||||
if (active) {
|
||||
// activate
|
||||
// ActionManager & EventManager
|
||||
actionManager && actionManager.resumeTarget(this);
|
||||
eventManager.resumeTarget(this);
|
||||
if (this._touchListener) {
|
||||
@@ -1506,7 +1526,7 @@ var Node = cc.Class({
|
||||
*/
|
||||
setPosition (newPosOrX, y) {
|
||||
var x;
|
||||
if (typeof y === 'undefined') {
|
||||
if (y === undefined) {
|
||||
x = newPosOrX.x;
|
||||
y = newPosOrX.y;
|
||||
}
|
||||
@@ -1535,7 +1555,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
return cc.error(ERR_INVALID_NUMBER, 'y of new position');
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(POSITION_DIRTY_FLAG);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -1577,7 +1597,7 @@ var Node = cc.Class({
|
||||
* node.setScale(1, 1);
|
||||
*/
|
||||
setScale (scaleX, scaleY) {
|
||||
if (typeof scaleX === 'object') {
|
||||
if (scaleX && typeof scaleX !== 'number') {
|
||||
scaleY = scaleX.y;
|
||||
scaleX = scaleX.x;
|
||||
}
|
||||
@@ -1587,7 +1607,7 @@ var Node = cc.Class({
|
||||
if (this._scale.x !== scaleX || this._scale.y !== scaleY) {
|
||||
this._scale.x = scaleX;
|
||||
this._scale.y = scaleY;
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(SCALE_DIRTY_FLAG);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[SCALE_CHANGED]) {
|
||||
@@ -1725,7 +1745,7 @@ var Node = cc.Class({
|
||||
locAnchorPoint.x = point;
|
||||
locAnchorPoint.y = y;
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(POSITION_DIRTY_FLAG);
|
||||
this.emit(ANCHOR_CHANGED);
|
||||
},
|
||||
|
||||
@@ -1792,8 +1812,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
math.vec3.copy(this._position, pos);
|
||||
}
|
||||
|
||||
this._localMatDirty = true;
|
||||
this.setLocalDirty(POSITION_DIRTY_FLAG);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -1880,29 +1899,70 @@ var Node = cc.Class({
|
||||
},
|
||||
|
||||
_updateLocalMatrix () {
|
||||
if (this._localMatDirty) {
|
||||
// Update transform
|
||||
let t = this._matrix;
|
||||
math.mat4.fromRTS(t, this._quat, this._position, this._scale);
|
||||
let dirtyFlag = this._localMatDirty;
|
||||
if (!dirtyFlag) return;
|
||||
|
||||
// skew
|
||||
if (this._skewX || this._skewY) {
|
||||
let a = t.m00, b = t.m01, c = t.m04, d = t.m05;
|
||||
let skx = Math.tan(this._skewX * ONE_DEGREE);
|
||||
let sky = Math.tan(this._skewY * ONE_DEGREE);
|
||||
if (skx === Infinity)
|
||||
skx = 99999999;
|
||||
if (sky === Infinity)
|
||||
sky = 99999999;
|
||||
t.m00 = a + c * sky;
|
||||
t.m01 = b + d * sky;
|
||||
t.m04 = c + a * skx;
|
||||
t.m05 = d + b * skx;
|
||||
// Update transform
|
||||
let t = this._matrix;
|
||||
//math.mat4.fromRTS(t, this._quat, this._position, this._scale);
|
||||
|
||||
if (dirtyFlag & RT_DIRTY_FLAG) {
|
||||
let hasRotation = this._rotationX || this._rotationY;
|
||||
let hasSkew = this._skewX || this._skewY;
|
||||
let sx = this._scale.x, sy = this._scale.y;
|
||||
|
||||
if (hasRotation || hasSkew) {
|
||||
let a = 1, b = 0, c = 0, d = 1;
|
||||
// rotation
|
||||
if (hasRotation) {
|
||||
let rotationRadiansX = this._rotationX * ONE_DEGREE;
|
||||
c = Math.sin(rotationRadiansX);
|
||||
d = Math.cos(rotationRadiansX);
|
||||
if (this._rotationY === this._rotationX) {
|
||||
a = d;
|
||||
b = -c;
|
||||
}
|
||||
else {
|
||||
let rotationRadiansY = this._rotationY * ONE_DEGREE;
|
||||
a = Math.cos(rotationRadiansY);
|
||||
b = -Math.sin(rotationRadiansY);
|
||||
}
|
||||
}
|
||||
// scale
|
||||
t.m00 = a *= sx;
|
||||
t.m01 = b *= sx;
|
||||
t.m04 = c *= sy;
|
||||
t.m05 = d *= sy;
|
||||
// skew
|
||||
if (hasSkew) {
|
||||
let a = t.m00, b = t.m01, c = t.m04, d = t.m05;
|
||||
let skx = Math.tan(this._skewX * ONE_DEGREE);
|
||||
let sky = Math.tan(this._skewY * ONE_DEGREE);
|
||||
if (skx === Infinity)
|
||||
skx = 99999999;
|
||||
if (sky === Infinity)
|
||||
sky = 99999999;
|
||||
t.m00 = a + c * sky;
|
||||
t.m01 = b + d * sky;
|
||||
t.m04 = c + a * skx;
|
||||
t.m05 = d + b * skx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
t.m00 = sx;
|
||||
t.m01 = 0;
|
||||
t.m04 = 0;
|
||||
t.m05 = sy;
|
||||
}
|
||||
this._localMatDirty = false;
|
||||
// Register dirty status of world matrix so that it can be recalculated
|
||||
this._worldMatDirty = true;
|
||||
}
|
||||
|
||||
// position
|
||||
t.m12 = this._position.x;
|
||||
t.m13 = this._position.y;
|
||||
|
||||
this._localMatDirty = 0;
|
||||
// Register dirty status of world matrix so that it can be recalculated
|
||||
this._worldMatDirty = true;
|
||||
},
|
||||
|
||||
_calculWorldMatrix () {
|
||||
@@ -1912,34 +1972,64 @@ var Node = cc.Class({
|
||||
}
|
||||
|
||||
// Assume parent world matrix is correct
|
||||
if (this._parent) {
|
||||
let parentMat = this._parent._worldMatrix;
|
||||
math.mat4.mul(this._worldMatrix, parentMat, this._matrix);
|
||||
let parent = this._parent;
|
||||
if (parent) {
|
||||
let pt = parent._worldMatrix;
|
||||
let t = this._matrix;
|
||||
let wt = this._worldMatrix;
|
||||
let aa=t.m00, ab=t.m01, ac=t.m04, ad=t.m05, atx=t.m12, aty=t.m13;
|
||||
let ba=pt.m00, bb=pt.m01, bc=pt.m04, bd=pt.m05, btx=pt.m12, bty=pt.m13;
|
||||
if (bb !== 0 || bc !== 0) {
|
||||
wt.m00 = aa * ba + ab * bc;
|
||||
wt.m01 = aa * bb + ab * bd;
|
||||
wt.m04 = ac * ba + ad * bc;
|
||||
wt.m05 = ac * bb + ad * bd;
|
||||
wt.m12 = ba * atx + bc * aty + btx;
|
||||
wt.m13 = bb * atx + bd * aty + bty;
|
||||
}
|
||||
else {
|
||||
wt.m00 = aa * ba;
|
||||
wt.m01 = ab * bd;
|
||||
wt.m04 = ac * ba;
|
||||
wt.m05 = ad * bd;
|
||||
wt.m12 = ba * atx + btx;
|
||||
wt.m13 = bd * aty + bty;
|
||||
}
|
||||
}
|
||||
else {
|
||||
math.mat4.copy(this._worldMatrix, this._matrix);
|
||||
}
|
||||
this._worldMatDirty = false;
|
||||
|
||||
this.emit(WORLD_MATRIX_CHANGED);
|
||||
|
||||
for (let i = 0, len = this._children.length; i < len; ++i) {
|
||||
let child = this._children[i];
|
||||
child._calculWorldMatrix();
|
||||
}
|
||||
},
|
||||
|
||||
_updateWorldMatrix () {
|
||||
let curr = this;
|
||||
let changedRoot = null;
|
||||
while (curr) {
|
||||
if (curr._localMatDirty || curr._worldMatDirty) {
|
||||
changedRoot = curr;
|
||||
}
|
||||
curr = curr._parent;
|
||||
let n = -1;
|
||||
// Find root of world matrix changing
|
||||
for (let node = this; node && node._worldMatDirty; node = node._parent) {
|
||||
n++;
|
||||
_parents[n] = node;
|
||||
}
|
||||
if (changedRoot) {
|
||||
changedRoot._calculWorldMatrix();
|
||||
// Update world matrix of all changed parents
|
||||
for (let i = n; i >= 0; i--) {
|
||||
_parents[i]._calculWorldMatrix();
|
||||
_parents[i] = null;
|
||||
}
|
||||
},
|
||||
|
||||
setLocalDirty (flag) {
|
||||
if (!this._localMatDirty) {
|
||||
this.setWorldDirty();
|
||||
}
|
||||
this._localMatDirty = this._localMatDirty | flag;
|
||||
},
|
||||
|
||||
setWorldDirty () {
|
||||
if (!this._worldMatDirty) {
|
||||
this._worldMatDirty = true;
|
||||
// Sync world mat dirty to sub tree
|
||||
if (this._children.length > 0) {
|
||||
_syncWorldDirty(this._children);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2400,9 +2490,6 @@ var Node = cc.Class({
|
||||
},
|
||||
|
||||
onRestore: CC_EDITOR && function () {
|
||||
this._localMatDirty = true;
|
||||
this._worldMatDirty = true;
|
||||
|
||||
this._onRestoreBase();
|
||||
|
||||
var actionManager = cc.director.getActionManager();
|
||||
|
||||
@@ -56,6 +56,26 @@ let RenderTexture = cc.Class({
|
||||
this.emit("load");
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Draw a texture to the specified position
|
||||
* !#zh 将指定的图片渲染到指定的位置上
|
||||
* @param {Texture2D} texture
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
drawTextureAt (texture, x, y) {
|
||||
if (!texture._image) return;
|
||||
|
||||
this._texture.updateSubImage({
|
||||
x, y,
|
||||
image: texture._image,
|
||||
width: texture.width,
|
||||
height: texture.height,
|
||||
level: 0,
|
||||
flipY: false
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Get pixels from render texture, the pixels data stores in a RGBA Uint8Array.
|
||||
|
||||
@@ -158,6 +158,9 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
this._texture = null;
|
||||
this._textureFilename = '';
|
||||
|
||||
// store original info before packed to dynamic atlas
|
||||
this._original = null;
|
||||
|
||||
if (CC_EDITOR) {
|
||||
// Atlas asset uuid
|
||||
this._atlasUuid = '';
|
||||
|
||||
@@ -367,9 +367,6 @@ var Texture2D = cc.Class({
|
||||
this._image = options.images[0];
|
||||
}
|
||||
else if (options.image !== undefined) {
|
||||
// Release previous gl texture if existed
|
||||
this._texture.destroy();
|
||||
|
||||
this._image = options.image;
|
||||
if (!options.images) {
|
||||
_images.length = 0;
|
||||
|
||||
@@ -291,9 +291,8 @@ let Camera = cc.Class({
|
||||
},
|
||||
|
||||
onEnable () {
|
||||
this.node.on('world-matrix-changed', this._onMatrixDirty, this);
|
||||
this._matrixDirty = true;
|
||||
|
||||
cc.director.on(cc.Director.EVENT_BEFORE_DRAW, this.beforeDraw, this);
|
||||
if (game.renderType === game.RENDER_TYPE_WEBGL) {
|
||||
renderer.scene.addCamera(this._camera);
|
||||
}
|
||||
@@ -301,8 +300,7 @@ let Camera = cc.Class({
|
||||
},
|
||||
|
||||
onDisable () {
|
||||
this.node.off('world-matrix-changed', this._onMatrixDirty, this);
|
||||
|
||||
cc.director.off(cc.Director.EVENT_BEFORE_DRAW, this.beforeDraw, this);
|
||||
if (game.renderType === game.RENDER_TYPE_WEBGL) {
|
||||
renderer.scene.removeCamera(this._camera);
|
||||
}
|
||||
@@ -432,17 +430,19 @@ let Camera = cc.Class({
|
||||
root = root || cc.director.getScene();
|
||||
if (!root) return null;
|
||||
|
||||
this.lateUpdate();
|
||||
// force update node world matrix
|
||||
this.node.getWorldMatrix(_mat4_temp_1);
|
||||
this.beforeDraw();
|
||||
renderer._walker.visit(root);
|
||||
renderer._forward.renderCamera(this._camera, renderer.scene);
|
||||
},
|
||||
|
||||
lateUpdate: !CC_EDITOR && function () {
|
||||
beforeDraw: !CC_EDITOR && function () {
|
||||
let node = this.node;
|
||||
node.getWorldMatrix(_mat4_temp_1);
|
||||
|
||||
if (!this._matrixDirty) return;
|
||||
|
||||
if (!this._matrixDirty && !node._worldMatDirty)
|
||||
return;
|
||||
|
||||
let camera = this._camera;
|
||||
let fov = Math.atan(Math.tan(this._fov/2) / this.zoomRatio)*2;
|
||||
camera.setFov(fov);
|
||||
@@ -454,8 +454,9 @@ let Camera = cc.Class({
|
||||
height = targetTexture.height;
|
||||
}
|
||||
|
||||
_vec3_temp_1.x = _mat4_temp_1.m12;
|
||||
_vec3_temp_1.y = _mat4_temp_1.m13;
|
||||
node._updateWorldMatrix();
|
||||
_vec3_temp_1.x = node._worldMatrix.m12;
|
||||
_vec3_temp_1.y = node._worldMatrix.m13;
|
||||
_vec3_temp_1.z = 0;
|
||||
|
||||
node.z = height / 1.1566;
|
||||
|
||||
@@ -504,7 +504,6 @@ var Label = cc.Class({
|
||||
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.worldMatDirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -51,6 +51,12 @@ var RenderComponent = cc.Class({
|
||||
this.__allocedDatas = [];
|
||||
this._vertexFormat = defaultVertexFormat;
|
||||
this._toPostHandle = false;
|
||||
// Render component chain entries
|
||||
this._chain = {
|
||||
comp: this,
|
||||
next: null
|
||||
};
|
||||
this._postChain = null;
|
||||
},
|
||||
|
||||
onEnable () {
|
||||
|
||||
@@ -464,9 +464,9 @@ var Sprite = cc.Class({
|
||||
* @param state {Sprite.State} NORMAL or GRAY State.
|
||||
*/
|
||||
setState: function (state) {
|
||||
if (this._state === state) return;
|
||||
this._state = state;
|
||||
this._material = null;
|
||||
this._activateMaterial();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -483,11 +483,8 @@ var Sprite = cc.Class({
|
||||
|
||||
this._updateAssembler();
|
||||
|
||||
this._activateMaterial();
|
||||
|
||||
this.node.on('size-changed', this._onNodeSizeDirty, this);
|
||||
this.node.on('anchor-changed', this._onNodeSizeDirty, this);
|
||||
this.node.on('world-matrix-changed', this._onNodeMatrixDirty, this);
|
||||
},
|
||||
|
||||
onDisable: function () {
|
||||
@@ -495,7 +492,6 @@ var Sprite = cc.Class({
|
||||
|
||||
this.node.off('size-changed', this._onNodeSizeDirty, this);
|
||||
this.node.off('anchor-changed', this._onNodeSizeDirty, this);
|
||||
this.node.off('world-matrix-changed', this._onNodeMatrixDirty, this);
|
||||
},
|
||||
|
||||
_onNodeSizeDirty () {
|
||||
@@ -504,12 +500,6 @@ var Sprite = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
_onNodeMatrixDirty () {
|
||||
if (this._renderData) {
|
||||
this._renderData.worldMatDirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
_updateAssembler: function () {
|
||||
let assembler = Sprite._assembler.getAssembler(this);
|
||||
|
||||
@@ -520,46 +510,50 @@ var Sprite = cc.Class({
|
||||
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.worldMatDirty = true;
|
||||
this._renderData.material = this._material;
|
||||
}
|
||||
},
|
||||
|
||||
_activateMaterial: function () {
|
||||
if (this._material) return;
|
||||
|
||||
let spriteFrame = this._spriteFrame;
|
||||
// cannot be activated if texture not loaded yet
|
||||
if (!this._spriteFrame || !this._spriteFrame.textureLoaded()) {
|
||||
if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get material
|
||||
if (!this._material) {
|
||||
let texture = this._spriteFrame.getTexture();
|
||||
let url = texture.url;
|
||||
let key = url;
|
||||
if (this._state === State.GRAY) {
|
||||
key = url + ':gray';
|
||||
}
|
||||
if (this._state === State.GRAY) {
|
||||
this._material = new GraySpriteMaterial();
|
||||
}
|
||||
else {
|
||||
this._material = new SpriteMaterial();
|
||||
}
|
||||
// TODO: old texture in material have been released by loader
|
||||
this._material.texture = texture;
|
||||
let texture = spriteFrame.getTexture();
|
||||
let url = texture.url;
|
||||
let key = url;
|
||||
if (this._state === State.GRAY) {
|
||||
key = url + ':gray';
|
||||
}
|
||||
|
||||
let material;
|
||||
if (this._state === State.GRAY) {
|
||||
material = new GraySpriteMaterial();
|
||||
}
|
||||
else {
|
||||
material = new SpriteMaterial();
|
||||
}
|
||||
// TODO: old texture in material have been released by loader
|
||||
material.texture = texture;
|
||||
|
||||
if (this.srcBlendFactor !== gfx.BLEND_SRC_ALPHA || this.dstBlendFactor !== gfx.BLEND_ONE_MINUS_SRC_ALPHA) {
|
||||
// Update hash inside
|
||||
this._updateBlendFunc();
|
||||
}
|
||||
else {
|
||||
this._material.updateHash();
|
||||
material.updateHash();
|
||||
}
|
||||
|
||||
if (this._renderData) {
|
||||
this._renderData.material = this._material;
|
||||
this._renderData.material = material;
|
||||
}
|
||||
|
||||
this._material = material;
|
||||
},
|
||||
|
||||
_updateBlendFunc: function () {
|
||||
@@ -641,10 +635,7 @@ var Sprite = cc.Class({
|
||||
if (!this.isValid) {
|
||||
return;
|
||||
}
|
||||
// Reactivate material
|
||||
if (this.enabledInHierarchy) {
|
||||
this._activateMaterial();
|
||||
}
|
||||
|
||||
this._applySpriteSize();
|
||||
},
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ var NodeActivator = cc.Class({
|
||||
if (cc.engine._isPlaying || comp.constructor._executeInEditMode) {
|
||||
if (!(comp._objFlags & IsPreloadStarted)) {
|
||||
comp._objFlags |= IsPreloadStarted;
|
||||
if (typeof comp.__preload === 'function') {
|
||||
if (comp.__preload) {
|
||||
if (preloadInvoker) {
|
||||
preloadInvoker.add(comp);
|
||||
}
|
||||
@@ -285,7 +285,7 @@ var NodeActivator = cc.Class({
|
||||
} : function (comp, preloadInvoker, onLoadInvoker, onEnableInvoker) {
|
||||
if (!(comp._objFlags & IsPreloadStarted)) {
|
||||
comp._objFlags |= IsPreloadStarted;
|
||||
if (typeof comp.__preload === 'function') {
|
||||
if (comp.__preload) {
|
||||
if (preloadInvoker) {
|
||||
preloadInvoker.add(comp);
|
||||
}
|
||||
@@ -337,7 +337,7 @@ var NodeActivator = cc.Class({
|
||||
},
|
||||
|
||||
resetComp: CC_EDITOR && function (comp) {
|
||||
if (typeof comp.resetInEditor === 'function') {
|
||||
if (comp.resetInEditor) {
|
||||
callResetInTryCatch(comp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ var inputManager = {
|
||||
var docElem = document.documentElement;
|
||||
var leftOffset = window.pageXOffset - docElem.clientLeft;
|
||||
var topOffset = window.pageYOffset - docElem.clientTop;
|
||||
if (typeof element.getBoundingClientRect === 'function') {
|
||||
if (element.getBoundingClientRect) {
|
||||
var box = element.getBoundingClientRect();
|
||||
return {
|
||||
left: box.left + leftOffset,
|
||||
|
||||
@@ -92,7 +92,7 @@ cc.screen = /** @lends cc.screen# */{
|
||||
}
|
||||
}
|
||||
|
||||
this._supportsFullScreen = (typeof this._fn.requestFullscreen !== 'undefined');
|
||||
this._supportsFullScreen = (this._fn.requestFullscreen !== undefined);
|
||||
this._touchEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown';
|
||||
},
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ var _Deserializer = (function () {
|
||||
// 和 _deserializeObject 不同的地方在于会判断 id 和 uuid
|
||||
prototype._deserializeObjField = function (obj, jsonObj, propName, target, _stillUseUrl) {
|
||||
var id = jsonObj.__id__;
|
||||
if (typeof id === 'undefined') {
|
||||
if (id === undefined) {
|
||||
var uuid = jsonObj.__uuid__;
|
||||
if (uuid) {
|
||||
//if (ENABLE_TARGET) {
|
||||
@@ -413,7 +413,7 @@ var _Deserializer = (function () {
|
||||
for (var i = 0; i < fastDefinedProps.length; i++) {
|
||||
var propName = fastDefinedProps[i];
|
||||
var prop = serialized[propName];
|
||||
if (typeof prop !== 'undefined' && serialized.hasOwnProperty(propName)) {
|
||||
if (prop !== undefined && serialized.hasOwnProperty(propName)) {
|
||||
if (typeof prop !== 'object') {
|
||||
instance[propName] = prop;
|
||||
}
|
||||
@@ -612,7 +612,7 @@ var _Deserializer = (function () {
|
||||
|
||||
prop = d[propNameToRead];
|
||||
|
||||
if (typeof prop !== 'undefined') {
|
||||
if (prop !== undefined) {
|
||||
var stillUseUrl = attrs[propName + SAVE_URL_AS_ASSET];
|
||||
// function undefined object(null) string boolean number
|
||||
var defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]);
|
||||
|
||||
@@ -269,7 +269,7 @@ var tmpGetSetDesc = {
|
||||
* @param {Object} obj
|
||||
* @param {String} prop
|
||||
* @param {Function} getter
|
||||
* @param {Function} setter
|
||||
* @param {Function} [setter=null]
|
||||
* @param {Boolean} [enumerable=false]
|
||||
*/
|
||||
js.getset = function (obj, prop, getter, setter, enumerable) {
|
||||
@@ -897,7 +897,7 @@ js.array = {
|
||||
* constructor(size: number)
|
||||
*/
|
||||
function Pool (cleanupFunc, size) {
|
||||
if (typeof cleanupFunc === 'number') {
|
||||
if (size === undefined) {
|
||||
size = cleanupFunc;
|
||||
cleanupFunc = null;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ const sin = Math.sin;
|
||||
const atan2 = Math.atan2;
|
||||
const abs = Math.abs;
|
||||
|
||||
let _matrix = math.mat4.create();
|
||||
let _renderData = null;
|
||||
let _impl = null;
|
||||
let _curColor = 0;
|
||||
@@ -95,9 +94,9 @@ let graphicsAssembler = js.addon({
|
||||
z = node._position.z;
|
||||
|
||||
// vertex buffer
|
||||
node.getWorldMatrix(_matrix);
|
||||
let a = _matrix.m00, b = _matrix.m01, c = _matrix.m04, d = _matrix.m05,
|
||||
tx = _matrix.m12, ty = _matrix.m13;
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
let nodeColor = node.color,
|
||||
nodeR = nodeColor.r / 255,
|
||||
|
||||
@@ -28,20 +28,26 @@ const renderEngine = require('../../render-engine');
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const bmfontUtls = require('../../utils/label/bmfont');
|
||||
const assembler = require('../assembler');
|
||||
const ttfAssembler = require('./ttf');
|
||||
|
||||
module.exports = js.addon({
|
||||
createData (comp) {
|
||||
return comp.requestRenderData();
|
||||
},
|
||||
|
||||
fillVertexBuffer (comp, off, vbuf, uintbuf) {
|
||||
updateRenderData: ttfAssembler.updateRenderData,
|
||||
|
||||
fillBuffers (comp, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
let vertexOffset = batchData.byteOffset / 4,
|
||||
indiceOffset = batchData.indiceOffset;
|
||||
|
||||
let node = comp.node;
|
||||
let renderData = comp._renderData;
|
||||
let data = renderData._data;
|
||||
let z = node._position.z;
|
||||
let color = node.color._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
@@ -54,26 +60,22 @@ module.exports = js.addon({
|
||||
let length = renderData.dataLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
vert = data[i];
|
||||
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[off + 2] = z;
|
||||
vbuf[off + 4] = vert.u;
|
||||
vbuf[off + 5] = vert.v;
|
||||
uintbuf[off + 3] = color;
|
||||
off += 6;
|
||||
vbuf[vertexOffset + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[vertexOffset + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[vertexOffset + 2] = z;
|
||||
vbuf[vertexOffset + 4] = vert.u;
|
||||
vbuf[vertexOffset + 5] = vert.v;
|
||||
uintbuf[vertexOffset + 3] = color;
|
||||
vertexOffset += 6;
|
||||
}
|
||||
},
|
||||
|
||||
fillIndexBuffer (comp, offset, vertexId, ibuf) {
|
||||
let renderData = comp._renderData;
|
||||
let length = renderData.indiceCount;
|
||||
length = renderData.indiceCount;
|
||||
for (let i = 0; i < length; i+=6) {
|
||||
ibuf[offset++] = vertexId;
|
||||
ibuf[offset++] = vertexId+1;
|
||||
ibuf[offset++] = vertexId+2;
|
||||
ibuf[offset++] = vertexId+1;
|
||||
ibuf[offset++] = vertexId+3;
|
||||
ibuf[offset++] = vertexId+2;
|
||||
ibuf[indiceOffset++] = vertexId;
|
||||
ibuf[indiceOffset++] = vertexId+1;
|
||||
ibuf[indiceOffset++] = vertexId+2;
|
||||
ibuf[indiceOffset++] = vertexId+1;
|
||||
ibuf[indiceOffset++] = vertexId+3;
|
||||
ibuf[indiceOffset++] = vertexId+2;
|
||||
vertexId += 4;
|
||||
}
|
||||
},
|
||||
@@ -132,4 +134,4 @@ module.exports = js.addon({
|
||||
data[dataOffset+3].x = x + rectWidth * scale;
|
||||
data[dataOffset+3].y = y;
|
||||
},
|
||||
}, bmfontUtls);
|
||||
}, bmfontUtls, assembler);
|
||||
|
||||
@@ -23,14 +23,11 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const assembler = require('../assembler');
|
||||
const Label = require('../../../components/CCLabel');
|
||||
const ttfAssembler = require('./ttf');
|
||||
const bmfontAssembler = require('./bmfont');
|
||||
|
||||
var labelAssembler = js.addon({
|
||||
|
||||
var labelAssembler = {
|
||||
getAssembler (comp) {
|
||||
let assembler = ttfAssembler;
|
||||
|
||||
@@ -41,40 +38,11 @@ var labelAssembler = js.addon({
|
||||
return assembler;
|
||||
},
|
||||
|
||||
updateRenderData (comp) {
|
||||
this.datas.length = 0;
|
||||
|
||||
if (comp.string === undefined ||
|
||||
comp.string === null ||
|
||||
comp.string === "" ||
|
||||
!comp._assembler) {
|
||||
return this.datas;
|
||||
}
|
||||
|
||||
let renderData = comp._renderData;
|
||||
|
||||
// let size = comp.node._contentSize;
|
||||
// let anchor = comp.node._anchorPoint;
|
||||
// renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
|
||||
|
||||
comp._assembler.update(comp);
|
||||
|
||||
renderData.material = comp.getMaterial();
|
||||
this.datas.push(renderData);
|
||||
return this.datas;
|
||||
},
|
||||
|
||||
fillBuffers (comp, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
let assembler = comp._assembler;
|
||||
if (!assembler) return;
|
||||
|
||||
let vertexOffset = batchData.byteOffset / 4,
|
||||
indiceOffset = batchData.indiceOffset;
|
||||
|
||||
assembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
|
||||
assembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
|
||||
// Skip invalid labels (without own _assembler)
|
||||
updateRenderData (label) {
|
||||
return label.__allocedDatas;
|
||||
}
|
||||
}, assembler);
|
||||
};
|
||||
|
||||
Label._assembler = labelAssembler;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ const renderEngine = require('../../render-engine');
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const ttfUtls = require('../../utils/label/ttf');
|
||||
const assembler = require('../assembler');
|
||||
|
||||
module.exports = js.addon({
|
||||
createData (comp) {
|
||||
@@ -49,14 +50,32 @@ module.exports = js.addon({
|
||||
return renderData;
|
||||
},
|
||||
|
||||
fillVertexBuffer (comp, off, vbuf, uintbuf) {
|
||||
updateRenderData (comp) {
|
||||
let datas = this.datas;
|
||||
datas.length = 0;
|
||||
|
||||
if (!comp.string) {
|
||||
return datas;
|
||||
}
|
||||
|
||||
let renderData = comp._renderData;
|
||||
this.update(comp);
|
||||
|
||||
renderData.material = comp.getMaterial();
|
||||
datas.push(renderData);
|
||||
return datas;
|
||||
},
|
||||
|
||||
fillBuffers (comp, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
let vertexOffset = batchData.byteOffset / 4,
|
||||
indiceOffset = batchData.indiceOffset;
|
||||
|
||||
let node = comp.node;
|
||||
let renderData = comp._renderData;
|
||||
let data = renderData._data;
|
||||
let z = node._position.z;
|
||||
let color = cc.Color.WHITE._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
@@ -69,23 +88,21 @@ module.exports = js.addon({
|
||||
let length = renderData.dataLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
vert = data[i];
|
||||
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[off + 2] = z;
|
||||
vbuf[off + 4] = vert.u;
|
||||
vbuf[off + 5] = vert.v;
|
||||
uintbuf[off + 3] = color;
|
||||
off += 6;
|
||||
vbuf[vertexOffset + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[vertexOffset + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[vertexOffset + 2] = z;
|
||||
vbuf[vertexOffset + 4] = vert.u;
|
||||
vbuf[vertexOffset + 5] = vert.v;
|
||||
uintbuf[vertexOffset + 3] = color;
|
||||
vertexOffset += 6;
|
||||
}
|
||||
},
|
||||
|
||||
fillIndexBuffer (comp, offset, vertexId, ibuf) {
|
||||
ibuf[offset + 0] = vertexId;
|
||||
ibuf[offset + 1] = vertexId + 1;
|
||||
ibuf[offset + 2] = vertexId + 2;
|
||||
ibuf[offset + 3] = vertexId + 1;
|
||||
ibuf[offset + 4] = vertexId + 3;
|
||||
ibuf[offset + 5] = vertexId + 2;
|
||||
|
||||
ibuf[indiceOffset + 0] = vertexId;
|
||||
ibuf[indiceOffset + 1] = vertexId + 1;
|
||||
ibuf[indiceOffset + 2] = vertexId + 2;
|
||||
ibuf[indiceOffset + 3] = vertexId + 1;
|
||||
ibuf[indiceOffset + 4] = vertexId + 3;
|
||||
ibuf[indiceOffset + 5] = vertexId + 2;
|
||||
},
|
||||
|
||||
_updateVerts (comp) {
|
||||
@@ -107,4 +124,4 @@ module.exports = js.addon({
|
||||
data[3].x = width - appx;
|
||||
data[3].y = height - appy;
|
||||
}
|
||||
}, ttfUtls);
|
||||
}, ttfUtls, assembler);
|
||||
|
||||
@@ -94,7 +94,7 @@ let maskFrontAssembler = js.addon({
|
||||
if (mask.spriteFrame) {
|
||||
datas = mask._renderDatas;
|
||||
datas.length = 0;
|
||||
renderData.dataLength = 8;
|
||||
renderData.dataLength = 4;
|
||||
spriteAssembler.update(mask);
|
||||
renderData.material = mask.getMaterial();
|
||||
datas.push(renderData);
|
||||
|
||||
@@ -104,7 +104,6 @@ var motionStreakAssembler = js.addon({
|
||||
let stroke = comp._stroke / 2;
|
||||
|
||||
let node = comp.node;
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
@@ -26,46 +26,62 @@
|
||||
const Sprite = require('../../../components/CCSprite');
|
||||
const FillType = Sprite.FillType;
|
||||
|
||||
const simpleRenderUtil = require('./simple');
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
module.exports = {
|
||||
update (sprite) {
|
||||
let renderData = sprite._renderData;
|
||||
let uvDirty = renderData.uvDirty,
|
||||
vertDirty = renderData.vertDirty;
|
||||
|
||||
if (!uvDirty && !vertDirty) return;
|
||||
|
||||
let fillStart = sprite._fillStart;
|
||||
let fillRange = sprite._fillRange;
|
||||
|
||||
if (fillRange < 0) {
|
||||
fillStart += fillRange;
|
||||
fillRange = -fillRange;
|
||||
}
|
||||
|
||||
fillRange = fillStart + fillRange;
|
||||
|
||||
fillStart = fillStart > 1.0 ? 1.0 : fillStart;
|
||||
fillStart = fillStart < 0.0 ? 0.0 : fillStart;
|
||||
|
||||
fillRange = fillRange > 1.0 ? 1.0 : fillRange;
|
||||
fillRange = fillRange < 0.0 ? 0.0 : fillRange;
|
||||
fillRange = fillRange - fillStart;
|
||||
fillRange = fillRange < 0 ? 0 : fillRange;
|
||||
useModel: false,
|
||||
updateRenderData (sprite) {
|
||||
let frame = sprite.spriteFrame;
|
||||
|
||||
let fillEnd = fillStart + fillRange;
|
||||
fillEnd = fillEnd > 1 ? 1 : fillEnd;
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
|
||||
if (uvDirty) {
|
||||
this.updateUVs(sprite, fillStart, fillEnd);
|
||||
}
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite, fillStart, fillEnd);
|
||||
}
|
||||
if (vertDirty || renderData.worldMatDirty) {
|
||||
this.updateWorldVerts(sprite);
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
let uvDirty = renderData.uvDirty,
|
||||
vertDirty = renderData.vertDirty;
|
||||
|
||||
if (!uvDirty && !vertDirty) return;
|
||||
|
||||
let fillStart = sprite._fillStart;
|
||||
let fillRange = sprite._fillRange;
|
||||
|
||||
if (fillRange < 0) {
|
||||
fillStart += fillRange;
|
||||
fillRange = -fillRange;
|
||||
}
|
||||
|
||||
fillRange = fillStart + fillRange;
|
||||
|
||||
fillStart = fillStart > 1.0 ? 1.0 : fillStart;
|
||||
fillStart = fillStart < 0.0 ? 0.0 : fillStart;
|
||||
|
||||
fillRange = fillRange > 1.0 ? 1.0 : fillRange;
|
||||
fillRange = fillRange < 0.0 ? 0.0 : fillRange;
|
||||
fillRange = fillRange - fillStart;
|
||||
fillRange = fillRange < 0 ? 0 : fillRange;
|
||||
|
||||
let fillEnd = fillStart + fillRange;
|
||||
fillEnd = fillEnd > 1 ? 1 : fillEnd;
|
||||
|
||||
if (uvDirty) {
|
||||
this.updateUVs(sprite, fillStart, fillEnd);
|
||||
}
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite, fillStart, fillEnd);
|
||||
}
|
||||
if (vertDirty || batchData.worldMatUpdated) {
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
}
|
||||
return sprite.__allocedDatas;
|
||||
},
|
||||
|
||||
updateUVs (sprite, fillStart, fillEnd) {
|
||||
@@ -175,7 +191,56 @@ module.exports = {
|
||||
renderData.vertDirty = false;
|
||||
},
|
||||
|
||||
updateWorldVerts: simpleRenderUtil.updateWorldVerts,
|
||||
createData: simpleRenderUtil.createData,
|
||||
fillBuffers: simpleRenderUtil.fillBuffers
|
||||
createData (sprite) {
|
||||
let renderData = sprite.requestRenderData();
|
||||
// 0-4 for world verts
|
||||
// 5-8 for local verts
|
||||
renderData.dataLength = 8;
|
||||
renderData.vertexCount = 4;
|
||||
renderData.indiceCount = 6;
|
||||
return renderData;
|
||||
},
|
||||
|
||||
updateWorldVerts (sprite) {
|
||||
let node = sprite.node,
|
||||
data = sprite._renderData._data;
|
||||
|
||||
let matrix = node._worldMatrix,
|
||||
a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let local = data[i+4];
|
||||
let world = data[i];
|
||||
world.x = local.x * a + local.y * c + tx;
|
||||
world.y = local.x * b + local.y * d + ty;
|
||||
}
|
||||
},
|
||||
|
||||
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
let vertexOffset = batchData.byteOffset / 4,
|
||||
indiceOffset = batchData.indiceOffset;
|
||||
|
||||
let data = sprite._renderData._data;
|
||||
let node = sprite.node;
|
||||
let z = node._position.z;
|
||||
let color = node._color._val;
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let vert = data[i];
|
||||
vbuf[vertexOffset ++] = vert.x;
|
||||
vbuf[vertexOffset ++] = vert.y;
|
||||
vbuf[vertexOffset ++] = z;
|
||||
uintbuf[vertexOffset ++] = color;
|
||||
vbuf[vertexOffset ++] = vert.u;
|
||||
vbuf[vertexOffset ++] = vert.v;
|
||||
}
|
||||
|
||||
ibuf[indiceOffset ++] = vertexId;
|
||||
ibuf[indiceOffset ++] = vertexId + 1;
|
||||
ibuf[indiceOffset ++] = vertexId + 2;
|
||||
ibuf[indiceOffset ++] = vertexId + 1;
|
||||
ibuf[indiceOffset ++] = vertexId + 3;
|
||||
ibuf[indiceOffset ++] = vertexId + 2;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const assembler = require('../assembler');
|
||||
const Sprite = require('../../../components/CCSprite');
|
||||
const renderEngine = require('../../render-engine');
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
const SpriteType = Sprite.Type;
|
||||
const FillType = Sprite.FillType;
|
||||
|
||||
@@ -38,9 +37,8 @@ const barFilledRenderUtil = require('./bar-filled');
|
||||
const meshRenderUtil = require('./mesh');
|
||||
|
||||
// Inline all type switch to avoid jit deoptimization during inlined function change
|
||||
let spriteAssembler = js.addon({
|
||||
useModel: false,
|
||||
|
||||
let spriteAssembler = {
|
||||
getAssembler (sprite) {
|
||||
let util = simpleRenderUtil;
|
||||
|
||||
@@ -67,21 +65,11 @@ let spriteAssembler = js.addon({
|
||||
return util;
|
||||
},
|
||||
|
||||
// Skip invalid sprites (without own _assembler)
|
||||
updateRenderData (sprite) {
|
||||
let datas = sprite.__allocedDatas;
|
||||
if (!sprite.spriteFrame || !sprite.getMaterial() || !sprite._renderData) {
|
||||
return datas;
|
||||
}
|
||||
|
||||
sprite._assembler.update(sprite);
|
||||
|
||||
return datas;
|
||||
},
|
||||
|
||||
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
sprite._assembler.fillBuffers(sprite, batchData, vertexId, vbuf, uintbuf, ibuf);
|
||||
return sprite.__allocedDatas;
|
||||
}
|
||||
}, assembler);
|
||||
};
|
||||
|
||||
Sprite._assembler = spriteAssembler;
|
||||
|
||||
|
||||
@@ -23,38 +23,55 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
module.exports = {
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
module.exports = {
|
||||
useModel: false,
|
||||
|
||||
createData (sprite) {
|
||||
return sprite.requestRenderData();
|
||||
},
|
||||
|
||||
update (sprite) {
|
||||
let renderData = sprite._renderData;
|
||||
updateRenderData (sprite) {
|
||||
let frame = sprite.spriteFrame;
|
||||
|
||||
let vertices = frame.vertices;
|
||||
if (!vertices) return;
|
||||
|
||||
if (renderData.vertexCount !== vertices.x.length) {
|
||||
renderData.vertexCount = vertices.x.length;
|
||||
renderData.indiceCount = vertices.triangles.length;
|
||||
|
||||
// 1 for world vertices, 2 for local vertices
|
||||
renderData.dataLength = renderData.vertexCount * 2;
|
||||
|
||||
renderData.uvDirty = renderData.vertDirty = true;
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
|
||||
if (renderData.uvDirty) {
|
||||
this.updateUVs(sprite);
|
||||
}
|
||||
let vertDirty = renderData.vertDirty;
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
if (vertDirty || renderData.worldMatDirty) {
|
||||
this.updateWorldVerts(sprite);
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
let vertices = frame.vertices;
|
||||
if (vertices) {
|
||||
if (renderData.vertexCount !== vertices.x.length) {
|
||||
renderData.vertexCount = vertices.x.length;
|
||||
renderData.indiceCount = vertices.triangles.length;
|
||||
|
||||
// 1 for world vertices, 2 for local vertices
|
||||
renderData.dataLength = renderData.vertexCount * 2;
|
||||
|
||||
renderData.uvDirty = renderData.vertDirty = true;
|
||||
}
|
||||
|
||||
if (renderData.uvDirty) {
|
||||
this.updateUVs(sprite);
|
||||
}
|
||||
let vertDirty = renderData.vertDirty;
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
if (vertDirty || batchData.worldMatUpdated) {
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sprite.__allocedDatas;
|
||||
},
|
||||
|
||||
updateUVs (sprite) {
|
||||
@@ -125,8 +142,8 @@ module.exports = {
|
||||
updateWorldVerts (sprite) {
|
||||
let node = sprite.node,
|
||||
renderData = sprite._renderData,
|
||||
data = renderData._data,
|
||||
matrix = node._worldMatrix;
|
||||
data = renderData._data;
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
@@ -136,8 +153,6 @@ module.exports = {
|
||||
world.x = local.x * a + local.y * c + tx;
|
||||
world.y = local.x * b + local.y * d + ty;
|
||||
}
|
||||
|
||||
renderData.worldMatDirty = false;
|
||||
},
|
||||
|
||||
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
@@ -166,5 +181,5 @@ module.exports = {
|
||||
for (let i = 0, l = triangles.length; i < l; i++) {
|
||||
ibuf[indiceOffset++] = vertexId + triangles[i];
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -23,11 +23,13 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const simpleRenderUtil = require('./simple');
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
const PI_2 = Math.PI * 2;
|
||||
|
||||
module.exports = {
|
||||
useModel: false,
|
||||
|
||||
_vertPos: [cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0)],
|
||||
_vertices: [0, 0, 0, 0],
|
||||
_uvs: [0, 0, 0, 0, 0, 0, 0, 0],
|
||||
@@ -40,100 +42,114 @@ module.exports = {
|
||||
return sprite.requestRenderData();
|
||||
},
|
||||
|
||||
update (sprite) {
|
||||
let renderData = sprite._renderData;
|
||||
if (!renderData.vertDirty && !renderData.uvDirty) return;
|
||||
|
||||
let data = renderData._data;
|
||||
let spriteFrame = sprite._spriteFrame;
|
||||
|
||||
let fillStart = sprite._fillStart;
|
||||
let fillRange = sprite._fillRange;
|
||||
if (fillRange < 0) {
|
||||
fillStart += fillRange;
|
||||
fillRange = -fillRange;
|
||||
updateRenderData (sprite) {
|
||||
let frame = sprite.spriteFrame;
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
|
||||
//do round fill start [0,1), include 0, exclude 1
|
||||
while (fillStart >= 1.0) fillStart -= 1.0;
|
||||
while (fillStart < 0.0) fillStart += 1.0;
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
if (renderData.vertDirty || renderData.uvDirty) {
|
||||
let data = renderData._data;
|
||||
|
||||
fillStart *= PI_2;
|
||||
fillRange *= PI_2;
|
||||
let fillEnd = fillStart + fillRange;
|
||||
let fillStart = sprite._fillStart;
|
||||
let fillRange = sprite._fillRange;
|
||||
if (fillRange < 0) {
|
||||
fillStart += fillRange;
|
||||
fillRange = -fillRange;
|
||||
}
|
||||
|
||||
//build vertices
|
||||
this._calculateVertices(sprite);
|
||||
//build uvs
|
||||
this._calculateUVs(spriteFrame);
|
||||
//do round fill start [0,1), include 0, exclude 1
|
||||
while (fillStart >= 1.0) fillStart -= 1.0;
|
||||
while (fillStart < 0.0) fillStart += 1.0;
|
||||
|
||||
let center = this._center;
|
||||
fillStart *= PI_2;
|
||||
fillRange *= PI_2;
|
||||
let fillEnd = fillStart + fillRange;
|
||||
|
||||
let vertPos = this._vertPos,
|
||||
vertices = this._vertices;
|
||||
//build vertices
|
||||
this._calculateVertices(sprite);
|
||||
//build uvs
|
||||
this._calculateUVs(frame);
|
||||
|
||||
let triangles = this._triangles;
|
||||
let center = this._center;
|
||||
|
||||
this._calcInsectedPoints(vertices[0], vertices[2], vertices[1], vertices[3], center, fillStart, this._intersectPoint_1);
|
||||
this._calcInsectedPoints(vertices[0], vertices[2], vertices[1], vertices[3], center, fillStart + fillRange, this._intersectPoint_2);
|
||||
let vertPos = this._vertPos,
|
||||
vertices = this._vertices;
|
||||
|
||||
let offset = 0;
|
||||
for (let triangleIndex = 0; triangleIndex < 4; ++triangleIndex) {
|
||||
let triangle = triangles[triangleIndex];
|
||||
if (!triangle) {
|
||||
continue;
|
||||
}
|
||||
//all in
|
||||
if (fillRange >= PI_2) {
|
||||
renderData.dataLength = offset + 3;
|
||||
this._generateTriangle(data, offset, center, vertPos[triangle[0]], vertPos[triangle[1]]);
|
||||
offset += 3;
|
||||
continue;
|
||||
}
|
||||
//test against
|
||||
let startAngle = this._getVertAngle(center, vertPos[triangle[0]]);
|
||||
let endAngle = this._getVertAngle(center, vertPos[triangle[1]]);
|
||||
if(endAngle < startAngle) endAngle += PI_2;
|
||||
startAngle -= PI_2;
|
||||
endAngle -= PI_2;
|
||||
//testing
|
||||
for(let testIndex = 0; testIndex < 3; ++testIndex) {
|
||||
if(startAngle >= fillEnd) {
|
||||
//all out
|
||||
} else if (startAngle >= fillStart) {
|
||||
renderData.dataLength = offset + 3;
|
||||
if(endAngle >= fillEnd) {
|
||||
//startAngle to fillEnd
|
||||
this._generateTriangle(data, offset, center, vertPos[triangle[0]], this._intersectPoint_2[triangleIndex]);
|
||||
} else {
|
||||
//startAngle to endAngle
|
||||
this._generateTriangle(data, offset, center, vertPos[triangle[0]], vertPos[triangle[1]]);
|
||||
let triangles = this._triangles;
|
||||
|
||||
this._calcInsectedPoints(vertices[0], vertices[2], vertices[1], vertices[3], center, fillStart, this._intersectPoint_1);
|
||||
this._calcInsectedPoints(vertices[0], vertices[2], vertices[1], vertices[3], center, fillStart + fillRange, this._intersectPoint_2);
|
||||
|
||||
let offset = 0;
|
||||
for (let triangleIndex = 0; triangleIndex < 4; ++triangleIndex) {
|
||||
let triangle = triangles[triangleIndex];
|
||||
if (!triangle) {
|
||||
continue;
|
||||
}
|
||||
offset += 3;
|
||||
} else {
|
||||
//startAngle < fillStart
|
||||
if(endAngle <= fillStart) {
|
||||
//all out
|
||||
} else if(endAngle <= fillEnd) {
|
||||
//all in
|
||||
if (fillRange >= PI_2) {
|
||||
renderData.dataLength = offset + 3;
|
||||
//fillStart to endAngle
|
||||
this._generateTriangle(data, offset, center, this._intersectPoint_1[triangleIndex], vertPos[triangle[1]]);
|
||||
offset += 3;
|
||||
} else {
|
||||
renderData.dataLength = offset + 3;
|
||||
//fillStart to fillEnd
|
||||
this._generateTriangle(data, offset, center, this._intersectPoint_1[triangleIndex], this._intersectPoint_2[triangleIndex]);
|
||||
this._generateTriangle(data, offset, center, vertPos[triangle[0]], vertPos[triangle[1]]);
|
||||
offset += 3;
|
||||
continue;
|
||||
}
|
||||
//test against
|
||||
let startAngle = this._getVertAngle(center, vertPos[triangle[0]]);
|
||||
let endAngle = this._getVertAngle(center, vertPos[triangle[1]]);
|
||||
if(endAngle < startAngle) endAngle += PI_2;
|
||||
startAngle -= PI_2;
|
||||
endAngle -= PI_2;
|
||||
//testing
|
||||
for(let testIndex = 0; testIndex < 3; ++testIndex) {
|
||||
if(startAngle >= fillEnd) {
|
||||
//all out
|
||||
} else if (startAngle >= fillStart) {
|
||||
renderData.dataLength = offset + 3;
|
||||
if(endAngle >= fillEnd) {
|
||||
//startAngle to fillEnd
|
||||
this._generateTriangle(data, offset, center, vertPos[triangle[0]], this._intersectPoint_2[triangleIndex]);
|
||||
} else {
|
||||
//startAngle to endAngle
|
||||
this._generateTriangle(data, offset, center, vertPos[triangle[0]], vertPos[triangle[1]]);
|
||||
}
|
||||
offset += 3;
|
||||
} else {
|
||||
//startAngle < fillStart
|
||||
if(endAngle <= fillStart) {
|
||||
//all out
|
||||
} else if(endAngle <= fillEnd) {
|
||||
renderData.dataLength = offset + 3;
|
||||
//fillStart to endAngle
|
||||
this._generateTriangle(data, offset, center, this._intersectPoint_1[triangleIndex], vertPos[triangle[1]]);
|
||||
offset += 3;
|
||||
} else {
|
||||
renderData.dataLength = offset + 3;
|
||||
//fillStart to fillEnd
|
||||
this._generateTriangle(data, offset, center, this._intersectPoint_1[triangleIndex], this._intersectPoint_2[triangleIndex]);
|
||||
offset += 3;
|
||||
}
|
||||
}
|
||||
//add 2 * PI
|
||||
startAngle += PI_2;
|
||||
endAngle += PI_2;
|
||||
}
|
||||
}
|
||||
//add 2 * PI
|
||||
startAngle += PI_2;
|
||||
endAngle += PI_2;
|
||||
|
||||
renderData.indiceCount = renderData.vertexCount = offset;
|
||||
renderData.vertDirty = renderData.uvDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
renderData.indiceCount = renderData.vertexCount = offset;
|
||||
renderData.vertDirty = renderData.uvDirty = false;
|
||||
return sprite.__allocedDatas;
|
||||
},
|
||||
|
||||
_getVertAngle: function(start, end) {
|
||||
@@ -339,5 +355,5 @@ module.exports = {
|
||||
for (let i = 0; i < count; i++) {
|
||||
ibuf[indiceOffset+i] = vertexId+i;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -24,25 +24,35 @@
|
||||
****************************************************************************/
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const assembler = require('../assembler');
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
module.exports = js.addon({
|
||||
module.exports = {
|
||||
useModel: false,
|
||||
|
||||
update (sprite) {
|
||||
let renderData = sprite._renderData;
|
||||
|
||||
updateRenderData (sprite) {
|
||||
let frame = sprite._spriteFrame;
|
||||
|
||||
if (renderData.uvDirty) {
|
||||
this.updateUVs(sprite);
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
|
||||
let vertDirty = renderData.vertDirty;
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
if (vertDirty || renderData.worldMatDirty) {
|
||||
this.updateWorldVerts(sprite);
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
if (renderData.uvDirty) {
|
||||
this.updateUVs(sprite);
|
||||
}
|
||||
|
||||
if (renderData.vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
}
|
||||
return sprite.__allocedDatas;
|
||||
},
|
||||
|
||||
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
@@ -53,11 +63,14 @@ module.exports = js.addon({
|
||||
let node = sprite.node;
|
||||
let z = node._position.z;
|
||||
let color = node._color._val;
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let vert = data[i];
|
||||
vbuf[vertexOffset ++] = vert.x;
|
||||
vbuf[vertexOffset ++] = vert.y;
|
||||
vbuf[vertexOffset ++] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[vertexOffset ++] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[vertexOffset ++] = z;
|
||||
uintbuf[vertexOffset ++] = color;
|
||||
vbuf[vertexOffset ++] = vert.u;
|
||||
@@ -74,9 +87,7 @@ module.exports = js.addon({
|
||||
|
||||
createData (sprite) {
|
||||
let renderData = sprite.requestRenderData();
|
||||
// 0-4 for world verts
|
||||
// 5-8 for local verts
|
||||
renderData.dataLength = 8;
|
||||
renderData.dataLength = 4;
|
||||
renderData.vertexCount = 4;
|
||||
renderData.indiceCount = 6;
|
||||
return renderData;
|
||||
@@ -124,24 +135,6 @@ module.exports = js.addon({
|
||||
renderData.uvDirty = false;
|
||||
},
|
||||
|
||||
updateWorldVerts (sprite) {
|
||||
let node = sprite.node,
|
||||
renderData = sprite._renderData,
|
||||
data = renderData._data,
|
||||
matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let local = data[i+4];
|
||||
let world = data[i];
|
||||
world.x = local.x * a + local.y * c + tx;
|
||||
world.y = local.x * b + local.y * d + ty;
|
||||
}
|
||||
|
||||
renderData.worldMatDirty = false;
|
||||
},
|
||||
|
||||
updateVerts (sprite) {
|
||||
let renderData = sprite._renderData,
|
||||
node = sprite.node,
|
||||
@@ -171,15 +164,15 @@ module.exports = js.addon({
|
||||
t = ch + trimTop * scaleY - appy;
|
||||
}
|
||||
|
||||
data[4].x = l;
|
||||
data[4].y = b;
|
||||
data[5].x = r;
|
||||
data[5].y = b;
|
||||
data[6].x = l;
|
||||
data[6].y = t;
|
||||
data[7].x = r;
|
||||
data[7].y = t;
|
||||
data[0].x = l;
|
||||
data[0].y = b;
|
||||
data[1].x = r;
|
||||
data[1].y = b;
|
||||
data[2].x = l;
|
||||
data[2].y = t;
|
||||
data[3].x = r;
|
||||
data[3].y = t;
|
||||
|
||||
renderData.vertDirty = false;
|
||||
}
|
||||
}, assembler);
|
||||
};
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
****************************************************************************/
|
||||
|
||||
const Sprite = require('../../../components/CCSprite');
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
const FillType = Sprite.FillType;
|
||||
|
||||
const simpleRenderUtil = require('./simple');
|
||||
|
||||
module.exports = {
|
||||
useModel: false,
|
||||
|
||||
createData (sprite) {
|
||||
let renderData = sprite.requestRenderData();
|
||||
// 0-4 for local verts
|
||||
@@ -39,6 +40,36 @@ module.exports = {
|
||||
renderData.indiceCount = 54;
|
||||
return renderData;
|
||||
},
|
||||
|
||||
updateRenderData (sprite, batchData) {
|
||||
let frame = sprite.spriteFrame;
|
||||
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
if (renderData.uvDirty) {
|
||||
this.updateUVs(sprite);
|
||||
}
|
||||
|
||||
let vertDirty = renderData.vertDirty;
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
if (vertDirty || batchData.worldMatUpdated) {
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
}
|
||||
return sprite.__allocedDatas;
|
||||
},
|
||||
|
||||
updateUVs (sprite) {
|
||||
let material = sprite.getMaterial();
|
||||
@@ -79,6 +110,17 @@ module.exports = {
|
||||
data[1].v = (topHeight + centerHeight + rect.y) / atlasHeight;
|
||||
data[0].v = (rect.y + rect.height) / atlasHeight;
|
||||
}
|
||||
|
||||
for (let row = 0; row < 4; ++row) {
|
||||
let rowD = data[row];
|
||||
for (let col = 0; col < 4; ++col) {
|
||||
let colD = data[col];
|
||||
let world = data[4 + row*4 + col];
|
||||
world.u = colD.u;
|
||||
world.v = rowD.v;
|
||||
}
|
||||
}
|
||||
|
||||
renderData.uvDirty = false;
|
||||
},
|
||||
|
||||
@@ -137,7 +179,7 @@ module.exports = {
|
||||
uintbuf[vertexOffset + 3] = color;
|
||||
vertexOffset += 6;
|
||||
}
|
||||
|
||||
|
||||
for (let r = 0; r < 3; ++r) {
|
||||
for (let c = 0; c < 3; ++c) {
|
||||
let start = vertexId + r*4 + c;
|
||||
@@ -153,10 +195,10 @@ module.exports = {
|
||||
|
||||
updateWorldVerts (sprite) {
|
||||
let node = sprite.node,
|
||||
renderData = sprite._renderData,
|
||||
data = renderData._data,
|
||||
matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
data = sprite._renderData._data;
|
||||
|
||||
let matrix = node._worldMatrix,
|
||||
a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
for (let row = 0; row < 4; ++row) {
|
||||
@@ -166,13 +208,7 @@ module.exports = {
|
||||
let world = data[4 + row*4 + col];
|
||||
world.x = colD.x*a + rowD.y*c + tx;
|
||||
world.y = colD.x*b + rowD.y*d + ty;
|
||||
world.u = colD.u;
|
||||
world.v = rowD.v;
|
||||
}
|
||||
}
|
||||
|
||||
renderData.worldMatDirty = false;
|
||||
},
|
||||
|
||||
update: simpleRenderUtil.update
|
||||
};
|
||||
|
||||
@@ -23,101 +23,117 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const dynamicAtlasManager = require('../../utils/dynamic-atlas/manager');
|
||||
|
||||
module.exports = {
|
||||
useModel: false,
|
||||
|
||||
createData (sprite) {
|
||||
return sprite.requestRenderData();
|
||||
},
|
||||
|
||||
update (sprite) {
|
||||
let renderData = sprite._renderData;
|
||||
if (!renderData.uvDirty && !renderData.vertDirty) return;
|
||||
|
||||
let material = sprite.getMaterial();
|
||||
|
||||
let texture = material.effect.getProperty('texture');
|
||||
let texw = texture._width,
|
||||
texh = texture._height;
|
||||
updateRenderData (sprite) {
|
||||
let frame = sprite.spriteFrame;
|
||||
let rect = frame._rect;
|
||||
|
||||
let node = sprite.node,
|
||||
contentWidth = Math.abs(node.width),
|
||||
contentHeight = Math.abs(node.height),
|
||||
appx = node.anchorX * contentWidth,
|
||||
appy = node.anchorY * contentHeight;
|
||||
|
||||
let rectWidth = rect.width;
|
||||
let rectHeight = rect.height;
|
||||
let hRepeat = contentWidth / rectWidth;
|
||||
let vRepeat = contentHeight / rectHeight;
|
||||
let row = Math.ceil(vRepeat),
|
||||
col = Math.ceil(hRepeat);
|
||||
|
||||
let data = renderData._data;
|
||||
renderData.dataLength = Math.max(8, row+1, col+1);
|
||||
|
||||
let l, b, r, t;
|
||||
if (!frame._rotated) {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectWidth) / texw;
|
||||
b = (rect.y + rectHeight) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[0].u = l;
|
||||
data[0].v = b;
|
||||
data[1].u = r;
|
||||
data[1].v = b;
|
||||
data[2].u = l;
|
||||
data[2].v = t;
|
||||
data[3].u = r;
|
||||
data[3].v = t;
|
||||
|
||||
data[4].u = l;
|
||||
data[4].v = b;
|
||||
data[5].u = l + (r-l) * Math.min(1, hRepeat - col + 1);
|
||||
data[5].v = b;
|
||||
data[6].u = l;
|
||||
data[6].v = b + (t-b) * Math.min(1, vRepeat - row + 1);
|
||||
data[7].u = data[5].u;
|
||||
data[7].v = data[6].v;
|
||||
} else {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectHeight) / texw;
|
||||
b = (rect.y + rectWidth) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[0].u = l;
|
||||
data[0].v = t;
|
||||
data[1].u = l;
|
||||
data[1].v = b;
|
||||
data[2].u = r;
|
||||
data[2].v = t;
|
||||
data[3].u = r;
|
||||
data[3].v = b;
|
||||
|
||||
data[4].u = l;
|
||||
data[4].v = t;
|
||||
data[5].u = l;
|
||||
data[5].v = t + (b - t) * Math.min(1, vRepeat - col + 1);
|
||||
data[6].u = l + (r - l) * Math.min(1, hRepeat - row + 1);
|
||||
data[6].v = t;
|
||||
data[7].u = data[5].u;
|
||||
data[7].v = data[6].v;
|
||||
}
|
||||
|
||||
for (let i = 0; i <= col; ++i) {
|
||||
data[i].x = Math.min(rectWidth * i, contentWidth) - appx;
|
||||
}
|
||||
|
||||
for (let i = 0; i <= row; ++i) {
|
||||
data[i].y = Math.min(rectHeight * i, contentHeight) - appy;
|
||||
}
|
||||
|
||||
// update data property
|
||||
renderData.vertexCount = row * col * 4;
|
||||
renderData.indiceCount = row * col * 6;
|
||||
renderData.uvDirty = false;
|
||||
renderData.vertDirty = false;
|
||||
// TODO: Material API design and export from editor could affect the material activation process
|
||||
// need to update the logic here
|
||||
if (!sprite._material && frame) {
|
||||
// Avoid as much function call as possible
|
||||
if (!frame._original) {
|
||||
dynamicAtlasManager.insertSpriteFrame(frame);
|
||||
}
|
||||
sprite._activateMaterial();
|
||||
}
|
||||
|
||||
let renderData = sprite._renderData;
|
||||
if (renderData && frame) {
|
||||
if (renderData.uvDirty || renderData.vertDirty) {
|
||||
let texture = frame._texture;
|
||||
let texw = texture._width,
|
||||
texh = texture._height;
|
||||
let rect = frame._rect;
|
||||
|
||||
let node = sprite.node,
|
||||
contentWidth = Math.abs(node.width),
|
||||
contentHeight = Math.abs(node.height),
|
||||
appx = node.anchorX * contentWidth,
|
||||
appy = node.anchorY * contentHeight;
|
||||
|
||||
let rectWidth = rect.width;
|
||||
let rectHeight = rect.height;
|
||||
let hRepeat = contentWidth / rectWidth;
|
||||
let vRepeat = contentHeight / rectHeight;
|
||||
let row = Math.ceil(vRepeat),
|
||||
col = Math.ceil(hRepeat);
|
||||
|
||||
let data = renderData._data;
|
||||
renderData.dataLength = Math.max(8, row+1, col+1);
|
||||
|
||||
let l, b, r, t;
|
||||
if (!frame._rotated) {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectWidth) / texw;
|
||||
b = (rect.y + rectHeight) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[0].u = l;
|
||||
data[0].v = b;
|
||||
data[1].u = r;
|
||||
data[1].v = b;
|
||||
data[2].u = l;
|
||||
data[2].v = t;
|
||||
data[3].u = r;
|
||||
data[3].v = t;
|
||||
|
||||
data[4].u = l;
|
||||
data[4].v = b;
|
||||
data[5].u = l + (r-l) * Math.min(1, hRepeat - col + 1);
|
||||
data[5].v = b;
|
||||
data[6].u = l;
|
||||
data[6].v = b + (t-b) * Math.min(1, vRepeat - row + 1);
|
||||
data[7].u = data[5].u;
|
||||
data[7].v = data[6].v;
|
||||
} else {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectHeight) / texw;
|
||||
b = (rect.y + rectWidth) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[0].u = l;
|
||||
data[0].v = t;
|
||||
data[1].u = l;
|
||||
data[1].v = b;
|
||||
data[2].u = r;
|
||||
data[2].v = t;
|
||||
data[3].u = r;
|
||||
data[3].v = b;
|
||||
|
||||
data[4].u = l;
|
||||
data[4].v = t;
|
||||
data[5].u = l;
|
||||
data[5].v = t + (b - t) * Math.min(1, vRepeat - col + 1);
|
||||
data[6].u = l + (r - l) * Math.min(1, hRepeat - row + 1);
|
||||
data[6].v = t;
|
||||
data[7].u = data[5].u;
|
||||
data[7].v = data[6].v;
|
||||
}
|
||||
|
||||
for (let i = 0; i <= col; ++i) {
|
||||
data[i].x = Math.min(rectWidth * i, contentWidth) - appx;
|
||||
}
|
||||
|
||||
for (let i = 0; i <= row; ++i) {
|
||||
data[i].y = Math.min(rectHeight * i, contentHeight) - appy;
|
||||
}
|
||||
|
||||
// update data property
|
||||
renderData.vertexCount = row * col * 4;
|
||||
renderData.indiceCount = row * col * 6;
|
||||
renderData.uvDirty = false;
|
||||
renderData.vertDirty = false;
|
||||
}
|
||||
}
|
||||
return sprite.__allocedDatas;
|
||||
},
|
||||
|
||||
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
@@ -139,14 +155,9 @@ module.exports = {
|
||||
let row = Math.ceil(vRepeat),
|
||||
col = Math.ceil(hRepeat);
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
c = matrix.m04,
|
||||
d = matrix.m05,
|
||||
tx = matrix.m12,
|
||||
ty = matrix.m13;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
let x, x1, y, y1, lastx, lasty;
|
||||
for (let yindex = 0, ylength = row; yindex < ylength; ++yindex) {
|
||||
@@ -203,5 +214,5 @@ module.exports = {
|
||||
ibuf[indiceOffset++] = vertexId+2;
|
||||
vertexId += 4;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -42,10 +42,6 @@ RenderComponentWalker.prototype = {
|
||||
reset() {},
|
||||
|
||||
_handleRender (node) {
|
||||
if (node._localMatDirty) {
|
||||
node._calculWorldMatrix();
|
||||
}
|
||||
|
||||
let comp = node._renderComponent;
|
||||
let opacity = node.opacity;
|
||||
let assembler = comp && comp.constructor._assembler;
|
||||
@@ -67,6 +63,10 @@ RenderComponentWalker.prototype = {
|
||||
let ctx = this._device._ctx;
|
||||
let cam = this._camera;
|
||||
ctx.setTransform(cam.a, cam.b, cam.c, cam.d, cam.tx, cam.ty);
|
||||
let node = comp.node;
|
||||
if (node._worldMatDirty) {
|
||||
node._updateWorldMatrix();
|
||||
}
|
||||
let drawCall = renderer.draw(ctx, comp);
|
||||
this._device._stats.drawcalls += drawCall;
|
||||
},
|
||||
|
||||
@@ -66,7 +66,7 @@ module.exports = {
|
||||
this.Texture2D = renderEngine.Texture2D;
|
||||
|
||||
this.canvas = canvas;
|
||||
if (CC_JSB) {
|
||||
if (CC_JSB && CC_NATIVERENDERER) {
|
||||
// native codes will create an instance of Device, so just use the global instance.
|
||||
this.device = window.device;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ const macro = require('../platform/CCMacro');
|
||||
const renderEngine = require('./render-engine');
|
||||
const defaultVertexFormat = require('./vertex-format');
|
||||
const StencilManager = require('./stencil-manager');
|
||||
const atlasManager = require('./utils/dynamic-atlas/manager');
|
||||
|
||||
const gfx = renderEngine.gfx;
|
||||
const RecyclePool = renderEngine.RecyclePool;
|
||||
const InputAssembler = renderEngine.InputAssembler;
|
||||
@@ -40,50 +42,28 @@ const MAX_VERTEX_BYTES = MAX_VERTEX * defaultVertexFormat._bytes;
|
||||
const MAX_INDICE = MAX_VERTEX * BYTE_PER_INDEX;
|
||||
const MAX_INDICE_BYTES = MAX_INDICE * 2;
|
||||
|
||||
var _batchData = {
|
||||
node: null,
|
||||
vfmt: null,
|
||||
material: null,
|
||||
data: null,
|
||||
vertexOffset: 0,
|
||||
byteOffset: 0,
|
||||
indiceOffset: 0,
|
||||
cullingMask: 1,
|
||||
MAX_VERTEX: MAX_VERTEX,
|
||||
MAX_INDICE: MAX_INDICE
|
||||
};
|
||||
|
||||
var RenderComponentWalker = function (device, renderScene) {
|
||||
this._renderScene = renderScene;
|
||||
this._device = device;
|
||||
this._stencilMgr = StencilManager.sharedManager;
|
||||
|
||||
// Buffers
|
||||
this._vData = new Float32Array(MAX_VERTEX * FLOATS_PER_VERT);
|
||||
this._uintVData = new Uint32Array(this._vData.buffer);
|
||||
this._iData = new Uint16Array(MAX_INDICE);
|
||||
|
||||
this._batchData = {
|
||||
node: null,
|
||||
worldMatUpdated: false,
|
||||
vfmt: null,
|
||||
material: null,
|
||||
data: null,
|
||||
vertexOffset: 0,
|
||||
byteStart: 0,
|
||||
byteOffset: 0,
|
||||
indiceStart: 0,
|
||||
indiceOffset: 0,
|
||||
cullingMask: 1,
|
||||
MAX_VERTEX: MAX_VERTEX,
|
||||
MAX_INDICE: MAX_INDICE
|
||||
};
|
||||
|
||||
let defaultFormat = new gfx.VertexFormat([]);
|
||||
this._vbPool = new RecyclePool(function () {
|
||||
let vb = new gfx.VertexBuffer(
|
||||
device,
|
||||
defaultFormat,
|
||||
gfx.USAGE_DYNAMIC,
|
||||
null,
|
||||
0
|
||||
);
|
||||
return vb;
|
||||
}, 16);
|
||||
this._ibPool = new RecyclePool(function () {
|
||||
var ib = new gfx.IndexBuffer(
|
||||
device,
|
||||
gfx.INDEX_FMT_UINT16,
|
||||
gfx.USAGE_STATIC,
|
||||
null,
|
||||
0
|
||||
);
|
||||
return ib;
|
||||
}, 16);
|
||||
this._iaPool = new RecyclePool(function () {
|
||||
return new InputAssembler();
|
||||
}, 16);
|
||||
@@ -91,15 +71,21 @@ var RenderComponentWalker = function (device, renderScene) {
|
||||
this._modelPool = new RecyclePool(() => {
|
||||
return new renderEngine.Model();
|
||||
}, 16);
|
||||
|
||||
|
||||
// buffers
|
||||
this._vb = null;
|
||||
this._ib = null;
|
||||
this._buffersToDestroy = [];
|
||||
|
||||
this._maxVertexCount = MAX_VERTEX;
|
||||
this._maxIndiceCount = MAX_INDICE;
|
||||
this._reallocBuffer(this._maxVertexCount, this._maxIndiceCount);
|
||||
|
||||
this._batchedModels = [];
|
||||
this._dummyNode = new cc.Node();
|
||||
this._sortKey = 0;
|
||||
|
||||
this._curCameraNode = null;
|
||||
|
||||
this._handleRender = this._handleRender.bind(this);
|
||||
this._postHandleRender = this._postHandleRender.bind(this);
|
||||
};
|
||||
|
||||
RenderComponentWalker.prototype = {
|
||||
@@ -108,8 +94,6 @@ RenderComponentWalker.prototype = {
|
||||
reset() {
|
||||
// Reset pools
|
||||
this._iaPool.reset();
|
||||
this._vbPool.reset();
|
||||
this._ibPool.reset();
|
||||
|
||||
// Reset scene
|
||||
let scene = this._renderScene;
|
||||
@@ -124,92 +108,98 @@ RenderComponentWalker.prototype = {
|
||||
models.length = 0;
|
||||
this._sortKey = 0;
|
||||
|
||||
// Reset useless buffers
|
||||
if (this._buffersToDestroy.length !== 0) {
|
||||
for (let i = 0, l = this._buffersToDestroy.length; i < l; i++) {
|
||||
this._buffersToDestroy[i].destroy();
|
||||
}
|
||||
this._buffersToDestroy.length = 0;
|
||||
}
|
||||
|
||||
// reset caches for handle render components
|
||||
_batchData.node = null;
|
||||
_batchData.vfmt = null;
|
||||
_batchData.material = null;
|
||||
_batchData.data = null;
|
||||
_batchData.vertexOffset = 0;
|
||||
_batchData.byteOffset = 0;
|
||||
_batchData.indiceOffset = 0;
|
||||
_batchData.cullingMask = 1;
|
||||
let batchData = this._batchData;
|
||||
batchData.node = null;
|
||||
batchData.worldMatUpdated = false;
|
||||
batchData.vfmt = null;
|
||||
batchData.material = null;
|
||||
batchData.data = null;
|
||||
batchData.vertexOffset = 0;
|
||||
batchData.byteStart = 0;
|
||||
batchData.byteOffset = 0;
|
||||
batchData.indiceStart = 0;
|
||||
batchData.indiceOffset = 0;
|
||||
batchData.cullingMask = 1;
|
||||
|
||||
// reset stencil manager's cache
|
||||
this._stencilMgr.reset();
|
||||
},
|
||||
|
||||
_handleRender (node) {
|
||||
if (node._localMatDirty) {
|
||||
node._calculWorldMatrix();
|
||||
}
|
||||
_uploadData () {
|
||||
// update vertext data
|
||||
let vertexsData = new Float32Array(this._vData.buffer, 0, this._batchData.byteOffset / 4);
|
||||
let indicesData = new Uint16Array(this._iData.buffer, 0, this._batchData.indiceOffset);
|
||||
|
||||
if (node.groupIndex !== 0) {
|
||||
this._curCameraNode = node;
|
||||
}
|
||||
let gl = this._device._gl;
|
||||
let vb = this._vb;
|
||||
vb.update(0, vertexsData);
|
||||
|
||||
let group = this._curCameraNode ? this._curCameraNode.groupIndex : node.groupIndex;
|
||||
node._cullingMask = 1 << group;
|
||||
|
||||
let comp = node._renderComponent;
|
||||
if (comp) {
|
||||
this.renderComp(comp, comp.constructor._assembler);
|
||||
}
|
||||
let ib = this._ib;
|
||||
ib.update(0, indicesData);
|
||||
},
|
||||
|
||||
_postHandleRender (node) {
|
||||
let comp = node._renderComponent;
|
||||
if (comp && comp.constructor._postAssembler) {
|
||||
this.renderComp(comp, comp.constructor._postAssembler);
|
||||
_reallocBuffer (vertexCount, indiceCount) {
|
||||
let batchData = this._batchData;
|
||||
batchData.vertexOffset = 0;
|
||||
batchData.byteStart = 0;
|
||||
batchData.byteOffset = 0;
|
||||
batchData.indiceStart = 0;
|
||||
batchData.indiceOffset = 0;
|
||||
|
||||
if (this._vb) {
|
||||
this._buffersToDestroy.push(this._vb);
|
||||
}
|
||||
if (this._ib) {
|
||||
this._buffersToDestroy.push(this._ib);
|
||||
}
|
||||
|
||||
if (this._curCameraNode === node) {
|
||||
this._curCameraNode = null;
|
||||
}
|
||||
this._vData = new Float32Array(vertexCount * FLOATS_PER_VERT);
|
||||
this._uintVData = new Uint32Array(this._vData.buffer);
|
||||
this._iData = new Uint16Array(indiceCount);
|
||||
|
||||
this._vb = new gfx.VertexBuffer(
|
||||
this._device,
|
||||
defaultVertexFormat,
|
||||
gfx.USAGE_DYNAMIC,
|
||||
this._vData.buffer,
|
||||
vertexCount
|
||||
);
|
||||
|
||||
this._ib = new gfx.IndexBuffer(
|
||||
this._device,
|
||||
gfx.INDEX_FMT_UINT16,
|
||||
gfx.USAGE_STATIC,
|
||||
this._iData.buffer,
|
||||
indiceCount
|
||||
);
|
||||
},
|
||||
|
||||
_flush (batchData) {
|
||||
let vfmt = batchData.vfmt,
|
||||
_flush () {
|
||||
let batchData = this._batchData,
|
||||
material = batchData.material,
|
||||
vertexByte = batchData.byteOffset,
|
||||
cullingMask = batchData.cullingMask,
|
||||
vertexCount = batchData.vertexOffset,
|
||||
indiceCount = batchData.indiceOffset,
|
||||
vDataSize = Math.min(bits.nextPow2(vertexByte), MAX_VERTEX_BYTES),
|
||||
vertexsData = null,
|
||||
indicesData = null;
|
||||
|
||||
// Prepare data view for vb ib
|
||||
if (material && vertexCount > 0 && indiceCount > 0) {
|
||||
vertexsData = new Float32Array(this._vData.buffer, 0, vDataSize / 4);
|
||||
indicesData = new Uint16Array(this._iData.buffer, 0, indiceCount);
|
||||
}
|
||||
else {
|
||||
indiceStart = batchData.indiceStart,
|
||||
indiceOffset = batchData.indiceOffset,
|
||||
indiceCount = indiceOffset - indiceStart;
|
||||
if (!material || indiceCount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let effect = material.effect;
|
||||
|
||||
// Generate vb, ib, ia
|
||||
let device = this._device;
|
||||
let vb = this._vbPool.add();
|
||||
device._stats.vb -= vb._bytes;
|
||||
vb._format = vfmt;
|
||||
vb._numVertices = vertexCount;
|
||||
vb._bytes = vDataSize;
|
||||
vb.update(0, vertexsData);
|
||||
device._stats.vb += vb._bytes;
|
||||
|
||||
let ib = this._ibPool.add();
|
||||
device._stats.ib -= ib._bytes;
|
||||
ib._numIndices = indiceCount;
|
||||
ib._bytes = BYTE_PER_INDEX * indiceCount;
|
||||
ib.update(0, indicesData);
|
||||
device._stats.ib += ib._bytes;
|
||||
|
||||
// Generate ia
|
||||
let ia = this._iaPool.add();
|
||||
ia._vertexBuffer = vb;
|
||||
ia._indexBuffer = ib;
|
||||
ia._start = 0;
|
||||
ia._vertexBuffer = this._vb;
|
||||
ia._indexBuffer = this._ib;
|
||||
ia._start = indiceStart;
|
||||
ia._count = indiceCount;
|
||||
|
||||
// Check stencil state and modify pass
|
||||
@@ -219,16 +209,20 @@ RenderComponentWalker.prototype = {
|
||||
let model = this._modelPool.add();
|
||||
this._batchedModels.push(model);
|
||||
model.sortKey = this._sortKey++;
|
||||
model._cullingMask = CC_EDITOR ? 1 : cullingMask;
|
||||
model._cullingMask = CC_EDITOR ? 1 : batchData.cullingMask;
|
||||
model.setNode(batchData.node);
|
||||
model.addEffect(effect);
|
||||
model.addInputAssembler(ia);
|
||||
|
||||
this._renderScene.addModel(model);
|
||||
|
||||
batchData.byteStart = batchData.byteOffset;
|
||||
batchData.indiceStart = batchData.indiceOffset;
|
||||
},
|
||||
|
||||
_flushIA (batchData) {
|
||||
let material = batchData.material,
|
||||
_flushIA () {
|
||||
let batchData = this._batchData,
|
||||
material = batchData.material,
|
||||
cullingMask = batchData.cullingMask,
|
||||
iaRenderData = batchData.data;
|
||||
|
||||
@@ -251,22 +245,16 @@ RenderComponentWalker.prototype = {
|
||||
this._renderScene.addModel(model);
|
||||
},
|
||||
|
||||
renderComp (comp, assembler) {
|
||||
if (!assembler) {
|
||||
return;
|
||||
}
|
||||
|
||||
let material = null,
|
||||
_commitComp (comp, assembler, cullingMask) {
|
||||
let batchData = this._batchData,
|
||||
material = null,
|
||||
datas = null,
|
||||
data = null,
|
||||
cullingMask = 1,
|
||||
broken = false,
|
||||
iaData = false;
|
||||
|
||||
// Update render data
|
||||
datas = assembler.updateRenderData(comp, _batchData);
|
||||
|
||||
cullingMask = comp.node._cullingMask;
|
||||
datas = assembler.updateRenderData(comp, batchData);
|
||||
|
||||
for (let id = 0; id < datas.length; id ++) {
|
||||
data = datas[id];
|
||||
@@ -276,46 +264,118 @@ RenderComponentWalker.prototype = {
|
||||
continue;
|
||||
}
|
||||
|
||||
// need to realloc buffers
|
||||
if ((batchData.vertexOffset + data.vertexCount) > this._maxVertexCount ||
|
||||
(batchData.indiceOffset + data.indiceCount) > this._maxIndiceCount) {
|
||||
this._uploadData();
|
||||
|
||||
this._maxVertexCount *= 2;
|
||||
this._maxIndiceCount *= 2;
|
||||
this._reallocBuffer(this._maxVertexCount, this._maxIndiceCount);
|
||||
}
|
||||
|
||||
// Check ia data, each ia data should be packed into a separated model
|
||||
iaData = data.type === IARenderData.type;
|
||||
|
||||
// breaking batch
|
||||
broken = iaData ||
|
||||
!_batchData.material || _batchData.material._hash != material._hash ||
|
||||
_batchData.cullingMask !== cullingMask ||
|
||||
(_batchData.vertexOffset + data.vertexCount > MAX_VERTEX) ||
|
||||
(_batchData.indiceOffset + data.indiceCount > MAX_INDICE);
|
||||
!batchData.material || batchData.material._hash != material._hash ||
|
||||
batchData.cullingMask !== cullingMask;
|
||||
if (broken) {
|
||||
this._flush(_batchData);
|
||||
_batchData.node = assembler.useModel ? comp.node : this._dummyNode;
|
||||
_batchData.material = material;
|
||||
_batchData.vfmt = comp._vertexFormat;
|
||||
_batchData.vertexOffset = 0;
|
||||
_batchData.byteOffset = 0;
|
||||
_batchData.indiceOffset = 0;
|
||||
_batchData.cullingMask = cullingMask;
|
||||
this._flush(batchData);
|
||||
|
||||
batchData.node = assembler.useModel ? comp.node : this._dummyNode;
|
||||
batchData.material = material;
|
||||
batchData.vfmt = comp._vertexFormat;
|
||||
batchData.cullingMask = cullingMask;
|
||||
}
|
||||
|
||||
_batchData.data = data;
|
||||
batchData.data = data;
|
||||
if (iaData) {
|
||||
this._flushIA(_batchData);
|
||||
this._flushIA();
|
||||
}
|
||||
else {
|
||||
assembler.fillBuffers(comp, _batchData, _batchData.vertexOffset, this._vData, this._uintVData, this._iData);
|
||||
_batchData.vertexOffset += data.vertexCount;
|
||||
_batchData.byteOffset += data.vertexCount * comp._vertexFormat._bytes;
|
||||
_batchData.indiceOffset += data.indiceCount;
|
||||
assembler.fillBuffers(comp, batchData, batchData.vertexOffset, this._vData, this._uintVData, this._iData);
|
||||
batchData.byteOffset += data.vertexCount * comp._vertexFormat._bytes;
|
||||
batchData.indiceOffset += data.indiceCount;
|
||||
batchData.vertexOffset += data.vertexCount;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_findEntry (node) {
|
||||
if (node._renderComponent) {
|
||||
return node._renderComponent._chain;
|
||||
}
|
||||
|
||||
let children = node._children;
|
||||
let first;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
let child = children[i];
|
||||
first = this._findEntry(child);
|
||||
if (first) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
_visitNode (node) {
|
||||
if (!node._activeInHierarchy) {
|
||||
return;
|
||||
}
|
||||
|
||||
let batchData = this._batchData;
|
||||
// Transform
|
||||
if (node._worldMatDirty) {
|
||||
node._updateWorldMatrix();
|
||||
batchData.worldMatUpdated = true;
|
||||
}
|
||||
|
||||
// Culling mask
|
||||
if (node.groupIndex !== 0) {
|
||||
this._curCameraNode = node;
|
||||
}
|
||||
let group = this._curCameraNode ? this._curCameraNode.groupIndex : node.groupIndex;
|
||||
let cullingMask = node._cullingMask = 1 << group;
|
||||
|
||||
// Render self
|
||||
let comp = node._renderComponent;
|
||||
let needDraw = !!(comp && comp._enabled);
|
||||
if (needDraw) {
|
||||
let assembler = comp._assembler || comp.constructor._assembler;
|
||||
this._commitComp(comp, assembler, cullingMask);
|
||||
}
|
||||
// Reset worldMatUpdated
|
||||
batchData.worldMatUpdated = false;
|
||||
|
||||
// Render children
|
||||
let children = node._children;
|
||||
for (let i = 0, l = children.length; i < l; i++) {
|
||||
this._visitNode(children[i]);
|
||||
}
|
||||
|
||||
// Post render
|
||||
if (needDraw && comp.constructor._postAssembler) {
|
||||
this._commitComp(comp, comp.constructor._postAssembler, cullingMask);
|
||||
}
|
||||
|
||||
// Reset current camera node
|
||||
if (this._curCameraNode === node) {
|
||||
this._curCameraNode = null;
|
||||
}
|
||||
},
|
||||
|
||||
visit (scene) {
|
||||
this.reset();
|
||||
|
||||
// Store all render components to _queue
|
||||
scene.walk(this._handleRender, this._postHandleRender);
|
||||
for (let i = 0, l = scene._children.length; i < l; i++) {
|
||||
this._visitNode(scene._children[i]);
|
||||
}
|
||||
|
||||
this._flush(_batchData);
|
||||
atlasManager.update();
|
||||
this._flush();
|
||||
this._uploadData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15056,7 +15056,13 @@ var Model$2 = renderer.Model;
|
||||
var InputAssembler$2 = renderer.InputAssembler;
|
||||
|
||||
// Add stage to renderer
|
||||
renderer.addStage('transparent');
|
||||
if (renderer.config) {
|
||||
// JSB adaptation
|
||||
renderer.config.addStage('transparent');
|
||||
}
|
||||
else {
|
||||
renderer.addStage('transparent');
|
||||
}
|
||||
|
||||
var renderEngine = {
|
||||
// core classes
|
||||
|
||||
@@ -10045,7 +10045,13 @@ var Model = renderer.Model;
|
||||
var InputAssembler = renderer.InputAssembler;
|
||||
|
||||
// Add stage to renderer
|
||||
renderer.addStage('transparent');
|
||||
if (renderer.config) {
|
||||
// JSB adaptation
|
||||
renderer.config.addStage('transparent');
|
||||
}
|
||||
else {
|
||||
renderer.addStage('transparent');
|
||||
}
|
||||
|
||||
var renderEngine = {
|
||||
// core classes
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
const space = 1;
|
||||
|
||||
class Atlas {
|
||||
constructor (width, height) {
|
||||
let texture = new cc.RenderTexture();
|
||||
texture.initWithSize(width, height);
|
||||
texture.update();
|
||||
|
||||
this._texture = texture;
|
||||
|
||||
this._x = space;
|
||||
this._y = space;
|
||||
this._nexty = space;
|
||||
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
|
||||
this._innerTextureInfos = {};
|
||||
this._innerSpriteFrames = [];
|
||||
}
|
||||
|
||||
insertSpriteFrame (spriteFrame) {
|
||||
let rect = spriteFrame._rect,
|
||||
texture = spriteFrame._texture,
|
||||
info = this._innerTextureInfos[texture.__instanceId];
|
||||
|
||||
let sx = rect.x, sy = rect.y;
|
||||
|
||||
if (info) {
|
||||
rect.x += info.x;
|
||||
rect.y += info.y;
|
||||
}
|
||||
else {
|
||||
let width = texture.width, height = texture.height;
|
||||
|
||||
if ((this._x + width) > this._width) {
|
||||
this._x = space;
|
||||
this._y = this._nexty;
|
||||
}
|
||||
|
||||
if ((this._y + height) > this._nexty) {
|
||||
this._nexty = this._y + height;
|
||||
}
|
||||
|
||||
if (this._nexty > this._height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._texture.drawTextureAt(texture, this._x, this._y);
|
||||
|
||||
this._innerTextureInfos[texture.__instanceId] = {
|
||||
x: this._x,
|
||||
y: this._y,
|
||||
texture: texture
|
||||
};
|
||||
|
||||
rect.x += this._x;
|
||||
rect.y += this._y;
|
||||
|
||||
this._x += width;
|
||||
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
spriteFrame._original = {
|
||||
x: sx,
|
||||
y: sy,
|
||||
texture: spriteFrame._texture
|
||||
}
|
||||
|
||||
spriteFrame._texture = this._texture;
|
||||
|
||||
this._innerSpriteFrames.push(spriteFrame);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
update () {
|
||||
if (!this._dirty) return;
|
||||
this._texture.update();
|
||||
this._dirty = false;
|
||||
}
|
||||
|
||||
reset () {
|
||||
this._x = space;
|
||||
this._y = space;
|
||||
this._nexty = space;
|
||||
|
||||
let frames = this._innerSpriteFrames;
|
||||
for (let i = 0, l = frames.length; i < l; i++) {
|
||||
let frame = frames[i];
|
||||
if (!frame.isValid) {
|
||||
continue;
|
||||
}
|
||||
let oriInfo = frame._original;
|
||||
frame._rect.x = oriInfo.x;
|
||||
frame._rect.y = oriInfo.y;
|
||||
frame._texture = oriInfo.texture;
|
||||
frame._original = null;
|
||||
}
|
||||
this._innerSpriteFrames.length = 0;
|
||||
this._innerTextureInfos = {};
|
||||
}
|
||||
|
||||
destroy () {
|
||||
this.reset();
|
||||
this._texture.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Atlas;
|
||||
@@ -0,0 +1,214 @@
|
||||
const Atlas = require('./atlas');
|
||||
|
||||
let _atlases = [];
|
||||
let _atlasIndex = -1;
|
||||
|
||||
let _maxAtlasCount = 5;
|
||||
let _textureSize = 2048;
|
||||
let _maxFrameSize = 512;
|
||||
|
||||
let _enabled = true;
|
||||
|
||||
let _debugNode = null;
|
||||
|
||||
function newAtlas () {
|
||||
let atlas = new Atlas(_textureSize, _textureSize);
|
||||
_atlases.push(atlas);
|
||||
_atlasIndex++;
|
||||
return atlas;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* !#en Manager the dynamic atlas.
|
||||
* !#zh 管理动态图集。
|
||||
* @class DynamicAtlasManager
|
||||
*/
|
||||
let dynamicAtlasManager = {
|
||||
|
||||
/**
|
||||
* !#en Enabled or Disabled dynamic atlas.
|
||||
* !#zh 开启或者关闭动态图集。
|
||||
* @property enabled
|
||||
* @type {Boolean}
|
||||
*/
|
||||
get enabled () {
|
||||
return _enabled;
|
||||
},
|
||||
set enabled (value) {
|
||||
if (_enabled === value) return;
|
||||
|
||||
if (value) {
|
||||
this.reset();
|
||||
}
|
||||
_enabled = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en The maximum number of atlas that can be created.
|
||||
* !#zh 可以创建的最大图集数量。
|
||||
* @property maxAtlasCount
|
||||
* @type {Number}
|
||||
*/
|
||||
get maxAtlasCount () {
|
||||
return _maxAtlasCount;
|
||||
},
|
||||
set maxAtlasCount (value) {
|
||||
_maxAtlasCount = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en The size of the atlas that was created
|
||||
* !#zh 创建的图集的宽高
|
||||
* @property textureSize
|
||||
* @type {Number}
|
||||
*/
|
||||
get textureSize () {
|
||||
return _textureSize;
|
||||
},
|
||||
set textureSize (value) {
|
||||
_textureSize = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en The maximum size of the picture that can be added to the atlas.
|
||||
* !#zh 可以添加进图集的图片的最大尺寸。
|
||||
* @property maxFrameSize
|
||||
* @type {Number}
|
||||
*/
|
||||
get maxFrameSize () {
|
||||
return _maxFrameSize;
|
||||
},
|
||||
set maxFrameSize (value) {
|
||||
_maxFrameSize = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Append a sprite frame into the dynamic atlas.
|
||||
* !#zh 添加碎图进入动态图集。
|
||||
* @method insertSpriteFrame
|
||||
* @param {SpriteFrame} spriteFrame
|
||||
*/
|
||||
insertSpriteFrame (spriteFrame) {
|
||||
if (CC_EDITOR) return;
|
||||
if (!_enabled || _atlasIndex === _maxAtlasCount ||
|
||||
!spriteFrame || spriteFrame._original) return;
|
||||
|
||||
let texture = spriteFrame._texture;
|
||||
if (texture.width > _maxFrameSize || texture.height > _maxFrameSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
let atlas = _atlases[_atlasIndex];
|
||||
if (!atlas) {
|
||||
atlas = newAtlas();
|
||||
}
|
||||
|
||||
if (!atlas.insertSpriteFrame(spriteFrame) && _atlasIndex !== _maxAtlasCount) {
|
||||
atlas = newAtlas();
|
||||
atlas.insertSpriteFrame(spriteFrame);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Resets all dynamic atlas, and the existing ones are not destroyed, but are reused.
|
||||
* !#zh 重置所有动态图集,已有的动态图集并不会被销毁,而是会被复用。
|
||||
* @method reset
|
||||
*/
|
||||
reset () {
|
||||
for (let i = 0; i <= _atlasIndex; i++) {
|
||||
_atlases[i].reset();
|
||||
}
|
||||
_atlasIndex = -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Releases all dynamic atlas, which are destroyed.
|
||||
* !#zh 释放所有动态图集,这些图集会被销毁掉。
|
||||
* @method releaseAll
|
||||
*/
|
||||
releaseAll () {
|
||||
for (let i = 0, l = _atlases.length; i < l; i++) {
|
||||
_atlases[i].destroy();
|
||||
}
|
||||
_atlases.length = 0;
|
||||
_atlasIndex = -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Displays all the dynamic atlas in the current scene, which you can use to view the current atlas state.
|
||||
* !#zh 在当前场景中显示所有动态图集,可以用来查看当前的合图状态。
|
||||
* @method showDebug
|
||||
* @param {Boolean} show
|
||||
*/
|
||||
showDebug: CC_DEV && function (show) {
|
||||
if (show) {
|
||||
if (!_debugNode) {
|
||||
let width = cc.visibleRect.width;
|
||||
let height = cc.visibleRect.height;
|
||||
|
||||
_debugNode = new cc.Node('DYNAMIC_ATLAS_DEBUG_NODE');
|
||||
_debugNode.width = width;
|
||||
_debugNode.height = height;
|
||||
_debugNode.x = width/2;
|
||||
_debugNode.y = height/2;
|
||||
_debugNode._zIndex = cc.macro.MAX_ZINDEX;
|
||||
_debugNode.parent = cc.director.getScene();
|
||||
|
||||
let scroll = _debugNode.addComponent(cc.ScrollView);
|
||||
|
||||
let content = new cc.Node('CONTENT');
|
||||
let layout = content.addComponent(cc.Layout);
|
||||
layout.type = cc.Layout.Type.VERTICAL;
|
||||
layout.resizeMode = cc.Layout.ResizeMode.CONTAINER;
|
||||
content.parent = _debugNode;
|
||||
content.width = _textureSize;
|
||||
content.anchorY = 1;
|
||||
content.x = _textureSize;
|
||||
|
||||
scroll.content = content;
|
||||
|
||||
for (let i = 0; i <= _atlasIndex; i++) {
|
||||
let node = new cc.Node('ATLAS');
|
||||
|
||||
let texture = _atlases[i]._texture;
|
||||
let spriteFrame = new cc.SpriteFrame();
|
||||
spriteFrame.setTexture(_atlases[i]._texture);
|
||||
|
||||
let sprite = node.addComponent(cc.Sprite)
|
||||
sprite.spriteFrame = spriteFrame;
|
||||
// sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
||||
|
||||
// node.width = height;
|
||||
// node.height = height;
|
||||
|
||||
node.parent = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (_debugNode) {
|
||||
_debugNode.parent = null;
|
||||
_debugNode = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
update () {
|
||||
if (!this.enabled) return;
|
||||
|
||||
for (let i = 0; i <= _atlasIndex; i++) {
|
||||
_atlases[i].update();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
|
||||
/**
|
||||
* @property dynamicAtlasManager
|
||||
* @type DynamicAtlasManager
|
||||
*/
|
||||
module.exports = cc.dynamicAtlasManager = dynamicAtlasManager;
|
||||
@@ -24,20 +24,19 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var PrefabHelper = require('./prefab-helper');
|
||||
var Flags = require('../platform/CCObject').Flags;
|
||||
var misc = require('./misc');
|
||||
var js = require('../platform/js');
|
||||
var IdGenerater = require('../platform/id-generater');
|
||||
var eventManager = require('../event-manager');
|
||||
const PrefabHelper = require('./prefab-helper');
|
||||
const Flags = require('../platform/CCObject').Flags;
|
||||
const misc = require('./misc');
|
||||
const js = require('../platform/js');
|
||||
const IdGenerater = require('../platform/id-generater');
|
||||
const eventManager = require('../event-manager');
|
||||
|
||||
var Destroying = Flags.Destroying;
|
||||
var DontDestroy = Flags.DontDestroy;
|
||||
var Deactivating = Flags.Deactivating;
|
||||
|
||||
var CHILD_ADDED = 'child-added';
|
||||
var CHILD_REMOVED = 'child-removed';
|
||||
const Destroying = Flags.Destroying;
|
||||
const DontDestroy = Flags.DontDestroy;
|
||||
const Deactivating = Flags.Deactivating;
|
||||
|
||||
const CHILD_ADDED = 'child-added';
|
||||
const CHILD_REMOVED = 'child-removed';
|
||||
|
||||
var idGenerater = new IdGenerater('Node');
|
||||
|
||||
@@ -148,6 +147,14 @@ var BaseNode = cc.Class({
|
||||
|
||||
_active: true,
|
||||
|
||||
/**
|
||||
* @property _level
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
* @private
|
||||
*/
|
||||
_level: 0,
|
||||
|
||||
/**
|
||||
* @property _components
|
||||
* @type {Component[]}
|
||||
@@ -323,7 +330,7 @@ var BaseNode = cc.Class({
|
||||
* @param {String} [name]
|
||||
*/
|
||||
ctor (name) {
|
||||
this._name = typeof name !== 'undefined' ? name : 'New Node';
|
||||
this._name = name !== undefined ? name : 'New Node';
|
||||
|
||||
this._activeInHierarchy = false;
|
||||
// Support for ActionManager and EventManager
|
||||
@@ -373,6 +380,7 @@ var BaseNode = cc.Class({
|
||||
if (CC_DEBUG && (value._objFlags & Deactivating)) {
|
||||
cc.errorID(3821);
|
||||
}
|
||||
this._level = value._level + 1;
|
||||
eventManager._setDirtyForNode(this);
|
||||
value._children.push(this);
|
||||
value.emit(CHILD_ADDED, this);
|
||||
|
||||
@@ -121,8 +121,9 @@ function generateStats () {
|
||||
mode: { desc: cc.game.renderType === cc.game.RENDER_TYPE_WEBGL ? 'WebGL' : 'Canvas', min: 1 }
|
||||
};
|
||||
|
||||
let now = performance.now();
|
||||
for (let id in _stats) {
|
||||
_stats[id]._counter = new PerfCounter(id, _stats[id]);
|
||||
_stats[id]._counter = new PerfCounter(id, _stats[id], now);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,18 +164,20 @@ function generateNode () {
|
||||
function beforeUpdate () {
|
||||
generateNode();
|
||||
|
||||
_stats['frame']._counter.start();
|
||||
_stats['logic']._counter.start();
|
||||
let now = cc.director._lastUpdate;
|
||||
_stats['frame']._counter.start(now);
|
||||
_stats['logic']._counter.start(now);
|
||||
}
|
||||
|
||||
function afterUpdate () {
|
||||
let now = performance.now();
|
||||
if (cc.director.isPaused()) {
|
||||
_stats['frame']._counter.start();
|
||||
_stats['frame']._counter.start(now);
|
||||
}
|
||||
else {
|
||||
_stats['logic']._counter.end();
|
||||
_stats['logic']._counter.end(now);
|
||||
}
|
||||
_stats['render']._counter.start();
|
||||
_stats['render']._counter.start(now);
|
||||
}
|
||||
|
||||
function updateLabel (stat) {
|
||||
@@ -185,16 +188,17 @@ function updateLabel (stat) {
|
||||
}
|
||||
|
||||
function afterDraw () {
|
||||
_stats['render']._counter.end();
|
||||
let now = performance.now();
|
||||
_stats['render']._counter.end(now);
|
||||
_stats['draws']._counter.value = cc.renderer.drawCalls;
|
||||
_stats['frame']._counter.end();
|
||||
_stats['fps']._counter.frame();
|
||||
_stats['frame']._counter.end(now);
|
||||
_stats['fps']._counter.frame(now);
|
||||
|
||||
let left = '';
|
||||
let right = '';
|
||||
for (let id in _stats) {
|
||||
let stat = _stats[id];
|
||||
stat._counter.sample();
|
||||
stat._counter.sample(now);
|
||||
|
||||
left += stat.desc + '\n';
|
||||
right += stat._counter.human() + '\n';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Counter {
|
||||
constructor(id, opts) {
|
||||
constructor(id, opts, now) {
|
||||
this._id = id;
|
||||
this._opts = opts || {};
|
||||
|
||||
@@ -8,15 +8,15 @@ class Counter {
|
||||
this._averageValue = 0;
|
||||
this._accumValue = 0;
|
||||
this._accumSamples = 0;
|
||||
this._accumStart = window.performance.now();
|
||||
this._accumStart = now;
|
||||
}
|
||||
|
||||
_average(v) {
|
||||
_average(v, now) {
|
||||
if (this._opts.average) {
|
||||
this._accumValue += v;
|
||||
++this._accumSamples;
|
||||
|
||||
let t = performance.now();
|
||||
let t = now;
|
||||
if (t - this._accumStart >= this._opts.average) {
|
||||
this._averageValue = this._accumValue / this._accumSamples;
|
||||
this._accumValue = 0;
|
||||
@@ -31,8 +31,8 @@ class Counter {
|
||||
this._value = v;
|
||||
}
|
||||
|
||||
sample() {
|
||||
this._average(this._value);
|
||||
sample(now) {
|
||||
this._average(this._value, now);
|
||||
}
|
||||
|
||||
human() {
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
const Counter = require('./counter');
|
||||
|
||||
class PerfCounter extends Counter {
|
||||
constructor(id, opts) {
|
||||
super(id, opts);
|
||||
constructor(id, opts, now) {
|
||||
super(id, opts, now);
|
||||
|
||||
// DISABLE
|
||||
// this._idstart = `${id}_start`;
|
||||
// this._idend = `${id}_end`;
|
||||
|
||||
this._time = window.performance.now();
|
||||
this._time = now;
|
||||
}
|
||||
|
||||
start() {
|
||||
this._time = window.performance.now();
|
||||
start(now) {
|
||||
this._time = now;
|
||||
|
||||
// DISABLE: long time running will cause performance drop down
|
||||
// window.performance.mark(this._idstart);
|
||||
}
|
||||
|
||||
end() {
|
||||
this._value = window.performance.now() - this._time;
|
||||
end(now) {
|
||||
this._value = now - this._time;
|
||||
|
||||
// DISABLE: long time running will cause performance drop down
|
||||
// window.performance.mark(this._idend);
|
||||
@@ -33,8 +33,8 @@ class PerfCounter extends Counter {
|
||||
this.start();
|
||||
}
|
||||
|
||||
frame() {
|
||||
let t = window.performance.now();
|
||||
frame(now) {
|
||||
let t = now;
|
||||
let e = t - this._time;
|
||||
this._total++;
|
||||
let avg = this._opts.average || 1000;
|
||||
|
||||
@@ -110,7 +110,7 @@ let tmxAssembler = js.addon({
|
||||
let appx = node._anchorPoint.x * node._contentSize.width,
|
||||
appy = node._anchorPoint.y * node._contentSize.height;
|
||||
|
||||
node.getWorldMatrix(_mat4_temp);
|
||||
mat4.copy(_mat4_temp, node._worldMatrix);
|
||||
vec3.set(_vec3_temp, -appx, -appy, 0);
|
||||
mat4.translate(_mat4_temp, _mat4_temp, _vec3_temp);
|
||||
|
||||
|
||||
@@ -366,7 +366,6 @@ let VideoPlayerImpl = cc.Class({
|
||||
updateMatrix (node) {
|
||||
if (!this._video || !this._visible) return;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
var mat = node._worldMatrix;
|
||||
if (!this._forceUpdate &&
|
||||
this._m00 === mat.m00 && this._m01 === mat.m01 && this._m04 === mat.m04 && this._m05 === mat.m05 && this._m12 === mat.m12 && this._m13 === mat.m13 &&
|
||||
|
||||
@@ -299,7 +299,6 @@ var WebViewImpl = cc.Class({
|
||||
updateMatrix (node) {
|
||||
if (!this._div || !this._visible) return;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
var mat = node._worldMatrix;
|
||||
if (!this._forceUpdate &&
|
||||
this._m00 === mat.m00 && this._m01 === mat.m01 && this._m04 === mat.m04 && this._m05 === mat.m05 && this._m12 === mat.m12 && this._m13 === mat.m13 &&
|
||||
|
||||
@@ -354,7 +354,7 @@ dragonBones.CCSlot = cc.Class({
|
||||
let node = this._display.node;
|
||||
math.mat4.copy(node._matrix, t);
|
||||
node._localMatDirty = false;
|
||||
node._worldMatDirty = true;
|
||||
node.setWorldDirty();
|
||||
}
|
||||
|
||||
this._updateVertices();
|
||||
|
||||
@@ -17,7 +17,6 @@ let armatureAssembler = {
|
||||
ctx.save();
|
||||
|
||||
let node = comp.node;
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
|
||||
let texture = comp.dragonAtlasAsset.texture;
|
||||
|
||||
@@ -99,8 +99,7 @@ let armatureAssembler = js.addon({
|
||||
|
||||
let node = comp.node;
|
||||
_z = node._position.z;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
|
||||
_worldMatrix = node._worldMatrix;
|
||||
_a = _worldMatrix.m00; _b = _worldMatrix.m01; _c = _worldMatrix.m04; _d = _worldMatrix.m05;
|
||||
_tx = _worldMatrix.m12; _ty = _worldMatrix.m13;
|
||||
|
||||
+10
-6
@@ -217,9 +217,11 @@ exports.buildJsb = function (sourceFile, outputFile, excludes, opt_macroFlags, c
|
||||
var outFile = Path.basename(outputFile);
|
||||
var outDir = Path.dirname(outputFile);
|
||||
|
||||
var bundler = createBundler(sourceFile, {
|
||||
aliasifyConfig: aliasifyConfig
|
||||
});
|
||||
var opts = {};
|
||||
if (opt_macroFlags && opt_macroFlags.nativeRenderer) {
|
||||
opts.aliasifyConfig = aliasifyConfig;
|
||||
}
|
||||
var bundler = createBundler(sourceFile, opts);
|
||||
excludes = excludes.concat(jsbSkipModules);
|
||||
excludes.forEach(function (module) {
|
||||
bundler.ignore(require.resolve(module));
|
||||
@@ -249,9 +251,11 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, opt_macroFlags
|
||||
var outFile = Path.basename(outputFile);
|
||||
var outDir = Path.dirname(outputFile);
|
||||
|
||||
var bundler = createBundler(sourceFile, {
|
||||
aliasifyConfig: aliasifyConfig
|
||||
});
|
||||
var opts = {};
|
||||
if (opt_macroFlags && opt_macroFlags.nativeRenderer) {
|
||||
opts.aliasifyConfig = aliasifyConfig;
|
||||
}
|
||||
var bundler = createBundler(sourceFile, opts);
|
||||
excludes = excludes.concat(jsbSkipModules);
|
||||
excludes.forEach(function (module) {
|
||||
bundler.ignore(require.resolve(module));
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
|
||||
const PLATFORM_MACROS = ['CC_EDITOR', 'CC_PREVIEW', 'CC_BUILD', 'CC_TEST'];
|
||||
const FLAGS = ['jsb', 'wechatgame', 'qqplay', 'debug'];
|
||||
const FLAGS = ['jsb', 'wechatgame', 'qqplay', 'debug', 'nativeRenderer'];
|
||||
|
||||
// generate macros for uglify's global_defs
|
||||
// available platforms: 'editor' | 'preview' | 'build' | 'test'
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+46
-29
@@ -24,10 +24,11 @@
|
||||
****************************************************************************/
|
||||
|
||||
window.CC_JSB = true;
|
||||
window.CC_WECHATGAME = true;
|
||||
window.CC_WECHATGAME = true; //FIXME: remove CC_WECHATGAME
|
||||
|
||||
// Simulate wechat game API:
|
||||
|
||||
//FIXME: remove wx
|
||||
window.wx = {
|
||||
getSystemInfoSync() {
|
||||
return {
|
||||
@@ -48,30 +49,61 @@ window.wx = {
|
||||
}
|
||||
}
|
||||
|
||||
let oldRequestFrameCallback = null;
|
||||
let requestAnimationFrameID = 0;
|
||||
let requestAnimationFrameCallbacks = {};
|
||||
window.CanvasRenderingContext2D = cc.CanvasRenderingContext2D;
|
||||
delete cc.CanvasRenderingContext2D;
|
||||
|
||||
const { btoa, atob } = require('./base64/base64.min');
|
||||
window.btoa = btoa;
|
||||
window.atob = atob;
|
||||
const { Blob, URL } = require('./Blob');
|
||||
window.Blob = Blob;
|
||||
window.URL = URL;
|
||||
window.DOMParser = require('./xmldom/dom-parser').DOMParser;
|
||||
|
||||
require('./jsb_prepare');
|
||||
require('./jsb_opengl');
|
||||
require('./jsb-adapter');
|
||||
require('./jsb_audioengine');
|
||||
|
||||
let _oldRequestFrameCallback = null;
|
||||
let _requestAnimationFrameID = 0;
|
||||
let _requestAnimationFrameCallbacks = {};
|
||||
let _firstTick = true;
|
||||
|
||||
window.requestAnimationFrame = function(cb) {
|
||||
let id = ++requestAnimationFrameID;
|
||||
requestAnimationFrameCallbacks[id] = cb;
|
||||
let id = ++_requestAnimationFrameID;
|
||||
_requestAnimationFrameCallbacks[id] = cb;
|
||||
return id;
|
||||
};
|
||||
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
delete requestAnimationFrameCallbacks[id];
|
||||
delete _requestAnimationFrameCallbacks[id];
|
||||
};
|
||||
|
||||
const {disableBatchGLCommandsToNative, flushCommands} = require('./glOptMode');
|
||||
window.optConfig = {
|
||||
disableBatchGLCommandsToNative: disableBatchGLCommandsToNative
|
||||
};
|
||||
|
||||
function tick(nowMilliSeconds) {
|
||||
fireTimeout(nowMilliSeconds);
|
||||
|
||||
for (let id in requestAnimationFrameCallbacks) {
|
||||
oldRequestFrameCallback = requestAnimationFrameCallbacks[id];
|
||||
if (oldRequestFrameCallback) {
|
||||
delete requestAnimationFrameCallbacks[id];
|
||||
oldRequestFrameCallback(nowMilliSeconds);
|
||||
if (_firstTick) {
|
||||
_firstTick = false;
|
||||
if (window.onload) {
|
||||
var event = new Event('load');
|
||||
event._target = window;
|
||||
window.onload(event);
|
||||
}
|
||||
}
|
||||
fireTimeout(nowMilliSeconds);
|
||||
|
||||
for (let id in _requestAnimationFrameCallbacks) {
|
||||
_oldRequestFrameCallback = _requestAnimationFrameCallbacks[id];
|
||||
if (_oldRequestFrameCallback) {
|
||||
delete _requestAnimationFrameCallbacks[id];
|
||||
_oldRequestFrameCallback(nowMilliSeconds);
|
||||
}
|
||||
}
|
||||
flushCommands();
|
||||
}
|
||||
|
||||
let _timeoutIDIndex = 0;
|
||||
@@ -159,23 +191,8 @@ jsb.fileUtils = cc.fileUtils;
|
||||
delete cc.FileUtils;
|
||||
delete cc.fileUtils;
|
||||
|
||||
window.CanvasRenderingContext2D = cc.CanvasRenderingContext2D;
|
||||
delete cc.CanvasRenderingContext2D;
|
||||
|
||||
jsb.urlRegExp = new RegExp("^(?:https?|ftp)://\\S*$", "i");
|
||||
|
||||
require('./jsb_prepare');
|
||||
require('./jsb_opengl');
|
||||
const { btoa, atob } = require('./base64/base64.min');
|
||||
window.btoa = btoa;
|
||||
window.atob = atob;
|
||||
const { Blob, URL } = require('./Blob');
|
||||
window.Blob = Blob;
|
||||
window.URL = URL;
|
||||
window.DOMParser = require('./xmldom/dom-parser').DOMParser;
|
||||
require('./jsb-adapter');
|
||||
require('./jsb_audioengine');
|
||||
|
||||
/**
|
||||
* @type {Object}
|
||||
* @name jsb.reflection
|
||||
|
||||
@@ -44,7 +44,7 @@ class Element extends Node {
|
||||
}
|
||||
|
||||
getBoundingClientRect() {
|
||||
return new DOMRect();
|
||||
return new DOMRect(0, 0, window.innerWidth, window.innerHeight);
|
||||
}
|
||||
|
||||
// attrName is a string that names the attribute to be removed from element.
|
||||
|
||||
@@ -37,7 +37,7 @@ class Event {
|
||||
|
||||
constructor(type, eventInit) {
|
||||
this._type = type
|
||||
this._eventTarget = null
|
||||
this._target = null
|
||||
this._eventPhase = 2
|
||||
this._currentTarget = null
|
||||
this._canceled = false
|
||||
@@ -59,7 +59,7 @@ class Event {
|
||||
* @type {EventTarget}
|
||||
*/
|
||||
get target() {
|
||||
return this._eventTarget
|
||||
return this._target
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -152,15 +152,29 @@ EventTarget.prototype = {
|
||||
throw new TypeError("\"event.type\" should be a string.")
|
||||
}
|
||||
|
||||
const eventName = event.type
|
||||
var onFunc = this['on' + eventName];
|
||||
if (onFunc && typeof onFunc === 'function') {
|
||||
event._target = event._currentTarget = this;
|
||||
onFunc.call(this, event);
|
||||
event._target = event._currentTarget = null
|
||||
event._eventPhase = 0
|
||||
event._passiveListener = null
|
||||
|
||||
if (event.defaultPrevented)
|
||||
return false;
|
||||
}
|
||||
|
||||
// If listeners aren't registered, terminate.
|
||||
const listeners = this._listeners
|
||||
const eventName = event.type
|
||||
|
||||
let node = listeners.get(eventName)
|
||||
if (!node) {
|
||||
return true
|
||||
}
|
||||
|
||||
event._target = event._currentTarget = this;
|
||||
|
||||
// This doesn't process capturing phase and bubbling phase.
|
||||
// This isn't participating in a tree.
|
||||
let prev = null
|
||||
@@ -186,9 +200,6 @@ EventTarget.prototype = {
|
||||
if (typeof node.listener === "function") {
|
||||
node.listener.call(this, event)
|
||||
}
|
||||
else if (node.listenerType !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
|
||||
node.listener.handleEvent(event)
|
||||
}
|
||||
|
||||
// Break if `event.stopImmediatePropagation` was called.
|
||||
if (event._stopped) {
|
||||
|
||||
@@ -42,7 +42,8 @@ class FileReader extends EventTarget {
|
||||
// Starts reading the contents of the specified Blob, once finished, the result attribute contains a data: URL representing the file's data.
|
||||
readAsDataURL(blob) {
|
||||
this.result = 'data:image/png;base64,' + window.btoa(blob);
|
||||
this.onload();
|
||||
var event = new Event('load');
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
// Starts reading the contents of the specified Blob, once finished, the result attribute contains the contents of the file as a text string.
|
||||
|
||||
@@ -218,8 +218,8 @@ class HTMLCanvasElement extends HTMLElement {
|
||||
|
||||
this.top = 0;
|
||||
this.left = 0;
|
||||
this._width = width ? width : window.innerWidth;
|
||||
this._height = height ? height : window.innerHeight;
|
||||
this._width = width ? Math.ceil(width) : 1;
|
||||
this._height = height ? Math.ceil(height) : 1;
|
||||
this._context2D = null;
|
||||
this._data = null;
|
||||
}
|
||||
@@ -227,15 +227,14 @@ class HTMLCanvasElement extends HTMLElement {
|
||||
//TODO: implement opts.
|
||||
getContext(name, opts) {
|
||||
var self = this;
|
||||
console.log(`==> Canvas getContext(${name})`);
|
||||
// console.log(`==> Canvas getContext(${name})`);
|
||||
if (name === 'webgl' || name === 'experimental-webgl') {
|
||||
return window.gl;
|
||||
return window.__gl;
|
||||
} else if (name === '2d') {
|
||||
if (!this._context2D) {
|
||||
this._context2D = new CanvasRenderingContext2D(this._width, this._height);
|
||||
this._context2D._canvas = this;
|
||||
this._context2D.setCanvasBufferUpdatedCallback(function(data) {
|
||||
console.log('setCanvasBufferUpdatedCallback: dataLen: ' + data.length);
|
||||
this._context2D._setCanvasBufferUpdatedCallback(function(data) {
|
||||
self._data = new ImageData(data, self._width, self._height);
|
||||
});
|
||||
}
|
||||
@@ -251,7 +250,8 @@ class HTMLCanvasElement extends HTMLElement {
|
||||
}
|
||||
|
||||
set width(width) {
|
||||
console.log(`==> HTMLCanvasElement.width = ${width}`);
|
||||
width = Math.ceil(width);
|
||||
// console.log(`==> HTMLCanvasElement.width = ${width}`);
|
||||
if (this._width !== width) {
|
||||
this._width = width;
|
||||
if (this._context2D) {
|
||||
@@ -265,7 +265,8 @@ class HTMLCanvasElement extends HTMLElement {
|
||||
}
|
||||
|
||||
set height(height) {
|
||||
console.log(`==> HTMLCanvasElement.height = ${height}`);
|
||||
height = Math.ceil(height);
|
||||
// console.log(`==> HTMLCanvasElement.height = ${height}`);
|
||||
if (this._height !== height) {
|
||||
this._height = height;
|
||||
if (this._context2D) {
|
||||
@@ -340,7 +341,7 @@ function touchEventHandlerFactory(type) {
|
||||
const touchEvent = new TouchEvent(type)
|
||||
|
||||
touchEvent.touches = touches;
|
||||
// touchEvent.targetTouches = Array.prototype.slice.call(event.touches)
|
||||
touchEvent.targetTouches = Array.prototype.slice.call(touchEvent.touches)
|
||||
touchEvent.changedTouches = touches;//event.changedTouches
|
||||
// touchEvent.timeStamp = event.timeStamp
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
const HTMLElement = require('./HTMLElement');
|
||||
const Event = require('./Event');
|
||||
const gl = window.__gl;
|
||||
|
||||
class HTMLImageElement extends HTMLElement {
|
||||
constructor(width, height) {
|
||||
@@ -32,7 +33,6 @@ class HTMLImageElement extends HTMLElement {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this._data = null;
|
||||
this.onload = null;
|
||||
this._src = null;
|
||||
this.complete = false;
|
||||
this._glFormat = this._glInternalFormat = gl.RGBA;
|
||||
@@ -67,11 +67,8 @@ class HTMLImageElement extends HTMLElement {
|
||||
|
||||
this.complete = true;
|
||||
|
||||
this.dispatchEvent(new Event('load'));
|
||||
|
||||
if (this.onload) {
|
||||
this.onload();
|
||||
}
|
||||
var event = new Event('load');
|
||||
this.dispatchEvent(event);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
let HTMLMediaElement = require('./HTMLMediaElement');
|
||||
|
||||
class HTMLVideoElement extends HTMLMediaElement {
|
||||
constructor() {
|
||||
super('video')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HTMLVideoElement;
|
||||
@@ -23,12 +23,13 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
let HTMLElement = require('./HTMLElement');
|
||||
let Image = require('./Image');
|
||||
let Audio = require('./Audio');
|
||||
let HTMLCanvasElement = require('./HTMLCanvasElement');
|
||||
let Node = require('./Node');
|
||||
let FontFaceSet = require('./FontFaceSet')
|
||||
const HTMLElement = require('./HTMLElement');
|
||||
const Image = require('./Image');
|
||||
const Audio = require('./Audio');
|
||||
const HTMLCanvasElement = require('./HTMLCanvasElement');
|
||||
const HTMLVideoElement = require('./HTMLVideoElement');
|
||||
const Node = require('./Node');
|
||||
const FontFaceSet = require('./FontFaceSet')
|
||||
|
||||
class Document extends Node {
|
||||
|
||||
@@ -61,21 +62,17 @@ class Document extends Node {
|
||||
} else if (tagName === 'img') {
|
||||
return new Image()
|
||||
} else if (tagName === 'video') {
|
||||
return {
|
||||
canPlayType: () => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
return new HTMLVideoElement();
|
||||
}
|
||||
|
||||
return new HTMLElement(tagName)
|
||||
}
|
||||
|
||||
getElementById(id) {
|
||||
if (id === window.canvas.id) {
|
||||
if (id === window.canvas.id || id === 'canvas') {
|
||||
return window.canvas
|
||||
}
|
||||
return null
|
||||
return new HTMLElement(id);
|
||||
}
|
||||
|
||||
getElementsByTagName(tagName) {
|
||||
@@ -86,7 +83,7 @@ class Document extends Node {
|
||||
} else if (tagName === 'canvas') {
|
||||
return [window.canvas]
|
||||
}
|
||||
return []
|
||||
return [new HTMLElement(tagName)]
|
||||
}
|
||||
|
||||
getElementsByName(tagName) {
|
||||
@@ -97,7 +94,7 @@ class Document extends Node {
|
||||
} else if (tagName === 'canvas') {
|
||||
return [window.canvas]
|
||||
}
|
||||
return []
|
||||
return [new HTMLElement(tagName)]
|
||||
}
|
||||
|
||||
querySelector(query) {
|
||||
@@ -110,7 +107,7 @@ class Document extends Node {
|
||||
} else if (query === `#${window.canvas.id}`) {
|
||||
return window.canvas
|
||||
}
|
||||
return null
|
||||
return new HTMLElement(query);
|
||||
}
|
||||
|
||||
querySelectorAll(query) {
|
||||
@@ -121,7 +118,7 @@ class Document extends Node {
|
||||
} else if (query === 'canvas') {
|
||||
return [window.canvas]
|
||||
}
|
||||
return []
|
||||
return [new HTMLElement(query)];
|
||||
}
|
||||
|
||||
createTextNode() {
|
||||
|
||||
@@ -24,10 +24,12 @@
|
||||
****************************************************************************/
|
||||
|
||||
const location = {
|
||||
href: 'game.js',
|
||||
hash: '',
|
||||
reload() {
|
||||
}
|
||||
href: 'game.js',
|
||||
pathname: 'game.js',
|
||||
search: '',
|
||||
hash: '',
|
||||
reload() {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = location;
|
||||
|
||||
@@ -31,7 +31,7 @@ const navigator = {
|
||||
platform: 'wx', //cjh added wx
|
||||
language: 'zh-cn',
|
||||
appVersion: '5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
|
||||
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 MicroMessenger/6.6.0 MiniGame NetType/WIFI Language/zh_CN',
|
||||
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 NetType/WIFI Language/zh_CN',
|
||||
onLine: true, // TODO 用 wx.getNetworkStateChange 和 wx.onNetworkStateChange 来返回真实的状态
|
||||
|
||||
// TODO 用 wx.getLocation 来封装 geolocation
|
||||
|
||||
@@ -41,9 +41,9 @@ function inject () {
|
||||
window.HTMLImageElement = require('./HTMLImageElement');
|
||||
window.HTMLMediaElement = require('./HTMLMediaElement');
|
||||
window.HTMLAudioElement = require('./HTMLAudioElement');
|
||||
window.HTMLVideoElement = require('./HTMLVideoElement');
|
||||
window.canvas = new HTMLCanvasElement();
|
||||
window.gl.canvas = window.canvas;
|
||||
window.WebGLRenderingContext = window.gl;
|
||||
window.__gl.canvas = window.canvas;
|
||||
window.navigator = require('./navigator');
|
||||
window.Image = require('./Image');
|
||||
window.Audio = require('./Audio');
|
||||
@@ -74,15 +74,15 @@ function inject () {
|
||||
|
||||
window.addEventListener = function(eventName, listener, options) {
|
||||
window.canvas.addEventListener(eventName, listener, options);
|
||||
}
|
||||
};
|
||||
|
||||
window.removeEventListener = function(eventName, listener, options) {
|
||||
window.canvas.removeEventListener(eventName, listener, options);
|
||||
}
|
||||
};
|
||||
|
||||
window.dispatchEvent = function(event) {
|
||||
window.canvas.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
window.getComputedStyle = function(element) {
|
||||
return {
|
||||
@@ -91,7 +91,9 @@ function inject () {
|
||||
top: '0px',
|
||||
height: '0px'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
window.focus = function() {};
|
||||
|
||||
window._isInjected = true;
|
||||
}
|
||||
|
||||
+13
-390
@@ -28,391 +28,12 @@
|
||||
*/
|
||||
|
||||
require('./jsb_opengl_constants');
|
||||
window.gl = window.gl || {};
|
||||
|
||||
const gl = __gl;
|
||||
|
||||
gl.drawingBufferWidth = window.innerWidth;
|
||||
gl.drawingBufferHeight = window.innerHeight;
|
||||
|
||||
//
|
||||
// Create functions
|
||||
//
|
||||
gl.createTexture = function() {
|
||||
// Returns a "WebGLTexture" object
|
||||
var ret = gl._createTexture();
|
||||
return { texture_id:ret };
|
||||
};
|
||||
|
||||
gl.createBuffer = function() {
|
||||
// Returns a "WebGLBuffer" object
|
||||
var ret = gl._createBuffer();
|
||||
return { buffer_id:ret };
|
||||
};
|
||||
|
||||
gl.createRenderbuffer = function() {
|
||||
// Returns a "WebGLRenderBuffer" object
|
||||
var ret = gl._createRenderbuffer();
|
||||
return { renderbuffer_id:ret};
|
||||
};
|
||||
|
||||
gl.createFramebuffer = function() {
|
||||
// Returns a "WebGLFramebuffer" object
|
||||
var ret = gl._createFramebuffer();
|
||||
return {framebuffer_id:ret};
|
||||
};
|
||||
|
||||
gl.createProgram = function() {
|
||||
// Returns a "WebGLProgram" object
|
||||
var ret = gl._createProgram();
|
||||
return {program_id:ret};
|
||||
};
|
||||
|
||||
gl.createShader = function(shaderType) {
|
||||
// Returns a "WebGLShader" object
|
||||
var ret = gl._createShader(shaderType);
|
||||
return {shader_id:ret};
|
||||
};
|
||||
|
||||
//
|
||||
// Delete Functions
|
||||
//
|
||||
gl.deleteTexture = function(texture) {
|
||||
var texture_id = texture.texture_id;
|
||||
// Accept numbers too. eg: gl.deleteTexture(0)
|
||||
if (typeof texture === 'number')
|
||||
texture_id = texture;
|
||||
|
||||
gl._deleteTexture(texture_id);
|
||||
};
|
||||
|
||||
gl.deleteBuffer = function(buffer) {
|
||||
var buffer_id = buffer.buffer_id;
|
||||
// Accept numbers too. eg: gl.deleteBuffer(0)
|
||||
if( typeof buffer === 'number' )
|
||||
buffer_id = buffer;
|
||||
|
||||
gl._deleteBuffer(buffer_id);
|
||||
};
|
||||
|
||||
gl.deleteRenderbuffer = function(buffer) {
|
||||
var buffer_id = buffer.renderbuffer_id;
|
||||
// Accept numbers too. eg: gl.deleteRenderbuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
|
||||
gl._deleteRenderbuffer(renderbuffer_id);
|
||||
};
|
||||
|
||||
gl.deleteFramebuffer = function(buffer) {
|
||||
var buffer_id;
|
||||
if (buffer)
|
||||
buffer_id = buffer.framebuffer_id;
|
||||
else
|
||||
buffer_id = null;
|
||||
gl._deleteFramebuffer(buffer_id);
|
||||
};
|
||||
|
||||
gl.deleteProgram = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.deleteShader(0)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
gl._deleteProgram(program_id);
|
||||
};
|
||||
|
||||
gl.deleteShader = function(shader) {
|
||||
var shader_id = shader.shader_id;
|
||||
// Accept numbers too. eg: gl.deleteShader(0)
|
||||
if (typeof shader === 'number')
|
||||
shader_id = shader;
|
||||
|
||||
gl._deleteShader(shader_id);
|
||||
};
|
||||
|
||||
//
|
||||
// Bind Related
|
||||
//
|
||||
// void bindTexture(GLenum target, WebGLTexture? texture);
|
||||
gl.bindTexture = function(target, texture) {
|
||||
|
||||
var texture_id;
|
||||
// Accept numbers too. eg: gl.bindTexture(0)
|
||||
if (typeof texture === 'number')
|
||||
texture_id = texture;
|
||||
else if( texture === null )
|
||||
texture_id = 0;
|
||||
else
|
||||
texture_id = texture.texture_id;
|
||||
|
||||
gl._bindTexture( target, texture_id );
|
||||
};
|
||||
|
||||
// void bindBuffer(GLenum target, WebGLBuffer? buffer);
|
||||
gl.bindBuffer = function(target, buffer) {
|
||||
var buffer_id;
|
||||
// Accept numbers too. eg: gl.bindBuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
else if (buffer === null)
|
||||
buffer_id = 0;
|
||||
else
|
||||
buffer_id = buffer.buffer_id;
|
||||
|
||||
gl._bindBuffer(target, buffer_id);
|
||||
};
|
||||
|
||||
// void bindRenderbuffer(GLenum target, WebGLRenderbuffer? renderbuffer);
|
||||
gl.bindRenderbuffer = function(target, buffer) {
|
||||
var buffer_id;
|
||||
|
||||
// Accept numbers too. eg: gl.bindRenderbuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
else if (buffer === null)
|
||||
buffer_id = 0;
|
||||
else
|
||||
buffer_id = buffer.renderbuffer_id;
|
||||
|
||||
gl._bindRenderbuffer(target, buffer_id);
|
||||
};
|
||||
|
||||
// void bindFramebuffer(GLenum target, WebGLFramebuffer? framebuffer);
|
||||
gl.bindFramebuffer = function(target, buffer) {
|
||||
var buffer_id;
|
||||
|
||||
// Accept numbers too. eg: gl.bindFramebuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
else if( buffer === null )
|
||||
buffer_id = null;
|
||||
else
|
||||
buffer_id = buffer.framebuffer_id;
|
||||
|
||||
gl._bindFramebuffer(target, buffer_id);
|
||||
};
|
||||
|
||||
gl.framebufferRenderbuffer = function(target, attachment, renderbuffertarget, renderbuffer) {
|
||||
gl._framebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer.renderbuffer_id);
|
||||
};
|
||||
|
||||
gl.framebufferTexture2D = function(target, attachment, textarget, texture, level) {
|
||||
gl._framebufferTexture2D(target, attachment, textarget, texture.texture_id, level);
|
||||
};
|
||||
|
||||
gl.isFramebuffer = function(buffer) {
|
||||
if (buffer && buffer.framebuffer_id) {
|
||||
return gl._isFramebuffer(buffer.framebuffer_id);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
gl.isProgram = function(program) {
|
||||
if (program && program.program_id) {
|
||||
return gl._isProgram(program.program_id);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
gl.isRenderbuffer = function(buffer) {
|
||||
if (buffer && buffer.renderbuffer_id) {
|
||||
return gl._isRenderbuffer(buffer.renderbuffer_id);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
gl.isShader = function(shader) {
|
||||
if (shader && shader.shader_id) {
|
||||
return gl._isShader(shader.shader_id);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
gl.isTexture = function(texture) {
|
||||
if (texture && texture.texture_id) {
|
||||
return gl._isTexture(texture.texture_id);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
//
|
||||
// Uniform related
|
||||
//
|
||||
// any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
|
||||
gl.getUniform = function(program, location) {
|
||||
var program_id;
|
||||
var location_id;
|
||||
|
||||
// Accept numbers too. eg: gl.bindFramebuffer(0)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
else
|
||||
program_id = program.program_id;
|
||||
|
||||
if (typeof location === 'number')
|
||||
location_id = location;
|
||||
else
|
||||
location_id = location.location_id;
|
||||
|
||||
return gl._getUniform(program_id, location_id);
|
||||
};
|
||||
|
||||
// gl.uniformMatrix2fv = function(location, bool, matrix) {
|
||||
// gl._uniformMatrix2fv(program.program_id, bool, matrix);
|
||||
// };
|
||||
|
||||
// gl.uniformMatrix3fv = function(program, bool, matrix) {
|
||||
// gl._uniformMatrix3fv(program.program_id, bool, matrix);
|
||||
// };
|
||||
|
||||
// gl.uniformMatrix4fv = function(program, bool, matrix) {
|
||||
// gl._uniformMatrix4fv(program.program_id, bool, matrix);
|
||||
// };
|
||||
|
||||
|
||||
//
|
||||
// Shader related
|
||||
//
|
||||
// void compileShader(WebGLShader? shader);
|
||||
gl.compileShader = function(shader) {
|
||||
gl._compileShader( shader.shader_id);
|
||||
};
|
||||
|
||||
// void shaderSource(WebGLShader? shader, DOMString source);
|
||||
gl.shaderSource = function(shader, source) {
|
||||
gl._shaderSource(shader.shader_id, source);
|
||||
};
|
||||
|
||||
// any getShaderParameter(WebGLShader? shader, GLenum pname);
|
||||
gl.getShaderParameter = function(shader, e) {
|
||||
return gl._getShaderParameter(shader.shader_id,e);
|
||||
};
|
||||
|
||||
// DOMString? getShaderInfoLog(WebGLShader? shader);
|
||||
gl.getShaderInfoLog = function(shader) {
|
||||
return gl._getShaderInfoLog(shader.shader_id);
|
||||
};
|
||||
|
||||
// DOMString gl.getShaderSource(shader);
|
||||
gl.getShaderSource = function(shader) {
|
||||
return gl._getShaderSource(shader.shader_id);
|
||||
};
|
||||
|
||||
//
|
||||
// program related
|
||||
//
|
||||
// void attachShader(WebGLProgram? program, WebGLShader? shader);
|
||||
gl.attachShader = function(program, shader) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.attachShader(17)
|
||||
if( typeof program === 'number' )
|
||||
program_id = program;
|
||||
|
||||
gl._attachShader(program_id, shader.shader_id);
|
||||
};
|
||||
|
||||
// void linkProgram(WebGLProgram? program);
|
||||
gl.linkProgram = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.linkProgram(17)
|
||||
if( typeof program === 'number' )
|
||||
program_id = program;
|
||||
|
||||
gl._linkProgram(program_id);
|
||||
};
|
||||
|
||||
gl.bindAttribLocation = function(program, index, name) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.linkProgram(17)
|
||||
if( typeof program === 'number' )
|
||||
program_id = program;
|
||||
|
||||
gl._bindAttribLocation(program_id, index, name);
|
||||
};
|
||||
|
||||
// any getProgramParameter(WebGLProgram? program, GLenum pname);
|
||||
gl.getProgramParameter = function(program, e) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getProgramParameter(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getProgramParameter(program_id, e);
|
||||
};
|
||||
|
||||
gl.getProgramInfoLog = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getProgramParameter(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getProgramInfoLog(program_id);
|
||||
};
|
||||
|
||||
// void useProgram(WebGLProgram? program);
|
||||
gl.useProgram = function(program) {
|
||||
var program_id;
|
||||
// Accept numbers too. eg: gl.useProgram(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
else
|
||||
program_id = program.program_id;
|
||||
|
||||
gl._useProgram (program_id);
|
||||
};
|
||||
|
||||
|
||||
// [WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram? program, DOMString name);
|
||||
gl.getAttribLocation = function(program, name) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getAttribLocation(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getAttribLocation(program_id, name);
|
||||
};
|
||||
|
||||
// WebGLUniformLocation? getUniformLocation(WebGLProgram? program, DOMString name);
|
||||
gl.getUniformLocation = function(program, name) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getUniformLocation(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
// XXX: it should return an object, not an integer
|
||||
return gl._getUniformLocation(program_id,name);
|
||||
};
|
||||
|
||||
|
||||
// WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
|
||||
gl.getActiveAttrib = function(program, index) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getActiveAttrib(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getActiveAttrib(program_id, index);
|
||||
};
|
||||
|
||||
// WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index);
|
||||
gl.getActiveUniform = function(program, index) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getActiveUniform(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getActiveUniform(program_id, index);
|
||||
};
|
||||
|
||||
// sequence<WebGLShader>? getAttachedShaders(WebGLProgram? program);
|
||||
gl.getAttachedShaders = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getAttachedShaders(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getAttachedShaders(program_id);
|
||||
};
|
||||
|
||||
//
|
||||
// Extensions
|
||||
//
|
||||
@@ -447,24 +68,23 @@ void gl.texImage2D(target, level, internalformat, format, type, ImageBitmap? pix
|
||||
gl.texImage2D = function(target, level, internalformat, width, height, border, format, type, pixels) {
|
||||
let argCount = arguments.length;
|
||||
if (argCount == 6) {
|
||||
|
||||
var image = border;
|
||||
type = height;
|
||||
format = width;
|
||||
|
||||
if (image instanceof HTMLImageElement) {
|
||||
// console.log(`==> texImage2D HTMLImageElement internalformat: ${image._glInternalFormat}, format: ${image._glFormat}, image: w:${image.width}, h:${image.height}, dataLen:${image._data.length}`);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, image._alignment);
|
||||
|
||||
_glTexImage2D(target, level, image._glInternalFormat, image.width, image.height, 0, image._glFormat, image._glType, image._data);
|
||||
}
|
||||
else if (image instanceof HTMLCanvasElement) {
|
||||
// console.log(`==> texImage2D HTMLCanvasElement internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);//, dataLen:${image._data.length}`);
|
||||
var data = null;
|
||||
if (image._data) {
|
||||
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data._data);
|
||||
data = image._data._data;
|
||||
}
|
||||
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, data);
|
||||
}
|
||||
else if (image instanceof ImageData) {
|
||||
// console.log(`==> texImage2D ImageData internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);
|
||||
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data);
|
||||
}
|
||||
else {
|
||||
@@ -473,7 +93,8 @@ gl.texImage2D = function(target, level, internalformat, width, height, border, f
|
||||
}
|
||||
else if (argCount == 9) {
|
||||
_glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
console.error("gl.texImage2D: invalid argument count!");
|
||||
}
|
||||
}
|
||||
@@ -496,15 +117,16 @@ gl.texSubImage2D = function(target, level, xoffset, yoffset, width, height, form
|
||||
type = height;
|
||||
format = width;
|
||||
|
||||
//TODO: ImageData
|
||||
if (image instanceof HTMLImageElement) {
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, image._alignment);
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, image._glFormat, image._glType, image._data);
|
||||
}
|
||||
else if (image instanceof HTMLCanvasElement) {
|
||||
var data = null;
|
||||
if (image._data) {
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data._data);
|
||||
data = image._data._data;
|
||||
}
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, data);
|
||||
}
|
||||
else if (image instanceof ImageData) {
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data);
|
||||
@@ -515,7 +137,8 @@ gl.texSubImage2D = function(target, level, xoffset, yoffset, width, height, form
|
||||
}
|
||||
else if (argCount == 9) {
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
console.error((new Error("gl.texImage2D: invalid argument count!").stack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* AUTOGENERATED FILE. DO NOT EDIT IT
|
||||
* Generated by "generate_jsb.py -c opengl_jsb.ini" on 2013-03-18
|
||||
* Script version: v0.6
|
||||
*/
|
||||
|
||||
window.gl = window.gl || {};
|
||||
const gl = __gl;
|
||||
|
||||
gl.GCCSO_SHADER_BINARY_FJ = 0x9260;
|
||||
gl._3DC_XY_AMD = 0x87fa;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
let _stageOffset = 0;
|
||||
let _name2stageID = {};
|
||||
|
||||
var config = {
|
||||
addStage: function (name) {
|
||||
// already added
|
||||
if (_name2stageID[name] !== undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
let stageID = 1 << _stageOffset;
|
||||
_name2stageID[name] = stageID;
|
||||
|
||||
_stageOffset += 1;
|
||||
|
||||
renderer.addStage(name);
|
||||
},
|
||||
|
||||
stageID: function (name) {
|
||||
let id = _name2stageID[name];
|
||||
if (id === undefined) {
|
||||
return -1;
|
||||
}
|
||||
return id;
|
||||
},
|
||||
|
||||
stageIDs: function (nameList) {
|
||||
let key = 0;
|
||||
for (let i = 0; i < nameList.length; ++i) {
|
||||
let id = _name2stageID[nameList[i]];
|
||||
if (id !== undefined) {
|
||||
key |= id;
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
@@ -0,0 +1,89 @@
|
||||
let config = renderer.config;
|
||||
|
||||
class Effect {
|
||||
/**
|
||||
* @param {Array} techniques
|
||||
*/
|
||||
constructor(techniques, properties = {}, defines = []) {
|
||||
this._techniques = techniques;
|
||||
this._properties = properties;
|
||||
this._defines = defines;
|
||||
|
||||
var techniqueObjs = [];
|
||||
var techniqueObj;
|
||||
for (var i = 0, len = techniques.length; i < len; ++i) {
|
||||
techniqueObj = techniques[i]._nativeObj;
|
||||
techniqueObjs.push(techniqueObj);
|
||||
}
|
||||
|
||||
this._nativeObj = new renderer.EffectNative(techniqueObjs, properties, defines);
|
||||
this._nativePtr = this._nativeObj.self();
|
||||
|
||||
// TODO: check if params is valid for current technique???
|
||||
}
|
||||
|
||||
clear() {
|
||||
this._techniques.length = 0;
|
||||
this._properties = null;
|
||||
this._defines.length = 0;
|
||||
}
|
||||
|
||||
getTechnique(stage) {
|
||||
let stageID = config.stageID(stage);
|
||||
for (let i = 0; i < this._techniques.length; ++i) {
|
||||
let tech = this._techniques[i];
|
||||
if (tech.stageIDs & stageID) {
|
||||
return tech;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getProperty(name) {
|
||||
return this._properties[name];
|
||||
}
|
||||
|
||||
setProperty(name, value) {
|
||||
// TODO: check if params is valid for current technique???
|
||||
this._properties[name] = value;
|
||||
this._nativeObj.setProperty(name, value);
|
||||
}
|
||||
|
||||
getDefine(name) {
|
||||
for (let i = 0; i < this._defines.length; ++i) {
|
||||
let def = this._defines[i];
|
||||
if ( def.name === name ) {
|
||||
return def.value;
|
||||
}
|
||||
}
|
||||
|
||||
console.warn(`Failed to get define ${name}, define not found.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
define(name, value) {
|
||||
for (let i = 0; i < this._defines.length; ++i) {
|
||||
let def = this._defines[i];
|
||||
if ( def.name === name ) {
|
||||
def.value = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._nativeObj.setDefine(name, value);
|
||||
|
||||
console.warn(`Failed to set define ${name}, define not found.`);
|
||||
}
|
||||
|
||||
extractDefines(out = {}) {
|
||||
for (let i = 0; i < this._defines.length; ++i) {
|
||||
let def = this._defines[i];
|
||||
out[def.name] = def.value;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Effect;
|
||||
+3
-1
@@ -49,13 +49,15 @@ _p._ctor = function(device, options) {
|
||||
|
||||
_p = gfx.VertexBuffer.prototype;
|
||||
_p._ctor = function(device, format, usage, data, numVertices) {
|
||||
this.init(device, format, usage, data, numVertices);
|
||||
this.init(device, format._nativeObj, usage, data, numVertices);
|
||||
this._nativePtr = this.self();
|
||||
};
|
||||
cc.defineGetterSetter(_p, "count", _p.getCount);
|
||||
|
||||
_p = gfx.IndexBuffer.prototype;
|
||||
_p._ctor = function(device, format, usage, data, numIndices) {
|
||||
this.init(device, format, usage, data, numIndices);
|
||||
this._nativePtr = this.self();
|
||||
};
|
||||
cc.defineGetterSetter(_p, "count", _p.getCount);
|
||||
|
||||
|
||||
+5
-2
@@ -22,8 +22,11 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
require('./gfx');
|
||||
require('./renderer');
|
||||
|
||||
if (CC_NATIVERENDERER) {
|
||||
require('./gfx');
|
||||
require('./renderer');
|
||||
}
|
||||
require('../index')
|
||||
require('./jsb-audio')
|
||||
require('./jsb-loader')
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
class InputAssembler {
|
||||
constructor(vb, ib, pt = gfx.PT_TRIANGLES) {
|
||||
this._vertexBuffer = vb;
|
||||
this._indexBuffer = ib;
|
||||
this._primitiveType = pt;
|
||||
this._start = 0;
|
||||
this._count = -1;
|
||||
|
||||
// TODO: instancing data
|
||||
// this._stream = 0;
|
||||
}
|
||||
|
||||
getPrimitiveCount () {
|
||||
if (this._count !== -1) {
|
||||
return this._count;
|
||||
}
|
||||
|
||||
if (this._indexBuffer) {
|
||||
return this._indexBuffer.count;
|
||||
}
|
||||
|
||||
return this._vertexBuffer.count;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InputAssembler;
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
class Model {
|
||||
constructor() {
|
||||
this._poolID = -1;
|
||||
this._node = null;
|
||||
this._inputAssemblers = [];
|
||||
this._effects = [];
|
||||
this._defines = [];
|
||||
this._dynamicIA = false;
|
||||
this._viewID = -1;
|
||||
|
||||
// TODO: we calculate aabb based on vertices
|
||||
// this._aabb
|
||||
}
|
||||
|
||||
get inputAssemblerCount() {
|
||||
return this._inputAssemblers.length;
|
||||
}
|
||||
|
||||
get dynamicIA() {
|
||||
return this._dynamicIA;
|
||||
}
|
||||
|
||||
get drawItemCount() {
|
||||
return this._dynamicIA ? 1 : this._inputAssemblers.length;
|
||||
}
|
||||
|
||||
setNode(node) {
|
||||
this._node = node;
|
||||
}
|
||||
|
||||
setDynamicIA(enabled) {
|
||||
this._dynamicIA = enabled;
|
||||
}
|
||||
|
||||
addInputAssembler(ia) {
|
||||
if (this._inputAssemblers.indexOf(ia) !== -1) {
|
||||
return;
|
||||
}
|
||||
this._inputAssemblers.push(ia);
|
||||
}
|
||||
|
||||
clearInputAssemblers() {
|
||||
this._inputAssemblers.length = 0;
|
||||
}
|
||||
|
||||
addEffect(effect) {
|
||||
if (this._effects.indexOf(effect) !== -1) {
|
||||
return;
|
||||
}
|
||||
this._effects.push(effect);
|
||||
|
||||
//
|
||||
// let defs = Object.create(null);
|
||||
// effect.extractDefines(defs);
|
||||
// this._defines.push(defs);
|
||||
}
|
||||
|
||||
clearEffects() {
|
||||
this._effects.length = 0;
|
||||
this._defines.length = 0;
|
||||
}
|
||||
|
||||
extractDrawItem(out, index) {
|
||||
if (this._dynamicIA) {
|
||||
out.model = this;
|
||||
out.node = this._node;
|
||||
out.ia = null;
|
||||
out.effect = this._effects[0];
|
||||
out.defines = out.effect.extractDefines(this._defines[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (index >= this._inputAssemblers.length ) {
|
||||
out.model = null;
|
||||
out.node = null;
|
||||
out.ia = null;
|
||||
out.effect = null;
|
||||
out.defines = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
out.model = this;
|
||||
out.node = this._node;
|
||||
out.ia = this._inputAssemblers[index];
|
||||
|
||||
let effect, defines;
|
||||
if (index < this._effects.length) {
|
||||
effect = this._effects[index];
|
||||
defines = this._defines[index];
|
||||
} else {
|
||||
effect = this._effects[this._effects.length-1];
|
||||
defines = this._defines[this._effects.length-1];
|
||||
}
|
||||
out.effect = effect;
|
||||
out.defines = effect.extractDefines(defines);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Model;
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
class Pass {
|
||||
constructor(name) {
|
||||
this._programName = name;
|
||||
|
||||
// cullmode
|
||||
this._cullMode = gfx.CULL_BACK;
|
||||
|
||||
// blending
|
||||
this._blend = false;
|
||||
this._blendEq = gfx.BLEND_FUNC_ADD;
|
||||
this._blendAlphaEq = gfx.BLEND_FUNC_ADD;
|
||||
this._blendSrc = gfx.BLEND_ONE;
|
||||
this._blendDst = gfx.BLEND_ZERO;
|
||||
this._blendSrcAlpha = gfx.BLEND_ONE;
|
||||
this._blendDstAlpha = gfx.BLEND_ZERO;
|
||||
this._blendColor = 0xffffffff;
|
||||
|
||||
// depth
|
||||
this._depthTest = false;
|
||||
this._depthWrite = false;
|
||||
this._depthFunc = gfx.DS_FUNC_LESS,
|
||||
|
||||
// stencil
|
||||
this._stencilTest = false;
|
||||
// front
|
||||
this._stencilFuncFront = gfx.DS_FUNC_ALWAYS;
|
||||
this._stencilRefFront = 0;
|
||||
this._stencilMaskFront = 0xff;
|
||||
this._stencilFailOpFront = gfx.STENCIL_OP_KEEP;
|
||||
this._stencilZFailOpFront = gfx.STENCIL_OP_KEEP;
|
||||
this._stencilZPassOpFront = gfx.STENCIL_OP_KEEP;
|
||||
this._stencilWriteMaskFront = 0xff;
|
||||
// back
|
||||
this._stencilFuncBack = gfx.DS_FUNC_ALWAYS;
|
||||
this._stencilRefBack = 0;
|
||||
this._stencilMaskBack = 0xff;
|
||||
this._stencilFailOpBack = gfx.STENCIL_OP_KEEP;
|
||||
this._stencilZFailOpBack = gfx.STENCIL_OP_KEEP;
|
||||
this._stencilZPassOpBack = gfx.STENCIL_OP_KEEP;
|
||||
this._stencilWriteMaskBack = 0xff;
|
||||
|
||||
this._binary = new Uint32Array(25);
|
||||
this._updateBinary();
|
||||
}
|
||||
|
||||
setCullMode(cullMode) {
|
||||
this._cullMode = cullMode;
|
||||
this._binary[0] = cullMode;
|
||||
}
|
||||
|
||||
setBlend(
|
||||
blendEq = gfx.BLEND_FUNC_ADD,
|
||||
blendSrc = gfx.BLEND_ONE,
|
||||
blendDst = gfx.BLEND_ZERO,
|
||||
blendAlphaEq = gfx.BLEND_FUNC_ADD,
|
||||
blendSrcAlpha = gfx.BLEND_ONE,
|
||||
blendDstAlpha = gfx.BLEND_ZERO,
|
||||
blendColor = 0xffffffff
|
||||
) {
|
||||
this._blend = true;
|
||||
this._blendEq = blendEq;
|
||||
this._blendSrc = blendSrc;
|
||||
this._blendDst = blendDst;
|
||||
this._blendAlphaEq = blendAlphaEq;
|
||||
this._blendSrcAlpha = blendSrcAlpha;
|
||||
this._blendDstAlpha = blendDstAlpha;
|
||||
this._blendColor = blendColor;
|
||||
|
||||
this._binary[1] = this._blendEq;
|
||||
this._binary[2] = this._blendSrc;
|
||||
this._binary[3] = this._blendDst;
|
||||
this._binary[4] = this._blendAlphaEq;
|
||||
this._binary[5] = this._blendSrcAlpha;
|
||||
this._binary[6] = this._blendDstAlpha;
|
||||
this._binary[7] = this._blendColor;
|
||||
}
|
||||
|
||||
setDepth(
|
||||
depthTest = false,
|
||||
depthWrite = false,
|
||||
depthFunc = gfx.DS_FUNC_LESS
|
||||
) {
|
||||
this._depthTest = depthTest;
|
||||
this._depthWrite = depthWrite;
|
||||
this._depthFunc = depthFunc;
|
||||
|
||||
this._binary[8] = this._depthTest;
|
||||
this._binary[9] = this._depthWrite;
|
||||
this._binary[10] = this._depthFunc;
|
||||
}
|
||||
|
||||
setStencilFront(
|
||||
stencilFunc = gfx.DS_FUNC_ALWAYS,
|
||||
stencilRef = 0,
|
||||
stencilMask = 0xff,
|
||||
stencilFailOp = gfx.STENCIL_OP_KEEP,
|
||||
stencilZFailOp = gfx.STENCIL_OP_KEEP,
|
||||
stencilZPassOp = gfx.STENCIL_OP_KEEP,
|
||||
stencilWriteMask = 0xff
|
||||
) {
|
||||
this._stencilTest = true;
|
||||
this._stencilFuncFront = stencilFunc;
|
||||
this._stencilRefFront = stencilRef;
|
||||
this._stencilMaskFront = stencilMask;
|
||||
this._stencilFailOpFront = stencilFailOp;
|
||||
this._stencilZFailOpFront = stencilZFailOp;
|
||||
this._stencilZPassOpFront = stencilZPassOp;
|
||||
this._stencilWriteMaskFront = stencilWriteMask;
|
||||
|
||||
this._binary[11] = this._stencilFuncFront;
|
||||
this._binary[12] = this._stencilRefFront;
|
||||
this._binary[13] = this._stencilMaskFront;
|
||||
this._binary[14] = this._stencilFailOpFront;
|
||||
this._binary[15] = this._stencilZFailOpFront;
|
||||
this._binary[16] = this._stencilZPassOpFront;
|
||||
this._binary[17] = this._stencilWriteMaskFront;
|
||||
}
|
||||
|
||||
setStencilBack(
|
||||
stencilFunc = gfx.DS_FUNC_ALWAYS,
|
||||
stencilRef = 0,
|
||||
stencilMask = 0xff,
|
||||
stencilFailOp = gfx.STENCIL_OP_KEEP,
|
||||
stencilZFailOp = gfx.STENCIL_OP_KEEP,
|
||||
stencilZPassOp = gfx.STENCIL_OP_KEEP,
|
||||
stencilWriteMask = 0xff
|
||||
) {
|
||||
this._stencilTest = true;
|
||||
this._stencilFuncBack = stencilFunc;
|
||||
this._stencilRefBack = stencilRef;
|
||||
this._stencilMaskBack = stencilMask;
|
||||
this._stencilFailOpBack = stencilFailOp;
|
||||
this._stencilZFailOpBack = stencilZFailOp;
|
||||
this._stencilZPassOpBack = stencilZPassOp;
|
||||
this._stencilWriteMaskBack = stencilWriteMask;
|
||||
|
||||
this._binary[18] = this._stencilFuncBack;
|
||||
this._binary[19] = this._stencilRefBack;
|
||||
this._binary[20] = this._stencilMaskBack;
|
||||
this._binary[21] = this._stencilFailOpBack;
|
||||
this._binary[22] = this._stencilZFailOpBack;
|
||||
this._binary[23] = this._stencilZPassOpBack;
|
||||
this._binary[24] = this._stencilWriteMaskBack;
|
||||
}
|
||||
|
||||
_updateBinary() {
|
||||
this._binary[0] = this._cullMode;
|
||||
this._binary[1] = this._blendEq;
|
||||
this._binary[2] = this._blendSrc;
|
||||
this._binary[3] = this._blendDst;
|
||||
this._binary[4] = this._blendAlphaEq;
|
||||
this._binary[5] = this._blendSrcAlpha;
|
||||
this._binary[6] = this._blendDstAlpha;
|
||||
this._binary[7] = this._blendColor;
|
||||
this._binary[8] = this._depthTest;
|
||||
this._binary[9] = this._depthWrite;
|
||||
this._binary[10] = this._depthFunc;
|
||||
this._binary[11] = this._stencilFuncFront;
|
||||
this._binary[12] = this._stencilRefFront;
|
||||
this._binary[13] = this._stencilMaskFront;
|
||||
this._binary[14] = this._stencilFailOpFront;
|
||||
this._binary[15] = this._stencilZFailOpFront;
|
||||
this._binary[16] = this._stencilZPassOpFront;
|
||||
this._binary[17] = this._stencilWriteMaskFront;
|
||||
this._binary[18] = this._stencilFuncBack;
|
||||
this._binary[19] = this._stencilRefBack;
|
||||
this._binary[20] = this._stencilMaskBack;
|
||||
this._binary[21] = this._stencilFailOpBack;
|
||||
this._binary[22] = this._stencilZFailOpBack;
|
||||
this._binary[23] = this._stencilZPassOpBack;
|
||||
this._binary[24] = this._stencilWriteMaskBack;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Pass;
|
||||
+53
-13
@@ -22,7 +22,9 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
const utils = require('./utils');
|
||||
|
||||
// projection
|
||||
renderer.PROJ_PERSPECTIVE = 0;
|
||||
renderer.PROJ_ORTHO = 1;
|
||||
@@ -58,27 +60,65 @@ renderer.PARAM_TEXTURE_CUBE = 14;
|
||||
renderer.CLEAR_COLOR = 1;
|
||||
renderer.CLEAR_DEPTH = 2;
|
||||
renderer.CLEAR_STENCIL = 4;
|
||||
renderer.InputAssembler = require('./input-assembler');
|
||||
renderer.config = require('./config');
|
||||
renderer.Effect = require('./Effect');
|
||||
renderer.Technique = require('./Technique');
|
||||
renderer.Pass = require('./Pass');
|
||||
renderer.Model = require('./Model');
|
||||
|
||||
renderer.addStage = renderer.Config.addStage;
|
||||
var models = [];
|
||||
var sizeOfModel = 23;
|
||||
// length + 500 modles(8 for each model)
|
||||
var modlesData = new Float64Array(1 + 500*sizeOfModel);
|
||||
var fillModelData = function() {
|
||||
if (models.length > 500)
|
||||
modlesData = new FloatArray64(1 + models.length*sizeOfModel);
|
||||
|
||||
modlesData[0] = models.length;
|
||||
var index = 1;
|
||||
var model;
|
||||
var worldMatrix;
|
||||
var ia;
|
||||
for (var i = 0, len = models.length; i < len; ++i) {
|
||||
model = models[i];
|
||||
modlesData[index++] = model._dynamicIA;
|
||||
modlesData[index++] = model._viewID;
|
||||
worldMatrix = utils.getWorldRTInAB(model._node);
|
||||
modlesData.set(worldMatrix, index);
|
||||
index += 16;
|
||||
|
||||
// ia
|
||||
ia = model._inputAssemblers[0];
|
||||
modlesData[index++] = ia._vertexBuffer._nativePtr;
|
||||
modlesData[index++] = ia._indexBuffer._nativePtr;
|
||||
modlesData[index++] = ia._start;
|
||||
modlesData[index++] = ia._count;
|
||||
|
||||
// effect
|
||||
modlesData[index++] = model._effects[0]._nativePtr;
|
||||
}
|
||||
}
|
||||
|
||||
// ForwardRenderer adapter
|
||||
var _p;
|
||||
|
||||
_p = renderer.ForwardRenderer.prototype;
|
||||
_p._ctor = function(device, builtin) {
|
||||
this.init(device, builtin.programTemplates, builtin.defaultTexture, canvas.width, canvas.height);
|
||||
this.init(device, builtin.programTemplates, builtin.defaultTexture, canvas.width, canvas.height);
|
||||
};
|
||||
_p.render = function(scene) {
|
||||
fillModelData();
|
||||
this.renderNative(scene, modlesData);
|
||||
|
||||
// InputAssembler adapter
|
||||
_p = renderer.InputAssembler.prototype;
|
||||
_p._ctor = function(vb, ib, pt = gfx.PT_TRIANGLES) {
|
||||
this.init(vb, ib, pt);
|
||||
};
|
||||
models.length = 0;
|
||||
}
|
||||
|
||||
cc.defineGetterSetter(_p, "_vertexBuffer", _p.getVertexBuffer, _p.setVertexBuffer);
|
||||
cc.defineGetterSetter(_p, "_indexBuffer", _p.getIndexBuffer, _p.setIndexBuffer);
|
||||
cc.defineGetterSetter(_p, "_primitiveType", _p.getPrimitiveType, _p.setPrimitiveType);
|
||||
cc.defineGetterSetter(_p, "_start", _p.getStart, _p.setStart);
|
||||
cc.defineGetterSetter(_p, "_count", _p.getCount, _p.setCount);
|
||||
// Scene
|
||||
_p = renderer.Scene.prototype;
|
||||
_p.addModel = function(model) {
|
||||
models.push(model);
|
||||
}
|
||||
_p.removeModel = function() {}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
let config = renderer.config;
|
||||
|
||||
let _genID = 0;
|
||||
|
||||
class Technique {
|
||||
/**
|
||||
* @param {Array} stages
|
||||
* @param {Array} parameters
|
||||
* @param {Array} passes
|
||||
* @param {Number} layer
|
||||
*/
|
||||
constructor(stages, parameters, passes, layer = 0) {
|
||||
this._id = _genID++;
|
||||
this._stageIDs = config.stageIDs(stages);
|
||||
this.stageIDs = this._stageIDs;
|
||||
this._parameters = parameters; // {name, type, size, val}
|
||||
this._passes = passes;
|
||||
this.passes = this._passes;
|
||||
this._layer = layer;
|
||||
this._stages = stages;
|
||||
// TODO: this._version = 'webgl' or 'webgl2' // ????
|
||||
|
||||
this._nativeObj = new renderer.TechniqueNative(stages, parameters, passes, layer);
|
||||
|
||||
}
|
||||
|
||||
setStages(stages) {
|
||||
this._stageIDs = config.stageIDs(stages);
|
||||
this._stages = stages;
|
||||
|
||||
this._nativeObj.setStages(stages);
|
||||
}
|
||||
|
||||
// get passes() {
|
||||
// return this._passes;
|
||||
// }
|
||||
|
||||
// get stageIDs() {
|
||||
// return this._stageIDs;
|
||||
// }
|
||||
}
|
||||
|
||||
module.exports = Technique;
|
||||
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
'use strict';
|
||||
|
||||
let _typedArray_temp = new Float32Array(16);
|
||||
var _mat4_temp = cc.vmath.mat4.create();
|
||||
|
||||
function _mat4ToArray(typedArray, mat4) {
|
||||
typedArray[0] = mat4.m00;
|
||||
typedArray[1] = mat4.m01;
|
||||
typedArray[2] = mat4.m02;
|
||||
typedArray[3] = mat4.m03;
|
||||
typedArray[4] = mat4.m04;
|
||||
typedArray[5] = mat4.m05;
|
||||
typedArray[6] = mat4.m06;
|
||||
typedArray[7] = mat4.m07;
|
||||
typedArray[8] = mat4.m08;
|
||||
typedArray[9] = mat4.m09;
|
||||
typedArray[10] = mat4.m10;
|
||||
typedArray[11] = mat4.m11;
|
||||
typedArray[12] = mat4.m12;
|
||||
typedArray[13] = mat4.m13;
|
||||
typedArray[14] = mat4.m14;
|
||||
typedArray[15] = mat4.m15;
|
||||
}
|
||||
|
||||
function getWorldRTInAB (node) {
|
||||
node.getWorldRT(_mat4_temp);
|
||||
_mat4ToArray(_typedArray_temp, _mat4_temp);
|
||||
return _typedArray_temp;
|
||||
}
|
||||
|
||||
function getWorldMatrixInAB (node) {
|
||||
node._updateWorldMatrix();
|
||||
_mat4ToArray(_typedArray_temp, node._worldMatrix);
|
||||
return _typedArray_temp;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getWorldRTInAB,
|
||||
getWorldMatrixInAB
|
||||
}
|
||||
@@ -72,6 +72,8 @@ class VertexFormat {
|
||||
let el = this._elements[i];
|
||||
el.stride = this._bytes;
|
||||
}
|
||||
|
||||
this._nativeObj = new gfx.VertexFormatNative(this._elements);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user