Skip to content

Commit

Permalink
Merge pull request #150 from greggman/webgl2-3d-textures
Browse files Browse the repository at this point in the history
Webgl2 3d textures
  • Loading branch information
benvanik authored Feb 21, 2017
2 parents 005aaa3 + 7568765 commit c0906c7
Show file tree
Hide file tree
Showing 9 changed files with 2,004 additions and 200 deletions.
89 changes: 87 additions & 2 deletions core/host/resources/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ define([
}
}
if (call.args.length == 9) {
return [call.args[3], call.args[4]];
return [call.args[3], call.args[4], 1];
} else {
var sourceObj = call.args[5];
if (sourceObj) {
Expand All @@ -77,7 +77,13 @@ define([
continue;
}
}
return [call.args[3], call.args[4]];
return [call.args[3], call.args[4], 1];
} else if (call.name == "texImage3D") {
// Ignore all but level 0
if (call.args[1]) {
continue;
}
return [call.args[3], call.args[4], call.args[5]];
}
}
return null;
Expand Down Expand Up @@ -265,6 +271,83 @@ define([
return original_texSubImage2D.apply(gl, arguments);
};

var original_texImage3D = gl.texImage3D;
gl.texImage3D = function (target, level, internalFormat, width, height, depth, border, format, type, source, offset) {
// Track texture writes
var totalBytes = 0;
totalBytes = textureInfo.calculateNumSourceBytes(width, height, depth, internalFormat, format, type);
gl.statistics.textureWrites.value += totalBytes;

var tracked = Texture.getTracked(gl, arguments);
if (tracked) {
const targetInfo = textureInfo.getTargetInfo(target);
tracked.type = targetInfo.target;

// Track total texture bytes consumed
gl.statistics.textureBytes.value -= tracked.estimatedSize;
gl.statistics.textureBytes.value += totalBytes;
tracked.estimatedSize = totalBytes;

// If !face texture this is always a reset, otherwise it may be a single face of the cube
if (!targetInfo.face) {
tracked.markDirty(true);
tracked.currentVersion.setParameters(tracked.parameters);
} else {
// Cube face - always partial
tracked.markDirty(false);
}
tracked.currentVersion.target = tracked.type;
if (level == 0) {
tracked.currentVersion.setExtraParameters("format", {
internalFormat: internalFormat,
width: width,
height: height,
depth: depth,
});
}

pushPixelStoreState(gl.rawgl, tracked.currentVersion);
tracked.currentVersion.pushCall("texImage3D", arguments);

// If this is an upload from something with a URL and we haven't been named yet, auto name us
if (source instanceof HTMLCanvasElement || source instanceof HTMLImageElement) {
if (!tracked.target.displayName) {
var filename = sourceArg.src;
var lastSlash = filename.lastIndexOf("/");
if (lastSlash >= 0) {
filename = filename.substr(lastSlash + 1);
}
var lastDot = filename.lastIndexOf(".");
if (lastDot >= 0) {
filename = filename.substr(0, lastDot);
}
tracked.setName(filename, true);
}
}
}

return original_texImage3D.apply(gl, arguments);
};

var original_texSubImage3D = gl.texSubImage3D;
gl.texSubImage3D = function (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, source, offset) {
// Track texture writes
var totalBytes = 0;
totalBytes = textureInfo.calculateNumSourceBytes(width, height, depth, undefined, format, type);
gl.statistics.textureWrites.value += totalBytes;

var tracked = Texture.getTracked(gl, arguments);
if (tracked) {
tracked.type = textureInfo.getTargetInfo(target).target;
tracked.markDirty(false);
tracked.currentVersion.target = tracked.type;
pushPixelStoreState(gl.rawgl, tracked.currentVersion);
tracked.currentVersion.pushCall("texSubImage3D", arguments);
}

return original_texSubImage3D.apply(gl, arguments);
};

var original_compressedTexImage2D = gl.compressedTexImage2D;
gl.compressedTexImage2D = function (target, level, internalFormat, width, height) {
// Track texture writes
Expand Down Expand Up @@ -390,7 +473,9 @@ define([
// Filter uploads if requested
if (options.ignoreTextureUploads) {
if ((call.name === "texImage2D") ||
(call.name === "texImage3D") ||
(call.name === "texSubImage2D") ||
(call.name === "texSubImage3D") ||
(call.name === "compressedTexImage2D") ||
(call.name === "compressedTexSubImage2D") ||
(call.name === "generateMipmap")) {
Expand Down
5 changes: 2 additions & 3 deletions core/replay/RedundancyChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,8 @@ define([
return util.arrayCompare(this.stateCache["SCISSOR_BOX"], [x, y, width, height]);
},
stencilFunc: function (func, ref, mask) {
return
(this.stateCache["STENCIL_FUNC"] == func) && (this.stateCache["STENCIL_REF"] == ref) && (this.stateCache["STENCIL_VALUE_MASK"] == mask) &&
(this.stateCache["STENCIL_BACK_FUNC"] == func) && (this.stateCache["STENCIL_BACK_REF"] == ref) && (this.stateCache["STENCIL_BACK_VALUE_MASK"] == mask);
return (this.stateCache["STENCIL_FUNC"] == func) && (this.stateCache["STENCIL_REF"] == ref) && (this.stateCache["STENCIL_VALUE_MASK"] == mask) &&
(this.stateCache["STENCIL_BACK_FUNC"] == func) && (this.stateCache["STENCIL_BACK_REF"] == ref) && (this.stateCache["STENCIL_BACK_VALUE_MASK"] == mask);
},
stencilFuncSeparate: function (face, func, ref, mask) {
switch (face) {
Expand Down
10 changes: 5 additions & 5 deletions core/shared/Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define([
"UNSIGNED_INT_2_10_10_10_REV",
"UNSIGNED_INT_5_9_9_9_REV",
"UNSIGNED_SHORT",
"UNSIGNED_SHORT, UNSIGNED_INT",
"UNSIGNED_INT",
"UNSIGNED_SHORT_4_4_4_4",
"UNSIGNED_SHORT_5_5_5_1",
"UNSIGNED_SHORT_5_6_5",
Expand Down Expand Up @@ -166,7 +166,7 @@ define([
];
const bindTextureTargets = [
...texture2DTargets,
...texture2DTargets,
...texture3DTargets,
];
const faceTextureTargets = [
"TEXTURE_2D",
Expand Down Expand Up @@ -1468,7 +1468,7 @@ define([
args.push(new FunctionParam(gl, "depth", new UIInfo(UIType.LONG)));
args.push(new FunctionParam(gl, "border", new UIInfo(UIType.LONG)));
args.push(new FunctionParam(gl, "format", new UIInfo(UIType.ENUM, textureFormats)));
args.push(new FunctionParam(gl, "type", new UIInfo(UIType.ENUM, textureTypes)));
args.push(new FunctionParam(gl, "type", textureTypes));
if (typeof(call.args[9]) === "number") {
args.push(new FunctionParam(gl, "pboOffset", new UIInfo(UIType.LONG)));
} else if (util.isTypedArray(call.args[9])) {
Expand All @@ -1491,8 +1491,8 @@ define([
args.push(new FunctionParam(gl, "width", new UIInfo(UIType.LONG)));
args.push(new FunctionParam(gl, "height", new UIInfo(UIType.LONG)));
args.push(new FunctionParam(gl, "depth", new UIInfo(UIType.LONG)));
args.push(new FunctionParam(gl, "format", new UIInfo(UIType.ENUM, textureFormaats)));
args.push(new FunctionParam(gl, "type", new UIInfo(UIType.ENUM, textureTypes)));
args.push(new FunctionParam(gl, "format", new UIInfo(UIType.ENUM, textureFormats)));
args.push(new FunctionParam(gl, "type", textureTypes));
if (typeof(call.args[10]) === "number") {
args.push(new FunctionParam(gl, "pboOffset", new UIInfo(UIType.LONG)));
} else if (util.isTypedArray(call.args[10])) {
Expand Down
Loading

0 comments on commit c0906c7

Please sign in to comment.