Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

13.4 KB
Raw Blame
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/**
 * @file    core-render.ts
 * @brief   Rendering + graphics surface.
 *
 * Draw / Material / Geometry / PostProcess / Renderer APIs, render-pipeline
 * composition, render textures, frame capture, filters, graphics primitives,
 * texture parameters, and camera utilities.
 *
 * Re-exported wholesale by `core.ts`.
 */

// =============================================================================
// Filters
// =============================================================================

export { Filters } from './render/filters';
export { planarReflectionStatus, refreshPlanarReflection, type PlanarReflectionStatus } from './render/planarReflection';

export { LIGHT_FORWARD, lightAimRotation, lightAimOf } from './render/lightAim';

export {
    SpriteFilter,
    type OutlineFilterOptions,
    type DropShadowFilterOptions,
} from './render/spriteFilter';

// =============================================================================
// Graphics
// =============================================================================

export { Graphics } from './render/graphics';

// =============================================================================
// Texture
// =============================================================================

export { TextureFilter, TextureWrap, setTextureFilter, setTextureWrap, setTextureParams, setTextureSliceBorder } from './render/textureParams';

// =============================================================================
// Camera
// =============================================================================

export { CameraView, CameraViewAPI, PresentedCameraView, presentedCameraView, type CameraLens } from './camera/Camera';
export { CameraCommit, onCameraCommitChanged, cameraCommitChanged,
         type CameraCommitData, type CameraCommitListener } from './camera/CameraCommit';
export { EditorView, DEFAULT_EDITOR_VIEW, editorViewHalfHeight, editorViewHalfExtent, editorViewWorldPerPixel, setEditorViewHalfHeight, editorViewIsOrbited, editorViewAxes, editorViewAxisAngles, editorViewBasis, editorViewEye, editorViewStandoff, editorViewClipFar, editorViewClipNear, editorViewWorkPlane, editorViewGridPlane, screenWorkAxes, worldAxisVector, moveEditorViewFocus, editorViewBoxExtent } from './camera/EditorView';
export type { EditorViewData, ScreenAxis, EditorViewBasis, EditorWorkPlane, WorldAxis } from './camera/EditorView';
export { EditorViewLighting, DEFAULT_EDITOR_VIEW_LIGHTING, EDITOR_EXPOSURE_RANGE, editorViewLightingIsOverriding, resetEditorViewLighting, editorViewLightingArgs, studioPreviewReport } from './camera/EditorViewLighting';
export type { EditorViewLightingData, EditorLightingMode, StudioPreviewReport, SkyUnavailable, SceneDark } from './camera/EditorViewLighting';
export { EditorViewShading, DEFAULT_EDITOR_VIEW_SHADING, editorViewShadingMode } from './camera/EditorViewShading';
export type { EditorViewShadingData } from './camera/EditorViewShading';
export { ScreenScaling, DEFAULT_SCREEN_SCALING, SCREEN_FIT_OFF } from './camera/ScreenScaling';
export type { ScreenScalingData } from './camera/ScreenScaling';
export { EditorGrid, DEFAULT_EDITOR_GRID } from './camera/EditorGrid';
export type { EditorGridData, GridColor } from './camera/EditorGrid';
export { installEditorGrid } from './camera/editorGridRenderer';
export { CameraDirector, setViewTarget, setTimelineShot, shakeCamera, BlendCurve } from './camera/CameraDirector';
export { FollowTarget } from './camera/FollowTarget';
export type { FollowTargetData } from './camera/FollowTarget';
export { CameraBounds } from './camera/CameraBounds';
export type { CameraBoundsData } from './camera/CameraBounds';
export type { CameraDirectorState, TimelineShot } from './camera/CameraDirector';
export type { CameraPOV } from './camera/CameraPlugin';
export { cameraFrustumCorners, renderCameraFrame } from './camera/CameraPlugin';
export type { CameraFields, CameraTransformFields } from './camera/CameraPlugin';
export { computeEffectiveOrthoSize, uiLayoutRect, EDITOR_VIEW_ENTITY, EDITOR_UI_ANCHOR } from './camera/uiLayoutRect';
export type { CameraExtents, CanvasScale, WorldRect } from './camera/uiLayoutRect';

// =============================================================================
// Draw API
// =============================================================================

export {
    Draw,
    BlendMode,
    shutdownDrawAPI,
    type DrawAPI,
} from './render/draw';

// =============================================================================
// Material API
// =============================================================================

