@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.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  * Name: @predy-js/render-interface
3
3
  * Description: undefined
4
4
  * Author: undefined
5
- * Version: v0.1.8
5
+ * Version: v0.1.11
6
6
  */
7
7
 
8
8
  /******************************************************************************
@@ -149,7 +149,7 @@ var TextureSourceType;
149
149
  TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
150
150
  })(TextureSourceType || (TextureSourceType = {}));
151
151
 
152
- var _a$6;
152
+ var _a$6, _b$2;
153
153
  // @ts-expect-error safe to assign
154
154
  var constants = {};
155
155
  {
@@ -188,6 +188,14 @@ function getBytesPerElementByGLType(type) {
188
188
  var _a;
189
189
  return ((_a = map[type]) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT) || 0;
190
190
  }
191
+ var MatAttrLocPairMap = (_b$2 = {},
192
+ _b$2[constants.FLOAT_MAT2] = [2, 2],
193
+ _b$2[constants.FLOAT_MAT3] = [3, 3],
194
+ _b$2[constants.FLOAT_MAT4] = [4, 4],
195
+ _b$2);
196
+ function getMatAttrLocPair(type) {
197
+ return MatAttrLocPairMap[type] || [1, 1];
198
+ }
191
199
 
192
200
  var ShaderCompileResultStatus;
193
201
  (function (ShaderCompileResultStatus) {
@@ -636,6 +644,7 @@ var GPUCapabilityEmpty = /** @class */ (function () {
636
644
  function GPUCapabilityEmpty() {
637
645
  this.level = 0;
638
646
  this.capability = {
647
+ maxSample: 0,
639
648
  floatTexture: 0,
640
649
  halfFloatTexture: 0,
641
650
  maxVertexUniforms: 0,
@@ -1840,7 +1849,7 @@ var GLProgram = /** @class */ (function () {
1840
1849
  var uniformInfo = DATA_DICT[info.type];
1841
1850
  var subInfos = info.subInfos;
1842
1851
  if (subInfos.length > 0 && Array.isArray(value) && Array.isArray(value[0])) {
1843
- for (var i = 0; i < subInfos.length; ++i) {
1852
+ for (var i = 0; i < subInfos.length && i < value.length; ++i) {
1844
1853
  var subInfo = subInfos[i];
1845
1854
  uniformInfo.uniform(gl, subInfo, value[i], this.renderer);
1846
1855
  }
@@ -1852,6 +1861,7 @@ var GLProgram = /** @class */ (function () {
1852
1861
  var _a;
1853
1862
  var gl = this.renderer.gl;
1854
1863
  var vao = geometry.createVao(this.id);
1864
+ var gpu = this.renderer.gpu;
1855
1865
  if (vao) {
1856
1866
  vao.bind();
1857
1867
  if (vao.ready) {
@@ -1869,8 +1879,26 @@ var GLProgram = /** @class */ (function () {
1869
1879
  throw Error("no buffer named ".concat(attribute.dataSource || name));
1870
1880
  }
1871
1881
  buffer.bind();
1872
- gl.enableVertexAttribArray(attrInfo.loc);
1873
- gl.vertexAttribPointer(attrInfo.loc, attribute.size, attribute.type, attribute.normalize, attribute.stride || 0, attribute.offset || 0);
1882
+ if (attribute.size > 4) {
1883
+ var _a = getMatAttrLocPair(attrInfo.type), row = _a[0], col = _a[1];
1884
+ var bytesPerRow = getBytesPerElementByGLType(attribute.type) * col;
1885
+ var stride = row * bytesPerRow;
1886
+ for (var i = 0; i < row; i++) {
1887
+ var loc = attrInfo.loc + i;
1888
+ gl.enableVertexAttribArray(loc);
1889
+ gl.vertexAttribPointer(loc, col, attribute.type, attribute.normalize, stride, i * bytesPerRow);
1890
+ if (attribute.instanceDivisor && gpu.capability.instanceDraw) {
1891
+ gpu.vertexAttribDivisor(gl, loc, attribute.instanceDivisor);
1892
+ }
1893
+ }
1894
+ }
1895
+ else {
1896
+ gl.enableVertexAttribArray(attrInfo.loc);
1897
+ gl.vertexAttribPointer(attrInfo.loc, attribute.size, attribute.type, attribute.normalize, attribute.stride || 0, attribute.offset || 0);
1898
+ if (attribute.instanceDivisor && gpu.capability.instanceDraw) {
1899
+ gpu.vertexAttribDivisor(gl, attrInfo.loc, attribute.instanceDivisor);
1900
+ }
1901
+ }
1874
1902
  }
1875
1903
  });
1876
1904
  (_a = geometry._indexBuffer) === null || _a === void 0 ? void 0 : _a.bind();
@@ -2223,6 +2251,7 @@ var GLGPUCapability = /** @class */ (function () {
2223
2251
  }
2224
2252
  this.internalFormatDepth16 = level2 ? gl.DEPTH_COMPONENT16 : gl.DEPTH_COMPONENT;
2225
2253
  this.internalFormatDepth24_stencil8 = level2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL;
2254
+ this.instanceDrawExt = gl.getExtension('ANGLE_instanced_arrays');
2226
2255
  var floatTexture = (level2 || gl.getExtension('OES_texture_float')) ? gl.FLOAT : 0;
2227
2256
  var halfFloatTexture = level2 ? WebGL2RenderingContext.HALF_FLOAT : (((_a = gl.getExtension('OES_texture_half_float')) === null || _a === void 0 ? void 0 : _a.HALF_FLOAT_OES) || 0);
2228
2257
  var detail = {
@@ -2242,7 +2271,7 @@ var GLGPUCapability = /** @class */ (function () {
2242
2271
  floatLinear: floatLinear,
2243
2272
  maxTextureAnisotropy: textureAnisotropicExt ? gl.getParameter(textureAnisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0,
2244
2273
  shaderTextureLod: level2 || !!gl.getExtension('EXT_shader_texture_lod'),
2245
- instanceDraw: level2 || !!gl.getExtension('ANGLE_instanced_arrays'),
2274
+ instanceDraw: level2 || !!this.instanceDrawExt,
2246
2275
  drawBuffers: level2 || !!this.drawBufferExtension,
2247
2276
  asyncShaderCompile: !!gl.getExtension('KHR_parallel_shader_compile'),
2248
2277
  intIndexElementBuffer: !!gl.getExtension('OES_element_index_uint'),
@@ -2292,6 +2321,39 @@ var GLGPUCapability = /** @class */ (function () {
2292
2321
  consoleError('invalid color attachment index:' + index);
2293
2322
  }
2294
2323
  };
2324
+ GLGPUCapability.prototype.vertexAttribDivisor = function (gl, loc, divisor) {
2325
+ if (this.level === 2) {
2326
+ gl.vertexAttribDivisor(loc, divisor);
2327
+ }
2328
+ else if (this.instanceDrawExt) {
2329
+ this.instanceDrawExt.vertexAttribDivisorANGLE(loc, divisor);
2330
+ }
2331
+ else {
2332
+ consoleWarn('instance draw not support');
2333
+ }
2334
+ };
2335
+ GLGPUCapability.prototype.drawElementsInstanced = function (gl, mode, count, type, offset, instanceCount) {
2336
+ if (this.level === 2) {
2337
+ gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
2338
+ }
2339
+ else if (this.instanceDrawExt) {
2340
+ this.instanceDrawExt.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
2341
+ }
2342
+ else {
2343
+ consoleWarn('instance draw not support');
2344
+ }
2345
+ };
2346
+ GLGPUCapability.prototype.drawArraysInstanced = function (gl, mode, first, count, instanceCount) {
2347
+ if (this.level === 2) {
2348
+ gl.drawArraysInstanced(mode, first, count, instanceCount);
2349
+ }
2350
+ else if (this.instanceDrawExt) {
2351
+ this.instanceDrawExt.drawArraysInstancedANGLE(mode, first, count, instanceCount);
2352
+ }
2353
+ else {
2354
+ consoleWarn('instance draw not support');
2355
+ }
2356
+ };
2295
2357
  GLGPUCapability.prototype.drawBuffers = function (gl, bufferStates) {
2296
2358
  var ext = this.drawBufferExtension;
2297
2359
  if (this.level === 1 && !ext) {
@@ -2769,9 +2831,6 @@ var GLGPURenderer = /** @class */ (function () {
2769
2831
  GLGPURenderer.prototype.createBuffer = function (options) {
2770
2832
  return new GLGPUBuffer(options, this);
2771
2833
  };
2772
- GLGPURenderer.prototype.parseSceneSchema = function (schema) {
2773
- throw new Error('Method not implemented.');
2774
- };
2775
2834
  GLGPURenderer.prototype.resize = function (width, height) {
2776
2835
  var gl = this.gl;
2777
2836
  if (gl && gl.drawingBufferWidth !== width || gl.drawingBufferHeight !== height) {
@@ -2845,7 +2904,10 @@ var GLGPURenderer = /** @class */ (function () {
2845
2904
  };
2846
2905
  GLGPURenderer.prototype.deleteGLFrameBuffer = function (frameBuffer) {
2847
2906
  if (frameBuffer && !this._isDestroyed) {
2848
- this.gl.deleteFramebuffer(frameBuffer.fbo);
2907
+ var gl = this.gl;
2908
+ gl.deleteFramebuffer(frameBuffer.fbo);
2909
+ gl.deleteFramebuffer(frameBuffer.multisampleFbo);
2910
+ frameBuffer.multisampleRbs.forEach(function (rb) { return rb.destroy(); });
2849
2911
  arrRemove(this._frameBuffers, frameBuffer);
2850
2912
  delete frameBuffer.fbo;
2851
2913
  }
@@ -2978,13 +3040,14 @@ var CanvasEmpty = /** @class */ (function () {
2978
3040
 
2979
3041
  var GLRenderBuffer = /** @class */ (function () {
2980
3042
  function GLRenderBuffer(renderer, options) {
3043
+ var _a;
2981
3044
  this.storageType = options.storageType;
2982
3045
  this.renderer = renderer;
2983
3046
  this.glHandle = renderer.createGLRenderBuffer(this);
2984
3047
  this.internalFormat = this.format = options.format;
2985
3048
  this.attachment = options.attachment;
2986
3049
  this.size = [0, 0];
2987
- this.multiSample = 1;
3050
+ this.multiSample = (_a = options.multisample) !== null && _a !== void 0 ? _a : 0;
2988
3051
  }
2989
3052
  GLRenderBuffer.prototype.setSize = function (width, height) {
2990
3053
  if (width !== this.size[0] || height !== this.size[1]) {
@@ -2994,6 +3057,10 @@ var GLRenderBuffer = /** @class */ (function () {
2994
3057
  state.bindRenderBuffer(gl.RENDERBUFFER, this.glHandle);
2995
3058
  if (width && height) {
2996
3059
  gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, this.size[0] = width, this.size[1] = height);
3060
+ if (this.multiSample > 1) {
3061
+ var if2 = internalFormat === gl.DEPTH_STENCIL ? gl.DEPTH24_STENCIL8 : internalFormat;
3062
+ gl.renderbufferStorageMultisample(gl.RENDERBUFFER, this.multiSample, if2, width, height);
3063
+ }
2997
3064
  }
2998
3065
  else {
2999
3066
  consoleError("invalid render buffer size ".concat(width, "x").concat(height));
@@ -3015,6 +3082,7 @@ var seed$5 = 1;
3015
3082
  var GLFrameBuffer = /** @class */ (function () {
3016
3083
  function GLFrameBuffer(options, renderer) {
3017
3084
  var _a;
3085
+ this.multisampleRbs = [];
3018
3086
  this.renderer = renderer;
3019
3087
  this.depthStencilStorageType = ((_a = options.depthStencilAttachment) === null || _a === void 0 ? void 0 : _a.storageType) || RenderPassAttachmentStorageType.none;
3020
3088
  this.viewport = options.viewport;
@@ -3023,6 +3091,7 @@ var GLFrameBuffer = /** @class */ (function () {
3023
3091
  this.name = options.name || ('GLFrameBuffer' + seed$5++);
3024
3092
  this.storeAction = options.storeAction;
3025
3093
  this._attachmentHandles = [];
3094
+ this.multisample = renderer.level > 1 ? options.multisample || 0 : 0;
3026
3095
  this.checkOptions(options);
3027
3096
  }
3028
3097
  Object.defineProperty(GLFrameBuffer.prototype, "stencilStorage", {
@@ -3061,6 +3130,7 @@ var GLFrameBuffer = /** @class */ (function () {
3061
3130
  var capability = renderer.gpu.capability;
3062
3131
  var depthStencilAttachment = options.depthStencilAttachment || { storageType: RenderPassAttachmentStorageType.none };
3063
3132
  var willUseFbo = options.attachments.length > 0;
3133
+ var willMultisample = this.multisample > 1;
3064
3134
  this.externalStorage = false;
3065
3135
  var separateDepthStencil = true;
3066
3136
  if (options.attachments.length > 1 && !capability.drawBuffers) {
@@ -3075,10 +3145,16 @@ var GLFrameBuffer = /** @class */ (function () {
3075
3145
  if (willUseFbo) {
3076
3146
  this.fbo = renderer.createGLFrameBuffer(this, this.name);
3077
3147
  }
3148
+ if (willMultisample) {
3149
+ this.multisampleFbo = renderer.createGLFrameBuffer(this, this.name + '_multisample');
3150
+ }
3078
3151
  var storageType = depthStencilAttachment.storageType;
3079
3152
  if (storageType === RenderPassAttachmentStorageType.depth_stencil_opaque) {
3080
3153
  if (depthStencilAttachment.storage) {
3081
3154
  if (depthStencilAttachment.storage instanceof GLRenderBuffer) {
3155
+ if (this.multisample !== depthStencilAttachment.storage.multiSample && this.multisample > 1) {
3156
+ throw Error('fbo multisample not eql depth stencil attachment');
3157
+ }
3082
3158
  this.depthStencilRenderBuffer = depthStencilAttachment.storage;
3083
3159
  this.externalStorage = true;
3084
3160
  }
@@ -3090,6 +3166,7 @@ var GLFrameBuffer = /** @class */ (function () {
3090
3166
  this.depthStencilRenderBuffer = new GLRenderBuffer(renderer, {
3091
3167
  format: constants.DEPTH_STENCIL,
3092
3168
  attachment: constants.DEPTH_STENCIL_ATTACHMENT,
3169
+ multisample: this.multisample,
3093
3170
  storageType: storageType,
3094
3171
  });
3095
3172
  }
@@ -3097,6 +3174,9 @@ var GLFrameBuffer = /** @class */ (function () {
3097
3174
  }
3098
3175
  else if (storageType === RenderPassAttachmentStorageType.depth_16_opaque) {
3099
3176
  if (depthStencilAttachment.storage) {
3177
+ if (this.multisample !== depthStencilAttachment.storage.multiSample && this.multisample > 1) {
3178
+ throw Error('fbo multisample not eql depth attachment');
3179
+ }
3100
3180
  if (depthStencilAttachment.storage instanceof GLRenderBuffer) {
3101
3181
  this.depthStencilRenderBuffer = depthStencilAttachment.storage;
3102
3182
  this.externalStorage = true;
@@ -3108,6 +3188,7 @@ var GLFrameBuffer = /** @class */ (function () {
3108
3188
  else {
3109
3189
  this.depthStencilRenderBuffer = new GLRenderBuffer(renderer, {
3110
3190
  attachment: constants.DEPTH_ATTACHMENT,
3191
+ multisample: this.multisample,
3111
3192
  format: constants.DEPTH_COMPONENT16,
3112
3193
  storageType: storageType,
3113
3194
  });
@@ -3116,6 +3197,9 @@ var GLFrameBuffer = /** @class */ (function () {
3116
3197
  else if (storageType === RenderPassAttachmentStorageType.stencil_8_opaque) {
3117
3198
  if (depthStencilAttachment.storage) {
3118
3199
  if (depthStencilAttachment.storage instanceof GLRenderBuffer) {
3200
+ if (this.multisample !== depthStencilAttachment.storage.multiSample && this.multisample > 1) {
3201
+ throw Error('fbo multisample not eql stencil attachment');
3202
+ }
3119
3203
  this.depthStencilRenderBuffer = depthStencilAttachment.storage;
3120
3204
  this.externalStorage = true;
3121
3205
  }
@@ -3127,6 +3211,7 @@ var GLFrameBuffer = /** @class */ (function () {
3127
3211
  this.depthStencilRenderBuffer = new GLRenderBuffer(renderer, {
3128
3212
  attachment: constants.STENCIL_ATTACHMENT,
3129
3213
  format: constants.STENCIL_INDEX8,
3214
+ multisample: this.multisample,
3130
3215
  storageType: storageType,
3131
3216
  });
3132
3217
  }
@@ -3180,6 +3265,7 @@ var GLFrameBuffer = /** @class */ (function () {
3180
3265
  };
3181
3266
  GLFrameBuffer.prototype.unbind = function () {
3182
3267
  var att = this.storeInvalidAttachments;
3268
+ this.resolveMultiSample();
3183
3269
  if (att && att.length) {
3184
3270
  var gl = this.renderer.gl;
3185
3271
  gl.invalidateFramebuffer(gl.FRAMEBUFFER, att);
@@ -3190,9 +3276,14 @@ var GLFrameBuffer = /** @class */ (function () {
3190
3276
  GLFrameBuffer.prototype.bind = function () {
3191
3277
  var gl = this.renderer.gl;
3192
3278
  var state = this.renderer.state;
3193
- if (this.fbo) {
3194
- var FRAMEBUFFER = gl.FRAMEBUFFER;
3195
- var viewport = this.viewport;
3279
+ var FRAMEBUFFER = gl.FRAMEBUFFER;
3280
+ var viewport = this.viewport;
3281
+ var multisampleFbo = this.multisampleFbo;
3282
+ if (multisampleFbo) {
3283
+ state.bindFramebuffer(FRAMEBUFFER, multisampleFbo);
3284
+ state.viewport(viewport[0], viewport[1], viewport[2], viewport[3]);
3285
+ }
3286
+ else if (this.fbo) {
3196
3287
  state.bindFramebuffer(FRAMEBUFFER, this.fbo);
3197
3288
  state.viewport(viewport[0], viewport[1], viewport[2], viewport[3]);
3198
3289
  var r_1 = this.renderer.emptyTexture2D.glHandle;
@@ -3204,30 +3295,74 @@ var GLFrameBuffer = /** @class */ (function () {
3204
3295
  state.bindTexture(constants.TEXTURE_2D, r_1, true);
3205
3296
  }
3206
3297
  });
3207
- if (!this.ready) {
3208
- var _a = this, depthStencilRenderBuffer = _a.depthStencilRenderBuffer, depthTexture = _a.depthTexture, stencilTexture = _a.stencilTexture;
3209
- state.activeTexture(gl.TEXTURE0);
3210
- if (depthStencilRenderBuffer) {
3211
- depthStencilRenderBuffer.setSize(viewport[2], viewport[3]);
3212
- gl.framebufferRenderbuffer(FRAMEBUFFER, depthStencilRenderBuffer.attachment, gl.RENDERBUFFER, depthStencilRenderBuffer.glHandle);
3213
- }
3214
- else if (depthTexture) {
3215
- depthTexture.update({ data: { width: viewport[2], height: viewport[3], data: new Uint16Array(0) } });
3216
- var attachment = depthTexture && stencilTexture ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
3217
- gl.framebufferTexture2D(FRAMEBUFFER, attachment, gl.TEXTURE_2D, depthTexture.glHandle, 0);
3298
+ }
3299
+ if (!this.ready) {
3300
+ var _a = this, depthStencilRenderBuffer = _a.depthStencilRenderBuffer, depthTexture = _a.depthTexture, stencilTexture = _a.stencilTexture;
3301
+ state.activeTexture(gl.TEXTURE0);
3302
+ if (depthStencilRenderBuffer) {
3303
+ depthStencilRenderBuffer.setSize(viewport[2], viewport[3]);
3304
+ gl.framebufferRenderbuffer(FRAMEBUFFER, depthStencilRenderBuffer.attachment, gl.RENDERBUFFER, depthStencilRenderBuffer.glHandle);
3305
+ }
3306
+ else if (depthTexture) {
3307
+ if (multisampleFbo) {
3308
+ var attachment_1 = gl.DEPTH_ATTACHMENT;
3309
+ var format = gl.DEPTH_COMPONENT16;
3310
+ if (this.depthStencilStorageType === RenderPassAttachmentStorageType.depth_24_stencil_8_texture) {
3311
+ attachment_1 = gl.DEPTH_STENCIL_ATTACHMENT;
3312
+ format = gl.DEPTH24_STENCIL8;
3313
+ }
3314
+ var renderBuffer = new GLRenderBuffer(this.renderer, {
3315
+ storageType: this.depthStencilStorageType,
3316
+ attachment: attachment_1,
3317
+ format: format,
3318
+ multisample: this.multisample,
3319
+ });
3320
+ gl.bindFramebuffer(gl.FRAMEBUFFER, multisampleFbo);
3321
+ this.multisampleRbs.push(renderBuffer);
3322
+ renderBuffer.setSize(viewport[2], viewport[3]);
3323
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment_1, gl.RENDERBUFFER, renderBuffer.glHandle);
3324
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.fbo);
3218
3325
  }
3219
- this.resetColorTextures(this.colorTextures);
3220
- var status_1 = gl.checkFramebufferStatus(FRAMEBUFFER);
3221
- if (status_1 !== gl.FRAMEBUFFER_COMPLETE) {
3222
- var error = gl.getError();
3223
- throw Error("framebuffer failed status ".concat(status_1, " error:").concat(error));
3326
+ depthTexture.update({ data: { width: viewport[2], height: viewport[3], data: new Uint16Array(0) } });
3327
+ var attachment = depthTexture && stencilTexture ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
3328
+ gl.framebufferTexture2D(FRAMEBUFFER, attachment, gl.TEXTURE_2D, depthTexture.glHandle, 0);
3329
+ }
3330
+ this.resetColorTextures(this.colorTextures);
3331
+ [multisampleFbo, this.fbo].forEach(function (fbo) {
3332
+ if (fbo) {
3333
+ gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
3334
+ var status_1 = gl.checkFramebufferStatus(FRAMEBUFFER);
3335
+ if (status_1 !== gl.FRAMEBUFFER_COMPLETE) {
3336
+ var error = gl.getError();
3337
+ throw Error("framebuffer failed status ".concat(status_1, " error:").concat(error));
3338
+ }
3224
3339
  }
3225
- //@ts-expect-error safe to assign
3226
- this.ready = true;
3340
+ });
3341
+ //@ts-expect-error safe to assign
3342
+ this.ready = true;
3343
+ }
3344
+ };
3345
+ GLFrameBuffer.prototype.resolveMultiSample = function () {
3346
+ var multisampleFbo = this.multisampleFbo;
3347
+ var fbo = this.fbo;
3348
+ if (multisampleFbo && fbo) {
3349
+ var gl = this.renderer.gl;
3350
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, multisampleFbo);
3351
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fbo);
3352
+ var vp = this.viewport;
3353
+ var bit = gl.COLOR_BUFFER_BIT;
3354
+ if (this.depthTexture) {
3355
+ bit = bit | gl.DEPTH_BUFFER_BIT;
3227
3356
  }
3357
+ gl.blitFramebuffer(0, 0, vp[2], vp[3], // Source region
3358
+ 0, 0, vp[2], vp[3], // Destination region
3359
+ bit, gl.LINEAR // Buffer mask and filter
3360
+ );
3361
+ gl.bindFramebuffer(gl.FRAMEBUFFER, multisampleFbo);
3228
3362
  }
3229
3363
  };
3230
3364
  GLFrameBuffer.prototype.resetColorTextures = function (colors) {
3365
+ var _this = this;
3231
3366
  var gl = this.renderer.gl;
3232
3367
  var gpu = this.renderer.gpu;
3233
3368
  var viewport = this.viewport;
@@ -3237,8 +3372,22 @@ var GLFrameBuffer = /** @class */ (function () {
3237
3372
  this.colorTextures = colors.slice();
3238
3373
  }
3239
3374
  this.renderer.state.activeTexture(gl.TEXTURE0);
3375
+ var multisampleFBO = this.multisampleFbo;
3240
3376
  this.colorTextures.forEach(function (tex, index) {
3241
3377
  tex.update({ data: data });
3378
+ if (multisampleFBO) {
3379
+ gl.bindFramebuffer(gl.FRAMEBUFFER, multisampleFBO);
3380
+ var renderBuffer = new GLRenderBuffer(_this.renderer, {
3381
+ format: gl.RGBA8,
3382
+ attachment: gl.COLOR_ATTACHMENT0 + index,
3383
+ storageType: RenderPassAttachmentStorageType.color,
3384
+ multisample: _this.multisample,
3385
+ });
3386
+ _this.multisampleRbs.push(renderBuffer);
3387
+ renderBuffer.setSize(tex.width, tex.height);
3388
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + index, gl.RENDERBUFFER, renderBuffer.glHandle);
3389
+ }
3390
+ gl.bindFramebuffer(gl.FRAMEBUFFER, _this.fbo);
3242
3391
  gpu.framebufferTexture2D(gl, gl.FRAMEBUFFER, index, gl.TEXTURE_2D, tex.glHandle);
3243
3392
  buffers.push(true);
3244
3393
  });
@@ -3257,7 +3406,7 @@ var GLFrameBuffer = /** @class */ (function () {
3257
3406
  (_b = this.depthTexture) === null || _b === void 0 ? void 0 : _b.destroy();
3258
3407
  }
3259
3408
  //@ts-expect-error safe to assign
3260
- this.renderer = this.stencilRenderBuffer = this.depthStencilRenderBuffer = null;
3409
+ this.renderer = this.depthStencilRenderBuffer = null;
3261
3410
  }
3262
3411
  };
3263
3412
  GLFrameBuffer.prototype.resize = function (x, y, width, height) {
@@ -3856,6 +4005,7 @@ var MarsRenderPassColorAttachment = /** @class */ (function () {
3856
4005
  }
3857
4006
  this._isDestroyed = false;
3858
4007
  this.readable = true;
4008
+ this.multisample = options.multiSample || 1;
3859
4009
  }
3860
4010
  Object.defineProperty(MarsRenderPassColorAttachment.prototype, "isDestroyed", {
3861
4011
  get: function () {
@@ -3903,6 +4053,10 @@ var MarsRenderPassColorAttachment = /** @class */ (function () {
3903
4053
  if (this.texture) {
3904
4054
  this.texture.assignRenderer(renderer);
3905
4055
  }
4056
+ if (this.multisample > 1) {
4057
+ this.multisample = Math.min(renderer.gpu.capability.maxSample, this.multisample);
4058
+ }
4059
+ this.texture.internal.multisample = this.multisample;
3906
4060
  return this;
3907
4061
  };
3908
4062
  MarsRenderPassColorAttachment.prototype.destroy = function () {
@@ -3949,6 +4103,14 @@ var MarsRenderPass = /** @class */ (function () {
3949
4103
  enumerable: false,
3950
4104
  configurable: true
3951
4105
  });
4106
+ Object.defineProperty(MarsRenderPass.prototype, "multisample", {
4107
+ get: function () {
4108
+ var _a;
4109
+ return ((_a = this.frameBuffer) === null || _a === void 0 ? void 0 : _a.multisample) || 0;
4110
+ },
4111
+ enumerable: false,
4112
+ configurable: true
4113
+ });
3952
4114
  Object.defineProperty(MarsRenderPass.prototype, "attachments", {
3953
4115
  get: function () {
3954
4116
  return this._attachments;
@@ -4113,6 +4275,7 @@ var MarsRenderPass = /** @class */ (function () {
4113
4275
  storeAction: this.storeAction,
4114
4276
  name: name,
4115
4277
  viewport: viewport,
4278
+ multisample: options.multiSample,
4116
4279
  viewportScale: this.viewportScale,
4117
4280
  isCustomViewport: this._isCustomViewport,
4118
4281
  attachments: attachments.map(function (att) { return (att.texture).internal; }),
@@ -4734,10 +4897,12 @@ var GLGeometry = /** @class */ (function () {
4734
4897
  return null;
4735
4898
  };
4736
4899
  GLGeometry.prototype.draw = function (state) {
4737
- var _a;
4900
+ var _a, _b;
4738
4901
  var index = this._indexBuffer;
4739
4902
  var gl = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.gl;
4740
- if (gl) {
4903
+ var gpu = (_b = this.renderer) === null || _b === void 0 ? void 0 : _b.gpu;
4904
+ var useInstancedDraw = (gpu === null || gpu === void 0 ? void 0 : gpu.capability.instanceDraw) && state.currentMesh.instanceCount > 0;
4905
+ if (gl && gpu) {
4741
4906
  var drawCount = this.drawCount;
4742
4907
  if (index) {
4743
4908
  var type = index.type;
@@ -4745,11 +4910,21 @@ var GLGeometry = /** @class */ (function () {
4745
4910
  //this._indexBuffer?.bind();
4746
4911
  var dc = isNaN(drawCount) ? index.elementCount : drawCount;
4747
4912
  if (dc > 0) {
4748
- gl.drawElements(this.mode, dc, type, this.drawStart || 0);
4913
+ if (useInstancedDraw) {
4914
+ gpu.drawElementsInstanced(gl, this.mode, dc, type, this.drawStart || 0, state.currentMesh.instanceCount);
4915
+ }
4916
+ else {
4917
+ gl.drawElements(this.mode, dc, type, this.drawStart || 0);
4918
+ }
4749
4919
  }
4750
4920
  }
4751
4921
  else if (drawCount > 0) {
4752
- gl.drawArrays(this.mode, this.drawStart, this.drawCount);
4922
+ if (useInstancedDraw) {
4923
+ gpu.drawArraysInstanced(gl, this.mode, this.drawStart, this.drawCount, state.currentMesh.instanceCount);
4924
+ }
4925
+ else {
4926
+ gl.drawArrays(this.mode, this.drawStart, this.drawCount);
4927
+ }
4753
4928
  }
4754
4929
  }
4755
4930
  };
@@ -4840,6 +5015,7 @@ var MarsGeometry = /** @class */ (function () {
4840
5015
  type: type || gltype,
4841
5016
  normalize: !!attr.normalize,
4842
5017
  dataSource: (name),
5018
+ instanceDivisor: attr.instanceDivisor,
4843
5019
  };
4844
5020
  attributesReleasable[name] = releasable || false;
4845
5021
  dirtyFlags[name] = {
@@ -5170,7 +5346,7 @@ var MarsGeometry = /** @class */ (function () {
5170
5346
 
5171
5347
  var seed = 1;
5172
5348
  var MarsMesh = /** @class */ (function () {
5173
- function MarsMesh(options) {
5349
+ function MarsMesh(options, renderer) {
5174
5350
  this._isDestroyed = false;
5175
5351
  this.material = options.material instanceof MarsMaterial ? options.material : new MarsMaterial(options.material);
5176
5352
  var geo = options.geometry;
@@ -5187,6 +5363,9 @@ var MarsMesh = /** @class */ (function () {
5187
5363
  this.priority = options.priority || 0;
5188
5364
  this.hide = false;
5189
5365
  this.worldMatrix = options.worldMatrix || [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5366
+ if (renderer) {
5367
+ this.assignRenderer(renderer);
5368
+ }
5190
5369
  }
5191
5370
  Object.defineProperty(MarsMesh.prototype, "isDestroyed", {
5192
5371
  get: function () {
@@ -5257,6 +5436,15 @@ var MarsMesh = /** @class */ (function () {
5257
5436
  };
5258
5437
  return MarsMesh;
5259
5438
  }());
5439
+ var MarsInstancedMesh = /** @class */ (function (_super) {
5440
+ __extends(MarsInstancedMesh, _super);
5441
+ function MarsInstancedMesh(options, renderer) {
5442
+ var _this = _super.call(this, options, renderer) || this;
5443
+ _this.instanceCount = options.instanceCount;
5444
+ return _this;
5445
+ }
5446
+ return MarsInstancedMesh;
5447
+ }(MarsMesh));
5260
5448
 
5261
5449
  var copyShaderId = '$mri-internal-copy';
5262
5450
  var MarsExtWrap = /** @class */ (function () {
@@ -5520,7 +5708,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5520
5708
  return MarsSharedGeometry;
5521
5709
  }(MarsGeometry));
5522
5710
 
5523
- consoleLog('version: ' + "0.1.8");
5711
+ consoleLog('version: ' + "0.1.11");
5524
5712
 
5525
- export { DestroyOptions, MarsGeometry as Geometry, MarsTextureFactory, MarsMaterial as Material, MarsMaterialDataBlock as MaterialDataBlock, MarsMesh as Mesh, MarsRenderFrame as RenderFrame, MarsRenderPass as RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassMeshOrder, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, MarsRenderer as Renderer, ShaderCompileResultStatus, ShaderLibraryEmpty, MarsSharedGeometry as SharedGeometry, MarsTexture as Texture, TextureLoadAction, TextureSourceType, TextureStoreAction, constants, getDefaultGPUCapability, getDefaultTextureFactory, setDefaultTextureFactory };
5713
+ export { DestroyOptions, MarsGeometry as Geometry, MarsInstancedMesh as InstancedMesh, MarsTextureFactory, MarsMaterial as Material, MarsMaterialDataBlock as MaterialDataBlock, MarsMesh as Mesh, MarsRenderFrame as RenderFrame, MarsRenderPass as RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassMeshOrder, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, MarsRenderer as Renderer, ShaderCompileResultStatus, ShaderLibraryEmpty, MarsSharedGeometry as SharedGeometry, MarsTexture as Texture, TextureLoadAction, TextureSourceType, TextureStoreAction, constants, getDefaultGPUCapability, getDefaultTextureFactory, setDefaultTextureFactory };
5526
5714
  //# sourceMappingURL=index.mjs.map