shute-technologies.octopus-web-framework 1.4.0 → 1.6.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 +4 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/data/ofIShaderCodeInfoInputData.d.ts +2 -0
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofEnumShaderDataTypes.d.ts +4 -1
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofEnumShaderDataTypes.js +3 -0
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofEnumShaderDataTypes.js.map +1 -1
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofEnumShaderLiterals.d.ts +4 -1
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofEnumShaderLiterals.js +3 -0
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofEnumShaderLiterals.js.map +1 -1
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofShaderAnalizer.js +13 -1
- package/lib/src/shute-technologies/modules/cross-cutting/shader-analizer/ofShaderAnalizer.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 +53 -0
- package/lib/src/shute-technologies/modules/framework/core/device/ofGraphicDevice.js +138 -0
- package/lib/src/shute-technologies/modules/framework/core/device/ofGraphicDevice.js.map +1 -1
- package/lib/src/shute-technologies/modules/framework/core/render/camera/ofRenderCamera.js +3 -3
- 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/ofSprite.d.ts +2 -0
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/ofSprite.js +4 -0
- 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 +4 -0
- 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 +2 -0
- package/lib/src/shute-technologies/modules/framework/core/render/graphics/d2d/optimization/ofPolygonBatcher.js +4 -0
- 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/shader/ofBaseShader.d.ts +2 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofBaseShader.js +4 -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 +10 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofEnumBlendMode.js +15 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofEnumBlendMode.js.map +1 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.d.ts +4 -0
- package/lib/src/shute-technologies/modules/framework/core/render/shader/ofShaderAbstract.js +49 -2
- 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 +4 -2
- 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 +6 -4
- 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
|
@@ -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
|
+
_GL.bindBuffer(_GL.ARRAY_BUFFER, this._vertexBuffer);
|
|
52
|
+
_GL.bufferData(_GL.ARRAY_BUFFER, OFFullscreenPass.QuadVertices, _GL.STATIC_DRAW);
|
|
53
|
+
_GL.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
|
+
_GL.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._graphicContext.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,k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AAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;SACxC;QAED,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,YAAY,+BAAc,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;SACzF;QAED,gGAAgG;QAChG,qEAAqE;QACrE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAEzF,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,8FAA8F;IAC9F,OAAO;QACL,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACtD,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ofRenderTarget.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/target/ofRenderTarget.ts"],"names":[],"mappings":";;;AACA,4EAAyE;AAKzE;;;;;;;;;;;;;;;GAeG;AACH,MAAa,cAAc;IAWzB,4DAA4D;IAC5D,IAAI,OAAO,KAAmB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,IAAI,WAAW,KAAuB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACjE,IAAI,KAAK,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,8FAA8F;IAC9F,IAAI,MAAM,KAA2B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,IAAI,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChD,IAAI,WAAW,KAAc,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEzD,YAA6B,cAA+B,EAAE,KAAa,EAAE,MAAc,EACzF,SAA+B,OAAO;QADX,mBAAc,GAAd,cAAc,CAAiB;QAhBpD,WAAM,GAAG,CAAC,CAAC;QACX,YAAO,GAAG,CAAC,CAAC;QAGZ,aAAQ,GAAG,KAAK,CAAC;QAcvB,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,cAAc,CAAC;QAEjE,IAAI,MAAM,KAAK,YAAY,IAAI,2CAAoB,CAAC,uBAAuB,CAAC,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AG,IAAI,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,2GAA2G;IACnG,QAAQ,CAAC,KAAa,EAAE,MAAc;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC;QAEjC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC/C,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAC7G,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;CACF;AAzHD,wCAyHC"}
|
package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTargetPool.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OFGraphicDevice } from '../../device/ofGraphicDevice';
|
|
2
|
+
import { OFRenderTarget, OFRenderTargetFormat } from './ofRenderTarget';
|
|
3
|
+
/**
|
|
4
|
+
* Render targets reused by size and format, so a pass that needs a few targets every frame allocates them once.
|
|
5
|
+
*
|
|
6
|
+
* acquire() hands out a free target of that size and format, or makes one; release() gives it back. Call
|
|
7
|
+
* endFrame() once a frame and trim() now and then: targets free for more than `maxIdleFrames` frames are
|
|
8
|
+
* destroyed, so a resize or a pass that stops running does not keep its textures forever.
|
|
9
|
+
*/
|
|
10
|
+
export declare class OFRenderTargetPool {
|
|
11
|
+
private readonly _graphicDevice;
|
|
12
|
+
private readonly _entries;
|
|
13
|
+
private _frame;
|
|
14
|
+
/** Targets the pool owns, in use or free. */
|
|
15
|
+
get count(): number;
|
|
16
|
+
/** Targets acquired and not yet released. */
|
|
17
|
+
get inUseCount(): number;
|
|
18
|
+
get frame(): number;
|
|
19
|
+
constructor(_graphicDevice: OFGraphicDevice);
|
|
20
|
+
acquire(width: number, height: number, format?: OFRenderTargetFormat): OFRenderTarget;
|
|
21
|
+
/** Gives the target back. A target the pool does not own, or one already released, is ignored. */
|
|
22
|
+
release(target: OFRenderTarget): void;
|
|
23
|
+
/** Counts a frame; trim() measures idleness in these. */
|
|
24
|
+
endFrame(): void;
|
|
25
|
+
/** Destroys free targets unused for more than `maxIdleFrames` frames. Targets in use are kept. */
|
|
26
|
+
trim(maxIdleFrames?: number): void;
|
|
27
|
+
/** Destroys every target, in use or not, last acquired first, so nested binds unwind in order. */
|
|
28
|
+
destroy(): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OFRenderTargetPool = void 0;
|
|
4
|
+
const ofRenderTarget_1 = require("./ofRenderTarget");
|
|
5
|
+
/**
|
|
6
|
+
* Render targets reused by size and format, so a pass that needs a few targets every frame allocates them once.
|
|
7
|
+
*
|
|
8
|
+
* acquire() hands out a free target of that size and format, or makes one; release() gives it back. Call
|
|
9
|
+
* endFrame() once a frame and trim() now and then: targets free for more than `maxIdleFrames` frames are
|
|
10
|
+
* destroyed, so a resize or a pass that stops running does not keep its textures forever.
|
|
11
|
+
*/
|
|
12
|
+
class OFRenderTargetPool {
|
|
13
|
+
/** Targets the pool owns, in use or free. */
|
|
14
|
+
get count() { return this._entries.length; }
|
|
15
|
+
/** Targets acquired and not yet released. */
|
|
16
|
+
get inUseCount() { return this._entries.filter((entry) => entry.inUse).length; }
|
|
17
|
+
get frame() { return this._frame; }
|
|
18
|
+
constructor(_graphicDevice) {
|
|
19
|
+
this._graphicDevice = _graphicDevice;
|
|
20
|
+
this._entries = [];
|
|
21
|
+
this._frame = 0;
|
|
22
|
+
}
|
|
23
|
+
acquire(width, height, format = 'rgba8') {
|
|
24
|
+
const w = Math.max(1, Math.floor(width));
|
|
25
|
+
const h = Math.max(1, Math.floor(height));
|
|
26
|
+
let entry = this._entries.find((candidate) => !candidate.inUse && candidate.requestedFormat === format
|
|
27
|
+
&& candidate.target.width === w && candidate.target.height === h);
|
|
28
|
+
if (!entry) {
|
|
29
|
+
entry = { target: new ofRenderTarget_1.OFRenderTarget(this._graphicDevice, w, h, format), requestedFormat: format, inUse: false, lastUsedFrame: 0 };
|
|
30
|
+
this._entries.push(entry);
|
|
31
|
+
}
|
|
32
|
+
entry.inUse = true;
|
|
33
|
+
entry.lastUsedFrame = this._frame;
|
|
34
|
+
return entry.target;
|
|
35
|
+
}
|
|
36
|
+
/** Gives the target back. A target the pool does not own, or one already released, is ignored. */
|
|
37
|
+
release(target) {
|
|
38
|
+
const entry = this._entries.find((candidate) => candidate.target === target);
|
|
39
|
+
if (!entry || !entry.inUse) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
target.unbind();
|
|
43
|
+
entry.inUse = false;
|
|
44
|
+
entry.lastUsedFrame = this._frame;
|
|
45
|
+
}
|
|
46
|
+
/** Counts a frame; trim() measures idleness in these. */
|
|
47
|
+
endFrame() {
|
|
48
|
+
this._frame++;
|
|
49
|
+
}
|
|
50
|
+
/** Destroys free targets unused for more than `maxIdleFrames` frames. Targets in use are kept. */
|
|
51
|
+
trim(maxIdleFrames = 60) {
|
|
52
|
+
for (let i = this._entries.length - 1; i >= 0; i--) {
|
|
53
|
+
const entry = this._entries[i];
|
|
54
|
+
if (!entry.inUse && this._frame - entry.lastUsedFrame > maxIdleFrames) {
|
|
55
|
+
entry.target.destroy();
|
|
56
|
+
this._entries.splice(i, 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Destroys every target, in use or not, last acquired first, so nested binds unwind in order. */
|
|
61
|
+
destroy() {
|
|
62
|
+
for (let i = this._entries.length - 1; i >= 0; i--) {
|
|
63
|
+
this._entries[i].target.destroy();
|
|
64
|
+
}
|
|
65
|
+
this._entries.length = 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.OFRenderTargetPool = OFRenderTargetPool;
|
|
69
|
+
//# sourceMappingURL=ofRenderTargetPool.js.map
|
package/lib/src/shute-technologies/modules/framework/core/render/target/ofRenderTargetPool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ofRenderTargetPool.js","sourceRoot":"","sources":["../../../../../../../../src/shute-technologies/modules/framework/core/render/target/ofRenderTargetPool.ts"],"names":[],"mappings":";;;AACA,qDAAwE;AAUxE;;;;;;GAMG;AACH,MAAa,kBAAkB;IAK7B,6CAA6C;IAC7C,IAAI,KAAK,KAAa,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,6CAA6C;IAC7C,IAAI,UAAU,KAAa,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACxF,IAAI,KAAK,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3C,YAA6B,cAA+B;QAA/B,mBAAc,GAAd,cAAc,CAAiB;QAT3C,aAAQ,GAAsB,EAAE,CAAC;QAC1C,WAAM,GAAG,CAAC,CAAC;IAQ4C,CAAC;IAEhE,OAAO,CAAC,KAAa,EAAE,MAAc,EAAE,SAA+B,OAAO;QAC3E,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,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ClG,IAAI,CAAC,aAAa,GAAG,EAAE;QACrB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAClD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAE/B,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,GAAG,aAAa,EAAE;gBACrE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aAC5B;SACF;IACH,CAAC;IAED,kGAAkG;IAClG,OAAO;QACL,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAClD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SACnC;QAED,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AAjED,gDAiEC"}
|
package/lib/src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare class IOFDefaultShaderSource {
|
|
|
5
5
|
export declare class OFDefaultShaderSources {
|
|
6
6
|
static readonly SourcesShaderPrimitive: IOFDefaultShaderSource;
|
|
7
7
|
static readonly SourcesShaderTexture: IOFDefaultShaderSource;
|
|
8
|
+
/** Draws a texture unchanged over a clip-space quad (OFFullscreenPass.copyShader). */
|
|
9
|
+
static readonly SourcesFullscreenCopy: IOFDefaultShaderSource;
|
|
8
10
|
static readonly SourcesSpineShaderTexture: IOFDefaultShaderSource;
|
|
9
11
|
static readonly SourcesTextShaderTexture: IOFDefaultShaderSource;
|
|
10
12
|
}
|
package/lib/src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.js
CHANGED
|
@@ -15,8 +15,10 @@ OFDefaultShaderSources.SourcesShaderPrimitive = {
|
|
|
15
15
|
" gl_Position = uWVPMatrix * vec4(aVertexPosition, 1.0);\n" +
|
|
16
16
|
"}",
|
|
17
17
|
fragment: "uniform lowp vec4 uColor : Color;\n\n" +
|
|
18
|
+
"uniform lowp float uPremultiplyAlpha : Shared;\n\n" +
|
|
18
19
|
"void main(void) {\n" +
|
|
19
20
|
" gl_FragColor = uColor;\n" +
|
|
21
|
+
" gl_FragColor.rgb *= mix(1.0, gl_FragColor.a, uPremultiplyAlpha);\n" +
|
|
20
22
|
"}"
|
|
21
23
|
};
|
|
22
24
|
OFDefaultShaderSources.SourcesShaderTexture = {
|
|
@@ -31,8 +33,26 @@ OFDefaultShaderSources.SourcesShaderTexture = {
|
|
|
31
33
|
fragment: "varying highp vec2 varyingTextureCoord;\n\n" +
|
|
32
34
|
"uniform lowp vec4 uColor : Color;\n" +
|
|
33
35
|
"uniform sampler2D uSamplerTexture : Texture;\n\n" +
|
|
36
|
+
"uniform lowp float uPremultiplyAlpha : Shared;\n\n" +
|
|
34
37
|
"void main(void) {\n" +
|
|
35
38
|
" gl_FragColor = texture2D(uSamplerTexture, varyingTextureCoord) * uColor;\n" +
|
|
39
|
+
" gl_FragColor.rgb *= mix(1.0, gl_FragColor.a, uPremultiplyAlpha);\n" +
|
|
40
|
+
"}"
|
|
41
|
+
};
|
|
42
|
+
/** Draws a texture unchanged over a clip-space quad (OFFullscreenPass.copyShader). */
|
|
43
|
+
OFDefaultShaderSources.SourcesFullscreenCopy = {
|
|
44
|
+
vertex: "attribute vec3 aVertexPosition;\n" +
|
|
45
|
+
"attribute vec2 aTextureCoord;\n\n" +
|
|
46
|
+
"uniform mat4 uWVPMatrix : Camera;\n\n" +
|
|
47
|
+
"varying highp vec2 varyingTextureCoord;\n\n" +
|
|
48
|
+
"void main(void) {\n" +
|
|
49
|
+
" varyingTextureCoord = aTextureCoord;\n" +
|
|
50
|
+
" gl_Position = uWVPMatrix * vec4(aVertexPosition, 1.0);\n" +
|
|
51
|
+
"}",
|
|
52
|
+
fragment: "varying highp vec2 varyingTextureCoord;\n\n" +
|
|
53
|
+
"uniform sampler2D uSamplerTexture : Texture;\n\n" +
|
|
54
|
+
"void main(void) {\n" +
|
|
55
|
+
" gl_FragColor = texture2D(uSamplerTexture, varyingTextureCoord);\n" +
|
|
36
56
|
"}"
|
|
37
57
|
};
|
|
38
58
|
OFDefaultShaderSources.SourcesSpineShaderTexture = {
|
|
@@ -50,8 +70,10 @@ OFDefaultShaderSources.SourcesSpineShaderTexture = {
|
|
|
50
70
|
fragment: "varying lowp vec4 varyingVertexColor;\n" +
|
|
51
71
|
"varying highp vec2 varyingTextureCoord;\n\n" +
|
|
52
72
|
"uniform sampler2D uSamplerTexture : Texture;\n\n" +
|
|
73
|
+
"uniform lowp float uPremultiplyAlpha : Shared;\n\n" +
|
|
53
74
|
"void main(void) {\n" +
|
|
54
75
|
" gl_FragColor = texture2D(uSamplerTexture, varyingTextureCoord) * varyingVertexColor;\n" +
|
|
76
|
+
" gl_FragColor.rgb *= mix(1.0, gl_FragColor.a, uPremultiplyAlpha);\n" +
|
|
55
77
|
"}"
|
|
56
78
|
};
|
|
57
79
|
OFDefaultShaderSources.SourcesTextShaderTexture = {
|
|
@@ -70,8 +92,10 @@ OFDefaultShaderSources.SourcesTextShaderTexture = {
|
|
|
70
92
|
"varying highp vec2 varyingTextureCoord;\n\n" +
|
|
71
93
|
"uniform lowp vec4 uTintColor : Color;\n" +
|
|
72
94
|
"uniform sampler2D uSamplerTexture : Texture;\n\n" +
|
|
95
|
+
"uniform lowp float uPremultiplyAlpha : Shared;\n\n" +
|
|
73
96
|
"void main(void) {\n" +
|
|
74
97
|
" gl_FragColor = texture2D(uSamplerTexture, varyingTextureCoord) * varyingVertexColor * uTintColor;\n" +
|
|
98
|
+
" gl_FragColor.rgb *= mix(1.0, gl_FragColor.a, uPremultiplyAlpha);\n" +
|
|
75
99
|
"}"
|
|
76
100
|
};
|
|
77
101
|
//# sourceMappingURL=ofDefaultShaderSources.js.map
|
package/lib/src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofDefaultShaderSources.js","sourceRoot":"","sources":["../../../../../../src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.ts"],"names":[],"mappings":";;;AAAA,MAAa,sBAAsB;CAGlC;AAHD,wDAGC;AAED,MAAa,sBAAsB;;AAAnC,
|
|
1
|
+
{"version":3,"file":"ofDefaultShaderSources.js","sourceRoot":"","sources":["../../../../../../src/shute-technologies/modules/framework/default-assets/ofDefaultShaderSources.ts"],"names":[],"mappings":";;;AAAA,MAAa,sBAAsB;CAGlC;AAHD,wDAGC;AAED,MAAa,sBAAsB;;AAAnC,wDA4IC;AA1IiB,6CAAsB,GAAG;IACvC,MAAM,EACF,qCAAqC;QAErC,uCAAuC;QAEvC,wCAAwC;QAExC,qBAAqB;QACjB,8DAA8D;QAClE,GAAG;IAEP,QAAQ,EACJ,uCAAuC;QAEvC,oDAAoD;QAEpD,qBAAqB;QACrB,8BAA8B;QAC9B,wEAAwE;QACxE,GAAG;CACkB,CAAC;AAEZ,2CAAoB,GAAG;IACrC,MAAM,EACF,mCAAmC;QACnC,mCAAmC;QAEnC,uCAAuC;QAEvC,6CAA6C;QAE7C,qBAAqB;QACjB,4CAA4C;QAC5C,8DAA8D;QAClE,GAAG;IAEP,QAAQ,EACJ,6CAA6C;QAE7C,qCAAqC;QACrC,kDAAkD;QAElD,oDAAoD;QAEpD,qBAAqB;QACrB,gFAAgF;QAChF,wEAAwE;QACxE,GAAG;CACkB,CAAC;AAE5B,sFAAsF;AACtE,4CAAqB,GAAG;IACtC,MAAM,EACF,mCAAmC;QACnC,mCAAmC;QAEnC,uCAAuC;QAEvC,6CAA6C;QAE7C,qBA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