export {
    Material,
    ShaderSources,
    shutdownMaterialAPI,
    isTextureRef,
    CullMode,
    MATERIAL_FORMAT_VERSION,
    type ShaderHandle,
    type MaterialHandle,
    type MaterialOptions,
    type MaterialData,
    type MaterialAssetData,
    type UniformValue,
    type TextureRef,
} from './render/material';

export { renderMeshPreview } from './render/assetPreview';
export { SkeletalPreview } from './render/skeletalPreview';
export type { SkeletalPreviewBatch } from './render/skeletalPreview';

export {
    BUILTIN_SHADER_TEMPLATES,
    builtinShaderTemplate,
    type BuiltinShaderTemplate,
} from './render/builtinShaders';

// What a `.esshader` declares, read from its source: the editor's parameter panel, the
// built-in templates' defaults and setUniform's "no such param" all read the one parser.
export {
    reflectEsshader,
    paramDefaultValue,
    type ShaderParam,
    type ShaderParamType,
    type ShaderReflection,
} from './render/shaderReflect';

export {
    compileMaterialGraph,
    newMaterialGraph,
    newMaterialSubgraph,
    flattenSubgraphs,
    subgraphInputs,
    extractSubgraph,
    subgraphOutputType,
    subgraphRefs,
    validateSubgraph,
    addNode,
    moveNode,
    connect,
    disconnect,
    removeNode,
    NODE_SPECS,
    type MaterialGraph,
    type MaterialGraphNode,
    type SubgraphResolver,
    type SubgraphInput,
    type GraphNodeType,
    type GraphType,
    type NodeSpec,
    type NodePort,
    type NodeParamSpec,
} from './render/materialGraph';

// =============================================================================
// Geometry API
// =============================================================================

export {
    Geometry,
    DataType,
    shutdownGeometryAPI,
    type GeometryHandle,
    type GeometryOptions,
    type VertexAttributeDescriptor,
} from './render/geometry';

// =============================================================================
// PostProcess API
// =============================================================================

export {
    PostProcess,
    PostProcessAPI,
    PostProcessStack,
    type OutputTransform,
    type HdrFormat,
    type EffectDef,
    type ComputeEffectSource,
    type EffectUniformDef,
    registerEffect,
    getEffectDef,
    uniformInUnits,
    getEffectTypes,
    getAllEffectDefs,
    registerWeatherPreset,
    weatherPresetId,
    weatherPresetNames,
    blendWeather,
    currentWeather,
    WeatherDrive,
    WEATHER_CLEAR,
    WEATHER_MIST,
    WEATHER_OVERCAST,
    WEATHER_RAIN,
    WEATHER_STORM,
    WEATHER_SNOW,
    skyClockState,
    setSkyClockState,
    type SkyClockState,
    WEATHER_NONE,
    type WeatherState,
    type WeatherPreset,
    timeOfDayAt,
    sunPosition,
    currentTimeOfDay,
    TimeDrive,
    type TimeOfDayState,
    defineSkyEffect,
    type SkyEffectSource,
} from './postprocess';

// =============================================================================
// Renderer API
// =============================================================================

export {
    Renderer,
    RenderStage,
    shutdownRendererAPI,
    type RenderTargetHandle,
    type RenderStats,
    type LodDecision,
    type ViewShading,
    type LightStatus,
    type ShadowStatus,
} from './render/renderer';

// =============================================================================
// Device Loss
// =============================================================================

export {
    DeviceStatus,
    DeviceLostReason,
    getDeviceStatus,
    getDeviceIdentity,
    type DeviceIdentity,
    getDeviceLostReport,
    reportDeviceLost,
    recoverDevice,
    deviceGeneration,
    onDeviceRestored,
    type DeviceRestoredListener,
    getContextLossGuardInfo,
} from './render/renderer';

/**
 * What the engine drew, from the backend that drew it — so a capture is not the
 * display's opinion of the frame.
 *
 * @beta Pre-1.0: the frame-advance callback may become a schedule hook.
 */
/**
 * What a WebGPU device has to be created with for the engine to use everything
 * it ships — compressed textures above all.
 *
 * @beta
 */
export {
    ENGINE_WEBGPU_FEATURES,
    engineWebGPUFeatures,
    type WebGPUAdapterLike,
} from './render/webgpuFeatures';

/**
 * Acquiring the device a WebGPU boot needs, before the module that reads it
 * exists — one answer for every host rather than one each.
 *
 * @beta
 */
export {
    acquireWebGPUDevice,
    type RenderBackendRequest,
    type WebGPUBootResult,
} from './render/webgpuBoot';

