mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
add GFXDevice.copyFramebufferToBuffer()
This commit is contained in:
@@ -733,6 +733,17 @@ class quat {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a quaternion back to euler angle (in degrees).
|
||||
*
|
||||
* @param {vec3} out - Euler angle stored as a vec3
|
||||
* @param {number} q - the quaternion to be converted
|
||||
* @returns {vec3} out.
|
||||
*/
|
||||
static toAxisX(out) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a quaternion back to euler angle (in degrees).
|
||||
*
|
||||
|
||||
@@ -47,6 +47,7 @@ export abstract class GFXDevice {
|
||||
|
||||
public abstract copyBufferToTexture(buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
|
||||
public abstract copyImageSourceToTexture(source: CanvasImageSource, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
|
||||
public abstract copyFramebufferToBuffer(srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]);
|
||||
|
||||
public get canvas(): HTMLCanvasElement {
|
||||
return <HTMLCanvasElement>this._canvas;
|
||||
|
||||
@@ -30,6 +30,10 @@ export abstract class GFXFramebuffer {
|
||||
return this._depthStencilView;
|
||||
}
|
||||
|
||||
public get isOffscreen(): boolean {
|
||||
return this._isOffscreen;
|
||||
}
|
||||
|
||||
protected _device: GFXDevice;
|
||||
protected _renderPass: GFXRenderPass | null = null;
|
||||
protected _colorViews: GFXTextureView[] = [];
|
||||
|
||||
@@ -31,7 +31,7 @@ import { WebGLGFXFramebuffer } from './webgl-framebuffer';
|
||||
import { WebGLGFXInputAssembler } from './webgl-input-assembler';
|
||||
import { GFXWindow, GFXWindowInfo } from '../window';
|
||||
import { WebGLGFXWindow } from './webgl-window';
|
||||
import { GFXBindingType, GFXFilter, GFXAddress, GFXTextureType, GFXTextureFlagBit, GFXTextureViewType, GFXBufferUsageBit, GFXQueueType, GFXFormat, GFXBufferTextureCopy, GFXMemoryUsageBit, GFXTextureLayout, GFXTextureSubres, GFXRect, GFXFormatInfos } from '../define';
|
||||
import { GFXBindingType, GFXFilter, GFXAddress, GFXTextureType, GFXTextureFlagBit, GFXTextureViewType, GFXBufferUsageBit, GFXQueueType, GFXFormat, GFXBufferTextureCopy, GFXMemoryUsageBit, GFXTextureLayout, GFXTextureSubres, GFXRect, GFXFormatInfos, GFXFormatSize } from '../define';
|
||||
import { WebGLGFXBindingLayout } from './webgl-binding-layout';
|
||||
|
||||
const WebGLPrimitives: GLenum[] = [
|
||||
@@ -408,6 +408,38 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
}
|
||||
}
|
||||
|
||||
public copyFramebufferToBuffer(srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]) {
|
||||
let gl = <WebGLRenderingContext>this._webGLRC;
|
||||
let gpuFramebuffer = (<WebGLGFXFramebuffer>srcFramebuffer).gpuFramebuffer;
|
||||
|
||||
let curFBO = this.stateCache.glFramebuffer;
|
||||
|
||||
if (this.stateCache.glFramebuffer !== gpuFramebuffer.glFramebuffer) {
|
||||
gl.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
|
||||
this.stateCache.glFramebuffer = gpuFramebuffer.glFramebuffer;
|
||||
}
|
||||
|
||||
let view = new Uint8Array(dstBuffer);
|
||||
|
||||
for (let r = 0; r < regions.length; ++r) {
|
||||
let region = regions[r];
|
||||
let buffOffset = region.buffOffset; + region.buffTexHeight * region.buffStride;
|
||||
|
||||
let w = region.texExtent.width;
|
||||
let h = region.texExtent.height;
|
||||
|
||||
let memSize = GFXFormatSize(GFXFormat.RGBA8, w, h, 1);
|
||||
let data = view.subarray(buffOffset, buffOffset + memSize);
|
||||
|
||||
gl.readPixels(region.texOffset.x, region.texOffset.y, w, h, WebGLRenderingContext.RGBA, WebGLRenderingContext.UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
if (this.stateCache.glFramebuffer !== curFBO) {
|
||||
gl.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER, curFBO);
|
||||
this.stateCache.glFramebuffer = curFBO;
|
||||
}
|
||||
}
|
||||
|
||||
public get gl(): WebGLRenderingContext {
|
||||
return <WebGLRenderingContext>this._webGLRC;
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuFramebuffer() : WebGLGPUFramebuffer | null {
|
||||
return this._gpuFramebuffer;
|
||||
public get gpuFramebuffer() : WebGLGPUFramebuffer {
|
||||
return <WebGLGPUFramebuffer>this._gpuFramebuffer;
|
||||
}
|
||||
|
||||
private _gpuFramebuffer : WebGLGPUFramebuffer | null = null;
|
||||
|
||||
Reference in New Issue
Block a user