Refactor: add IPlatformShaderProgram type (#2782)

* refactor: add IPlatformShaderProgram type
This commit is contained in:
鹅叔
2025-08-06 17:30:09 +08:00
committed by GitHub
parent 2e915a01d6
commit 3d372bb11c
5 changed files with 14 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
import { IPlatformShaderProgram } from "./IPlatformShaderProgram";
export interface IPlatformPrimitive {
draw(tech: any, subPrimitive: any): void;
draw(shaderProgram: IPlatformShaderProgram, subPrimitive: any): void;
destroy(): void;
}

View File

@@ -0,0 +1,4 @@
export interface IPlatformShaderProgram {
readonly id: number;
readonly attributeLocation: Record<string, GLint>;
}

View File

@@ -1,2 +1,3 @@
export type { IHardwareRenderer } from "./IHardwareRenderer";
export type { IPlatformPrimitive } from "./IPlatformPrimitive";
export type { IPlatformShaderProgram } from "./IPlatformShaderProgram";

View File

@@ -1,6 +1,6 @@
import { GLCapabilityType, Logger, Primitive } from "@galacean/engine-core";
import { SubPrimitive } from "@galacean/engine-core/types/graphic/SubPrimitive";
import { IPlatformPrimitive } from "@galacean/engine-design";
import { IPlatformPrimitive, IPlatformShaderProgram } from "@galacean/engine-design";
import { WebGLGraphicDevice } from "./WebGLGraphicDevice";
import { WebGLExtension } from "./type";
@@ -32,7 +32,7 @@ export class GLPrimitive implements IPlatformPrimitive {
/**
* Draw the primitive.
*/
draw(shaderProgram: any, subMesh: SubPrimitive): void {
draw(shaderProgram: IPlatformShaderProgram, subMesh: SubPrimitive): void {
const gl = this._gl;
const primitive = this._primitive;
const useVao = this._isSupportVAO && primitive.enableVAO;
@@ -100,7 +100,7 @@ export class GLPrimitive implements IPlatformPrimitive {
/**
* Bind buffer and attribute.
*/
private _bindBufferAndAttrib(shaderProgram: any): void {
private _bindBufferAndAttrib(shaderProgram: IPlatformShaderProgram): void {
const gl = this._gl;
const primitive = this._primitive;
const vertexBufferBindings = primitive.vertexBufferBindings;
@@ -148,7 +148,7 @@ export class GLPrimitive implements IPlatformPrimitive {
}
}
private _registerVAO(shaderProgram: any): void {
private _registerVAO(shaderProgram: IPlatformShaderProgram): void {
const gl = this._gl;
const vao = gl.createVertexArray();

View File

@@ -22,7 +22,7 @@ import {
TextureCubeFace,
TextureFormat
} from "@galacean/engine-core";
import { IHardwareRenderer, IPlatformPrimitive } from "@galacean/engine-design";
import { IHardwareRenderer, IPlatformPrimitive, IPlatformShaderProgram } from "@galacean/engine-design";
import { Color, Vector4 } from "@galacean/engine-math";
import { GLBuffer } from "./GLBuffer";
import { GLCapability } from "./GLCapability";
@@ -354,7 +354,7 @@ export class WebGLGraphicDevice implements IHardwareRenderer {
gl.clear(clearFlag);
}
drawPrimitive(primitive: GLPrimitive, subPrimitive: SubMesh, shaderProgram: any) {
drawPrimitive(primitive: GLPrimitive, subPrimitive: SubMesh, shaderProgram: IPlatformShaderProgram) {
// todo: VAO not support morph animation
if (primitive) {
primitive.draw(shaderProgram, subPrimitive);