export {
    captureFramePixels,
    canCaptureFramePixels,
    type FramePixels,
} from './render/framePixels';

export {
    LayerOrder,
    layerOrderOf,
    layerFrontness,
    compareDrawRank,
    rankPickCandidates,
    type DrawRank,
    type PickCandidate,
} from './render/layerOrder';

export {
    BatchBreak,
    CapturePass,
    RenderType,
    captureFrame,
    replayDraw,
    type DrawCallInfo,
    type FrameCaptureData,
    type NextFrame,
    type ReplaySnapshot,
} from './render/frameCapture';
export {
    captureFrameReport,
    frameDebugReport,
    replayFrameDraw,
    type FrameAssetNames,
    type FrameDebugReport,
    type FrameReplayImage,
} from './render/frameDebugReport';

// =============================================================================
// RenderTexture API
// =============================================================================

export {
    RenderTexture,
    type RenderTextureHandle,
    type RenderTextureOptions,
} from './render/renderTexture';

export {
    TextureAtlas,
    type TextureAtlasHandle,
    type TextureAtlasOptions,
    type AtlasEntry,
} from './render/textureAtlas';

export { uvRectFromPixels, type UvRect } from './render/uvRect';

export {
    TextureCanvas,
    type TextureCanvasHandle,
    type TextureCanvasOptions,
} from './render/textureCanvas';

// =============================================================================
// Render Pipeline
// =============================================================================

export {
    RenderPipeline,
    type Viewport,
    type RenderParams,
    type CameraRenderParams,
} from './render/renderPipeline';
export { setRenderOriginStep, renderOrigin, type RenderOriginState } from './render/renderOrigin';

// =============================================================================
// Custom Draw Callbacks
// =============================================================================

export {
    registerDrawCallback,
    unregisterDrawCallback,
    clearDrawCallbacks,
    type DrawCallback,
    type DrawFrameInfo,
    registerPreSceneDrawCallback,
    unregisterPreSceneDrawCallback,
    type PreSceneDrawCallback,
    type PreSceneDrawInfo,
} from './render/customDraw';
export { QualityController, judgeFrames, parseQualityConfig, resolveQualityProfile, defaultQualityProfile, defaultQualityMode, MOST_WATER_WAVES } from './render/quality';
export type {
    QualityConfig, QualityProfile, QualityLevel, QualityMode,
    QualityReport, QualitySample, FrameVerdict, DeviceQualityInfo, DeviceQualityRule,
} from './render/quality';
export { Quality } from './render/qualityRuntime';
export { warmShaders, shadersCompiled, pendingShaders, holdShaderWarmup } from './render/shaderWarmup';
export { RenderDemand } from './render/renderDemand';
export { buildPathGeometry, mergeGeometry, cubicBezier, quadraticBezier, circlePoints } from './render/vectorPath';
export type { PathStyle, PathFill, PathStroke, PathColor, LineJoin, LineCap } from './render/vectorPath';
export { setPath, clearPath } from './render/pathRenderer';
export { RainShelter, RainUpright, uprightOf, uprightRects, drynessOf, maskRects, shelterMaskSizeOf, ellipseStripsOf, type RainShelterData, type RainUprightData, type Upright, type Shelter, type MaskRect } from './render/rainShelter';
export { Footsteps, StepSurface, StepKind, surfaceAt, footAt, stampLook, type FootstepsData, type StepSurfaceData } from './render/footsteps';
export { decidePower, type PowerPolicy, type PowerDecision, type PowerLevel } from './render/power';
export { SwayPusher, nearestPushers, SWAY_PUSHERS, type SwayPusherData, type PushValue } from './render/swayPush';
export { FogOfWar, ExploredGrid, fanDistances, exploredToString, exploredFromString, type FogOfWarData } from './render/fogOfWar';
export { SightViewer, SightTarget, segmentBlocked, seesPoint, sightRingOf, ringContains, currentSightRings, type SightViewerData, type SightTargetData, type SightRing, type SightPoint } from './render/sight';
export { CoverFade, CoverFadeTarget, coveredGround, coversPoint, stepFade, type CoverFadeData } from './render/coverFade';
export { BlobShadow, setBlobShadowGround, buildBlobMesh, blobAlpha, type BlobShadowData, type BlobShadowGround } from './render/blobShadow';
export type { RenderOnDemandOptions } from './render/renderDemand';
export type { ShaderWarmup, ShaderWarmupOptions } from './render/shaderWarmup';