@predy-js/render-interface 0.1.8 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +228 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +228 -40
- package/dist/index.mjs.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/render/MarsMesh.d.ts +7 -2
- package/dist/src/render/MarsRenderPass.d.ts +1 -0
- package/dist/src/render/MarsRenderPassColorAttachment.d.ts +1 -0
- package/dist/src/webgl/GLFrameBuffer.d.ts +5 -0
- package/dist/src/webgl/GLGPUCapability.d.ts +5 -1
- package/dist/src/webgl/GLGPURenderer.d.ts +0 -2
- package/dist/src/webgl/GLRenderBuffer.d.ts +1 -0
- package/dist/src/webgl/constants.d.ts +2 -0
- package/dist/statistic.js +1 -1
- package/dist/types/GPUCapability.d.ts +2 -0
- package/dist/types/Geometry.d.ts +0 -1
- package/dist/types/Mesh.d.ts +11 -0
- package/dist/types/RenderFrame.d.ts +2 -1
- package/dist/types/RenderPass.d.ts +2 -1
- package/package.json +2 -2
- package/dist/types/Scene.d.ts +0 -48
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Name: @predy-js/render-interface
|
|
3
3
|
* Description: undefined
|
|
4
4
|
* Author: undefined
|
|
5
|
-
* Version: v0.1.
|
|
5
|
+
* Version: v0.1.11
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
@@ -153,7 +153,7 @@ exports.TextureSourceType = void 0;
|
|
|
153
153
|
TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
|
|
154
154
|
})(exports.TextureSourceType || (exports.TextureSourceType = {}));
|
|
155
155
|
|
|
156
|
-
var _a$6;
|
|
156
|
+
var _a$6, _b$2;
|
|
157
157
|
// @ts-expect-error safe to assign
|
|
158
158
|
var constants = {};
|
|
159
159
|
{
|
|
@@ -192,6 +192,14 @@ function getBytesPerElementByGLType(type) {
|
|
|
192
192
|
var _a;
|
|
193
193
|
return ((_a = map[type]) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT) || 0;
|
|
194
194
|
}
|
|
195
|
+
var MatAttrLocPairMap = (_b$2 = {},
|
|
196
|
+
_b$2[constants.FLOAT_MAT2] = [2, 2],
|
|
197
|
+
_b$2[constants.FLOAT_MAT3] = [3, 3],
|
|
198
|
+
_b$2[constants.FLOAT_MAT4] = [4, 4],
|
|
199
|
+
_b$2);
|
|
200
|
+
function getMatAttrLocPair(type) {
|
|
201
|
+
return MatAttrLocPairMap[type] || [1, 1];
|
|
202
|
+
}
|
|
195
203
|
|
|
196
204
|
exports.ShaderCompileResultStatus = void 0;
|
|
197
205
|
(function (ShaderCompileResultStatus) {
|
|
@@ -640,6 +648,7 @@ var GPUCapabilityEmpty = /** @class */ (function () {
|
|
|
640
648
|
function GPUCapabilityEmpty() {
|
|
641
649
|
this.level = 0;
|
|
642
650
|
this.capability = {
|
|
651
|
+
maxSample: 0,
|
|
643
652
|
floatTexture: 0,
|
|
644
653
|
halfFloatTexture: 0,
|
|
645
654
|
maxVertexUniforms: 0,
|
|
@@ -1844,7 +1853,7 @@ var GLProgram = /** @class */ (function () {
|
|
|
1844
1853
|
var uniformInfo = DATA_DICT[info.type];
|
|
1845
1854
|
var subInfos = info.subInfos;
|
|
1846
1855
|
if (subInfos.length > 0 && Array.isArray(value) && Array.isArray(value[0])) {
|
|
1847
|
-
for (var i = 0; i < subInfos.length; ++i) {
|
|
1856
|
+
for (var i = 0; i < subInfos.length && i < value.length; ++i) {
|
|
1848
1857
|
var subInfo = subInfos[i];
|
|
1849
1858
|
uniformInfo.uniform(gl, subInfo, value[i], this.renderer);
|
|
1850
1859
|
}
|
|
@@ -1856,6 +1865,7 @@ var GLProgram = /** @class */ (function () {
|
|
|
1856
1865
|
var _a;
|
|
1857
1866
|
var gl = this.renderer.gl;
|
|
1858
1867
|
var vao = geometry.createVao(this.id);
|
|
1868
|
+
var gpu = this.renderer.gpu;
|
|
1859
1869
|
if (vao) {
|
|
1860
1870
|
vao.bind();
|
|
1861
1871
|
if (vao.ready) {
|
|
@@ -1873,8 +1883,26 @@ var GLProgram = /** @class */ (function () {
|
|
|
1873
1883
|
throw Error("no buffer named ".concat(attribute.dataSource || name));
|
|
1874
1884
|
}
|
|
1875
1885
|
buffer.bind();
|
|
1876
|
-
|
|
1877
|
-
|
|
1886
|
+
if (attribute.size > 4) {
|
|
1887
|
+
var _a = getMatAttrLocPair(attrInfo.type), row = _a[0], col = _a[1];
|
|
1888
|
+
var bytesPerRow = getBytesPerElementByGLType(attribute.type) * col;
|
|
1889
|
+
var stride = row * bytesPerRow;
|
|
1890
|
+
for (var i = 0; i < row; i++) {
|
|
1891
|
+
var loc = attrInfo.loc + i;
|
|
1892
|
+
gl.enableVertexAttribArray(loc);
|
|
1893
|
+
gl.vertexAttribPointer(loc, col, attribute.type, attribute.normalize, stride, i * bytesPerRow);
|
|
1894
|
+
if (attribute.instanceDivisor && gpu.capability.instanceDraw) {
|
|
1895
|
+
gpu.vertexAttribDivisor(gl, loc, attribute.instanceDivisor);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
gl.enableVertexAttribArray(attrInfo.loc);
|
|
1901
|
+
gl.vertexAttribPointer(attrInfo.loc, attribute.size, attribute.type, attribute.normalize, attribute.stride || 0, attribute.offset || 0);
|
|
1902
|
+
if (attribute.instanceDivisor && gpu.capability.instanceDraw) {
|
|
1903
|
+
gpu.vertexAttribDivisor(gl, attrInfo.loc, attribute.instanceDivisor);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1878
1906
|
}
|
|
1879
1907
|
});
|
|
1880
1908
|
(_a = geometry._indexBuffer) === null || _a === void 0 ? void 0 : _a.bind();
|
|
@@ -2227,6 +2255,7 @@ var GLGPUCapability = /** @class */ (function () {
|
|
|
2227
2255
|
}
|
|
2228
2256
|
this.internalFormatDepth16 = level2 ? gl.DEPTH_COMPONENT16 : gl.DEPTH_COMPONENT;
|
|
2229
2257
|
this.internalFormatDepth24_stencil8 = level2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL;
|
|
2258
|
+
this.instanceDrawExt = gl.getExtension('ANGLE_instanced_arrays');
|
|
2230
2259
|
var floatTexture = (level2 || gl.getExtension('OES_texture_float')) ? gl.FLOAT : 0;
|
|
2231
2260
|
var halfFloatTexture = level2 ? WebGL2RenderingContext.HALF_FLOAT : (((_a = gl.getExtension('OES_texture_half_float')) === null || _a === void 0 ? void 0 : _a.HALF_FLOAT_OES) || 0);
|
|
2232
2261
|
var detail = {
|
|
@@ -2246,7 +2275,7 @@ var GLGPUCapability = /** @class */ (function () {
|
|
|
2246
2275
|
floatLinear: floatLinear,
|
|
2247
2276
|
maxTextureAnisotropy: textureAnisotropicExt ? gl.getParameter(textureAnisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0,
|
|
2248
2277
|
shaderTextureLod: level2 || !!gl.getExtension('EXT_shader_texture_lod'),
|
|
2249
|
-
instanceDraw: level2 || !!
|
|
2278
|
+
instanceDraw: level2 || !!this.instanceDrawExt,
|
|
2250
2279
|
drawBuffers: level2 || !!this.drawBufferExtension,
|
|
2251
2280
|
asyncShaderCompile: !!gl.getExtension('KHR_parallel_shader_compile'),
|
|
2252
2281
|
intIndexElementBuffer: !!gl.getExtension('OES_element_index_uint'),
|
|
@@ -2296,6 +2325,39 @@ var GLGPUCapability = /** @class */ (function () {
|
|
|
2296
2325
|
consoleError('invalid color attachment index:' + index);
|
|
2297
2326
|
}
|
|
2298
2327
|
};
|
|
2328
|
+
GLGPUCapability.prototype.vertexAttribDivisor = function (gl, loc, divisor) {
|
|
2329
|
+
if (this.level === 2) {
|
|
2330
|
+
gl.vertexAttribDivisor(loc, divisor);
|
|
2331
|
+
}
|
|
2332
|
+
else if (this.instanceDrawExt) {
|
|
2333
|
+
this.instanceDrawExt.vertexAttribDivisorANGLE(loc, divisor);
|
|
2334
|
+
}
|
|
2335
|
+
else {
|
|
2336
|
+
consoleWarn('instance draw not support');
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
GLGPUCapability.prototype.drawElementsInstanced = function (gl, mode, count, type, offset, instanceCount) {
|
|
2340
|
+
if (this.level === 2) {
|
|
2341
|
+
gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
|
|
2342
|
+
}
|
|
2343
|
+
else if (this.instanceDrawExt) {
|
|
2344
|
+
this.instanceDrawExt.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
|
|
2345
|
+
}
|
|
2346
|
+
else {
|
|
2347
|
+
consoleWarn('instance draw not support');
|
|
2348
|
+
}
|
|
2349
|
+
};
|
|
2350
|
+
GLGPUCapability.prototype.drawArraysInstanced = function (gl, mode, first, count, instanceCount) {
|
|
2351
|
+
if (this.level === 2) {
|
|
2352
|
+
gl.drawArraysInstanced(mode, first, count, instanceCount);
|
|
2353
|
+
}
|
|
2354
|
+
else if (this.instanceDrawExt) {
|
|
2355
|
+
this.instanceDrawExt.drawArraysInstancedANGLE(mode, first, count, instanceCount);
|
|
2356
|
+
}
|
|
2357
|
+
else {
|
|
2358
|
+
consoleWarn('instance draw not support');
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2299
2361
|
GLGPUCapability.prototype.drawBuffers = function (gl, bufferStates) {
|
|
2300
2362
|
var ext = this.drawBufferExtension;
|
|
2301
2363
|
if (this.level === 1 && !ext) {
|
|
@@ -2773,9 +2835,6 @@ var GLGPURenderer = /** @class */ (function () {
|
|
|
2773
2835
|
GLGPURenderer.prototype.createBuffer = function (options) {
|
|
2774
2836
|
return new GLGPUBuffer(options, this);
|
|
2775
2837
|
};
|
|
2776
|
-
GLGPURenderer.prototype.parseSceneSchema = function (schema) {
|
|
2777
|
-
throw new Error('Method not implemented.');
|
|
2778
|
-
};
|
|
2779
2838
|
GLGPURenderer.prototype.resize = function (width, height) {
|
|
2780
2839
|
var gl = this.gl;
|
|
2781
2840
|
if (gl && gl.drawingBufferWidth !== width || gl.drawingBufferHeight !== height) {
|
|
@@ -2849,7 +2908,10 @@ var GLGPURenderer = /** @class */ (function () {
|
|
|
2849
2908
|
};
|
|
2850
2909
|
GLGPURenderer.prototype.deleteGLFrameBuffer = function (frameBuffer) {
|
|
2851
2910
|
if (frameBuffer && !this._isDestroyed) {
|
|
2852
|
-
this.gl
|
|
2911
|
+
var gl = this.gl;
|
|
2912
|
+
gl.deleteFramebuffer(frameBuffer.fbo);
|
|
2913
|
+
gl.deleteFramebuffer(frameBuffer.multisampleFbo);
|
|
2914
|
+
frameBuffer.multisampleRbs.forEach(function (rb) { return rb.destroy(); });
|
|
2853
2915
|
arrRemove(this._frameBuffers, frameBuffer);
|
|
2854
2916
|
delete frameBuffer.fbo;
|
|
2855
2917
|
}
|
|
@@ -2982,13 +3044,14 @@ var CanvasEmpty = /** @class */ (function () {
|
|
|
2982
3044
|
|
|
2983
3045
|
var GLRenderBuffer = /** @class */ (function () {
|
|
2984
3046
|
function GLRenderBuffer(renderer, options) {
|
|
3047
|
+
var _a;
|
|
2985
3048
|
this.storageType = options.storageType;
|
|
2986
3049
|
this.renderer = renderer;
|
|
2987
3050
|
this.glHandle = renderer.createGLRenderBuffer(this);
|
|
2988
3051
|
this.internalFormat = this.format = options.format;
|
|
2989
3052
|
this.attachment = options.attachment;
|
|
2990
3053
|
this.size = [0, 0];
|
|
2991
|
-
this.multiSample =
|
|
3054
|
+
this.multiSample = (_a = options.multisample) !== null && _a !== void 0 ? _a : 0;
|
|
2992
3055
|
}
|
|
2993
3056
|
GLRenderBuffer.prototype.setSize = function (width, height) {
|
|
2994
3057
|
if (width !== this.size[0] || height !== this.size[1]) {
|
|
@@ -2998,6 +3061,10 @@ var GLRenderBuffer = /** @class */ (function () {
|
|
|
2998
3061
|
state.bindRenderBuffer(gl.RENDERBUFFER, this.glHandle);
|
|
2999
3062
|
if (width && height) {
|
|
3000
3063
|
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, this.size[0] = width, this.size[1] = height);
|
|
3064
|
+
if (this.multiSample > 1) {
|
|
3065
|
+
var if2 = internalFormat === gl.DEPTH_STENCIL ? gl.DEPTH24_STENCIL8 : internalFormat;
|
|
3066
|
+
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, this.multiSample, if2, width, height);
|
|
3067
|
+
}
|
|
3001
3068
|
}
|
|
3002
3069
|
else {
|
|
3003
3070
|
consoleError("invalid render buffer size ".concat(width, "x").concat(height));
|
|
@@ -3019,6 +3086,7 @@ var seed$5 = 1;
|
|
|
3019
3086
|
var GLFrameBuffer = /** @class */ (function () {
|
|
3020
3087
|
function GLFrameBuffer(options, renderer) {
|
|
3021
3088
|
var _a;
|
|
3089
|
+
this.multisampleRbs = [];
|
|
3022
3090
|
this.renderer = renderer;
|
|
3023
3091
|
this.depthStencilStorageType = ((_a = options.depthStencilAttachment) === null || _a === void 0 ? void 0 : _a.storageType) || exports.RenderPassAttachmentStorageType.none;
|
|
3024
3092
|
this.viewport = options.viewport;
|
|
@@ -3027,6 +3095,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3027
3095
|
this.name = options.name || ('GLFrameBuffer' + seed$5++);
|
|
3028
3096
|
this.storeAction = options.storeAction;
|
|
3029
3097
|
this._attachmentHandles = [];
|
|
3098
|
+
this.multisample = renderer.level > 1 ? options.multisample || 0 : 0;
|
|
3030
3099
|
this.checkOptions(options);
|
|
3031
3100
|
}
|
|
3032
3101
|
Object.defineProperty(GLFrameBuffer.prototype, "stencilStorage", {
|
|
@@ -3065,6 +3134,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3065
3134
|
var capability = renderer.gpu.capability;
|
|
3066
3135
|
var depthStencilAttachment = options.depthStencilAttachment || { storageType: exports.RenderPassAttachmentStorageType.none };
|
|
3067
3136
|
var willUseFbo = options.attachments.length > 0;
|
|
3137
|
+
var willMultisample = this.multisample > 1;
|
|
3068
3138
|
this.externalStorage = false;
|
|
3069
3139
|
var separateDepthStencil = true;
|
|
3070
3140
|
if (options.attachments.length > 1 && !capability.drawBuffers) {
|
|
@@ -3079,10 +3149,16 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3079
3149
|
if (willUseFbo) {
|
|
3080
3150
|
this.fbo = renderer.createGLFrameBuffer(this, this.name);
|
|
3081
3151
|
}
|
|
3152
|
+
if (willMultisample) {
|
|
3153
|
+
this.multisampleFbo = renderer.createGLFrameBuffer(this, this.name + '_multisample');
|
|
3154
|
+
}
|
|
3082
3155
|
var storageType = depthStencilAttachment.storageType;
|
|
3083
3156
|
if (storageType === exports.RenderPassAttachmentStorageType.depth_stencil_opaque) {
|
|
3084
3157
|
if (depthStencilAttachment.storage) {
|
|
3085
3158
|
if (depthStencilAttachment.storage instanceof GLRenderBuffer) {
|
|
3159
|
+
if (this.multisample !== depthStencilAttachment.storage.multiSample && this.multisample > 1) {
|
|
3160
|
+
throw Error('fbo multisample not eql depth stencil attachment');
|
|
3161
|
+
}
|
|
3086
3162
|
this.depthStencilRenderBuffer = depthStencilAttachment.storage;
|
|
3087
3163
|
this.externalStorage = true;
|
|
3088
3164
|
}
|
|
@@ -3094,6 +3170,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3094
3170
|
this.depthStencilRenderBuffer = new GLRenderBuffer(renderer, {
|
|
3095
3171
|
format: constants.DEPTH_STENCIL,
|
|
3096
3172
|
attachment: constants.DEPTH_STENCIL_ATTACHMENT,
|
|
3173
|
+
multisample: this.multisample,
|
|
3097
3174
|
storageType: storageType,
|
|
3098
3175
|
});
|
|
3099
3176
|
}
|
|
@@ -3101,6 +3178,9 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3101
3178
|
}
|
|
3102
3179
|
else if (storageType === exports.RenderPassAttachmentStorageType.depth_16_opaque) {
|
|
3103
3180
|
if (depthStencilAttachment.storage) {
|
|
3181
|
+
if (this.multisample !== depthStencilAttachment.storage.multiSample && this.multisample > 1) {
|
|
3182
|
+
throw Error('fbo multisample not eql depth attachment');
|
|
3183
|
+
}
|
|
3104
3184
|
if (depthStencilAttachment.storage instanceof GLRenderBuffer) {
|
|
3105
3185
|
this.depthStencilRenderBuffer = depthStencilAttachment.storage;
|
|
3106
3186
|
this.externalStorage = true;
|
|
@@ -3112,6 +3192,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3112
3192
|
else {
|
|
3113
3193
|
this.depthStencilRenderBuffer = new GLRenderBuffer(renderer, {
|
|
3114
3194
|
attachment: constants.DEPTH_ATTACHMENT,
|
|
3195
|
+
multisample: this.multisample,
|
|
3115
3196
|
format: constants.DEPTH_COMPONENT16,
|
|
3116
3197
|
storageType: storageType,
|
|
3117
3198
|
});
|
|
@@ -3120,6 +3201,9 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3120
3201
|
else if (storageType === exports.RenderPassAttachmentStorageType.stencil_8_opaque) {
|
|
3121
3202
|
if (depthStencilAttachment.storage) {
|
|
3122
3203
|
if (depthStencilAttachment.storage instanceof GLRenderBuffer) {
|
|
3204
|
+
if (this.multisample !== depthStencilAttachment.storage.multiSample && this.multisample > 1) {
|
|
3205
|
+
throw Error('fbo multisample not eql stencil attachment');
|
|
3206
|
+
}
|
|
3123
3207
|
this.depthStencilRenderBuffer = depthStencilAttachment.storage;
|
|
3124
3208
|
this.externalStorage = true;
|
|
3125
3209
|
}
|
|
@@ -3131,6 +3215,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3131
3215
|
this.depthStencilRenderBuffer = new GLRenderBuffer(renderer, {
|
|
3132
3216
|
attachment: constants.STENCIL_ATTACHMENT,
|
|
3133
3217
|
format: constants.STENCIL_INDEX8,
|
|
3218
|
+
multisample: this.multisample,
|
|
3134
3219
|
storageType: storageType,
|
|
3135
3220
|
});
|
|
3136
3221
|
}
|
|
@@ -3184,6 +3269,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3184
3269
|
};
|
|
3185
3270
|
GLFrameBuffer.prototype.unbind = function () {
|
|
3186
3271
|
var att = this.storeInvalidAttachments;
|
|
3272
|
+
this.resolveMultiSample();
|
|
3187
3273
|
if (att && att.length) {
|
|
3188
3274
|
var gl = this.renderer.gl;
|
|
3189
3275
|
gl.invalidateFramebuffer(gl.FRAMEBUFFER, att);
|
|
@@ -3194,9 +3280,14 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3194
3280
|
GLFrameBuffer.prototype.bind = function () {
|
|
3195
3281
|
var gl = this.renderer.gl;
|
|
3196
3282
|
var state = this.renderer.state;
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3283
|
+
var FRAMEBUFFER = gl.FRAMEBUFFER;
|
|
3284
|
+
var viewport = this.viewport;
|
|
3285
|
+
var multisampleFbo = this.multisampleFbo;
|
|
3286
|
+
if (multisampleFbo) {
|
|
3287
|
+
state.bindFramebuffer(FRAMEBUFFER, multisampleFbo);
|
|
3288
|
+
state.viewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
|
3289
|
+
}
|
|
3290
|
+
else if (this.fbo) {
|
|
3200
3291
|
state.bindFramebuffer(FRAMEBUFFER, this.fbo);
|
|
3201
3292
|
state.viewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
|
3202
3293
|
var r_1 = this.renderer.emptyTexture2D.glHandle;
|
|
@@ -3208,30 +3299,74 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3208
3299
|
state.bindTexture(constants.TEXTURE_2D, r_1, true);
|
|
3209
3300
|
}
|
|
3210
3301
|
});
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3302
|
+
}
|
|
3303
|
+
if (!this.ready) {
|
|
3304
|
+
var _a = this, depthStencilRenderBuffer = _a.depthStencilRenderBuffer, depthTexture = _a.depthTexture, stencilTexture = _a.stencilTexture;
|
|
3305
|
+
state.activeTexture(gl.TEXTURE0);
|
|
3306
|
+
if (depthStencilRenderBuffer) {
|
|
3307
|
+
depthStencilRenderBuffer.setSize(viewport[2], viewport[3]);
|
|
3308
|
+
gl.framebufferRenderbuffer(FRAMEBUFFER, depthStencilRenderBuffer.attachment, gl.RENDERBUFFER, depthStencilRenderBuffer.glHandle);
|
|
3309
|
+
}
|
|
3310
|
+
else if (depthTexture) {
|
|
3311
|
+
if (multisampleFbo) {
|
|
3312
|
+
var attachment_1 = gl.DEPTH_ATTACHMENT;
|
|
3313
|
+
var format = gl.DEPTH_COMPONENT16;
|
|
3314
|
+
if (this.depthStencilStorageType === exports.RenderPassAttachmentStorageType.depth_24_stencil_8_texture) {
|
|
3315
|
+
attachment_1 = gl.DEPTH_STENCIL_ATTACHMENT;
|
|
3316
|
+
format = gl.DEPTH24_STENCIL8;
|
|
3317
|
+
}
|
|
3318
|
+
var renderBuffer = new GLRenderBuffer(this.renderer, {
|
|
3319
|
+
storageType: this.depthStencilStorageType,
|
|
3320
|
+
attachment: attachment_1,
|
|
3321
|
+
format: format,
|
|
3322
|
+
multisample: this.multisample,
|
|
3323
|
+
});
|
|
3324
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, multisampleFbo);
|
|
3325
|
+
this.multisampleRbs.push(renderBuffer);
|
|
3326
|
+
renderBuffer.setSize(viewport[2], viewport[3]);
|
|
3327
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment_1, gl.RENDERBUFFER, renderBuffer.glHandle);
|
|
3328
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.fbo);
|
|
3222
3329
|
}
|
|
3223
|
-
|
|
3224
|
-
var
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3330
|
+
depthTexture.update({ data: { width: viewport[2], height: viewport[3], data: new Uint16Array(0) } });
|
|
3331
|
+
var attachment = depthTexture && stencilTexture ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
|
|
3332
|
+
gl.framebufferTexture2D(FRAMEBUFFER, attachment, gl.TEXTURE_2D, depthTexture.glHandle, 0);
|
|
3333
|
+
}
|
|
3334
|
+
this.resetColorTextures(this.colorTextures);
|
|
3335
|
+
[multisampleFbo, this.fbo].forEach(function (fbo) {
|
|
3336
|
+
if (fbo) {
|
|
3337
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
3338
|
+
var status_1 = gl.checkFramebufferStatus(FRAMEBUFFER);
|
|
3339
|
+
if (status_1 !== gl.FRAMEBUFFER_COMPLETE) {
|
|
3340
|
+
var error = gl.getError();
|
|
3341
|
+
throw Error("framebuffer failed status ".concat(status_1, " error:").concat(error));
|
|
3342
|
+
}
|
|
3228
3343
|
}
|
|
3229
|
-
|
|
3230
|
-
|
|
3344
|
+
});
|
|
3345
|
+
//@ts-expect-error safe to assign
|
|
3346
|
+
this.ready = true;
|
|
3347
|
+
}
|
|
3348
|
+
};
|
|
3349
|
+
GLFrameBuffer.prototype.resolveMultiSample = function () {
|
|
3350
|
+
var multisampleFbo = this.multisampleFbo;
|
|
3351
|
+
var fbo = this.fbo;
|
|
3352
|
+
if (multisampleFbo && fbo) {
|
|
3353
|
+
var gl = this.renderer.gl;
|
|
3354
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, multisampleFbo);
|
|
3355
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fbo);
|
|
3356
|
+
var vp = this.viewport;
|
|
3357
|
+
var bit = gl.COLOR_BUFFER_BIT;
|
|
3358
|
+
if (this.depthTexture) {
|
|
3359
|
+
bit = bit | gl.DEPTH_BUFFER_BIT;
|
|
3231
3360
|
}
|
|
3361
|
+
gl.blitFramebuffer(0, 0, vp[2], vp[3], // Source region
|
|
3362
|
+
0, 0, vp[2], vp[3], // Destination region
|
|
3363
|
+
bit, gl.LINEAR // Buffer mask and filter
|
|
3364
|
+
);
|
|
3365
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, multisampleFbo);
|
|
3232
3366
|
}
|
|
3233
3367
|
};
|
|
3234
3368
|
GLFrameBuffer.prototype.resetColorTextures = function (colors) {
|
|
3369
|
+
var _this = this;
|
|
3235
3370
|
var gl = this.renderer.gl;
|
|
3236
3371
|
var gpu = this.renderer.gpu;
|
|
3237
3372
|
var viewport = this.viewport;
|
|
@@ -3241,8 +3376,22 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3241
3376
|
this.colorTextures = colors.slice();
|
|
3242
3377
|
}
|
|
3243
3378
|
this.renderer.state.activeTexture(gl.TEXTURE0);
|
|
3379
|
+
var multisampleFBO = this.multisampleFbo;
|
|
3244
3380
|
this.colorTextures.forEach(function (tex, index) {
|
|
3245
3381
|
tex.update({ data: data });
|
|
3382
|
+
if (multisampleFBO) {
|
|
3383
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, multisampleFBO);
|
|
3384
|
+
var renderBuffer = new GLRenderBuffer(_this.renderer, {
|
|
3385
|
+
format: gl.RGBA8,
|
|
3386
|
+
attachment: gl.COLOR_ATTACHMENT0 + index,
|
|
3387
|
+
storageType: exports.RenderPassAttachmentStorageType.color,
|
|
3388
|
+
multisample: _this.multisample,
|
|
3389
|
+
});
|
|
3390
|
+
_this.multisampleRbs.push(renderBuffer);
|
|
3391
|
+
renderBuffer.setSize(tex.width, tex.height);
|
|
3392
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + index, gl.RENDERBUFFER, renderBuffer.glHandle);
|
|
3393
|
+
}
|
|
3394
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, _this.fbo);
|
|
3246
3395
|
gpu.framebufferTexture2D(gl, gl.FRAMEBUFFER, index, gl.TEXTURE_2D, tex.glHandle);
|
|
3247
3396
|
buffers.push(true);
|
|
3248
3397
|
});
|
|
@@ -3261,7 +3410,7 @@ var GLFrameBuffer = /** @class */ (function () {
|
|
|
3261
3410
|
(_b = this.depthTexture) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
3262
3411
|
}
|
|
3263
3412
|
//@ts-expect-error safe to assign
|
|
3264
|
-
this.renderer = this.
|
|
3413
|
+
this.renderer = this.depthStencilRenderBuffer = null;
|
|
3265
3414
|
}
|
|
3266
3415
|
};
|
|
3267
3416
|
GLFrameBuffer.prototype.resize = function (x, y, width, height) {
|
|
@@ -3860,6 +4009,7 @@ var MarsRenderPassColorAttachment = /** @class */ (function () {
|
|
|
3860
4009
|
}
|
|
3861
4010
|
this._isDestroyed = false;
|
|
3862
4011
|
this.readable = true;
|
|
4012
|
+
this.multisample = options.multiSample || 1;
|
|
3863
4013
|
}
|
|
3864
4014
|
Object.defineProperty(MarsRenderPassColorAttachment.prototype, "isDestroyed", {
|
|
3865
4015
|
get: function () {
|
|
@@ -3907,6 +4057,10 @@ var MarsRenderPassColorAttachment = /** @class */ (function () {
|
|
|
3907
4057
|
if (this.texture) {
|
|
3908
4058
|
this.texture.assignRenderer(renderer);
|
|
3909
4059
|
}
|
|
4060
|
+
if (this.multisample > 1) {
|
|
4061
|
+
this.multisample = Math.min(renderer.gpu.capability.maxSample, this.multisample);
|
|
4062
|
+
}
|
|
4063
|
+
this.texture.internal.multisample = this.multisample;
|
|
3910
4064
|
return this;
|
|
3911
4065
|
};
|
|
3912
4066
|
MarsRenderPassColorAttachment.prototype.destroy = function () {
|
|
@@ -3953,6 +4107,14 @@ var MarsRenderPass = /** @class */ (function () {
|
|
|
3953
4107
|
enumerable: false,
|
|
3954
4108
|
configurable: true
|
|
3955
4109
|
});
|
|
4110
|
+
Object.defineProperty(MarsRenderPass.prototype, "multisample", {
|
|
4111
|
+
get: function () {
|
|
4112
|
+
var _a;
|
|
4113
|
+
return ((_a = this.frameBuffer) === null || _a === void 0 ? void 0 : _a.multisample) || 0;
|
|
4114
|
+
},
|
|
4115
|
+
enumerable: false,
|
|
4116
|
+
configurable: true
|
|
4117
|
+
});
|
|
3956
4118
|
Object.defineProperty(MarsRenderPass.prototype, "attachments", {
|
|
3957
4119
|
get: function () {
|
|
3958
4120
|
return this._attachments;
|
|
@@ -4117,6 +4279,7 @@ var MarsRenderPass = /** @class */ (function () {
|
|
|
4117
4279
|
storeAction: this.storeAction,
|
|
4118
4280
|
name: name,
|
|
4119
4281
|
viewport: viewport,
|
|
4282
|
+
multisample: options.multiSample,
|
|
4120
4283
|
viewportScale: this.viewportScale,
|
|
4121
4284
|
isCustomViewport: this._isCustomViewport,
|
|
4122
4285
|
attachments: attachments.map(function (att) { return (att.texture).internal; }),
|
|
@@ -4738,10 +4901,12 @@ var GLGeometry = /** @class */ (function () {
|
|
|
4738
4901
|
return null;
|
|
4739
4902
|
};
|
|
4740
4903
|
GLGeometry.prototype.draw = function (state) {
|
|
4741
|
-
var _a;
|
|
4904
|
+
var _a, _b;
|
|
4742
4905
|
var index = this._indexBuffer;
|
|
4743
4906
|
var gl = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.gl;
|
|
4744
|
-
|
|
4907
|
+
var gpu = (_b = this.renderer) === null || _b === void 0 ? void 0 : _b.gpu;
|
|
4908
|
+
var useInstancedDraw = (gpu === null || gpu === void 0 ? void 0 : gpu.capability.instanceDraw) && state.currentMesh.instanceCount > 0;
|
|
4909
|
+
if (gl && gpu) {
|
|
4745
4910
|
var drawCount = this.drawCount;
|
|
4746
4911
|
if (index) {
|
|
4747
4912
|
var type = index.type;
|
|
@@ -4749,11 +4914,21 @@ var GLGeometry = /** @class */ (function () {
|
|
|
4749
4914
|
//this._indexBuffer?.bind();
|
|
4750
4915
|
var dc = isNaN(drawCount) ? index.elementCount : drawCount;
|
|
4751
4916
|
if (dc > 0) {
|
|
4752
|
-
|
|
4917
|
+
if (useInstancedDraw) {
|
|
4918
|
+
gpu.drawElementsInstanced(gl, this.mode, dc, type, this.drawStart || 0, state.currentMesh.instanceCount);
|
|
4919
|
+
}
|
|
4920
|
+
else {
|
|
4921
|
+
gl.drawElements(this.mode, dc, type, this.drawStart || 0);
|
|
4922
|
+
}
|
|
4753
4923
|
}
|
|
4754
4924
|
}
|
|
4755
4925
|
else if (drawCount > 0) {
|
|
4756
|
-
|
|
4926
|
+
if (useInstancedDraw) {
|
|
4927
|
+
gpu.drawArraysInstanced(gl, this.mode, this.drawStart, this.drawCount, state.currentMesh.instanceCount);
|
|
4928
|
+
}
|
|
4929
|
+
else {
|
|
4930
|
+
gl.drawArrays(this.mode, this.drawStart, this.drawCount);
|
|
4931
|
+
}
|
|
4757
4932
|
}
|
|
4758
4933
|
}
|
|
4759
4934
|
};
|
|
@@ -4844,6 +5019,7 @@ var MarsGeometry = /** @class */ (function () {
|
|
|
4844
5019
|
type: type || gltype,
|
|
4845
5020
|
normalize: !!attr.normalize,
|
|
4846
5021
|
dataSource: (name),
|
|
5022
|
+
instanceDivisor: attr.instanceDivisor,
|
|
4847
5023
|
};
|
|
4848
5024
|
attributesReleasable[name] = releasable || false;
|
|
4849
5025
|
dirtyFlags[name] = {
|
|
@@ -5174,7 +5350,7 @@ var MarsGeometry = /** @class */ (function () {
|
|
|
5174
5350
|
|
|
5175
5351
|
var seed = 1;
|
|
5176
5352
|
var MarsMesh = /** @class */ (function () {
|
|
5177
|
-
function MarsMesh(options) {
|
|
5353
|
+
function MarsMesh(options, renderer) {
|
|
5178
5354
|
this._isDestroyed = false;
|
|
5179
5355
|
this.material = options.material instanceof MarsMaterial ? options.material : new MarsMaterial(options.material);
|
|
5180
5356
|
var geo = options.geometry;
|
|
@@ -5191,6 +5367,9 @@ var MarsMesh = /** @class */ (function () {
|
|
|
5191
5367
|
this.priority = options.priority || 0;
|
|
5192
5368
|
this.hide = false;
|
|
5193
5369
|
this.worldMatrix = options.worldMatrix || [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
5370
|
+
if (renderer) {
|
|
5371
|
+
this.assignRenderer(renderer);
|
|
5372
|
+
}
|
|
5194
5373
|
}
|
|
5195
5374
|
Object.defineProperty(MarsMesh.prototype, "isDestroyed", {
|
|
5196
5375
|
get: function () {
|
|
@@ -5261,6 +5440,15 @@ var MarsMesh = /** @class */ (function () {
|
|
|
5261
5440
|
};
|
|
5262
5441
|
return MarsMesh;
|
|
5263
5442
|
}());
|
|
5443
|
+
var MarsInstancedMesh = /** @class */ (function (_super) {
|
|
5444
|
+
__extends(MarsInstancedMesh, _super);
|
|
5445
|
+
function MarsInstancedMesh(options, renderer) {
|
|
5446
|
+
var _this = _super.call(this, options, renderer) || this;
|
|
5447
|
+
_this.instanceCount = options.instanceCount;
|
|
5448
|
+
return _this;
|
|
5449
|
+
}
|
|
5450
|
+
return MarsInstancedMesh;
|
|
5451
|
+
}(MarsMesh));
|
|
5264
5452
|
|
|
5265
5453
|
var copyShaderId = '$mri-internal-copy';
|
|
5266
5454
|
var MarsExtWrap = /** @class */ (function () {
|
|
@@ -5524,9 +5712,10 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
|
5524
5712
|
return MarsSharedGeometry;
|
|
5525
5713
|
}(MarsGeometry));
|
|
5526
5714
|
|
|
5527
|
-
consoleLog('version: ' + "0.1.
|
|
5715
|
+
consoleLog('version: ' + "0.1.11");
|
|
5528
5716
|
|
|
5529
5717
|
exports.Geometry = MarsGeometry;
|
|
5718
|
+
exports.InstancedMesh = MarsInstancedMesh;
|
|
5530
5719
|
exports.MarsTextureFactory = MarsTextureFactory;
|
|
5531
5720
|
exports.Material = MarsMaterial;
|
|
5532
5721
|
exports.MaterialDataBlock = MarsMaterialDataBlock;
|