refactor: 删除 @motajs/client @motajs/client-base

This commit is contained in:
AncTe committed 2026-11-03 15:18:11 +08:00
1 parent ad37186068
commit 01c84ffb18
16 files changed
+200 -264

No files matched your search

+4 -10
View File
@@ -15,7 +15,7 @@ import vert from './shader/pack.vert?raw';
import frag from './shader/pack.frag?raw';
import { logger } from '@motajs/common';
import { isNil } from 'lodash-es';
import { compileProgramWith } from '@motajs/client-base';
import { compileProgramWith } from '../utils';
import { SizedCanvasImageSource } from '../types';
interface IndexMarkedComposedData {
@@ -32,9 +32,7 @@ export interface IGridComposerData {
readonly height: number;
}
export class TextureGridComposer
implements ITextureComposer<IGridComposerData>
{
export class TextureGridComposer implements ITextureComposer<IGridComposerData> {
/**
* 网格组合器,将等大小的贴图组合成图集,要求每个贴图的尺寸一致。
* 组合时按照先从左到右,再从上到下的顺序组合。
@@ -120,9 +118,7 @@ interface MaxRectsRectangle extends IRectangle {
readonly data: ITexture;
}
export class TextureMaxRectsComposer
implements ITextureComposer<IMaxRectsComposerData>
{
export class TextureMaxRectsComposer implements ITextureComposer<IMaxRectsComposerData> {
/**
* 使用 Max Rects 算法执行贴图整合,输入数据参考 {@link IMaxRectsComposerData},
* 输出的纹理的图像源将会是不同的画布,注意与 {@link TextureMaxRectsWebGL2Composer} 区分
@@ -187,9 +183,7 @@ interface RectProcessed {
readonly attrib: Float32Array;
}
export class TextureMaxRectsWebGL2Composer
implements ITextureComposer<IMaxRectsComposerData>
{
export class TextureMaxRectsWebGL2Composer implements ITextureComposer<IMaxRectsComposerData> {
/** 使用的画布 */
readonly canvas: HTMLCanvasElement;
/** 画布上下文 */
+2
View File
@@ -1,4 +1,6 @@
export * from './assets';
export * from './core';
export * from './style';
export * from './types';
export * from './utils';
+86
View File
@@ -0,0 +1,86 @@
import { logger } from '@motajs/common';
export interface ICompiledProgram {
/** 着色器程序 */
readonly program: WebGLProgram;
/** 顶点着色器对象 */
readonly vertexShader: WebGLShader;
/** 片段着色器对象 */
readonly fragmentShader: WebGLShader;
}
/**
* 编译着色器
* @param gl WebGL2 上下文
* @param type 着色器类型
* @param source 着色器代码
*/
export function compileShader(
gl: WebGL2RenderingContext,
type: number,
source: string
): WebGLShader | null {
const shader = gl.createShader(type);
if (!shader) return null;
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
const info = gl.getShaderInfoLog(shader);
const typeStr = type === gl.VERTEX_SHADER ? 'vertex' : 'fragment';
logger.error(10, typeStr, info ?? '');
return null;
}
return shader;
}
/**
* 编译链接着色器程序
* @param gl WebGL2 上下文
* @param vs 顶点着色器对象
* @param fs 片段着色器对象
*/
export function compileProgram(
gl: WebGL2RenderingContext,
vs: WebGLShader,
fs: WebGLShader
) {
const program = gl.createProgram();
gl.attachShader(program, vs);
gl.attachShader(program, fs);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
const info = gl.getProgramInfoLog(program);
logger.error(9, info ?? '');
return null;
}
return program;
}
/**
* 使用指定着色器代码编译链接程序
* @param gl WebGL2 上下文
* @param vs 顶点着色器代码
* @param fs 片段着色器代码
*/
export function compileProgramWith(
gl: WebGL2RenderingContext,
vs: string,
fs: string
): ICompiledProgram | null {
const vsShader = compileShader(gl, gl.VERTEX_SHADER, vs);
const fsShader = compileShader(gl, gl.FRAGMENT_SHADER, fs);
if (!vsShader || !fsShader) return null;
const program = compileProgram(gl, vsShader, fsShader);
if (!program) return null;
return {
program,
vertexShader: vsShader,
fragmentShader: fsShader
};
}