mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
resizable buffers (#3674)
This commit is contained in:
@@ -10,7 +10,7 @@ export default class RenderSystem {
|
||||
|
||||
update (dt) {
|
||||
this._scene.tick();
|
||||
cc.game._renderer.render(cc.game.canvas, this._scene);
|
||||
cc.game._renderer.render(this._scene);
|
||||
this._scene.reset();
|
||||
if (cc.director._scene) cc.director._scene.resetHasChanged();
|
||||
}
|
||||
|
||||
+12
-10
@@ -1,12 +1,11 @@
|
||||
import renderer from '../../renderer';
|
||||
import { Layers, find } from '../../scene-graph';
|
||||
import find from '../../scene-graph/find';
|
||||
import Mesh from '../assets/mesh';
|
||||
import gfx from '../../renderer/gfx/index';
|
||||
// import parseLevel from '../loaders/utils/level-parser';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../assets/skeleton").default} skinning
|
||||
*
|
||||
* @param {import("../assets/skeleton").default} skinning
|
||||
*/
|
||||
function createJointsTexture(skinning) {
|
||||
const jointCount = skinning.joints.length;
|
||||
@@ -52,14 +51,17 @@ function createMesh(context, data) {
|
||||
return meshAsset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} buffer
|
||||
*/
|
||||
function toPPM(buffer, w, h) {
|
||||
return `P3 ${w} ${h} 255\n${buffer.filter((e, i) => i % 4 < 3).toString()}\n`;
|
||||
}
|
||||
|
||||
export default {
|
||||
createJointsTexture,
|
||||
createMesh,
|
||||
|
||||
// parseLevel,
|
||||
|
||||
// walk: sceneUtils.walk,
|
||||
// flat: sceneUtils.flat,
|
||||
find: find,
|
||||
Layers: Layers,
|
||||
find,
|
||||
toPPM
|
||||
};
|
||||
|
||||
@@ -34,6 +34,7 @@ export default class RenderTexture extends Texture2D {
|
||||
colors: [ this._texture ],
|
||||
};
|
||||
if (depthStencilFormat) {
|
||||
if (this.depthStencilBuffer) this.depthStencilBuffer.destroy();
|
||||
let depthStencilBuffer = new gfx.RenderBuffer(cc.game._renderContext, depthStencilFormat, this.width, this.height);
|
||||
if (depthStencilFormat === gfx.RB_FMT_D24S8) {
|
||||
opts.depthStencil = depthStencilBuffer;
|
||||
@@ -44,17 +45,28 @@ export default class RenderTexture extends Texture2D {
|
||||
else if (depthStencilFormat === gfx.RB_FMT_D16) {
|
||||
opts.depth = depthStencilBuffer;
|
||||
}
|
||||
this.depthStencilBuffer = depthStencilBuffer;
|
||||
this.depthStencilFormat = depthStencilFormat;
|
||||
}
|
||||
|
||||
if (this._framebuffer) {
|
||||
this._framebuffer.destroy();
|
||||
}
|
||||
if (this._framebuffer) this._framebuffer.destroy();
|
||||
this._framebuffer = new gfx.FrameBuffer(cc.game._renderContext, this.width, this.height, opts);
|
||||
|
||||
this.loaded = true;
|
||||
this.emit("load");
|
||||
}
|
||||
|
||||
updateSize(width, height) {
|
||||
this.width = Math.floor(width || cc.visibleRect.width);
|
||||
this.height = Math.floor(height || cc.visibleRect.height);
|
||||
this._resetUnderlyingMipmaps();
|
||||
|
||||
let rbo = this.depthStencilBuffer;
|
||||
if (rbo) rbo.update(this.width, this.height);
|
||||
this._framebuffer._width = width;
|
||||
this._framebuffer._height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en Draw a texture to the specified position
|
||||
* !#zh 将指定的图片渲染到指定的位置上
|
||||
@@ -106,7 +118,6 @@ export default class RenderTexture extends Texture2D {
|
||||
let gl = cc.game._renderContext._gl;
|
||||
let oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer._glID);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._texture._glID, 0);
|
||||
gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, oldFBO);
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ export default class Texture2D extends TextureBase {
|
||||
* Resets sources and amount of the underlying texture's the mipmaps.
|
||||
* @param {ImageSource[]} mipmapSources
|
||||
*/
|
||||
_resetUnderlyingMipmaps(mipmapSources) {
|
||||
_resetUnderlyingMipmaps(mipmapSources = [null]) {
|
||||
const opts = this._getOpts();
|
||||
opts.images = mipmapSources;
|
||||
if (!this._texture) {
|
||||
|
||||
@@ -774,9 +774,9 @@ export default class Device {
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, fb._glID);
|
||||
|
||||
let numColors = this._framebuffer._colors.length;
|
||||
let numColors = fb._colors.length;
|
||||
for (let i = 0; i < numColors; ++i) {
|
||||
let colorBuffer = this._framebuffer._colors[i];
|
||||
let colorBuffer = fb._colors[i];
|
||||
_attach(gl, gl.COLOR_ATTACHMENT0 + i, colorBuffer);
|
||||
|
||||
// TODO: what about cubemap face??? should be the target parameter for colorBuffer
|
||||
@@ -791,15 +791,15 @@ export default class Device {
|
||||
);
|
||||
}
|
||||
|
||||
if (this._framebuffer._depth) {
|
||||
_attach(gl, gl.DEPTH_ATTACHMENT, this._framebuffer._depth);
|
||||
if (fb._depth) {
|
||||
_attach(gl, gl.DEPTH_ATTACHMENT, fb._depth);
|
||||
}
|
||||
|
||||
if (this._framebuffer._stencil) {
|
||||
if (fb._stencil) {
|
||||
_attach(gl, gl.STENCIL_ATTACHMENT, fb._stencil);
|
||||
}
|
||||
|
||||
if (this._framebuffer._depthStencil) {
|
||||
if (fb._depthStencil) {
|
||||
_attach(gl, gl.DEPTH_STENCIL_ATTACHMENT, fb._depthStencil);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,17 @@ export default class RenderBuffer {
|
||||
constructor(device, format, width, height) {
|
||||
this._device = device;
|
||||
this._format = format;
|
||||
|
||||
this._glID = device._gl.createRenderbuffer();
|
||||
this.update(width, height);
|
||||
}
|
||||
|
||||
update(width, height) {
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
|
||||
const gl = device._gl;
|
||||
this._glID = gl.createRenderbuffer();
|
||||
|
||||
const gl = this._device._gl;
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, this._glID);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, format, width, height);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, this._format, width, height);
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
||||
}
|
||||
|
||||
@@ -36,4 +39,4 @@ export default class RenderBuffer {
|
||||
|
||||
this._glID = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,11 @@ export default class ForwardRenderer extends BaseRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
render(canvas, scene) {
|
||||
render(scene) {
|
||||
this._reset();
|
||||
|
||||
const canvas = this._device._gl.canvas;
|
||||
|
||||
// update lights, extract shadow view.
|
||||
this.updateLights(scene);
|
||||
|
||||
|
||||
@@ -325,6 +325,11 @@ export default class Camera {
|
||||
* @param {number} height framebuffer height
|
||||
*/
|
||||
extractView(out, width, height) {
|
||||
if (this._framebuffer) {
|
||||
width = this._framebuffer._width;
|
||||
height = this._framebuffer._height;
|
||||
}
|
||||
|
||||
// priority
|
||||
out._priority = this._priority;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user