@lightningjs/renderer
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0-rc.2
@@ -44,2 +44,5 @@ /* | ||
export * from '../src/common/CommonTypes.js'; | ||
// Selected types exported from the Core Renderer that can be used in the | ||
// context of the main API. | ||
export { CoreTextureManager, } from '../src/core/CoreTextureManager.js'; | ||
// Shaders | ||
@@ -46,0 +49,0 @@ export * from '../src/core/renderers/webgl/WebGlCoreShader.js'; |
@@ -26,3 +26,3 @@ /** | ||
export * from '../src/common/CommonTypes.js'; | ||
export type { TextureMap } from '../src/core/CoreTextureManager.js'; | ||
export { CoreTextureManager, type TextureTypeMap, type TextureMap, } from '../src/core/CoreTextureManager.js'; | ||
export type { MemoryInfo } from '../src/core/TextureMemoryManager.js'; | ||
@@ -34,4 +34,7 @@ export type { ShaderMap, EffectMap } from '../src/core/CoreShaderManager.js'; | ||
export type { EffectProps, FadeOutEffectProps, LinearGradientEffectProps, RadialGradientEffectProps, GrayscaleEffectProps, GlitchEffectProps, RadialProgressEffectProps, } from '../src/core/CoreShaderManager.js'; | ||
export type { WebGlCoreRenderer } from '../src/core/renderers/webgl/WebGlCoreRenderer.js'; | ||
export type { WebGlCoreCtxTexture } from '../src/core/renderers/webgl/WebGlCoreCtxTexture.js'; | ||
export * from '../src/core/renderers/webgl/WebGlCoreShader.js'; | ||
export * from '../src/core/renderers/webgl/shaders/effects/ShaderEffect.js'; | ||
export type { ShaderProgramSources } from '../src/core/renderers/webgl/internal/ShaderUtils.js'; | ||
export * from '../src/core/textures/Texture.js'; | ||
@@ -38,0 +41,0 @@ export * from '../src/core/text-rendering/renderers/TextRenderer.js'; |
@@ -44,2 +44,5 @@ /* | ||
export * from '../src/common/CommonTypes.js'; | ||
// Selected types exported from the Core Renderer that can be used in the | ||
// context of the main API. | ||
export { CoreTextureManager, } from '../src/core/CoreTextureManager.js'; | ||
// Shaders | ||
@@ -46,0 +49,0 @@ export * from '../src/core/renderers/webgl/WebGlCoreShader.js'; |
@@ -23,2 +23,3 @@ /** | ||
export { assertTruthy, mergeColorAlpha, deg2Rad } from '../src/utils.js'; | ||
export { getNormalizedRgbaComponents } from '../src/core/lib/utils.js'; | ||
export { EventEmitter } from '../src/common/EventEmitter.js'; |
@@ -41,3 +41,4 @@ /* | ||
export { assertTruthy, mergeColorAlpha, deg2Rad } from '../src/utils.js'; | ||
export { getNormalizedRgbaComponents } from '../src/core/lib/utils.js'; | ||
export { EventEmitter } from '../src/common/EventEmitter.js'; | ||
//# sourceMappingURL=utils.js.map |
@@ -25,2 +25,3 @@ import type { BaseShaderController } from '../../../main-api/ShaderController.js'; | ||
renderToTexture(node: CoreNode): void; | ||
getBufferInfo(): null; | ||
} |
@@ -180,3 +180,6 @@ /* | ||
} | ||
getBufferInfo() { | ||
return null; | ||
} | ||
} | ||
//# sourceMappingURL=CanvasCoreRenderer.js.map |
@@ -50,2 +50,6 @@ import type { Dimensions } from '../../common/CommonTypes.js'; | ||
} | ||
export interface BufferInfo { | ||
totalUsed: number; | ||
totalAvailable: number; | ||
} | ||
export declare abstract class CoreRenderer { | ||
@@ -70,3 +74,4 @@ options: CoreRendererOptions; | ||
abstract renderToTexture(node: CoreNode): void; | ||
abstract getBufferInfo(): BufferInfo | null; | ||
abstract getDefShaderCtr(): BaseShaderController; | ||
} |
@@ -54,3 +54,5 @@ /* | ||
bindProps(props) { | ||
this.setUniform('u_radius', props.radius); | ||
const radiusFactor = Math.min(props.$dimensions.width, props.$dimensions.height) / | ||
(2.0 * props.radius); | ||
this.setUniform('u_radius', props.radius * Math.min(radiusFactor, 1)); | ||
} | ||
@@ -57,0 +59,0 @@ canBatchShaderProps(propsA, propsB) { |
@@ -1,2 +0,2 @@ | ||
import { CoreRenderer, type CoreRendererOptions, type QuadOptions } from '../CoreRenderer.js'; | ||
import { CoreRenderer, type BufferInfo, type CoreRendererOptions, type QuadOptions } from '../CoreRenderer.js'; | ||
import { WebGlCoreRenderOp } from './WebGlCoreRenderOp.js'; | ||
@@ -35,2 +35,3 @@ import type { CoreContextTexture } from '../CoreContextTexture.js'; | ||
defaultTexture: Texture; | ||
quadBufferUsage: number; | ||
/** | ||
@@ -99,4 +100,5 @@ * Whether the renderer is currently rendering to a texture. | ||
removeRTTNode(node: CoreNode): void; | ||
getBufferInfo(): BufferInfo | null; | ||
getDefShaderCtr(): BaseShaderController; | ||
} | ||
export {}; |
@@ -37,2 +37,3 @@ /* | ||
const WORDS_PER_QUAD = 24; | ||
const QUAD_BUFFER_SIZE = 4 * 1024 * 1024; | ||
export class WebGlCoreRenderer extends CoreRenderer { | ||
@@ -43,3 +44,3 @@ //// WebGL Native Context and Data | ||
//// Persistent data | ||
quadBuffer = new ArrayBuffer(1024 * 1024 * 4); | ||
quadBuffer = new ArrayBuffer(QUAD_BUFFER_SIZE); | ||
fQuadBuffer = new Float32Array(this.quadBuffer); | ||
@@ -61,2 +62,3 @@ uiQuadBuffer = new Uint32Array(this.quadBuffer); | ||
defaultTexture; | ||
quadBufferUsage = 0; | ||
/** | ||
@@ -455,2 +457,3 @@ * Whether the renderer is currently rendering to a texture. | ||
}); | ||
this.quadBufferUsage = this.curBufferIdx * arr.BYTES_PER_ELEMENT; | ||
} | ||
@@ -521,2 +524,9 @@ renderToTexture(node) { | ||
} | ||
getBufferInfo() { | ||
const bufferInfo = { | ||
totalAvailable: QUAD_BUFFER_SIZE, | ||
totalUsed: this.quadBufferUsage, | ||
}; | ||
return bufferInfo; | ||
} | ||
getDefShaderCtr() { | ||
@@ -523,0 +533,0 @@ return this.defShaderCtrl; |
@@ -347,2 +347,3 @@ import type { EffectMap, ShaderMap } from '../core/CoreShaderManager.js'; | ||
advanceFrame(): void; | ||
getBufferInfo(): import("../core/renderers/CoreRenderer.js").BufferInfo | null; | ||
/** | ||
@@ -349,0 +350,0 @@ * Re-render the current frame without advancing any running animations. |
@@ -333,2 +333,5 @@ /* | ||
} | ||
getBufferInfo() { | ||
return this.stage.renderer.getBufferInfo(); | ||
} | ||
/** | ||
@@ -335,0 +338,0 @@ * Re-render the current frame without advancing any running animations. |
@@ -49,3 +49,7 @@ /* | ||
// context of the main API. | ||
export type { TextureMap } from '../src/core/CoreTextureManager.js'; | ||
export { | ||
CoreTextureManager, | ||
type TextureTypeMap, | ||
type TextureMap, | ||
} from '../src/core/CoreTextureManager.js'; | ||
export type { MemoryInfo } from '../src/core/TextureMemoryManager.js'; | ||
@@ -65,2 +69,4 @@ export type { ShaderMap, EffectMap } from '../src/core/CoreShaderManager.js'; | ||
} from '../src/core/CoreShaderManager.js'; | ||
export type { WebGlCoreRenderer } from '../src/core/renderers/webgl/WebGlCoreRenderer.js'; | ||
export type { WebGlCoreCtxTexture } from '../src/core/renderers/webgl/WebGlCoreCtxTexture.js'; | ||
@@ -70,2 +76,3 @@ // Shaders | ||
export * from '../src/core/renderers/webgl/shaders/effects/ShaderEffect.js'; | ||
export type { ShaderProgramSources } from '../src/core/renderers/webgl/internal/ShaderUtils.js'; | ||
@@ -72,0 +79,0 @@ // Textures |
@@ -41,2 +41,3 @@ /* | ||
export { assertTruthy, mergeColorAlpha, deg2Rad } from '../src/utils.js'; | ||
export { getNormalizedRgbaComponents } from '../src/core/lib/utils.js'; | ||
export { EventEmitter } from '../src/common/EventEmitter.js'; |
{ | ||
"name": "@lightningjs/renderer", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0-rc.2", | ||
"description": "Lightning 3 Renderer", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -92,61 +92,40 @@ # Lightning 3 Renderer (Beta) | ||
## Core Extensions | ||
## Installing Fonts | ||
To load fonts, and/or other custom code into the Core Space, you must write a | ||
Core Extension and pass it via dynamically importable URL to the initialization | ||
of the Renderer. | ||
Fonts can be installed into the Font Manager exposed by the Renderer's Stage. | ||
There are two types of fonts that you can install, Web/Canvas2D fonts (WebTrFontFace) | ||
and SDF fonts (SdfTrFontFace). Install that fonts that your applications needs | ||
at start up so they are ready when your application is rendered. | ||
Just like with loading the ThreadX Core Web Worker for the ThreadX, you import | ||
your core extension using the `@lightningjs/vite-plugin-import-chunk-url` plugin so that | ||
it's code is bundled and loaded seperately from your main app's bundle. | ||
You can write a Core Extension by extending the CoreExtension class from the | ||
Core API like so: | ||
```ts | ||
import { | ||
CoreExtension, | ||
RendererMain, | ||
WebTrFontFace, | ||
SdfTrFontFace, | ||
type Stage, | ||
} from '@lightning/renderer/core'; | ||
} from '@lightningjs/renderer'; | ||
export default class MyCoreExtension extends CoreExtension { | ||
async run(stage: Stage) { | ||
// Load fonts into core | ||
stage.fontManager.addFontFace( | ||
new WebTrFontFace('Ubuntu', {}, '/fonts/Ubuntu-Regular.ttf'), | ||
); | ||
stage.fontManager.addFontFace( | ||
new SdfTrFontFace( | ||
'Ubuntu', | ||
{}, | ||
'msdf', | ||
stage, | ||
'/fonts/Ubuntu-Regular.msdf.png', | ||
'/fonts/Ubuntu-Regular.msdf.json', | ||
), | ||
); | ||
} | ||
} | ||
``` | ||
And then in your application's main entry point you can import it using | ||
`@lightningjs/vite-plugin-import-chunk-url`: | ||
```ts | ||
import coreExtensionModuleUrl from './MyCoreExtension.js?importChunkUrl'; | ||
// Set up driver, etc. | ||
// Initialize the Renderer | ||
const renderer = new RendererMain( | ||
{ | ||
// Other Renderer Config... | ||
coreExtensionModule: coreExtensionModuleUrl, | ||
appWidth: 1920, | ||
appHeight: 1080, | ||
// ...Other Renderer Config | ||
}, | ||
'app', | ||
driver, | ||
'app', // id of div to insert Canvas. | ||
); | ||
// Load fonts into renderer | ||
renderer.stage.fontManager.addFontFace( | ||
new WebTrFontFace('Ubuntu', {}, '/fonts/Ubuntu-Regular.ttf'), | ||
); | ||
renderer.stage.fontManager.addFontFace( | ||
new SdfTrFontFace( | ||
'Ubuntu', | ||
{}, | ||
'msdf', | ||
stage, | ||
'/fonts/Ubuntu-Regular.msdf.png', | ||
'/fonts/Ubuntu-Regular.msdf.json', | ||
), | ||
); | ||
``` |
@@ -242,2 +242,5 @@ /* | ||
} | ||
getBufferInfo(): null { | ||
return null; | ||
} | ||
} |
@@ -75,2 +75,7 @@ /* | ||
export interface BufferInfo { | ||
totalUsed: number; | ||
totalAvailable: number; | ||
} | ||
export abstract class CoreRenderer { | ||
@@ -106,3 +111,4 @@ public options: CoreRendererOptions; | ||
abstract renderToTexture(node: CoreNode): void; | ||
abstract getBufferInfo(): BufferInfo | null; | ||
abstract getDefShaderCtr(): BaseShaderController; | ||
} |
@@ -80,3 +80,6 @@ /* | ||
protected override bindProps(props: Required<RoundedRectangleProps>): void { | ||
this.setUniform('u_radius', props.radius); | ||
const radiusFactor = | ||
Math.min(props.$dimensions.width, props.$dimensions.height) / | ||
(2.0 * props.radius); | ||
this.setUniform('u_radius', props.radius * Math.min(radiusFactor, 1)); | ||
} | ||
@@ -83,0 +86,0 @@ |
@@ -23,2 +23,3 @@ /* | ||
CoreRenderer, | ||
type BufferInfo, | ||
type CoreRendererOptions, | ||
@@ -58,2 +59,3 @@ type QuadOptions, | ||
const WORDS_PER_QUAD = 24; | ||
const QUAD_BUFFER_SIZE = 4 * 1024 * 1024; | ||
// const BYTES_PER_QUAD = WORDS_PER_QUAD * 4; | ||
@@ -74,3 +76,3 @@ | ||
//// Persistent data | ||
quadBuffer: ArrayBuffer = new ArrayBuffer(1024 * 1024 * 4); | ||
quadBuffer: ArrayBuffer = new ArrayBuffer(QUAD_BUFFER_SIZE); | ||
fQuadBuffer: Float32Array = new Float32Array(this.quadBuffer); | ||
@@ -96,2 +98,3 @@ uiQuadBuffer: Uint32Array = new Uint32Array(this.quadBuffer); | ||
quadBufferUsage = 0; | ||
/** | ||
@@ -620,2 +623,3 @@ * Whether the renderer is currently rendering to a texture. | ||
}); | ||
this.quadBufferUsage = this.curBufferIdx * arr.BYTES_PER_ELEMENT; | ||
} | ||
@@ -702,2 +706,10 @@ | ||
getBufferInfo(): BufferInfo | null { | ||
const bufferInfo: BufferInfo = { | ||
totalAvailable: QUAD_BUFFER_SIZE, | ||
totalUsed: this.quadBufferUsage, | ||
}; | ||
return bufferInfo; | ||
} | ||
override getDefShaderCtr(): BaseShaderController { | ||
@@ -704,0 +716,0 @@ return this.defShaderCtrl; |
@@ -574,2 +574,6 @@ /* | ||
getBufferInfo() { | ||
return this.stage.renderer.getBufferInfo(); | ||
} | ||
/** | ||
@@ -576,0 +580,0 @@ * Re-render the current frame without advancing any running animations. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1703751
38344
131