fix resize bug

This commit is contained in:
jerrywwl
2019-04-03 02:22:43 +08:00
parent fc645bd8dc
commit 8dfe881a23
11 changed files with 270 additions and 116 deletions
+3 -2
View File
@@ -701,8 +701,9 @@ class Game extends EventTarget {
this._gfxDevice.initialize({
canvasElm: localCanvas,
debug: true,
nativeWidth: screen.width,
nativeHeight: screen.height,
devicePixelRatio: window.devicePixelRatio,
nativeWidth: screen.width * window.devicePixelRatio,
nativeHeight: screen.height * window.devicePixelRatio,
});
}
+6
View File
@@ -35,6 +35,7 @@ export interface IGFXDeviceInfo {
isAntialias?: boolean;
isPremultipliedAlpha?: boolean;
debug?: boolean;
devicePixelRatio?: number;
nativeWidth?: number;
nativeHeight?: number;
}
@@ -58,6 +59,10 @@ export abstract class GFXDevice {
return this._queue as GFXQueue;
}
public get devicePixelRatio (): number {
return this._devicePixelRatio;
}
public get width (): number {
return this._width;
}
@@ -151,6 +156,7 @@ export abstract class GFXDevice {
protected _version: string = '';
protected _features: boolean[] = new Array<boolean>(GFXFeature.COUNT);
protected _queue: GFXQueue | null = null;
protected _devicePixelRatio: number = 1.0;
protected _width: number = 0;
protected _height: number = 0;
protected _nativeWidth: number = 0;
+2 -1
View File
@@ -95,5 +95,6 @@ export abstract class GFXTexture extends GFXObject {
}
public abstract initialize (info: IGFXTextureInfo): boolean;
public abstract destroy (): void;
public abstract destroy ();
public abstract resize (width: number, height: number);
}
+85
View File
@@ -901,6 +901,91 @@ export function WebGLCmdFuncDestroyTexture (device: WebGLGFXDevice, gpuTexture:
}
}
export function WebGLCmdFuncResizeTexture (device: WebGLGFXDevice, gpuTexture: WebGLGPUTexture) {
const gl = device.gl;
gpuTexture.glInternelFmt = GFXFormatToWebGLInternalFormat(gpuTexture.format);
gpuTexture.glFormat = GFXFormatToWebGLFormat(gpuTexture.format);
gpuTexture.glType = GFXFormatToWebGLType(gpuTexture.format, device);
switch (gpuTexture.viewType) {
case GFXTextureViewType.TV2D: {
gpuTexture.viewType = GFXTextureViewType.TV2D;
gpuTexture.glTarget = gl.TEXTURE_2D;
if (gpuTexture.samples === GFXSampleCount.X1) {
const glTexUnit = device.stateCache.glTex2DUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(gl.TEXTURE_2D, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
let w = gpuTexture.width;
let h = gpuTexture.height;
if (!GFXFormatInfos[gpuTexture.format].isCompressed) {
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.texImage2D(gl.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
} else {
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.compressedTexImage2D(gl.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
}
}
break;
}
case GFXTextureViewType.CUBE: {
gpuTexture.viewType = GFXTextureViewType.CUBE;
gpuTexture.glTarget = gl.TEXTURE_CUBE_MAP;
const glTexUnit = device.stateCache.glTexCubeUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(gl.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
if (!GFXFormatInfos[gpuTexture.format].isCompressed) {
for (let f = 0; f < 6; ++f) {
let w = gpuTexture.width;
let h = gpuTexture.height;
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
}
} else {
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
for (let f = 0; f < 6; ++f) {
let w = gpuTexture.width;
let h = gpuTexture.height;
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
}
}
break;
}
default: {
console.error('Unsupported GFXTextureType, create texture failed.');
gpuTexture.viewType = GFXTextureViewType.TV2D;
gpuTexture.glTarget = gl.TEXTURE_2D;
}
}
}
export function WebGLCmdFuncCreateFramebuffer (device: WebGLGFXDevice, gpuFramebuffer: WebGLGPUFramebuffer) {
if (gpuFramebuffer.isOffscreen) {
+3 -1
View File
@@ -237,6 +237,7 @@ export class WebGLGFXDevice extends GFXDevice {
this._depthBits = gl.getParameter(WebGLRenderingContext.DEPTH_BITS);
this._stencilBits = gl.getParameter(WebGLRenderingContext.STENCIL_BITS);
this._devicePixelRatio = info.devicePixelRatio || 1.0;
this._width = this._canvas.width;
this._height = this._canvas.height;
this._nativeWidth = Math.max(info.nativeWidth || this._width, 0);
@@ -309,13 +310,14 @@ export class WebGLGFXDevice extends GFXDevice {
console.info('RENDERER: ' + this._renderer);
console.info('VENDOR: ' + this._vendor);
console.info('VERSION: ' + this._version);
console.info('DPR: ' + this._devicePixelRatio);
console.info('SCREEN_SIZE: ' + this._width + ' x ' + this._height);
console.info('NATIVE_SIZE: ' + this._nativeWidth + ' x ' + this._nativeHeight);
// console.info('COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
// console.info('DEPTH_STENCIL_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
// console.info('MAX_VERTEX_ATTRIBS: ' + this._maxVertexAttributes);
console.info('MAX_VERTEX_UNIFORM_VECTORS: ' + this._maxVertexUniformVectors);
console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
// console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
// console.info('MAX_TEXTURE_IMAGE_UNITS: ' + this._maxTextureUnits);
// console.info('MAX_VERTEX_TEXTURE_IMAGE_UNITS: ' + this._maxVertexTextureUnits);
console.info('DEPTH_BITS: ' + this._depthBits);
+17 -1
View File
@@ -1,7 +1,7 @@
import { GFXFormatSurfaceSize, GFXStatus, GFXTextureFlagBit, GFXTextureType, GFXTextureViewType } from '../define';
import { GFXDevice } from '../device';
import { GFXTexture, IGFXTextureInfo } from '../texture';
import { WebGLCmdFuncCreateTexture, WebGLCmdFuncDestroyTexture } from './webgl-commands';
import { WebGLCmdFuncCreateTexture, WebGLCmdFuncDestroyTexture, WebGLCmdFuncResizeTexture } from './webgl-commands';
import { WebGLGFXDevice } from './webgl-device';
import { WebGLGPUTexture } from './webgl-gpu-objects';
@@ -142,4 +142,20 @@ export class WebGLGFXTexture extends GFXTexture {
}
this._status = GFXStatus.UNREADY;
}
public resize (width: number, height: number) {
this._width = width;
this._height = height;
this._size = GFXFormatSurfaceSize(this._format, this.width, this.height,
this.depth, this.mipLevel) * this._arrayLayer;
if (this._gpuTexture) {
this._gpuTexture.width = this._width;
this._gpuTexture.height = this._height;
this._gpuTexture.size = this._size;
WebGLCmdFuncResizeTexture(this._device as WebGLGFXDevice, this._gpuTexture);
this._gpuTexture = null;
}
this._status = GFXStatus.UNREADY;
}
}
+96 -53
View File
@@ -1075,6 +1075,102 @@ export function WebGL2CmdFuncDestroyTexture (device: WebGL2GFXDevice, gpuTexture
}
}
export function WebGL2CmdFuncResizeTexture (device: WebGL2GFXDevice, gpuTexture: WebGL2GPUTexture) {
const gl = device.gl;
gpuTexture.glInternelFmt = GFXFormatToWebGLInternalFormat(gpuTexture.format);
gpuTexture.glFormat = GFXFormatToWebGLFormat(gpuTexture.format);
gpuTexture.glType = GFXFormatToWebGLType(gpuTexture.format, device);
switch (gpuTexture.viewType) {
case GFXTextureViewType.TV2D: {
gpuTexture.viewType = GFXTextureViewType.TV2D;
gpuTexture.glTarget = WebGL2RenderingContext.TEXTURE_2D;
if (gpuTexture.samples === GFXSampleCount.X1) {
const glTexUnit = device.stateCache.glTex2DUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(WebGL2RenderingContext.TEXTURE_2D, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
let w = gpuTexture.width;
let h = gpuTexture.height;
if (!GFXFormatInfos[gpuTexture.format].isCompressed) {
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.texImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
} else {
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
}
} else {
const glRenderbuffer = gl.createRenderbuffer();
if (glRenderbuffer && gpuTexture.size > 0) {
gpuTexture.glRenderbuffer = glRenderbuffer;
if (device.stateCache.glRenderbuffer !== gpuTexture.glRenderbuffer) {
gl.bindRenderbuffer(WebGL2RenderingContext.RENDERBUFFER, gpuTexture.glRenderbuffer);
device.stateCache.glRenderbuffer = gpuTexture.glRenderbuffer;
}
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, SAMPLES[gpuTexture.samples], gpuTexture.glInternelFmt, gpuTexture.width, gpuTexture.height);
}
}
break;
}
case GFXTextureViewType.CUBE: {
gpuTexture.viewType = GFXTextureViewType.CUBE;
gpuTexture.glTarget = WebGL2RenderingContext.TEXTURE_CUBE_MAP;
const glTexUnit = device.stateCache.glTexCubeUnits[device.stateCache.texUnit];
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
gl.bindTexture(WebGL2RenderingContext.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
glTexUnit.glTexture = gpuTexture.glTexture;
}
if (!GFXFormatInfos[gpuTexture.format].isCompressed) {
for (let f = 0; f < 6; ++f) {
let w = gpuTexture.width;
let h = gpuTexture.height;
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.texImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
}
} else {
const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 };
for (let f = 0; f < 6; ++f) {
let w = gpuTexture.width;
let h = gpuTexture.height;
for (let i = 0; i < gpuTexture.mipLevel; ++i) {
gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view);
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
}
}
break;
}
default: {
console.error('Unsupported GFXTextureType, create texture failed.');
gpuTexture.viewType = GFXTextureViewType.TV2D;
gpuTexture.glTarget = WebGL2RenderingContext.TEXTURE_2D;
}
}
}
export function WebGL2CmdFuncCreateSampler (device: WebGL2GFXDevice, gpuSampler: WebGL2GPUSampler) {
const gl = device.gl;
@@ -2144,59 +2240,6 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
}
}
}
/*
for (let a = 0; a < device.maxVertexAttributes; ++a) {
cache.glCurrentAttribLocs[a] = false;
}
let glAttrib: WebGL2Attrib | null;
for (const glInput of gpuShader.glInputs) {
glAttrib = null;
for (const attrib of gpuInputAssembler.glAttribs) {
if (attrib.name === glInput.name) {
glAttrib = attrib;
break;
}
}
if (glAttrib) {
if (cache.glArrayBuffer !== glAttrib.glBuffer) {
gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER, glAttrib.glBuffer);
cache.glArrayBuffer = glAttrib.glBuffer;
}
for (let c = 0; c < glAttrib.componentCount; ++c) {
const glLoc = glInput.glLoc + c;
const attribOffset = glAttrib.offset + glAttrib.size * c;
if (!cache.glEnabledAttribLocs[glLoc] && glLoc >= 0) {
gl.enableVertexAttribArray(glLoc);
cache.glEnabledAttribLocs[glLoc] = true;
}
cache.glCurrentAttribLocs[glLoc] = true;
gl.vertexAttribPointer(glLoc, glAttrib.count, glAttrib.glType, glAttrib.isNormalized, glAttrib.stride, attribOffset);
}
}
} // for
const gpuBuffer = gpuInputAssembler.gpuIndexBuffer;
if (gpuBuffer) {
if (cache.glElementArrayBuffer !== gpuBuffer.glBuffer) {
gl.bindBuffer(WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER, gpuBuffer.glBuffer);
cache.glElementArrayBuffer = gpuBuffer.glBuffer;
}
}
for (let a = 0; a < device.maxVertexAttributes; ++a) {
if (cache.glEnabledAttribLocs[a] !== cache.glCurrentAttribLocs[a]) {
gl.disableVertexAttribArray(a);
cache.glEnabledAttribLocs[a] = false;
}
}
*/
}
if (gpuPipelineState) {
+3 -1
View File
@@ -174,6 +174,7 @@ export class WebGL2GFXDevice extends GFXDevice {
// let maxFragmentUniformBlocks = gl.getParameter(WebGL2RenderingContext.MAX_FRAGMENT_UNIFORM_BLOCKS);
// let uboOffsetAlignment = gl.getParameter(WebGL2RenderingContext.UNIFORM_BUFFER_OFFSET_ALIGNMENT);
this._devicePixelRatio = info.devicePixelRatio || 1.0;
this._width = this._canvas.width;
this._height = this._canvas.height;
this._nativeWidth = Math.max(info.nativeWidth || this._width, 0);
@@ -230,13 +231,14 @@ export class WebGL2GFXDevice extends GFXDevice {
console.info('RENDERER: ' + this._renderer);
console.info('VENDOR: ' + this._vendor);
console.info('VERSION: ' + this._version);
console.info('DPR: ' + this._devicePixelRatio);
console.info('SCREEN_SIZE: ' + this._width + ' x ' + this._height);
console.info('NATIVE_SIZE: ' + this._nativeWidth + ' x ' + this._nativeHeight);
// console.info('COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
// console.info('DEPTH_STENCIL_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
// console.info('MAX_VERTEX_ATTRIBS: ' + this._maxVertexAttributes);
console.info('MAX_VERTEX_UNIFORM_VECTORS: ' + this._maxVertexUniformVectors);
console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
// console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
// console.info('MAX_TEXTURE_IMAGE_UNITS: ' + this._maxTextureUnits);
// console.info('MAX_VERTEX_TEXTURE_IMAGE_UNITS: ' + this._maxVertexTextureUnits);
console.info('MAX_UNIFORM_BUFFER_BINDINGS: ' + this._maxUniformBufferBindings);
+17 -2
View File
@@ -1,7 +1,7 @@
import { GFXFormatSurfaceSize, GFXStatus, GFXTextureFlagBit, GFXTextureType, GFXTextureViewType } from '../define';
import { GFXDevice } from '../device';
import { GFXTexture, IGFXTextureInfo } from '../texture';
import { WebGL2CmdFuncCreateTexture, WebGL2CmdFuncDestroyTexture } from './webgl2-commands';
import { WebGL2CmdFuncCreateTexture, WebGL2CmdFuncDestroyTexture, WebGL2CmdFuncResizeTexture } from './webgl2-commands';
import { WebGL2GFXDevice } from './webgl2-device';
import { WebGL2GPUTexture } from './webgl2-gpu-objects';
@@ -59,7 +59,6 @@ export class WebGL2GFXTexture extends GFXTexture {
}
let viewType: GFXTextureViewType;
switch (info.type) {
case GFXTextureType.TEX1D: {
@@ -142,4 +141,20 @@ export class WebGL2GFXTexture extends GFXTexture {
}
this._status = GFXStatus.UNREADY;
}
public resize (width: number, height: number) {
this._width = width;
this._height = height;
this._size = GFXFormatSurfaceSize(this._format, this.width, this.height,
this.depth, this.mipLevel) * this._arrayLayer;
if (this._gpuTexture) {
this._gpuTexture.width = this._width;
this._gpuTexture.height = this._height;
this._gpuTexture.size = this._size;
WebGL2CmdFuncResizeTexture(this._device as WebGL2GFXDevice, this._gpuTexture);
this._gpuTexture = null;
}
this._status = GFXStatus.UNREADY;
}
}
+2 -2
View File
@@ -52,8 +52,8 @@ export class ForwardStage extends RenderStage {
const vp = camera.viewport;
this._renderArea.x = vp.x * camera.width;
this._renderArea.y = vp.y * camera.height;
this._renderArea.width = vp.width * camera.width;
this._renderArea.height = vp.height * camera.height;
this._renderArea.width = vp.width * camera.width * this.pipeline.shadingScale;
this._renderArea.height = vp.height * camera.height * this.pipeline.shadingScale;
if (camera.clearFlag & GFXClearFlag.COLOR) {
colors[0] = camera.clearColor;
+36 -53
View File
@@ -37,7 +37,8 @@ const _outMat = new Mat4();
export interface IRenderPipelineInfo {
enableHDR?: boolean;
enableAA?: boolean;
enableMSAA?: boolean;
enableSMAA?: boolean;
}
export abstract class RenderPipeline {
@@ -66,6 +67,10 @@ export abstract class RenderPipeline {
return this._isHDR;
}
public get shadingScale (): number {
return this._shadingScale;
}
public set lightMeterScale (scale: number) {
this._lightMeterScale = scale;
}
@@ -166,6 +171,8 @@ export abstract class RenderPipeline {
protected _msaaDepthStencilTexView: GFXTextureView | null = null;
protected _msaaShadingFBO: GFXFramebuffer | null = null;
protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN;
protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN;
protected _shadingTextures: GFXTexture[] = [];
protected _shadingTexViews: GFXTextureView[] = [];
protected _depthStencilTex: GFXTexture | null = null;
@@ -173,6 +180,7 @@ export abstract class RenderPipeline {
protected _shadingFBOs: GFXFramebuffer[] = [];
protected _shadingTexWidth: number = 0.0;
protected _shadingTexHeight: number = 0.0;
protected _shadingScale: number = 1.0;
protected _curIdx: number = 0;
protected _prevIdx: number = 1;
protected _useMSAA: boolean = false;
@@ -303,71 +311,46 @@ export abstract class RenderPipeline {
this._shadingTexViews = new Array<GFXTextureView>(this._fboCount);
this._shadingFBOs = new Array<GFXFramebuffer>(this._fboCount);
let colorFmt: GFXFormat;
let depthStencilFmt: GFXFormat;
const enableHDR = (info.enableHDR !== undefined ? info.enableHDR : true);
if (enableHDR && this._isHDRSupported) {
// Try to use HDR format
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F)) {
colorFmt = GFXFormat.R11G11B10F;
this._colorFmt = GFXFormat.R11G11B10F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT)) {
colorFmt = GFXFormat.RGBA16F;
this._colorFmt = GFXFormat.RGBA16F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
colorFmt = GFXFormat.RGBA32F;
this._colorFmt = GFXFormat.RGBA32F;
this._isHDR = true;
} else {
colorFmt = GFXFormat.RGBA8;
this._colorFmt = GFXFormat.RGBA8;
this._isHDR = false;
console.error('RenderPipeline doesn\'t support HDR.');
}
} else { // Fallback to LDR
colorFmt = GFXFormat.RGBA8;
this._colorFmt = GFXFormat.RGBA8;
this._isHDR = false;
if (this._useSMAA && this._device.hasFeature(GFXFeature.MSAA)) {
this._useMSAA = true;
this._useSMAA = false;
}
}
// Config Anti-Aliasing
if (info.enableAA === false) {
this._useMSAA = false;
this._useSMAA = false;
} else {
if (this._isHDR) {
this._useSMAA = true;
} else {
if (this._device.hasFeature(GFXFeature.MSAA)){
this._useMSAA = true;
} else {
this._useSMAA = true;
}
}
this._useSMAA = info.enableSMAA !== undefined ? info.enableSMAA : false;
this._useMSAA = info.enableMSAA !== undefined ? info.enableMSAA : false;
if (this._useMSAA) {
this._useMSAA = this.device.hasFeature(GFXFeature.MSAA);
}
// this._useSMAA = false;
if (this._device.hasFeature(GFXFeature.FORMAT_D24S8)) {
depthStencilFmt = GFXFormat.D24S8;
this._depthStencilFmt = GFXFormat.D24S8;
} else {
depthStencilFmt = GFXFormat.D16;
this._depthStencilFmt = GFXFormat.D16;
}
this.updateMacros();
// colorFmt = GFXFormat.RGBA16F;
const scale = 1.0;
const texWidth = Math.min(this._device.width * scale, 2048);
const texHeight = Math.min(this._device.height * scale, 2048);
let screenScale = Math.min(texWidth / this._device.width, texHeight / this._device.height);
screenScale = Math.min(scale, screenScale);
// this._shadingTexWidth = Math.floor(this._device.width * screenScale);
// this._shadingTexHeight = Math.floor(this._device.height * screenScale);
this._shadingScale = this._device.devicePixelRatio;
this._shadingTexWidth = this._device.nativeWidth;
this._shadingTexHeight = this._device.nativeHeight;
@@ -375,13 +358,13 @@ export abstract class RenderPipeline {
console.info('USE_SMAA: ' + this._useSMAA);
console.info('CC_USE_HDR: ' + this._isHDR);
console.info('SHADING_SIZE: ' + this._shadingTexWidth + ' x ' + this._shadingTexHeight);
console.info('SCREEN_SCALE: ' + screenScale);
console.info('SHADING_COLOR_FORMAT: ' + GFXFormatInfos[colorFmt].name);
console.info('SHADING_DEPTH_FORMAT: ' + GFXFormatInfos[depthStencilFmt].name);
console.info('SCREEN_SCALE: ' + this._shadingScale.toFixed(2));
console.info('SHADING_COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
console.info('SHADING_DEPTH_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
this._shadingPass = this._device.createRenderPass({
colorAttachments: [{
format: colorFmt,
format: this._colorFmt,
loadOp: GFXLoadOp.CLEAR,
storeOp: GFXStoreOp.STORE,
sampleCount: 1,
@@ -389,7 +372,7 @@ export abstract class RenderPipeline {
endLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL,
}],
depthStencilAttachment: {
format : depthStencilFmt,
format : this._depthStencilFmt,
depthLoadOp : GFXLoadOp.CLEAR,
depthStoreOp : GFXStoreOp.STORE,
stencilLoadOp : GFXLoadOp.CLEAR,
@@ -404,26 +387,26 @@ export abstract class RenderPipeline {
this._msaaShadingTex = this._device.createTexture({
type: GFXTextureType.TEX2D,
usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format: colorFmt,
format: this._colorFmt,
width: this._shadingTexWidth,
height: this._shadingTexHeight,
});
this._msaaShadingTexView = this._device.createTextureView({
texture : this._msaaShadingTex,
type : GFXTextureViewType.TV2D,
format : colorFmt,
format : this._colorFmt,
});
this._msaaDepthStencilTex = this._device.createTexture({
type : GFXTextureType.TEX2D,
usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format : depthStencilFmt,
format : this._depthStencilFmt,
width : this._shadingTexWidth,
height : this._shadingTexHeight,
});
this._msaaDepthStencilTexView = this._device.createTextureView({
texture : this._msaaDepthStencilTex,
type : GFXTextureViewType.TV2D,
format : depthStencilFmt,
format : this._depthStencilFmt,
});
this._msaaShadingFBO = this._device.createFramebuffer({
renderPass: this._shadingPass,
@@ -435,7 +418,7 @@ export abstract class RenderPipeline {
this._depthStencilTex = this._device.createTexture({
type : GFXTextureType.TEX2D,
usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format : depthStencilFmt,
format : this._depthStencilFmt,
width : this._shadingTexWidth,
height : this._shadingTexHeight,
});
@@ -443,14 +426,14 @@ export abstract class RenderPipeline {
this._depthStencilTexView = this._device.createTextureView({
texture : this._depthStencilTex,
type : GFXTextureViewType.TV2D,
format : depthStencilFmt,
format : this._depthStencilFmt,
});
for (let i = 0; i < this._fboCount; ++i) {
this._shadingTextures[i] = this._device.createTexture({
type: GFXTextureType.TEX2D,
usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format: colorFmt,
format: this._colorFmt,
width: this._shadingTexWidth,
height: this._shadingTexHeight,
});
@@ -458,7 +441,7 @@ export abstract class RenderPipeline {
this._shadingTexViews[i] = this._device.createTextureView({
texture : this._shadingTextures[i],
type : GFXTextureViewType.TV2D,
format : colorFmt,
format : this._colorFmt,
});
this._shadingFBOs[i] = this._device.createFramebuffer({
@@ -790,8 +773,8 @@ export abstract class RenderPipeline {
_vec4Array[3] = 1.0 / _vec4Array[1];
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.SCREEN_SIZE_OFFSET);
_vec4Array[0] = camera.width / this._shadingTexWidth;
_vec4Array[1] = camera.height / this._shadingTexHeight;
_vec4Array[0] = camera.width / this._shadingTexWidth * this._shadingScale;
_vec4Array[1] = camera.height / this._shadingTexHeight * this._shadingScale;
_vec4Array[2] = 1.0 / _vec4Array[0];
_vec4Array[3] = 1.0 / _vec4Array[1];
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.SCREEN_SCALE_OFFSET);