mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 09:32:38 +08:00
39 lines
887 B
JavaScript
39 lines
887 B
JavaScript
export default class RenderBuffer {
|
|
/**
|
|
* @constructor
|
|
* @param {Device} device
|
|
* @param {RB_FMT_*} format
|
|
* @param {Number} width
|
|
* @param {Number} height
|
|
*/
|
|
constructor(device, format, width, height) {
|
|
this._device = device;
|
|
this._format = format;
|
|
this._width = width;
|
|
this._height = height;
|
|
|
|
const gl = device._gl;
|
|
this._glID = gl.createRenderbuffer();
|
|
|
|
gl.bindRenderbuffer(gl.RENDERBUFFER, this._glID);
|
|
gl.renderbufferStorage(gl.RENDERBUFFER, format, width, height);
|
|
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
}
|
|
|
|
/**
|
|
* @method destroy
|
|
*/
|
|
destroy() {
|
|
if (this._glID === null) {
|
|
console.error('The render-buffer already destroyed');
|
|
return;
|
|
}
|
|
|
|
const gl = this._device._gl;
|
|
|
|
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
gl.deleteRenderbuffer(this._glID);
|
|
|
|
this._glID = null;
|
|
}
|
|
} |