mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix webgl state cache error
This commit is contained in:
+2
-2
@@ -2,7 +2,7 @@ import { GFXBindingLayout, IGFXBindingLayoutInfo } from './binding-layout';
|
||||
import { GFXBuffer, IGFXBufferInfo } from './buffer';
|
||||
import { GFXCommandAllocator, IGFXCommandAllocatorInfo } from './command-allocator';
|
||||
import { GFXCommandBuffer, IGFXCommandBufferInfo } from './command-buffer';
|
||||
import { GFX_MAX_BUFFER_BINDINGS, GFXBufferTextureCopy, GFXFormat, IGFXRect, GFXFilter } from './define';
|
||||
import { GFX_MAX_BUFFER_BINDINGS, GFXBufferTextureCopy, GFXFilter, GFXFormat, IGFXRect } from './define';
|
||||
import { GFXFramebuffer, IGFXFramebufferInfo } from './framebuffer';
|
||||
import { GFXInputAssembler, IGFXInputAssemblerInfo } from './input-assembler';
|
||||
import { GFXPipelineLayout, IGFXPipelineLayoutInfo } from './pipeline-layout';
|
||||
@@ -206,7 +206,7 @@ export abstract class GFXDevice {
|
||||
}
|
||||
|
||||
public defineMacro (macro: string, value?: string) {
|
||||
const val = (value !== undefined? value : '');
|
||||
const val = (value !== undefined ? value : '');
|
||||
this._macros.set(macro, val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
vf32: null,
|
||||
indirects: [],
|
||||
glTarget: 0,
|
||||
glBuffer: 0,
|
||||
glBuffer: null,
|
||||
};
|
||||
|
||||
if (info.usage & GFXBufferUsageBit.INDIRECT) {
|
||||
|
||||
@@ -586,9 +586,9 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (device.useVAO) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
|
||||
gl.bufferData(WebGLRenderingContext.ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, null);
|
||||
device.stateCache.glArrayBuffer = 0;
|
||||
device.stateCache.glArrayBuffer = null;
|
||||
}
|
||||
}
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.INDEX) {
|
||||
@@ -611,9 +611,9 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (device.useVAO) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +624,7 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
|
||||
gl.bufferData(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, null);
|
||||
device.stateCache.glElementArrayBuffer = 0;
|
||||
device.stateCache.glElementArrayBuffer = null;
|
||||
}
|
||||
}
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.UNIFORM) {
|
||||
@@ -647,9 +647,9 @@ export function WebGLCmdFuncCreateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncDestroyBuffer (device: WebGLGFXDevice, gpuBuffer: WebGLGPUBuffer) {
|
||||
if (gpuBuffer.glBuffer !== 0) {
|
||||
if (gpuBuffer.glBuffer) {
|
||||
device.gl.deleteBuffer(gpuBuffer.glBuffer);
|
||||
gpuBuffer.glBuffer = 0;
|
||||
gpuBuffer.glBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,9 +661,9 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
|
||||
if (gpuBuffer.usage & GFXBufferUsageBit.VERTEX) {
|
||||
if (device.useVAO) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,12 +673,12 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
|
||||
gl.bufferData(WebGLRenderingContext.ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, null);
|
||||
device.stateCache.glArrayBuffer = 0;
|
||||
device.stateCache.glArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.INDEX) {
|
||||
if (device.useVAO) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ export function WebGLCmdFuncResizeBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
|
||||
gl.bufferData(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, null);
|
||||
device.stateCache.glElementArrayBuffer = 0;
|
||||
device.stateCache.glElementArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.UNIFORM) {
|
||||
// console.error("WebGL 1.0 doesn't support uniform buffer.");
|
||||
if (gpuBuffer.buffer) {
|
||||
@@ -722,9 +722,9 @@ export function WebGLCmdFuncUpdateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
switch (gpuBuffer.glTarget) {
|
||||
case WebGLRenderingContext.ARRAY_BUFFER: {
|
||||
if (device.useVAO) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,9 +736,9 @@ export function WebGLCmdFuncUpdateBuffer (device: WebGLGFXDevice, gpuBuffer: Web
|
||||
}
|
||||
case WebGLRenderingContext.ELEMENT_ARRAY_BUFFER: {
|
||||
if (device.useVAO) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
device.OES_vertex_array_object!.bindVertexArrayOES(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,14 +890,14 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncDestroyTexture (device: WebGLGFXDevice, gpuTexture: WebGLGPUTexture) {
|
||||
if (gpuTexture.glTexture !== 0) {
|
||||
if (gpuTexture.glTexture) {
|
||||
device.gl.deleteTexture(gpuTexture.glTexture);
|
||||
gpuTexture.glTexture = 0;
|
||||
gpuTexture.glTexture = null;
|
||||
}
|
||||
|
||||
if (gpuTexture.glRenderbuffer !== 0) {
|
||||
if (gpuTexture.glRenderbuffer) {
|
||||
device.gl.deleteRenderbuffer(gpuTexture.glRenderbuffer);
|
||||
gpuTexture.glRenderbuffer = 0;
|
||||
gpuTexture.glRenderbuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,7 +921,7 @@ export function WebGLCmdFuncCreateFramebuffer (device: WebGLGFXDevice, gpuFrameb
|
||||
|
||||
const cv = gpuFramebuffer.gpuColorViews[i];
|
||||
if (cv) {
|
||||
if (cv.gpuTexture.glTexture !== 0) {
|
||||
if (cv.gpuTexture.glTexture) {
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.COLOR_ATTACHMENT0 + i,
|
||||
@@ -944,7 +944,7 @@ export function WebGLCmdFuncCreateFramebuffer (device: WebGLGFXDevice, gpuFrameb
|
||||
const dsv = gpuFramebuffer.gpuDepthStencilView;
|
||||
if (dsv) {
|
||||
const glAttachment = GFXFormatInfos[dsv.format].hasStencil ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
|
||||
if (dsv.gpuTexture.glTexture !== 0) {
|
||||
if (dsv.gpuTexture.glTexture) {
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
glAttachment,
|
||||
@@ -992,9 +992,9 @@ export function WebGLCmdFuncCreateFramebuffer (device: WebGLGFXDevice, gpuFrameb
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncDestroyFramebuffer (device: WebGLGFXDevice, gpuFramebuffer: WebGLGPUFramebuffer) {
|
||||
if (gpuFramebuffer.glFramebuffer !== 0) {
|
||||
if (gpuFramebuffer.glFramebuffer) {
|
||||
device.gl.deleteFramebuffer(gpuFramebuffer.glFramebuffer);
|
||||
gpuFramebuffer.glFramebuffer = 0;
|
||||
gpuFramebuffer.glFramebuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1035,7 +1035,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLGFXDevice, gpuShader: Web
|
||||
console.error(gl.getShaderInfoLog(gpuStage.glShader));
|
||||
|
||||
gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
gpuStage.glShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1049,7 +1049,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLGFXDevice, gpuShader: Web
|
||||
|
||||
// link program
|
||||
for (const gpuStage of gpuShader.gpuStages) {
|
||||
gl.attachShader(gpuShader.glProgram, gpuStage.glShader);
|
||||
gl.attachShader(gpuShader.glProgram, gpuStage.glShader!);
|
||||
}
|
||||
|
||||
gl.linkProgram(gpuShader.glProgram);
|
||||
@@ -1060,9 +1060,9 @@ export function WebGLCmdFuncCreateShader (device: WebGLGFXDevice, gpuShader: Web
|
||||
console.error(gl.getProgramInfoLog(gpuShader.glProgram));
|
||||
|
||||
for (const gpuStage of gpuShader.gpuStages) {
|
||||
if (gpuStage.glShader !== 0) {
|
||||
if (gpuStage.glShader) {
|
||||
gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
gpuStage.glShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1267,15 +1267,15 @@ export function WebGLCmdFuncCreateShader (device: WebGLGFXDevice, gpuShader: Web
|
||||
export function WebGLCmdFuncDestroyShader (device: WebGLGFXDevice, gpuShader: WebGLGPUShader) {
|
||||
|
||||
for (const gpuStage of gpuShader.gpuStages) {
|
||||
if (gpuStage.glShader !== 0) {
|
||||
if (gpuStage.glShader) {
|
||||
device.gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
gpuStage.glShader = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (gpuShader.glProgram !== 0) {
|
||||
if (gpuShader.glProgram) {
|
||||
device.gl.deleteProgram(gpuShader.glProgram);
|
||||
gpuShader.glProgram = 0;
|
||||
gpuShader.glProgram = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1346,8 +1346,7 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
|
||||
|
||||
if (cmd0.gpuFramebuffer) {
|
||||
if (cache.glFramebuffer !== cmd0.gpuFramebuffer.glFramebuffer) {
|
||||
const glFBO = (cmd0.gpuFramebuffer.glFramebuffer !== 0 ? cmd0.gpuFramebuffer.glFramebuffer : null);
|
||||
gl.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER, glFBO);
|
||||
gl.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER, cmd0.gpuFramebuffer.glFramebuffer);
|
||||
cache.glFramebuffer = cmd0.gpuFramebuffer.glFramebuffer;
|
||||
}
|
||||
|
||||
@@ -1951,31 +1950,38 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
|
||||
if (glSampler) {
|
||||
for (const texUnit of glSampler.units) {
|
||||
|
||||
if (cache.texUnit !== texUnit) {
|
||||
gl.activeTexture(WebGLRenderingContext.TEXTURE0 + texUnit);
|
||||
cache.texUnit = texUnit;
|
||||
}
|
||||
|
||||
let glTexUnit: IWebGLTexUnit | null = null;
|
||||
|
||||
if (gpuBinding.gpuTexView &&
|
||||
gpuBinding.gpuTexView.gpuTexture.glTexture !== 0 &&
|
||||
gpuBinding.gpuTexView.gpuTexture.size > 0) {
|
||||
|
||||
if (cache.texUnit !== texUnit) {
|
||||
gl.activeTexture(WebGLRenderingContext.TEXTURE0 + texUnit);
|
||||
cache.texUnit = texUnit;
|
||||
}
|
||||
|
||||
const gpuTexture = gpuBinding.gpuTexView.gpuTexture;
|
||||
switch (glSampler.glType) {
|
||||
case WebGLRenderingContext.SAMPLER_2D: {
|
||||
case gl.SAMPLER_2D: {
|
||||
glTexUnit = cache.glTex2DUnits[texUnit];
|
||||
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
|
||||
gl.bindTexture(WebGLRenderingContext.TEXTURE_2D, gpuTexture.glTexture);
|
||||
if (gpuTexture.glTexture) {
|
||||
gl.bindTexture(gl.TEXTURE_2D, gpuTexture.glTexture);
|
||||
} else {
|
||||
gl.bindTexture(gl.TEXTURE_2D, device.nullTex2D!.gpuTexture.glTexture);
|
||||
}
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WebGLRenderingContext.SAMPLER_CUBE: {
|
||||
case gl.SAMPLER_CUBE: {
|
||||
glTexUnit = cache.glTexCubeUnits[texUnit];
|
||||
|
||||
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
|
||||
gl.bindTexture(WebGLRenderingContext.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
|
||||
if (gpuTexture.glTexture) {
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
|
||||
} else {
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, device.nullTexCube!.gpuTexture.glTexture);
|
||||
}
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
break;
|
||||
@@ -2046,15 +2052,15 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
|
||||
const vao = device.OES_vertex_array_object!;
|
||||
|
||||
// check vao
|
||||
const glVAO = gpuInputAssembler.glVAOs.get(gpuShader.glProgram);
|
||||
const glVAO = gpuInputAssembler.glVAOs.get(gpuShader.glProgram!);
|
||||
if (glVAO) {
|
||||
if (cache.glVAO !== glVAO) {
|
||||
vao.bindVertexArrayOES(glVAO);
|
||||
cache.glVAO = glVAO;
|
||||
}
|
||||
} else {
|
||||
const _glVAO = vao.createVertexArrayOES()!;
|
||||
gpuInputAssembler.glVAOs.set(gpuShader.glProgram, _glVAO);
|
||||
const _glVAO = vao.createVertexArrayOES();
|
||||
gpuInputAssembler.glVAOs.set(gpuShader.glProgram!, _glVAO!);
|
||||
|
||||
vao.bindVertexArrayOES(_glVAO);
|
||||
cache.glVAO = _glVAO;
|
||||
|
||||
@@ -4,11 +4,14 @@ import { GFXCommandAllocator, IGFXCommandAllocatorInfo } from '../command-alloca
|
||||
import { GFXCommandBuffer, IGFXCommandBufferInfo } from '../command-buffer';
|
||||
import {
|
||||
GFXBufferTextureCopy,
|
||||
GFXFilter,
|
||||
GFXFormat,
|
||||
GFXFormatSize,
|
||||
GFXQueueType,
|
||||
GFXTextureFlagBit,
|
||||
GFXTextureType,
|
||||
GFXTextureUsageBit,
|
||||
IGFXRect,
|
||||
GFXFilter,
|
||||
} from '../define';
|
||||
import { GFXAPI, GFXDevice, GFXFeature, IGFXDeviceInfo } from '../device';
|
||||
import { GFXFramebuffer, IGFXFramebufferInfo } from '../framebuffer';
|
||||
@@ -143,6 +146,8 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
}
|
||||
|
||||
public stateCache: WebGLStateCache = new WebGLStateCache();
|
||||
public nullTex2D: WebGLGFXTexture | null = null;
|
||||
public nullTexCube: WebGLGFXTexture | null = null;
|
||||
|
||||
private _webGLRC: WebGLRenderingContext | null = null;
|
||||
private _isAntialias: boolean = true;
|
||||
@@ -339,11 +344,74 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
this._cmdAllocator = this.createCommandAllocator({});
|
||||
|
||||
// create default null texture
|
||||
this.nullTex2D = new WebGLGFXTexture(this);
|
||||
this.nullTex2D.initialize({
|
||||
type: GFXTextureType.TEX2D,
|
||||
usage: GFXTextureUsageBit.SAMPLED,
|
||||
format: GFXFormat.RGBA8,
|
||||
width: 2,
|
||||
height: 2,
|
||||
flags: GFXTextureFlagBit.GEN_MIPMAP,
|
||||
});
|
||||
|
||||
this.nullTexCube = new WebGLGFXTexture(this);
|
||||
this.nullTexCube.initialize({
|
||||
type: GFXTextureType.TEX2D,
|
||||
usage: GFXTextureUsageBit.SAMPLED,
|
||||
format: GFXFormat.RGBA8,
|
||||
width: 2,
|
||||
height: 2,
|
||||
arrayLayer: 6,
|
||||
flags: GFXTextureFlagBit.CUBEMAP | GFXTextureFlagBit.GEN_MIPMAP,
|
||||
});
|
||||
|
||||
const nullTexRegion: GFXBufferTextureCopy = {
|
||||
buffOffset: 0,
|
||||
buffStride: 0,
|
||||
buffTexHeight: 0,
|
||||
texOffset: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
},
|
||||
texExtent: {
|
||||
width: 2,
|
||||
height: 2,
|
||||
depth: 1,
|
||||
},
|
||||
texSubres: {
|
||||
baseMipLevel: 0,
|
||||
levelCount: 1,
|
||||
baseArrayLayer: 0,
|
||||
layerCount: 1,
|
||||
},
|
||||
};
|
||||
|
||||
const nullTexBuff = new Uint8Array(this.nullTex2D.size);
|
||||
nullTexBuff.fill(0);
|
||||
this.copyBuffersToTexture([nullTexBuff], this.nullTex2D, [nullTexRegion]);
|
||||
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
this.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
|
||||
if (this.nullTex2D) {
|
||||
this.nullTex2D.destroy();
|
||||
this.nullTex2D = null;
|
||||
}
|
||||
|
||||
if (this.nullTexCube) {
|
||||
this.nullTexCube.destroy();
|
||||
this.nullTexCube = null;
|
||||
}
|
||||
|
||||
if (this._mainWindow) {
|
||||
this._mainWindow.destroy();
|
||||
this._mainWindow = null;
|
||||
|
||||
@@ -45,7 +45,7 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer {
|
||||
gpuColorViews,
|
||||
gpuDepthStencilView,
|
||||
isOffscreen: this._isOffscreen,
|
||||
glFramebuffer: 0,
|
||||
glFramebuffer: null,
|
||||
};
|
||||
|
||||
WebGLCmdFuncCreateFramebuffer(this._device as WebGLGFXDevice, this._gpuFramebuffer);
|
||||
@@ -55,7 +55,7 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer {
|
||||
gpuColorViews: [],
|
||||
gpuDepthStencilView: null,
|
||||
isOffscreen: info.isOffscreen,
|
||||
glFramebuffer: 0,
|
||||
glFramebuffer: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
GFXFormat,
|
||||
GFXMemoryUsage,
|
||||
GFXMemoryUsageBit,
|
||||
GFXSampleCount,
|
||||
GFXShaderType,
|
||||
GFXTextureFlagBit,
|
||||
GFXTextureFlags,
|
||||
@@ -15,7 +16,6 @@ import {
|
||||
GFXTextureUsageBit,
|
||||
GFXTextureViewType,
|
||||
GFXType,
|
||||
GFXSampleCount,
|
||||
} from '../define';
|
||||
import { IGFXInputAttribute } from '../input-assembler';
|
||||
import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState } from '../pipeline-state';
|
||||
@@ -38,7 +38,7 @@ export class WebGLGPUBuffer {
|
||||
public stride: number = 0;
|
||||
|
||||
public glTarget: GLenum = 0;
|
||||
public glBuffer: WebGLBuffer = 0;
|
||||
public glBuffer: WebGLBuffer | null = null;
|
||||
public buffer: ArrayBuffer | null = null;
|
||||
public vf32: Float32Array | null = null;
|
||||
public indirects: IGFXDrawInfo[] = [];
|
||||
@@ -64,8 +64,8 @@ export class WebGLGPUTexture {
|
||||
public glFormat: GLenum = 0;
|
||||
public glType: GLenum = 0;
|
||||
public glUsage: GLenum = 0;
|
||||
public glTexture: WebGLTexture = 0;
|
||||
public glRenderbuffer: WebGLRenderbuffer = 0;
|
||||
public glTexture: WebGLTexture | null = null;
|
||||
public glRenderbuffer: WebGLRenderbuffer | null = null;
|
||||
public glWrapS: GLenum = 0;
|
||||
public glWrapT: GLenum = 0;
|
||||
public glMinFilter: GLenum = 0;
|
||||
@@ -98,7 +98,7 @@ export class WebGLGPUFramebuffer {
|
||||
public gpuDepthStencilView: WebGLGPUTextureView | null = null;
|
||||
public isOffscreen?: boolean = false;
|
||||
|
||||
public glFramebuffer: WebGLFramebuffer = 0;
|
||||
public glFramebuffer: WebGLFramebuffer | null = null;
|
||||
|
||||
constructor (gpuRenderPass: WebGLGPURenderPass) {
|
||||
this.gpuRenderPass = gpuRenderPass;
|
||||
@@ -165,7 +165,7 @@ export class WebGLGPUShaderStage {
|
||||
public type: GFXShaderType = GFXShaderType.VERTEX;
|
||||
public source: string = '';
|
||||
public macros: IGFXShaderMacro[] = [];
|
||||
public glShader: WebGLShader = 0;
|
||||
public glShader: WebGLShader | null = null;
|
||||
}
|
||||
|
||||
export class WebGLGPUShader {
|
||||
@@ -174,7 +174,7 @@ export class WebGLGPUShader {
|
||||
public samplers: GFXUniformSampler[] = [];
|
||||
|
||||
public gpuStages: WebGLGPUShaderStage[] = [];
|
||||
public glProgram: WebGLProgram = 0;
|
||||
public glProgram: WebGLProgram | null = null;
|
||||
public glInputs: WebGLGPUInput[] = [];
|
||||
public glUniforms: IWebGLGPUUniform[] = [];
|
||||
public glBlocks: WebGLGPUUniformBlock[] = [];
|
||||
@@ -213,7 +213,7 @@ export class WebGLGPUBindingLayout {
|
||||
|
||||
export class WebGLAttrib {
|
||||
public name: string = '';
|
||||
public glBuffer: WebGLBuffer = 0;
|
||||
public glBuffer: WebGLBuffer | null = null;
|
||||
public glType: GLenum = 0;
|
||||
public size: number = 0;
|
||||
public count: number = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ export class WebGLGFXShader extends GFXShader {
|
||||
samplers: (info.samplers !== undefined ? info.samplers : []),
|
||||
|
||||
gpuStages: new Array<WebGLGPUShaderStage>(info.stages.length),
|
||||
glProgram: 0,
|
||||
glProgram: null,
|
||||
glInputs: [],
|
||||
glUniforms: [],
|
||||
glBlocks: [],
|
||||
@@ -49,7 +49,7 @@ export class WebGLGFXShader extends GFXShader {
|
||||
type: stage.type,
|
||||
source: stage.source,
|
||||
macros: stage.macros ? stage.macros : [],
|
||||
glShader: 0,
|
||||
glShader: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,24 +2,24 @@ import { GFX_MAX_TEXTURE_UNITS, GFX_MAX_VERTEX_ATTRIBUTES, IGFXRect, IGFXViewpor
|
||||
import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState } from '../pipeline-state';
|
||||
|
||||
export interface IWebGLTexUnit {
|
||||
glTexture: WebGLTexture;
|
||||
glTexture: WebGLTexture | null;
|
||||
}
|
||||
|
||||
export class WebGLStateCache {
|
||||
public glArrayBuffer: WebGLBuffer = 0;
|
||||
public glElementArrayBuffer: WebGLBuffer = 0;
|
||||
public glVAO: WebGLVertexArrayObjectOES = 0;
|
||||
public glArrayBuffer: WebGLBuffer | null = null;
|
||||
public glElementArrayBuffer: WebGLBuffer | null = null;
|
||||
public glVAO: WebGLVertexArrayObjectOES | null = null;
|
||||
public texUnit: number = 0;
|
||||
public glTex2DUnits: IWebGLTexUnit[];
|
||||
public glTexCubeUnits: IWebGLTexUnit[];
|
||||
public glRenderbuffer: WebGLRenderbuffer = 0;
|
||||
public glFramebuffer: WebGLFramebuffer = 0;
|
||||
public glRenderbuffer: WebGLRenderbuffer | null = null;
|
||||
public glFramebuffer: WebGLFramebuffer | null = null;
|
||||
public viewport: IGFXViewport;
|
||||
public scissorRect: IGFXRect;
|
||||
public rs: GFXRasterizerState;
|
||||
public dss: GFXDepthStencilState;
|
||||
public bs: GFXBlendState;
|
||||
public glProgram: WebGLProgram = 0;
|
||||
public glProgram: WebGLProgram | null = null;
|
||||
public glEnabledAttribLocs: boolean[];
|
||||
public glCurrentAttribLocs: boolean[];
|
||||
|
||||
@@ -33,19 +33,16 @@ export class WebGLStateCache {
|
||||
this.bs = new GFXBlendState();
|
||||
this.glEnabledAttribLocs = new Array<boolean>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
this.glCurrentAttribLocs = new Array<boolean>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
this.glEnabledAttribLocs.fill(false);
|
||||
this.glCurrentAttribLocs.fill(false);
|
||||
|
||||
for (let i = 0; i < GFX_MAX_TEXTURE_UNITS; ++i) {
|
||||
this.glTex2DUnits[i] = {
|
||||
glTexture: 0,
|
||||
glTexture: null,
|
||||
};
|
||||
this.glTexCubeUnits[i] = {
|
||||
glTexture: 0,
|
||||
glTexture: null,
|
||||
};
|
||||
}
|
||||
|
||||
for (let i = 0; i < GFX_MAX_VERTEX_ATTRIBUTES; ++i) {
|
||||
this.glEnabledAttribLocs[i] = false;
|
||||
this.glCurrentAttribLocs[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ export class WebGLGFXTexture extends GFXTexture {
|
||||
glFormat: 0,
|
||||
glType: 0,
|
||||
glUsage: 0,
|
||||
glTexture: 0,
|
||||
glRenderbuffer: 0,
|
||||
glTexture: null,
|
||||
glRenderbuffer: null,
|
||||
glWrapS: 0,
|
||||
glWrapT: 0,
|
||||
glMinFilter: 0,
|
||||
|
||||
@@ -44,7 +44,7 @@ export class WebGL2GFXBuffer extends GFXBuffer {
|
||||
vf32: null,
|
||||
indirects: [],
|
||||
glTarget: 0,
|
||||
glBuffer: 0,
|
||||
glBuffer: null,
|
||||
};
|
||||
|
||||
if (info.usage & GFXBufferUsageBit.INDIRECT) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { GFXCommandBuffer, IGFXCommandBufferInfo } from '../command-buffer';
|
||||
import {
|
||||
GFXBufferTextureCopy,
|
||||
GFXBufferUsageBit,
|
||||
GFXClearFlag,
|
||||
GFXCommandBufferType,
|
||||
GFXStatus,
|
||||
GFXStencilFace,
|
||||
@@ -11,8 +12,6 @@ import {
|
||||
IGFXColor,
|
||||
IGFXRect,
|
||||
IGFXViewport,
|
||||
GFXClearFlag,
|
||||
GFXFilter,
|
||||
} from '../define';
|
||||
import { GFXDevice } from '../device';
|
||||
import { GFXFramebuffer } from '../framebuffer';
|
||||
@@ -33,7 +32,7 @@ import {
|
||||
} from './webgl2-commands';
|
||||
import { WebGL2GFXDevice } from './webgl2-device';
|
||||
import { WebGL2GFXFramebuffer } from './webgl2-framebuffer';
|
||||
import { WebGL2GPUBindingLayout, IWebGL2GPUInputAssembler, WebGL2GPUPipelineState } from './webgl2-gpu-objects';
|
||||
import { IWebGL2GPUInputAssembler, WebGL2GPUBindingLayout, WebGL2GPUPipelineState } from './webgl2-gpu-objects';
|
||||
import { WebGL2GFXInputAssembler } from './webgl2-input-assembler';
|
||||
import { WebGL2GFXPipelineState } from './webgl2-pipeline-state';
|
||||
import { WebGL2GFXTexture } from './webgl2-texture';
|
||||
|
||||
@@ -727,9 +727,9 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
if (glBuffer) {
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
|
||||
if (device.stateCache.glArrayBuffer !== gpuBuffer.glBuffer) {
|
||||
@@ -740,7 +740,7 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
gl.bufferData(WebGL2RenderingContext.ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
|
||||
gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER, null);
|
||||
device.stateCache.glArrayBuffer = 0;
|
||||
device.stateCache.glArrayBuffer = null;
|
||||
}
|
||||
}
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.INDEX) {
|
||||
@@ -750,9 +750,9 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
if (glBuffer) {
|
||||
gpuBuffer.glBuffer = glBuffer;
|
||||
if (gpuBuffer.size > 0) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
|
||||
if (device.stateCache.glElementArrayBuffer !== gpuBuffer.glBuffer) {
|
||||
@@ -763,7 +763,7 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
gl.bufferData(WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
|
||||
gl.bindBuffer(WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER, null);
|
||||
device.stateCache.glElementArrayBuffer = 0;
|
||||
device.stateCache.glElementArrayBuffer = null;
|
||||
}
|
||||
}
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.UNIFORM) {
|
||||
@@ -780,7 +780,7 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
gl.bufferData(WebGL2RenderingContext.UNIFORM_BUFFER, gpuBuffer.size, glUsage);
|
||||
|
||||
gl.bindBuffer(WebGL2RenderingContext.UNIFORM_BUFFER, null);
|
||||
device.stateCache.glUniformBuffer = 0;
|
||||
device.stateCache.glUniformBuffer = null;
|
||||
}
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.INDIRECT) {
|
||||
gpuBuffer.glTarget = WebGL2RenderingContext.NONE;
|
||||
@@ -795,9 +795,9 @@ export function WebGL2CmdFuncCreateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
}
|
||||
|
||||
export function WebGL2CmdFuncDestroyBuffer (device: WebGL2GFXDevice, gpuBuffer: WebGL2GPUBuffer) {
|
||||
if (gpuBuffer.glBuffer !== 0) {
|
||||
if (gpuBuffer.glBuffer) {
|
||||
device.gl.deleteBuffer(gpuBuffer.glBuffer);
|
||||
gpuBuffer.glBuffer = 0;
|
||||
gpuBuffer.glBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,9 +808,9 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
const glUsage: GLenum = gpuBuffer.memUsage & GFXMemoryUsageBit.HOST ? WebGL2RenderingContext.DYNAMIC_DRAW : WebGL2RenderingContext.STATIC_DRAW;
|
||||
|
||||
if (gpuBuffer.usage & GFXBufferUsageBit.VERTEX) {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
|
||||
if (cache.glArrayBuffer !== gpuBuffer.glBuffer) {
|
||||
@@ -819,12 +819,12 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
|
||||
gl.bufferData(WebGL2RenderingContext.ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER, null);
|
||||
cache.glArrayBuffer = 0;
|
||||
cache.glArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.INDEX) {
|
||||
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
|
||||
if (device.stateCache.glElementArrayBuffer !== gpuBuffer.glBuffer) {
|
||||
@@ -833,7 +833,7 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
|
||||
gl.bufferData(WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER, null);
|
||||
device.stateCache.glElementArrayBuffer = 0;
|
||||
device.stateCache.glElementArrayBuffer = null;
|
||||
} else if (gpuBuffer.usage & GFXBufferUsageBit.UNIFORM) {
|
||||
if (device.stateCache.glUniformBuffer !== gpuBuffer.glBuffer) {
|
||||
gl.bindBuffer(WebGL2RenderingContext.UNIFORM_BUFFER, gpuBuffer.glBuffer);
|
||||
@@ -841,7 +841,7 @@ export function WebGL2CmdFuncResizeBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
|
||||
gl.bufferData(WebGL2RenderingContext.UNIFORM_BUFFER, gpuBuffer.size, glUsage);
|
||||
gl.bindBuffer(WebGL2RenderingContext.UNIFORM_BUFFER, null);
|
||||
device.stateCache.glUniformBuffer = 0;
|
||||
device.stateCache.glUniformBuffer = null;
|
||||
} else if ((gpuBuffer.usage & GFXBufferUsageBit.INDIRECT) ||
|
||||
(gpuBuffer.usage & GFXBufferUsageBit.TRANSFER_DST) ||
|
||||
(gpuBuffer.usage & GFXBufferUsageBit.TRANSFER_SRC)) {
|
||||
@@ -863,9 +863,9 @@ export function WebGL2CmdFuncUpdateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
|
||||
switch (gpuBuffer.glTarget) {
|
||||
case WebGL2RenderingContext.ARRAY_BUFFER: {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
|
||||
if (cache.glArrayBuffer !== gpuBuffer.glBuffer) {
|
||||
@@ -881,9 +881,9 @@ export function WebGL2CmdFuncUpdateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
break;
|
||||
}
|
||||
case WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER: {
|
||||
if (cache.glVAO !== 0) {
|
||||
if (cache.glVAO) {
|
||||
gl.bindVertexArray(null);
|
||||
cache.glVAO = 0;
|
||||
cache.glVAO = null;
|
||||
}
|
||||
|
||||
if (cache.glElementArrayBuffer !== gpuBuffer.glBuffer) {
|
||||
@@ -1064,14 +1064,14 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture:
|
||||
}
|
||||
|
||||
export function WebGL2CmdFuncDestroyTexture (device: WebGL2GFXDevice, gpuTexture: WebGL2GPUTexture) {
|
||||
if (gpuTexture.glTexture !== 0) {
|
||||
if (gpuTexture.glTexture) {
|
||||
device.gl.deleteTexture(gpuTexture.glTexture);
|
||||
gpuTexture.glTexture = 0;
|
||||
gpuTexture.glTexture = null;
|
||||
}
|
||||
|
||||
if (gpuTexture.glRenderbuffer !== 0) {
|
||||
if (gpuTexture.glRenderbuffer) {
|
||||
device.gl.deleteRenderbuffer(gpuTexture.glRenderbuffer);
|
||||
gpuTexture.glRenderbuffer = 0;
|
||||
gpuTexture.glRenderbuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1120,9 +1120,9 @@ export function WebGL2CmdFuncCreateSampler (device: WebGL2GFXDevice, gpuSampler:
|
||||
}
|
||||
|
||||
export function WebGL2CmdFuncDestroySampler (device: WebGL2GFXDevice, gpuSampler: WebGL2GPUSampler) {
|
||||
if (gpuSampler.glSampler !== 0) {
|
||||
if (gpuSampler.glSampler) {
|
||||
device.gl.deleteSampler(gpuSampler.glSampler);
|
||||
gpuSampler.glSampler = 0;
|
||||
gpuSampler.glSampler = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1146,7 +1146,7 @@ export function WebGL2CmdFuncCreateFramebuffer (device: WebGL2GFXDevice, gpuFram
|
||||
|
||||
const cv = gpuFramebuffer.gpuColorViews[i];
|
||||
if (cv) {
|
||||
if (cv.gpuTexture.glTexture !== 0) {
|
||||
if (cv.gpuTexture.glTexture) {
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.COLOR_ATTACHMENT0 + i,
|
||||
@@ -1169,7 +1169,7 @@ export function WebGL2CmdFuncCreateFramebuffer (device: WebGL2GFXDevice, gpuFram
|
||||
const dsv = gpuFramebuffer.gpuDepthStencilView;
|
||||
if (dsv) {
|
||||
const glAttachment = GFXFormatInfos[dsv.format].hasStencil ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
|
||||
if (dsv.gpuTexture.glTexture !== 0) {
|
||||
if (dsv.gpuTexture.glTexture) {
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
glAttachment,
|
||||
@@ -1215,9 +1215,9 @@ export function WebGL2CmdFuncCreateFramebuffer (device: WebGL2GFXDevice, gpuFram
|
||||
}
|
||||
|
||||
export function WebGL2CmdFuncDestroyFramebuffer (device: WebGL2GFXDevice, gpuFramebuffer: WebGL2GPUFramebuffer) {
|
||||
if (gpuFramebuffer.glFramebuffer !== 0) {
|
||||
if (gpuFramebuffer.glFramebuffer) {
|
||||
device.gl.deleteFramebuffer(gpuFramebuffer.glFramebuffer);
|
||||
gpuFramebuffer.glFramebuffer = 0;
|
||||
gpuFramebuffer.glFramebuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1258,7 +1258,7 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2GFXDevice, gpuShader: W
|
||||
console.error(gl.getShaderInfoLog(gpuStage.glShader));
|
||||
|
||||
gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
gpuStage.glShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1272,7 +1272,7 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2GFXDevice, gpuShader: W
|
||||
|
||||
// link program
|
||||
for (const gpuStage of gpuShader.gpuStages) {
|
||||
gl.attachShader(gpuShader.glProgram, gpuStage.glShader);
|
||||
gl.attachShader(gpuShader.glProgram, gpuStage.glShader!);
|
||||
}
|
||||
|
||||
gl.linkProgram(gpuShader.glProgram);
|
||||
@@ -1283,9 +1283,9 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2GFXDevice, gpuShader: W
|
||||
console.error(gl.getProgramInfoLog(gpuShader.glProgram));
|
||||
|
||||
for (const gpuStage of gpuShader.gpuStages) {
|
||||
if (gpuStage.glShader !== 0) {
|
||||
if (gpuStage.glShader) {
|
||||
gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
gpuStage.glShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1496,15 +1496,15 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2GFXDevice, gpuShader: W
|
||||
export function WebGL2CmdFuncDestroyShader (device: WebGL2GFXDevice, gpuShader: WebGL2GPUShader) {
|
||||
|
||||
for (const gpuStage of gpuShader.gpuStages) {
|
||||
if (gpuStage.glShader !== 0) {
|
||||
if (gpuStage.glShader) {
|
||||
device.gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
gpuStage.glShader = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (gpuShader.glProgram !== 0) {
|
||||
if (gpuShader.glProgram) {
|
||||
device.gl.deleteProgram(gpuShader.glProgram);
|
||||
gpuShader.glProgram = 0;
|
||||
gpuShader.glProgram = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1573,8 +1573,7 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
|
||||
|
||||
if (cmd0.gpuFramebuffer) {
|
||||
if (cache.glFramebuffer !== cmd0.gpuFramebuffer.glFramebuffer) {
|
||||
const glFBO = (cmd0.gpuFramebuffer.glFramebuffer !== 0 ? cmd0.gpuFramebuffer.glFramebuffer : null);
|
||||
gl.bindFramebuffer(WebGL2RenderingContext.FRAMEBUFFER, glFBO);
|
||||
gl.bindFramebuffer(WebGL2RenderingContext.FRAMEBUFFER, cmd0.gpuFramebuffer.glFramebuffer);
|
||||
cache.glFramebuffer = cmd0.gpuFramebuffer.glFramebuffer;
|
||||
}
|
||||
|
||||
@@ -2040,7 +2039,6 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
|
||||
switch (glSampler.glType) {
|
||||
case gl.SAMPLER_2D: {
|
||||
glTexUnit = cache.glTex2DUnits[texUnit];
|
||||
|
||||
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
|
||||
if (gpuTexture.glTexture) {
|
||||
gl.bindTexture(gl.TEXTURE_2D, gpuTexture.glTexture);
|
||||
@@ -2053,9 +2051,12 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
|
||||
}
|
||||
case gl.SAMPLER_CUBE: {
|
||||
glTexUnit = cache.glTexCubeUnits[texUnit];
|
||||
|
||||
if (glTexUnit.glTexture !== gpuTexture.glTexture) {
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
|
||||
if (gpuTexture.glTexture) {
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, gpuTexture.glTexture);
|
||||
} else {
|
||||
gl.bindTexture(gl.TEXTURE_CUBE_MAP, device.nullTexCube!.gpuTexture.glTexture);
|
||||
}
|
||||
glTexUnit.glTexture = gpuTexture.glTexture;
|
||||
}
|
||||
break;
|
||||
@@ -2065,9 +2066,10 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.glSamplerUnits[texUnit] !== gpuBinding.gpuSampler.glSampler) {
|
||||
gl.bindSampler(texUnit, gpuBinding.gpuSampler.glSampler);
|
||||
cache.glSamplerUnits[texUnit] = gpuBinding.gpuSampler.glSampler;
|
||||
const gpuSampler = gpuBinding.gpuSampler;
|
||||
if (cache.glSamplerUnits[texUnit] !== gpuSampler.glSampler) {
|
||||
gl.bindSampler(texUnit, gpuSampler.glSampler);
|
||||
cache.glSamplerUnits[texUnit] = gpuSampler.glSampler;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2086,15 +2088,15 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W
|
||||
gpuInputAssembler = cmd2.gpuInputAssembler;
|
||||
|
||||
// check vao
|
||||
const glVAO = gpuInputAssembler.glVAOs.get(gpuShader.glProgram);
|
||||
const glVAO = gpuInputAssembler.glVAOs.get(gpuShader.glProgram!);
|
||||
if (glVAO) {
|
||||
if (cache.glVAO !== glVAO) {
|
||||
gl.bindVertexArray(glVAO);
|
||||
cache.glVAO = glVAO;
|
||||
}
|
||||
} else {
|
||||
const _glVAO = gl.createVertexArray()!;
|
||||
gpuInputAssembler.glVAOs.set(gpuShader.glProgram, _glVAO);
|
||||
const _glVAO = gl.createVertexArray();
|
||||
gpuInputAssembler.glVAOs.set(gpuShader.glProgram!, _glVAO!);
|
||||
|
||||
gl.bindVertexArray(_glVAO);
|
||||
cache.glVAO = _glVAO;
|
||||
|
||||
@@ -2,7 +2,17 @@ import { GFXBindingLayout, IGFXBindingLayoutInfo } from '../binding-layout';
|
||||
import { GFXBuffer, IGFXBufferInfo } from '../buffer';
|
||||
import { GFXCommandAllocator, IGFXCommandAllocatorInfo } from '../command-allocator';
|
||||
import { GFXCommandBuffer, IGFXCommandBufferInfo } from '../command-buffer';
|
||||
import { GFXBufferTextureCopy, GFXFilter, GFXFormat, GFXFormatInfos, GFXFormatSize, GFXQueueType, IGFXRect, GFXTextureType, GFXTextureUsageBit, GFXTextureFlagBit, GFXTextureViewType } from '../define';
|
||||
import {
|
||||
GFXBufferTextureCopy,
|
||||
GFXFilter,
|
||||
GFXFormat,
|
||||
GFXFormatSize,
|
||||
GFXQueueType,
|
||||
GFXTextureFlagBit,
|
||||
GFXTextureType,
|
||||
GFXTextureUsageBit,
|
||||
IGFXRect,
|
||||
} from '../define';
|
||||
import { GFXAPI, GFXDevice, GFXFeature, IGFXDeviceInfo } from '../device';
|
||||
import { GFXFramebuffer, IGFXFramebufferInfo } from '../framebuffer';
|
||||
import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../input-assembler';
|
||||
@@ -259,6 +269,7 @@ export class WebGL2GFXDevice extends GFXDevice {
|
||||
|
||||
this._cmdAllocator = this.createCommandAllocator({});
|
||||
|
||||
// create default null texture
|
||||
this.nullTex2D = new WebGL2GFXTexture(this);
|
||||
this.nullTex2D.initialize({
|
||||
type: GFXTextureType.TEX2D,
|
||||
@@ -266,6 +277,7 @@ export class WebGL2GFXDevice extends GFXDevice {
|
||||
format: GFXFormat.RGBA8,
|
||||
width: 2,
|
||||
height: 2,
|
||||
flags: GFXTextureFlagBit.GEN_MIPMAP,
|
||||
});
|
||||
|
||||
this.nullTexCube = new WebGL2GFXTexture(this);
|
||||
@@ -276,9 +288,40 @@ export class WebGL2GFXDevice extends GFXDevice {
|
||||
width: 2,
|
||||
height: 2,
|
||||
arrayLayer: 6,
|
||||
flags: GFXTextureFlagBit.CUBEMAP,
|
||||
flags: GFXTextureFlagBit.CUBEMAP | GFXTextureFlagBit.GEN_MIPMAP,
|
||||
});
|
||||
|
||||
const nullTexRegion: GFXBufferTextureCopy = {
|
||||
buffOffset: 0,
|
||||
buffStride: 0,
|
||||
buffTexHeight: 0,
|
||||
texOffset: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
},
|
||||
texExtent: {
|
||||
width: 2,
|
||||
height: 2,
|
||||
depth: 1,
|
||||
},
|
||||
texSubres: {
|
||||
baseMipLevel: 0,
|
||||
levelCount: 1,
|
||||
baseArrayLayer: 0,
|
||||
layerCount: 1,
|
||||
},
|
||||
};
|
||||
|
||||
const nullTexBuff = new Uint8Array(this.nullTex2D.size);
|
||||
nullTexBuff.fill(0);
|
||||
this.copyBuffersToTexture([nullTexBuff], this.nullTex2D, [nullTexRegion]);
|
||||
|
||||
nullTexRegion.texSubres.layerCount = 6;
|
||||
this.copyBuffersToTexture(
|
||||
[nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff, nullTexBuff],
|
||||
this.nullTexCube, [nullTexRegion]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export class WebGL2GFXFramebuffer extends GFXFramebuffer {
|
||||
gpuColorViews,
|
||||
gpuDepthStencilView,
|
||||
isOffscreen: this._isOffscreen,
|
||||
glFramebuffer: 0,
|
||||
glFramebuffer: null,
|
||||
};
|
||||
|
||||
WebGL2CmdFuncCreateFramebuffer(this._device as WebGL2GFXDevice, this._gpuFramebuffer);
|
||||
@@ -55,7 +55,7 @@ export class WebGL2GFXFramebuffer extends GFXFramebuffer {
|
||||
gpuColorViews: [],
|
||||
gpuDepthStencilView: null,
|
||||
isOffscreen: info.isOffscreen,
|
||||
glFramebuffer: 0,
|
||||
glFramebuffer: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
GFXFormat,
|
||||
GFXMemoryUsage,
|
||||
GFXMemoryUsageBit,
|
||||
GFXSampleCount,
|
||||
GFXShaderType,
|
||||
GFXTextureFlagBit,
|
||||
GFXTextureFlags,
|
||||
@@ -17,7 +18,6 @@ import {
|
||||
GFXTextureUsageBit,
|
||||
GFXTextureViewType,
|
||||
GFXType,
|
||||
GFXSampleCount,
|
||||
} from '../define';
|
||||
import { IGFXInputAttribute } from '../input-assembler';
|
||||
import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState } from '../pipeline-state';
|
||||
@@ -40,7 +40,7 @@ export class WebGL2GPUBuffer {
|
||||
public stride: number = 0;
|
||||
|
||||
public glTarget: GLenum = 0;
|
||||
public glBuffer: WebGLBuffer = 0;
|
||||
public glBuffer: WebGLBuffer | null = null;
|
||||
public buffer: ArrayBuffer | null = null;
|
||||
public vf32: Float32Array | null = null;
|
||||
public indirects: IGFXDrawInfo[] = [];
|
||||
@@ -67,7 +67,7 @@ export class WebGL2GPUTexture {
|
||||
public glType: GLenum = 0;
|
||||
public glUsage: GLenum = 0;
|
||||
public glTexture: WebGLTexture | null = null;
|
||||
public glRenderbuffer: WebGLRenderbuffer = 0;
|
||||
public glRenderbuffer: WebGLRenderbuffer | null = null;
|
||||
public glWrapS: GLenum = 0;
|
||||
public glWrapT: GLenum = 0;
|
||||
public glMinFilter: GLenum = 0;
|
||||
@@ -100,7 +100,7 @@ export class WebGL2GPUFramebuffer {
|
||||
public gpuDepthStencilView: WebGL2GPUTextureView | null = null;
|
||||
public isOffscreen?: boolean = false;
|
||||
|
||||
public glFramebuffer: WebGLFramebuffer = 0;
|
||||
public glFramebuffer: WebGLFramebuffer | null = null;
|
||||
|
||||
constructor (gpuRenderPass: WebGL2GPURenderPass) {
|
||||
this.gpuRenderPass = gpuRenderPass;
|
||||
@@ -108,7 +108,7 @@ export class WebGL2GPUFramebuffer {
|
||||
}
|
||||
|
||||
export class WebGL2GPUSampler {
|
||||
public glSampler: WebGLSampler = 0;
|
||||
public glSampler: WebGLSampler | null = null;
|
||||
public minFilter: GFXFilter = GFXFilter.NONE;
|
||||
public magFilter: GFXFilter = GFXFilter.NONE;
|
||||
public mipFilter: GFXFilter = GFXFilter.NONE;
|
||||
@@ -178,7 +178,7 @@ export class WebGL2GPUShaderStage {
|
||||
public type: GFXShaderType = GFXShaderType.VERTEX;
|
||||
public source: string = '';
|
||||
public macros: IGFXShaderMacro[] = [];
|
||||
public glShader: WebGLShader = 0;
|
||||
public glShader: WebGLShader | null = null;
|
||||
}
|
||||
|
||||
export class WebGL2GPUShader {
|
||||
@@ -187,7 +187,7 @@ export class WebGL2GPUShader {
|
||||
public samplers: GFXUniformSampler[] = [];
|
||||
|
||||
public gpuStages: WebGL2GPUShaderStage[] = [];
|
||||
public glProgram: WebGLProgram = 0;
|
||||
public glProgram: WebGLProgram | null = null;
|
||||
public glInputs: WebGL2GPUInput[] = [];
|
||||
public glUniforms: IWebGL2GPUUniform[] = [];
|
||||
public glBlocks: WebGL2GPUUniformBlock[] = [];
|
||||
@@ -226,7 +226,7 @@ export class WebGL2GPUBindingLayout {
|
||||
|
||||
export class WebGL2Attrib {
|
||||
public name: string = '';
|
||||
public glBuffer: WebGLBuffer = 0;
|
||||
public glBuffer: WebGLBuffer | null = null;
|
||||
public glType: GLenum = 0;
|
||||
public size: number = 0;
|
||||
public count: number = 0;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../input-assembler';
|
||||
import { WebGL2GFXBuffer } from './webgl2-buffer';
|
||||
import { WebGL2CmdDraw, WebGL2CmdFuncCreateInputAssember, WebGL2CmdFuncDestroyInputAssembler } from './webgl2-commands';
|
||||
import { WebGL2GFXDevice } from './webgl2-device';
|
||||
import { WebGL2GPUBuffer, IWebGL2GPUInputAssembler } from './webgl2-gpu-objects';
|
||||
import { IWebGL2GPUInputAssembler, WebGL2GPUBuffer } from './webgl2-gpu-objects';
|
||||
|
||||
export class WebGL2GFXInputAssembler extends GFXInputAssembler {
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ export class WebGL2GFXSampler extends GFXSampler {
|
||||
}
|
||||
|
||||
this._gpuSampler = {
|
||||
glSampler: 0,
|
||||
glSampler: null,
|
||||
minFilter: this._state.minFilter,
|
||||
magFilter: this._state.magFilter,
|
||||
mipFilter: this._state.mipFilter,
|
||||
|
||||
@@ -36,7 +36,7 @@ export class WebGL2GFXShader extends GFXShader {
|
||||
samplers: (info.samplers !== undefined ? info.samplers : []),
|
||||
|
||||
gpuStages: new Array<WebGL2GPUShaderStage>(info.stages.length),
|
||||
glProgram: 0,
|
||||
glProgram: null,
|
||||
glInputs: [],
|
||||
glUniforms: [],
|
||||
glBlocks: [],
|
||||
@@ -49,7 +49,7 @@ export class WebGL2GFXShader extends GFXShader {
|
||||
type: stage.type,
|
||||
source: stage.source,
|
||||
macros: stage.macros ? stage.macros : [],
|
||||
glShader: 0,
|
||||
glShader: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,34 +6,36 @@ export interface IWebGL2TexUnit {
|
||||
}
|
||||
|
||||
export class WebGL2StateCache {
|
||||
public glArrayBuffer: WebGLBuffer = 0;
|
||||
public glElementArrayBuffer: WebGLBuffer = 0;
|
||||
public glUniformBuffer: WebGLBuffer = 0;
|
||||
public glBindUBOs: WebGLBuffer[];
|
||||
public glVAO: WebGLVertexArrayObject = 0;
|
||||
public glArrayBuffer: WebGLBuffer | null = null;
|
||||
public glElementArrayBuffer: WebGLBuffer | null = null;
|
||||
public glUniformBuffer: WebGLBuffer | null = null;
|
||||
public glBindUBOs: Array<WebGLBuffer | null>;
|
||||
public glVAO: WebGLVertexArrayObject | null = null;
|
||||
public texUnit: number = 0;
|
||||
public glTex2DUnits: IWebGL2TexUnit[];
|
||||
public glTexCubeUnits: IWebGL2TexUnit[];
|
||||
public glSamplerUnits: WebGLSampler[];
|
||||
public glRenderbuffer: WebGLRenderbuffer = 0;
|
||||
public glFramebuffer: WebGLFramebuffer = 0;
|
||||
public glReadFramebuffer: WebGLFramebuffer = 0;
|
||||
public glSamplerUnits: Array<WebGLSampler | null>;
|
||||
public glRenderbuffer: WebGLRenderbuffer | null = null;
|
||||
public glFramebuffer: WebGLFramebuffer | null = null;
|
||||
public glReadFramebuffer: WebGLFramebuffer | null = null;
|
||||
public viewport: IGFXViewport;
|
||||
public scissorRect: IGFXRect;
|
||||
public rs: GFXRasterizerState;
|
||||
public dss: GFXDepthStencilState;
|
||||
public bs: GFXBlendState;
|
||||
public glProgram: WebGLProgram = 0;
|
||||
public glProgram: WebGLProgram | null = null;
|
||||
public glEnabledAttribLocs: boolean[];
|
||||
public glCurrentAttribLocs: boolean[];
|
||||
|
||||
constructor () {
|
||||
this.glBindUBOs = new Array<WebGLBuffer>(GFX_MAX_BUFFER_BINDINGS);
|
||||
this.glBindUBOs.fill(0);
|
||||
this.glBindUBOs.fill(null);
|
||||
|
||||
this.glTex2DUnits = new Array<IWebGL2TexUnit>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.glTexCubeUnits = new Array<IWebGL2TexUnit>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.glSamplerUnits = new Array<WebGLSampler>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.glSamplerUnits.fill(null);
|
||||
|
||||
this.viewport = { left: 0.0, top: 0.0, width: 0.0, height: 0.0, minDepth: 0.0, maxDepth: 0.0 };
|
||||
this.scissorRect = { x: 0.0, y: 0.0, width: 0.0, height: 0.0 };
|
||||
this.rs = new GFXRasterizerState();
|
||||
@@ -41,6 +43,8 @@ export class WebGL2StateCache {
|
||||
this.bs = new GFXBlendState();
|
||||
this.glEnabledAttribLocs = new Array<boolean>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
this.glCurrentAttribLocs = new Array<boolean>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
this.glEnabledAttribLocs.fill(false);
|
||||
this.glCurrentAttribLocs.fill(false);
|
||||
|
||||
for (let i = 0; i < GFX_MAX_TEXTURE_UNITS; ++i) {
|
||||
this.glTex2DUnits[i] = {
|
||||
@@ -49,12 +53,6 @@ export class WebGL2StateCache {
|
||||
this.glTexCubeUnits[i] = {
|
||||
glTexture: null,
|
||||
};
|
||||
this.glSamplerUnits[i] = 0;
|
||||
}
|
||||
|
||||
for (let i = 0; i < GFX_MAX_VERTEX_ATTRIBUTES; ++i) {
|
||||
this.glEnabledAttribLocs[i] = false;
|
||||
this.glCurrentAttribLocs[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ export class WebGL2GFXTexture extends GFXTexture {
|
||||
glType: 0,
|
||||
glUsage: 0,
|
||||
glTexture: null,
|
||||
glRenderbuffer: 0,
|
||||
glRenderbuffer: null,
|
||||
glWrapS: 0,
|
||||
glWrapT: 0,
|
||||
glMinFilter: 0,
|
||||
|
||||
@@ -827,9 +827,9 @@ export abstract class RenderPipeline {
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.CAMERA_POS_OFFSET);
|
||||
|
||||
_vec4Array[0] = camera.exposure;
|
||||
_vec4Array[1] = 1.0 / camera.exposure;
|
||||
_vec4Array[1] = 1.0 / _vec4Array[0];
|
||||
_vec4Array[2] = this._isHDR ? 1.0 : 0.0;
|
||||
_vec4Array[3] = this._fpScale / camera.exposure;
|
||||
_vec4Array[3] = _vec4Array[1] * this._fpScale;
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.EXPOSURE_OFFSET);
|
||||
|
||||
vec3.array(_vec4Array, mainLight.direction);
|
||||
|
||||
Reference in New Issue
Block a user