shute-technologies.octopus-web-framework 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/device/ofDeviceCapabilities.d.ts +10 -0
- package/lib/src/shute-technologies/modules/framework/core/device/ofDeviceCapabilities.js +46 -0
- package/lib/src/shute-technologies/modules/framework/core/device/ofDeviceCapabilities.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/device/ofGraphicDevice.d.ts +77 -1
- package/lib/src/shute-technologies/modules/framework/core/device/ofGraphicDevice.js +209 -14
- package/lib/src/shute-technologies/modules/framework/core/device/ofGraphicDevice.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/device/optimization/gpu/ofVBOObject.js +2 -1
- package/lib/src/shute-technologies/modules/framework/core/device/optimization/gpu/ofVBOObject.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/camera/ofRenderCamera.js +2 -2
- package/lib/src/shute-technologies/modules/framework/core/render/camera/ofRenderCamera.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofAnimation.js +2 -2
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofAnimation.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofPrimitiveCircle.js +3 -3
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofPrimitiveCircle.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofPrimitiveGrid.js +4 -4
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofPrimitiveGrid.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofPrimitiveQuad.js +5 -5
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofPrimitiveQuad.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofSprite.js +2 -2
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofSprite.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofOptSpriteBatcher.d.ts +2 -0
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofOptSpriteBatcher.js +6 -5
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofOptSpriteBatcher.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofPolygonBatcher.d.ts +21 -0
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofPolygonBatcher.js +149 -23
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofPolygonBatcher.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofSpriteBatcher.js +2 -2
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofSpriteBatcher.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofBaseShader.d.ts +6 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofBaseShader.js +16 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofBaseShader.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofEnumBlendMode.d.ts +5 -1
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofEnumBlendMode.js +4 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofEnumBlendMode.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.d.ts +13 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.js +65 -6
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.d.ts +1 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.js +6 -3
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.d.ts +1 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.js +9 -8
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofFullscreenPass.d.ts +32 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofFullscreenPass.js +81 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofFullscreenPass.js.map +1 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTarget.d.ts +54 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTarget.js +131 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTarget.js.map +1 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTargetPool.d.ts +29 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTargetPool.js +69 -0
- package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTargetPool.js.map +1 -0
- package/lib/src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.d.ts +2 -0
- package/lib/src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.js +24 -0
- package/lib/src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,12 +5,21 @@ const ofBaseShader_1 = require("./ofBaseShader");
|
|
|
5
5
|
const gl_matrix_1 = require("gl-matrix");
|
|
6
6
|
const ofEnumShaderDataTypes_1 = require("../../../../cross-cutting/shader-analizer/ofEnumShaderDataTypes");
|
|
7
7
|
class OFShaderAbstract extends ofBaseShader_1.OFBaseShader {
|
|
8
|
+
/** The inputs the shader's source declares. */
|
|
9
|
+
get shaderCodeInfo() { return this._shaderCodeInfo; }
|
|
8
10
|
constructor(_shaderFactory, sourceTarget, shaderCodeInfo) {
|
|
9
11
|
super(_shaderFactory, sourceTarget, true);
|
|
10
12
|
this._shaderFactory = _shaderFactory;
|
|
11
13
|
// camera x model for the current draw. Never multiply into the camera matrix itself: with a
|
|
12
14
|
// custom camera that is `args.cameraMVP`, shared by every draw the caller makes with those args.
|
|
13
15
|
this._modelViewProjection = gl_matrix_1.mat4.create();
|
|
16
|
+
// The last value sent to each `: Camera`, `: Time` and `: Viewport` input of this program, by input name, while
|
|
17
|
+
// the device's stateEpoch is _sentEpoch. A draw sends such an input only when its value differs.
|
|
18
|
+
this._sentValues = new Map();
|
|
19
|
+
this._sentEpoch = -1;
|
|
20
|
+
// Scratch for the `: Time` and `: Viewport` values compared before sending.
|
|
21
|
+
this._timeValue = [0];
|
|
22
|
+
this._viewportValue = [0, 0, 0, 0];
|
|
14
23
|
this._attributeInterleavedDataSize = 0;
|
|
15
24
|
this._colorPropIndexCount = 0;
|
|
16
25
|
this._texturePropIndexCount = 0;
|
|
@@ -28,6 +37,40 @@ class OFShaderAbstract extends ofBaseShader_1.OFBaseShader {
|
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
getShaderLocations(_GL) { }
|
|
40
|
+
forgetSentUniform(uniformName) {
|
|
41
|
+
this._sentValues.delete(uniformName);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* True when `values` differ from the last values sent to the input `inputName` of this program, which it then
|
|
45
|
+
* records: the caller sends them. Every copy is dropped when the device's stateEpoch has moved (resetStateCache()).
|
|
46
|
+
* Kept as doubles, so `: Time` (a double) compares exactly; the camera's floats and the viewport fit unchanged.
|
|
47
|
+
*/
|
|
48
|
+
hasChanged(inputName, values) {
|
|
49
|
+
const epoch = this._graphicDevice.stateEpoch;
|
|
50
|
+
if (this._sentEpoch !== epoch) {
|
|
51
|
+
this._sentValues.clear();
|
|
52
|
+
this._sentEpoch = epoch;
|
|
53
|
+
}
|
|
54
|
+
let sent = this._sentValues.get(inputName);
|
|
55
|
+
if (sent && sent.length === values.length) {
|
|
56
|
+
let same = true;
|
|
57
|
+
for (let i = 0; i < values.length; i++) {
|
|
58
|
+
if (sent[i] !== values[i]) {
|
|
59
|
+
same = false;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (same) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
sent = new Float64Array(values.length);
|
|
69
|
+
this._sentValues.set(inputName, sent);
|
|
70
|
+
}
|
|
71
|
+
sent.set(values);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
31
74
|
// tslint:disable-next-line: cyclomatic-complexity
|
|
32
75
|
updateShader(sourceTarget, newShaderCodeInfo) {
|
|
33
76
|
const _GL = this.graphicContext;
|
|
@@ -63,9 +106,11 @@ class OFShaderAbstract extends ofBaseShader_1.OFBaseShader {
|
|
|
63
106
|
}
|
|
64
107
|
}
|
|
65
108
|
}
|
|
66
|
-
// Update ShaderProgram and ShaderCodeInfo
|
|
109
|
+
// Update ShaderProgram and ShaderCodeInfo. A new program starts with every uniform at zero: nothing sent to the
|
|
110
|
+
// old one counts.
|
|
67
111
|
this._shaderCodeInfo = newShaderCodeInfo;
|
|
68
112
|
this._shaderProgram = this._shaderFactory.instanceShader(sourceTarget);
|
|
113
|
+
this._sentValues.clear();
|
|
69
114
|
// Auto-Generate global variables for this context: Attributes
|
|
70
115
|
this._attributeLocations = [];
|
|
71
116
|
for (let i = 0; i < this._shaderCodeInfo.attributeCount; i++) {
|
|
@@ -165,14 +210,27 @@ class OFShaderAbstract extends ofBaseShader_1.OFBaseShader {
|
|
|
165
210
|
// multiply into `transformedMatrix` in place, i.e. into args.cameraMVP, so the second and
|
|
166
211
|
// later draws sharing those args got camera x M1 x M2 x ... and drifted.
|
|
167
212
|
gl_matrix_1.mat4.multiply(this._modelViewProjection, transformedMatrix, transformation ? transformation : this._world);
|
|
168
|
-
|
|
213
|
+
// Uniforms belong to the program: one this program already holds is not sent again.
|
|
214
|
+
if (this.hasChanged(uniformData.inputName, this._modelViewProjection)) {
|
|
215
|
+
_GL.uniformMatrix4fv(uniformLocation, false, this._modelViewProjection);
|
|
216
|
+
}
|
|
169
217
|
break;
|
|
170
218
|
case ofEnumShaderDataTypes_1.OFEnumShaderDataTypes.ITime:
|
|
171
|
-
|
|
219
|
+
this._timeValue[0] = this._graphicDevice.elapsedSeconds;
|
|
220
|
+
if (this.hasChanged(uniformData.inputName, this._timeValue)) {
|
|
221
|
+
_GL.uniform1f(this[uniformData.inputName], this._timeValue[0]);
|
|
222
|
+
}
|
|
172
223
|
break;
|
|
173
224
|
case ofEnumShaderDataTypes_1.OFEnumShaderDataTypes.IViewport:
|
|
174
225
|
const viewport = this._graphicDevice.currentViewport;
|
|
175
|
-
|
|
226
|
+
const viewportValue = this._viewportValue;
|
|
227
|
+
viewportValue[0] = viewport.x;
|
|
228
|
+
viewportValue[1] = viewport.y;
|
|
229
|
+
viewportValue[2] = viewport.width;
|
|
230
|
+
viewportValue[3] = viewport.height;
|
|
231
|
+
if (this.hasChanged(uniformData.inputName, viewportValue)) {
|
|
232
|
+
_GL.uniform4f(this[uniformData.inputName], viewport.x, viewport.y, viewport.width, viewport.height);
|
|
233
|
+
}
|
|
176
234
|
break;
|
|
177
235
|
case ofEnumShaderDataTypes_1.OFEnumShaderDataTypes.IShared:
|
|
178
236
|
if (this.sendSharedUniform(uniformData, nextTextureUnit)) {
|
|
@@ -183,7 +241,8 @@ class OFShaderAbstract extends ofBaseShader_1.OFBaseShader {
|
|
|
183
241
|
break;
|
|
184
242
|
}
|
|
185
243
|
}
|
|
186
|
-
|
|
244
|
+
// Through the device, which skips the bind when the buffer already is bound. Nothing unbinds it after the draw.
|
|
245
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, vertexBuffer);
|
|
187
246
|
// Auto-Generate WebGL calls for Attributes. Enabling goes through the device, which also
|
|
188
247
|
// disables what an earlier draw enabled and this program does not read.
|
|
189
248
|
this._graphicDevice.useVertexAttributes(this._attributeLocations);
|
|
@@ -206,7 +265,7 @@ class OFShaderAbstract extends ofBaseShader_1.OFBaseShader {
|
|
|
206
265
|
_GL.drawArrays(renderType, 0, 4);
|
|
207
266
|
}
|
|
208
267
|
else {
|
|
209
|
-
|
|
268
|
+
this._graphicDevice.bindBuffer(_GL.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
|
210
269
|
_GL.drawElements(renderType, indexCount, _GL.UNSIGNED_SHORT, 0);
|
|
211
270
|
}
|
|
212
271
|
}
|
package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofShaderAbstract.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAG9C,yCAAiC;AAIjC,2GAAwG;AAExG,MAAa,gBAAiB,SAAQ,2BAAY;
|
|
1
|
+
{"version":3,"file":"ofShaderAbstract.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAG9C,yCAAiC;AAIjC,2GAAwG;AAExG,MAAa,gBAAiB,SAAQ,2BAAY;IAoBhD,+CAA+C;IAC/C,IAAI,cAAc,KAAwB,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IAExE,YAA+B,cAA+B,EAAE,YAAoC,EAClG,cAAiC;QACjC,KAAK,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QAFb,mBAAc,GAAd,cAAc,CAAiB;QApB9D,4FAA4F;QAC5F,iGAAiG;QAChF,yBAAoB,GAAS,gBAAI,CAAC,MAAM,EAAE,CAAC;QAC5D,gHAAgH;QAChH,iGAAiG;QAChF,gBAAW,GAAG,IAAI,GAAG,EAAwB,CAAC;QAC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EAAE,iBAAiB,CAAC,CAAC;iBAC1D;gBAED,iBAAiB,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,oBAAoB;aAC1D;YAED,wCAAwC;YACxC,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC;YAE3D,0EAA0E;YAC1E,IAAI,CAAC,WAAW,EAAE;gBAChB,GAAG,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;aAClC;iBAAM;gBACL,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;gBACtE,GAAG,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;aACjE;SACF;IACH,CAAC;CACF;AAnTD,4CAmTC"}
|
package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class OFShaderPrimitive extends OFBaseShader {
|
|
|
9
9
|
private _vertexPositionAttr;
|
|
10
10
|
private _uniformWVPMatrix;
|
|
11
11
|
private _uniformColor;
|
|
12
|
+
private _uniformPremultiply;
|
|
12
13
|
color: OFColor;
|
|
13
14
|
constructor(_shaderFactory: OFShaderFactory, sourceTarget: IOFDefaultShaderSource);
|
|
14
15
|
getShaderLocations(_GL: WebGLRenderingContext): void;
|
package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OFShaderPrimitive = void 0;
|
|
4
4
|
const ofBaseShader_1 = require("./ofBaseShader");
|
|
5
5
|
const ofColor_1 = require("../graphics/ofColor");
|
|
6
|
+
const ofGraphicDevice_1 = require("../../device/ofGraphicDevice");
|
|
6
7
|
const gl_matrix_1 = require("gl-matrix");
|
|
7
8
|
class OFShaderPrimitive extends ofBaseShader_1.OFBaseShader {
|
|
8
9
|
constructor(_shaderFactory, sourceTarget) {
|
|
@@ -14,13 +15,15 @@ class OFShaderPrimitive extends ofBaseShader_1.OFBaseShader {
|
|
|
14
15
|
this._vertexPositionAttr = _GL.getAttribLocation(this._shaderProgram, 'aVertexPosition');
|
|
15
16
|
this._uniformWVPMatrix = _GL.getUniformLocation(this._shaderProgram, 'uWVPMatrix');
|
|
16
17
|
this._uniformColor = _GL.getUniformLocation(this._shaderProgram, 'uColor');
|
|
18
|
+
this._uniformPremultiply = _GL.getUniformLocation(this._shaderProgram, ofGraphicDevice_1.OFGraphicDevice.premultiplyUniformName);
|
|
17
19
|
}
|
|
18
20
|
draw(args, vertexBuffer, indexBuffer, renderType, count, overrideTransformation = null) {
|
|
19
21
|
const _GL = this._graphicContext;
|
|
20
22
|
// Enable blending
|
|
21
23
|
this._graphicDevice.useBlendMode(this.blendMode);
|
|
22
|
-
|
|
23
|
-
_GL.
|
|
24
|
+
this._graphicDevice.useShaderProgram(this._shaderProgram);
|
|
25
|
+
_GL.uniform1f(this._uniformPremultiply, ofGraphicDevice_1.OFGraphicDevice.premultipliesFor(this.blendMode) ? 1 : 0);
|
|
26
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, vertexBuffer);
|
|
24
27
|
// Through the device, which also disables what an earlier draw enabled (texture coordinates).
|
|
25
28
|
this._graphicDevice.useVertexAttributes([this._vertexPositionAttr]);
|
|
26
29
|
_GL.vertexAttribPointer(this._vertexPositionAttr, 3, _GL.FLOAT, false, 0, 0);
|
|
@@ -40,7 +43,7 @@ class OFShaderPrimitive extends ofBaseShader_1.OFBaseShader {
|
|
|
40
43
|
// Now draw arrays
|
|
41
44
|
renderType = !renderType ? _GL.TRIANGLE_STRIP : renderType;
|
|
42
45
|
if (indexBuffer) {
|
|
43
|
-
|
|
46
|
+
this._graphicDevice.bindBuffer(_GL.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
|
44
47
|
_GL.drawElements(renderType, count, _GL.UNSIGNED_SHORT, 0);
|
|
45
48
|
}
|
|
46
49
|
else {
|
package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofShaderPrimitive.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAI9C,iDAA8C;AAC9C,yCAAiC;AAEjC,MAAa,iBAAkB,SAAQ,2BAAY;
|
|
1
|
+
{"version":3,"file":"ofShaderPrimitive.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/shader/ofShaderPrimitive.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAI9C,iDAA8C;AAC9C,kEAA+D;AAC/D,yCAAiC;AAEjC,MAAa,iBAAkB,SAAQ,2BAAY;IASjD,YAA+B,cAA+B,EAAE,YAAoC;QAClG,KAAK,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QADP,mBAAc,GAAd,cAAc,CAAiB;QAG5D,IAAI,CAAC,KAAK,GAAG,iBAAO,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,kBAAkB,CAAC,GAA0B;QAC3C,IAAI,CAAC,mBAAmB,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QACzF,IAAI,CAAC,iBAAiB,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QACnF,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAC3E,IAAI,CAAC,mBAAmB,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,iCAAe,CAAC,sBAAsB,CAAC,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iBAAiB,CAAC,CAAC;QACvE,wBAAwB;QACxB,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE1F,kBAAkB;QAClB,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC;QAE3D,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;YACtE,GAAG,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;SAC5D;aAAM;YACL,GAAG,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;SACtC;IACH,CAAC;CACF;AA7DD,8CA6DC"}
|
package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class OFShaderTexture extends OFBaseShader {
|
|
|
12
12
|
private _samplerPositionUniform;
|
|
13
13
|
private _uniformWVPMatrix;
|
|
14
14
|
private _uniformColor;
|
|
15
|
+
private _uniformPremultiply;
|
|
15
16
|
constructor(_shaderFactory: OFShaderFactory, sourceTarget: IOFDefaultShaderSource);
|
|
16
17
|
getShaderLocations(_GL: WebGLRenderingContext): void;
|
|
17
18
|
draw(args: IOFRenderArgs, texture: WebGLTexture, vertexBuffer: WebGLBuffer, transformation?: mat4): void;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OFShaderTexture = void 0;
|
|
4
4
|
const ofBaseShader_1 = require("./ofBaseShader");
|
|
5
5
|
const ofColor_1 = require("../graphics/ofColor");
|
|
6
|
+
const ofGraphicDevice_1 = require("../../device/ofGraphicDevice");
|
|
6
7
|
const gl_matrix_1 = require("gl-matrix");
|
|
7
8
|
class OFShaderTexture extends ofBaseShader_1.OFBaseShader {
|
|
8
9
|
constructor(_shaderFactory, sourceTarget) {
|
|
@@ -16,16 +17,18 @@ class OFShaderTexture extends ofBaseShader_1.OFBaseShader {
|
|
|
16
17
|
this._samplerPositionUniform = _GL.getUniformLocation(this._shaderProgram, 'uSamplerTexture');
|
|
17
18
|
this._uniformWVPMatrix = _GL.getUniformLocation(this._shaderProgram, 'uWVPMatrix');
|
|
18
19
|
this._uniformColor = _GL.getUniformLocation(this._shaderProgram, 'uColor');
|
|
20
|
+
this._uniformPremultiply = _GL.getUniformLocation(this._shaderProgram, ofGraphicDevice_1.OFGraphicDevice.premultiplyUniformName);
|
|
19
21
|
}
|
|
20
22
|
draw(args, texture, vertexBuffer, transformation) {
|
|
21
23
|
const _GL = this._graphicContext;
|
|
22
24
|
// Enable blending
|
|
23
25
|
this._graphicDevice.useBlendMode(this.blendMode);
|
|
24
|
-
|
|
26
|
+
this._graphicDevice.useShaderProgram(this._shaderProgram);
|
|
27
|
+
_GL.uniform1f(this._uniformPremultiply, ofGraphicDevice_1.OFGraphicDevice.premultipliesFor(this.blendMode) ? 1 : 0);
|
|
25
28
|
_GL.activeTexture(_GL.TEXTURE0);
|
|
26
29
|
_GL.bindTexture(_GL.TEXTURE_2D, texture);
|
|
27
30
|
_GL.uniform1i(this._samplerPositionUniform, 0);
|
|
28
|
-
|
|
31
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, vertexBuffer);
|
|
29
32
|
this._graphicDevice.useVertexAttributes([this._vertexPositionAttr, this._textureCoordPositionAttr]);
|
|
30
33
|
_GL.vertexAttribPointer(this._vertexPositionAttr, 3, _GL.FLOAT, false, 20, 0);
|
|
31
34
|
_GL.vertexAttribPointer(this._textureCoordPositionAttr, 2, _GL.FLOAT, false, 20, 12);
|
|
@@ -50,11 +53,12 @@ class OFShaderTexture extends ofBaseShader_1.OFBaseShader {
|
|
|
50
53
|
const _GL = this._graphicContext;
|
|
51
54
|
// Enable blending
|
|
52
55
|
this._graphicDevice.useBlendMode(this.blendMode);
|
|
53
|
-
|
|
56
|
+
this._graphicDevice.useShaderProgram(this._shaderProgram);
|
|
57
|
+
_GL.uniform1f(this._uniformPremultiply, ofGraphicDevice_1.OFGraphicDevice.premultipliesFor(this.blendMode) ? 1 : 0);
|
|
54
58
|
_GL.activeTexture(_GL.TEXTURE0);
|
|
55
59
|
_GL.bindTexture(_GL.TEXTURE_2D, texture);
|
|
56
60
|
_GL.uniform1i(this._samplerPositionUniform, 0);
|
|
57
|
-
|
|
61
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, vertexBuffer);
|
|
58
62
|
this._graphicDevice.useVertexAttributes([this._vertexPositionAttr, this._textureCoordPositionAttr]);
|
|
59
63
|
_GL.vertexAttribPointer(this._vertexPositionAttr, 3, _GL.FLOAT, false, 20, 0);
|
|
60
64
|
_GL.vertexAttribPointer(this._textureCoordPositionAttr, 2, _GL.FLOAT, false, 20, 12);
|
|
@@ -69,11 +73,8 @@ class OFShaderTexture extends ofBaseShader_1.OFBaseShader {
|
|
|
69
73
|
_GL.uniform4f(this._uniformColor, this.color.r, this.color.g, this.color.b, this.color.a);
|
|
70
74
|
// Now draw arrays
|
|
71
75
|
// GL.drawArrays(GL.TRIANGLE_STRIP, 0, indexCount);
|
|
72
|
-
|
|
76
|
+
this._graphicDevice.bindBuffer(_GL.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
|
73
77
|
_GL.drawElements(_GL.TRIANGLE_STRIP, indexCount, _GL.UNSIGNED_SHORT, 0);
|
|
74
|
-
// clear
|
|
75
|
-
_GL.bindBuffer(_GL.ARRAY_BUFFER, null);
|
|
76
|
-
_GL.bindBuffer(_GL.ELEMENT_ARRAY_BUFFER, null);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
exports.OFShaderTexture = OFShaderTexture;
|
package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofShaderTexture.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAG9C,iDAA8C;AAE9C,yCAAiC;AAEjC,MAAa,eAAgB,SAAQ,2BAAY;
|
|
1
|
+
{"version":3,"file":"ofShaderTexture.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/shader/ofShaderTexture.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAG9C,iDAA8C;AAE9C,kEAA+D;AAC/D,yCAAiC;AAEjC,MAAa,eAAgB,SAAQ,2BAAY;IAW/C,YAA+B,cAA+B,EAAE,YAAoC;QAClG,KAAK,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QADP,mBAAc,GAAd,cAAc,CAAiB;QAG5D,IAAI,CAAC,KAAK,GAAG,iBAAO,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,kBAAkB,CAAC,GAA0B;QAC3C,IAAI,CAAC,mBAAmB,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QACzF,IAAI,CAAC,yBAAyB,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;QAC7F,IAAI,CAAC,uBAAuB,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QAC9F,IAAI,CAAC,iBAAiB,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QACnF,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,cAA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I,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE1F,kBAAkB;QAClB,mDAAmD;QACnD,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;QACtE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,EAAE,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF;AAtGD,0CAsGC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OFGraphicDevice } from '../../device/ofGraphicDevice';
|
|
2
|
+
import { OFShaderAbstract } from '../shader/ofShaderAbstract';
|
|
3
|
+
import { OFRenderTarget } from './ofRenderTarget';
|
|
4
|
+
/**
|
|
5
|
+
* Draws one quad over the current viewport with any OFShaderAbstract, to blit or post-process a texture.
|
|
6
|
+
*
|
|
7
|
+
* The quad is in clip space (-1..1) and the shader's `: Camera` input gets the identity matrix, so it covers
|
|
8
|
+
* the viewport whatever the device camera is. The pass sets no viewport itself: inside a bound render target
|
|
9
|
+
* it covers the target, on the canvas it covers the current viewport. The shader's own blendMode is applied.
|
|
10
|
+
* The source goes to the shader's first `: Texture` input; any other input is the caller's to set.
|
|
11
|
+
*
|
|
12
|
+
* draw() throws when the source is the render target currently bound (a feedback loop: WebGL draws nothing),
|
|
13
|
+
* and when the shader's attributes are not exactly a vec3 aVertexPosition and a vec2 aTextureCoord, the
|
|
14
|
+
* layout of the quad (20 bytes a vertex).
|
|
15
|
+
*/
|
|
16
|
+
export declare class OFFullscreenPass {
|
|
17
|
+
private readonly _graphicDevice;
|
|
18
|
+
/** The name the built-in copy shader is registered under in the shader factory. */
|
|
19
|
+
static readonly CopyShaderName = "OFFullscreenCopy";
|
|
20
|
+
private static readonly QuadVertices;
|
|
21
|
+
private readonly _graphicContext;
|
|
22
|
+
private readonly _identity;
|
|
23
|
+
private readonly _args;
|
|
24
|
+
private _vertexBuffer;
|
|
25
|
+
private _copyShader;
|
|
26
|
+
/** The built-in copy shader (the texture, unchanged), created on first use. */
|
|
27
|
+
get copyShader(): OFShaderAbstract;
|
|
28
|
+
constructor(_graphicDevice: OFGraphicDevice);
|
|
29
|
+
draw(shader: OFShaderAbstract, source?: OFRenderTarget | WebGLTexture): void;
|
|
30
|
+
/** Frees the quad's buffer. The copy shader belongs to the shader factory and stays there. */
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OFFullscreenPass = void 0;
|
|
4
|
+
const gl_matrix_1 = require("gl-matrix");
|
|
5
|
+
const ofRenderTarget_1 = require("./ofRenderTarget");
|
|
6
|
+
const ofEnumShaderDataTypes_1 = require("../../../../cross-cutting/shader-analizer/ofEnumShaderDataTypes");
|
|
7
|
+
const ofDefaultShaderSources_1 = require("../../../default-assets/ofDefaultShaderSources");
|
|
8
|
+
/**
|
|
9
|
+
* Draws one quad over the current viewport with any OFShaderAbstract, to blit or post-process a texture.
|
|
10
|
+
*
|
|
11
|
+
* The quad is in clip space (-1..1) and the shader's `: Camera` input gets the identity matrix, so it covers
|
|
12
|
+
* the viewport whatever the device camera is. The pass sets no viewport itself: inside a bound render target
|
|
13
|
+
* it covers the target, on the canvas it covers the current viewport. The shader's own blendMode is applied.
|
|
14
|
+
* The source goes to the shader's first `: Texture` input; any other input is the caller's to set.
|
|
15
|
+
*
|
|
16
|
+
* draw() throws when the source is the render target currently bound (a feedback loop: WebGL draws nothing),
|
|
17
|
+
* and when the shader's attributes are not exactly a vec3 aVertexPosition and a vec2 aTextureCoord, the
|
|
18
|
+
* layout of the quad (20 bytes a vertex).
|
|
19
|
+
*/
|
|
20
|
+
class OFFullscreenPass {
|
|
21
|
+
/** The built-in copy shader (the texture, unchanged), created on first use. */
|
|
22
|
+
get copyShader() {
|
|
23
|
+
if (!this._copyShader) {
|
|
24
|
+
const factory = this._graphicDevice.shaderFactory;
|
|
25
|
+
this._copyShader = factory.retrieveShader(OFFullscreenPass.CopyShaderName)
|
|
26
|
+
|| factory.loadAndAddShaderWithCodeInfo(OFFullscreenPass.CopyShaderName, ofDefaultShaderSources_1.OFDefaultShaderSources.SourcesFullscreenCopy, null, OFFullscreenPass.CopyShaderName);
|
|
27
|
+
}
|
|
28
|
+
return this._copyShader;
|
|
29
|
+
}
|
|
30
|
+
constructor(_graphicDevice) {
|
|
31
|
+
this._graphicDevice = _graphicDevice;
|
|
32
|
+
this._identity = gl_matrix_1.mat4.create();
|
|
33
|
+
this._vertexBuffer = null;
|
|
34
|
+
this._copyShader = null;
|
|
35
|
+
this._graphicContext = _graphicDevice.graphicContext;
|
|
36
|
+
this._args = { hasCustomCamera: true, cameraMVP: this._identity };
|
|
37
|
+
}
|
|
38
|
+
draw(shader, source) {
|
|
39
|
+
const _GL = this._graphicContext;
|
|
40
|
+
if (source instanceof ofRenderTarget_1.OFRenderTarget && source.framebuffer === this._graphicDevice.currentFramebuffer) {
|
|
41
|
+
throw new Error('OFFullscreenPass.draw: the source is the render target being drawn to (a feedback loop).');
|
|
42
|
+
}
|
|
43
|
+
const attributes = shader.shaderCodeInfo.attributes;
|
|
44
|
+
if (shader.shaderCodeInfo.attributeCount !== 2
|
|
45
|
+
|| attributes[0].inputName !== 'aVertexPosition' || attributes[0].inputVariableType !== ofEnumShaderDataTypes_1.OFEnumShaderDataTypes.Vector3
|
|
46
|
+
|| attributes[1].inputName !== 'aTextureCoord' || attributes[1].inputVariableType !== ofEnumShaderDataTypes_1.OFEnumShaderDataTypes.Vector2) {
|
|
47
|
+
throw new Error('OFFullscreenPass.draw: the shader attributes must be a vec3 aVertexPosition and a vec2 aTextureCoord.');
|
|
48
|
+
}
|
|
49
|
+
if (!this._vertexBuffer) {
|
|
50
|
+
this._vertexBuffer = _GL.createBuffer();
|
|
51
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, this._vertexBuffer);
|
|
52
|
+
_GL.bufferData(_GL.ARRAY_BUFFER, OFFullscreenPass.QuadVertices, _GL.STATIC_DRAW);
|
|
53
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, null);
|
|
54
|
+
}
|
|
55
|
+
if (source) {
|
|
56
|
+
shader.setTextureByIndex(0, source instanceof ofRenderTarget_1.OFRenderTarget ? source.texture : source);
|
|
57
|
+
}
|
|
58
|
+
// Identity camera and identity model: the quad stays in clip space. Passing the identity as the
|
|
59
|
+
// transformation also keeps the shader's own world matrix out of it.
|
|
60
|
+
shader.draw(this._args, this._vertexBuffer, this._identity, _GL.TRIANGLE_STRIP, null, 4);
|
|
61
|
+
this._graphicDevice.bindBuffer(_GL.ARRAY_BUFFER, null);
|
|
62
|
+
}
|
|
63
|
+
/** Frees the quad's buffer. The copy shader belongs to the shader factory and stays there. */
|
|
64
|
+
destroy() {
|
|
65
|
+
if (this._vertexBuffer) {
|
|
66
|
+
this._graphicDevice.deleteBuffer(this._vertexBuffer);
|
|
67
|
+
this._vertexBuffer = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.OFFullscreenPass = OFFullscreenPass;
|
|
72
|
+
/** The name the built-in copy shader is registered under in the shader factory. */
|
|
73
|
+
OFFullscreenPass.CopyShaderName = 'OFFullscreenCopy';
|
|
74
|
+
// aVertexPosition (vec3) + aTextureCoord (vec2), in TRIANGLE_STRIP order: 4 vertices, 20 bytes each.
|
|
75
|
+
OFFullscreenPass.QuadVertices = new Float32Array([
|
|
76
|
+
-1, -1, 0, 0, 0,
|
|
77
|
+
1, -1, 0, 1, 0,
|
|
78
|
+
-1, 1, 0, 0, 1,
|
|
79
|
+
1, 1, 0, 1, 1
|
|
80
|
+
]);
|
|
81
|
+
//# sourceMappingURL=ofFullscreenPass.js.map
|
package/lib/src/shute-technologies/modules/framework/core/render/target/ofFullscreenPass.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ofFullscreenPass.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/target/ofFullscreenPass.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAGjC,qDAAkD;AAClD,2GAAwG;AACxG,2FAAwF;AAGxF;;;;;;;;;;;GAWG;AACH,MAAa,gBAAgB;IAmB3B,+EAA+E;IAC/E,IAAI,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;YAElD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,cAAc,CAAmB,gBAAgB,CAAC,cAAc,CAAC;mBACvF,OAAO,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,cAAc,EACrE,+CAAsB,CAAC,qBAAqB,EAAE,IAAI,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;SAC1F;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,YAA6B,cAA+B;QAA/B,mBAAc,GAAd,cAAc,CAAiB;QAlB3C,cAAS,GAAS,gBAAI,CAAC,MAAM,EAAE,CAAC;QAEzC,kBAAa,GAAgB,IAAI,CAAC;QAClC,gBAAW,GAAqB,IAAI,CAAC;QAgB3C,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,cAAc,CAAC;QACrD,IAAI,CAAC,KAAK,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAuB,CAAC;IACzF,CAAC;IAED,IAAI,CAAC,MAAwB,EAAE,MAAsC;QACnE,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC;QAEjC,IAAI,MAAM,YAAY,+BAAc,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC,cAAc,CAAC,kBAAkB,EAAE;YACrG,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAC;SAC7G;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,cAAc,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;IAED,8FAA8F;IAC9F,OAAO;QACL,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACrD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;SAC3B;IACH,CAAC;;AA5EH,4CA6EC;AA3EC,mFAAmF;AACnE,+BAAc,GAAG,kBAAkB,CAAC;AAEpD,qGAAqG;AAC7E,6BAAY,GAAG,IAAI,YAAY,CAAC;IACtD,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACd,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { OFGraphicDevice } from '../../device/ofGraphicDevice';
|
|
2
|
+
/** A render target's colour format. 'half-float' falls back to 'rgba8' where the context cannot render to it. */
|
|
3
|
+
export type OFRenderTargetFormat = 'rgba8' | 'half-float';
|
|
4
|
+
/**
|
|
5
|
+
* A framebuffer with one colour texture, to draw into instead of the canvas and then sample.
|
|
6
|
+
*
|
|
7
|
+
* The texture is LINEAR and CLAMP_TO_EDGE with no mipmaps, so any size works on WebGL 1.
|
|
8
|
+
*
|
|
9
|
+
* Content: drawn into with Alpha from a transparent clear, a target holds premultiplied colour (rgb·a, a);
|
|
10
|
+
* composite it with the Premultiplied blend mode, copy it with Replace. Over an opaque clear it is the same
|
|
11
|
+
* as straight colour.
|
|
12
|
+
*
|
|
13
|
+
* Orientation: rows run bottom-up, as in any framebuffer. A full-screen pass reads it the right way up, but
|
|
14
|
+
* sampled as a sprite's image (whose v=0 is the top) it appears flipped vertically.
|
|
15
|
+
*
|
|
16
|
+
* bind() makes it the draw target (viewport 0, 0, width, height; scissor test off) and unbind() restores what
|
|
17
|
+
* was there before, through the device, so binds nest and a `: Viewport` input is right inside the target.
|
|
18
|
+
* Never use OFRenderCamera.setViewport for a target: it resizes the canvas of a non-child camera.
|
|
19
|
+
*/
|
|
20
|
+
export declare class OFRenderTarget {
|
|
21
|
+
private readonly _graphicDevice;
|
|
22
|
+
private readonly _graphicContext;
|
|
23
|
+
private _framebuffer;
|
|
24
|
+
private _texture;
|
|
25
|
+
private _width;
|
|
26
|
+
private _height;
|
|
27
|
+
private _format;
|
|
28
|
+
private _textureType;
|
|
29
|
+
private _isBound;
|
|
30
|
+
/** The colour texture: bind it to sample what was drawn. */
|
|
31
|
+
get texture(): WebGLTexture;
|
|
32
|
+
get framebuffer(): WebGLFramebuffer;
|
|
33
|
+
get width(): number;
|
|
34
|
+
get height(): number;
|
|
35
|
+
/** The format actually used: 'rgba8' when 'half-float' was asked for and is not supported. */
|
|
36
|
+
get format(): OFRenderTargetFormat;
|
|
37
|
+
get isBound(): boolean;
|
|
38
|
+
get isDestroyed(): boolean;
|
|
39
|
+
constructor(_graphicDevice: OFGraphicDevice, width: number, height: number, format?: OFRenderTargetFormat);
|
|
40
|
+
/** Reallocates the texture when the size changes; the same size makes no GL call. The contents are lost. */
|
|
41
|
+
resize(width: number, height: number): void;
|
|
42
|
+
/** Draws go here from now on, until unbind(). */
|
|
43
|
+
bind(): void;
|
|
44
|
+
/** Puts back the framebuffer, viewport and scissor test bind() replaced. */
|
|
45
|
+
unbind(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Clears the whole target to the colour, whether or not it is bound, and only this target. When it is not the
|
|
48
|
+
* one being drawn to, it is bound on top for the clear and unbound again, also when it is bound lower down.
|
|
49
|
+
*/
|
|
50
|
+
clear(r: number, g: number, b: number, a: number): void;
|
|
51
|
+
/** Frees the framebuffer and texture. Unbinds first if bound. */
|
|
52
|
+
destroy(): void;
|
|
53
|
+
private allocate;
|
|
54
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OFRenderTarget = void 0;
|
|
4
|
+
const ofDeviceCapabilities_1 = require("../../device/ofDeviceCapabilities");
|
|
5
|
+
/**
|
|
6
|
+
* A framebuffer with one colour texture, to draw into instead of the canvas and then sample.
|
|
7
|
+
*
|
|
8
|
+
* The texture is LINEAR and CLAMP_TO_EDGE with no mipmaps, so any size works on WebGL 1.
|
|
9
|
+
*
|
|
10
|
+
* Content: drawn into with Alpha from a transparent clear, a target holds premultiplied colour (rgb·a, a);
|
|
11
|
+
* composite it with the Premultiplied blend mode, copy it with Replace. Over an opaque clear it is the same
|
|
12
|
+
* as straight colour.
|
|
13
|
+
*
|
|
14
|
+
* Orientation: rows run bottom-up, as in any framebuffer. A full-screen pass reads it the right way up, but
|
|
15
|
+
* sampled as a sprite's image (whose v=0 is the top) it appears flipped vertically.
|
|
16
|
+
*
|
|
17
|
+
* bind() makes it the draw target (viewport 0, 0, width, height; scissor test off) and unbind() restores what
|
|
18
|
+
* was there before, through the device, so binds nest and a `: Viewport` input is right inside the target.
|
|
19
|
+
* Never use OFRenderCamera.setViewport for a target: it resizes the canvas of a non-child camera.
|
|
20
|
+
*/
|
|
21
|
+
class OFRenderTarget {
|
|
22
|
+
/** The colour texture: bind it to sample what was drawn. */
|
|
23
|
+
get texture() { return this._texture; }
|
|
24
|
+
get framebuffer() { return this._framebuffer; }
|
|
25
|
+
get width() { return this._width; }
|
|
26
|
+
get height() { return this._height; }
|
|
27
|
+
/** The format actually used: 'rgba8' when 'half-float' was asked for and is not supported. */
|
|
28
|
+
get format() { return this._format; }
|
|
29
|
+
get isBound() { return this._isBound; }
|
|
30
|
+
get isDestroyed() { return !this._framebuffer; }
|
|
31
|
+
constructor(_graphicDevice, width, height, format = 'rgba8') {
|
|
32
|
+
this._graphicDevice = _graphicDevice;
|
|
33
|
+
this._width = 0;
|
|
34
|
+
this._height = 0;
|
|
35
|
+
this._isBound = false;
|
|
36
|
+
const _GL = this._graphicContext = _graphicDevice.graphicContext;
|
|
37
|
+
if (format === 'half-float' && ofDeviceCapabilities_1.OFDeviceCapabilities.supportsHalfFloatTarget(_GL)) {
|
|
38
|
+
this._format = 'half-float';
|
|
39
|
+
this._textureType = _GL.getExtension('OES_texture_half_float').HALF_FLOAT_OES;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this._format = 'rgba8';
|
|
43
|
+
this._textureType = _GL.UNSIGNED_BYTE;
|
|
44
|
+
}
|
|
45
|
+
// Setup leaves the caller's bindings as they were: a texture set before this target is made stays bound.
|
|
46
|
+
const previousFramebuffer = _GL.getParameter(_GL.FRAMEBUFFER_BINDING);
|
|
47
|
+
const previousTexture = _GL.getParameter(_GL.TEXTURE_BINDING_2D);
|
|
48
|
+
this._texture = _GL.createTexture();
|
|
49
|
+
_GL.bindTexture(_GL.TEXTURE_2D, this._texture);
|
|
50
|
+
_GL.texParameteri(_GL.TEXTURE_2D, _GL.TEXTURE_MAG_FILTER, _GL.LINEAR);
|
|
51
|
+
_GL.texParameteri(_GL.TEXTURE_2D, _GL.TEXTURE_MIN_FILTER, _GL.LINEAR);
|
|
52
|
+
_GL.texParameteri(_GL.TEXTURE_2D, _GL.TEXTURE_WRAP_S, _GL.CLAMP_TO_EDGE);
|
|
53
|
+
_GL.texParameteri(_GL.TEXTURE_2D, _GL.TEXTURE_WRAP_T, _GL.CLAMP_TO_EDGE);
|
|
54
|
+
this.allocate(width, height);
|
|
55
|
+
this._framebuffer = _GL.createFramebuffer();
|
|
56
|
+
_GL.bindFramebuffer(_GL.FRAMEBUFFER, this._framebuffer);
|
|
57
|
+
_GL.framebufferTexture2D(_GL.FRAMEBUFFER, _GL.COLOR_ATTACHMENT0, _GL.TEXTURE_2D, this._texture, 0);
|
|
58
|
+
_GL.bindFramebuffer(_GL.FRAMEBUFFER, previousFramebuffer);
|
|
59
|
+
_GL.bindTexture(_GL.TEXTURE_2D, previousTexture);
|
|
60
|
+
}
|
|
61
|
+
/** Reallocates the texture when the size changes; the same size makes no GL call. The contents are lost. */
|
|
62
|
+
resize(width, height) {
|
|
63
|
+
if (width === this._width && height === this._height) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const _GL = this._graphicContext;
|
|
67
|
+
const previousTexture = _GL.getParameter(_GL.TEXTURE_BINDING_2D);
|
|
68
|
+
_GL.bindTexture(_GL.TEXTURE_2D, this._texture);
|
|
69
|
+
this.allocate(width, height);
|
|
70
|
+
_GL.bindTexture(_GL.TEXTURE_2D, previousTexture);
|
|
71
|
+
// While bound, the viewport follows the new size.
|
|
72
|
+
if (this._isBound) {
|
|
73
|
+
this._graphicDevice.setViewport(0, 0, this._width, this._height);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Draws go here from now on, until unbind(). */
|
|
77
|
+
bind() {
|
|
78
|
+
if (this._isBound) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
this._graphicDevice.bindRenderTarget(this._framebuffer, this._width, this._height);
|
|
82
|
+
this._isBound = true;
|
|
83
|
+
}
|
|
84
|
+
/** Puts back the framebuffer, viewport and scissor test bind() replaced. */
|
|
85
|
+
unbind() {
|
|
86
|
+
if (!this._isBound) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this._graphicDevice.unbindRenderTarget(this._framebuffer);
|
|
90
|
+
this._isBound = false;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clears the whole target to the colour, whether or not it is bound, and only this target. When it is not the
|
|
94
|
+
* one being drawn to, it is bound on top for the clear and unbound again, also when it is bound lower down.
|
|
95
|
+
*/
|
|
96
|
+
clear(r, g, b, a) {
|
|
97
|
+
const device = this._graphicDevice;
|
|
98
|
+
const isCurrent = device.currentFramebuffer === this._framebuffer;
|
|
99
|
+
if (!isCurrent) {
|
|
100
|
+
device.bindRenderTarget(this._framebuffer, this._width, this._height);
|
|
101
|
+
}
|
|
102
|
+
const _GL = this._graphicContext;
|
|
103
|
+
_GL.clearColor(r, g, b, a);
|
|
104
|
+
_GL.clear(_GL.COLOR_BUFFER_BIT);
|
|
105
|
+
if (!isCurrent) {
|
|
106
|
+
device.unbindRenderTarget(this._framebuffer);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Frees the framebuffer and texture. Unbinds first if bound. */
|
|
110
|
+
destroy() {
|
|
111
|
+
if (!this._framebuffer) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.unbind();
|
|
115
|
+
const _GL = this._graphicContext;
|
|
116
|
+
_GL.deleteFramebuffer(this._framebuffer);
|
|
117
|
+
_GL.deleteTexture(this._texture);
|
|
118
|
+
this._framebuffer = null;
|
|
119
|
+
this._texture = null;
|
|
120
|
+
}
|
|
121
|
+
// Expects the texture bound on TEXTURE_2D; leaves TEXTURE_2D unbound: the callers restore the old binding.
|
|
122
|
+
allocate(width, height) {
|
|
123
|
+
const _GL = this._graphicContext;
|
|
124
|
+
this._width = Math.max(1, Math.floor(width));
|
|
125
|
+
this._height = Math.max(1, Math.floor(height));
|
|
126
|
+
_GL.texImage2D(_GL.TEXTURE_2D, 0, _GL.RGBA, this._width, this._height, 0, _GL.RGBA, this._textureType, null);
|
|
127
|
+
_GL.bindTexture(_GL.TEXTURE_2D, null);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.OFRenderTarget = OFRenderTarget;
|
|
131
|
+
//# sourceMappingURL=ofRenderTarget.js.map
|