Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

even more type check for buffer pools #7214

Merged
merged 1 commit into from Aug 25, 2020
Merged

Conversation

YunHsiao
Copy link
Contributor

@YunHsiao YunHsiao commented Aug 25, 2020

https://github.com/cocos-creator/3d-tasks/pull/4249

All types can now be automatically inferred except the following usage:

SubModelPool.get(handle, SubModelView.SHADER_0 + passIndex); // the return value will have type GeneralBufferElement

There are two options to properly declare the variable type in situations like this:

const hShader = SubModelPool.get(handle, SubModelView.SHADER_0 + passIndex) as ShaderHandle; // option #1
const hShader = SubModelPool.get<SubModelView.SHADER_0>(handle, SubModelView.SHADER_0 + passIndex); // option #2

interface IPassViewType extends IBufferTypeManifest {
[PassView.PRIORITY]: number;
[PassView.STAGE]: RenderPassStage;
[PassView.PHASE]: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于存放 Vec3, Mat4 类型的数据该怎么写呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那就取决于怎么用了,理论上这个 interface 只用于 set 和 get,所以应该声明成 number。
后面加的 setVec3 之类的可能要根据需求再另加类型检查

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那是不是 GeneralBufferElement 的类型得支持 Vec3 等类型呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该不用,因为 buffer element 是单个元素,这个类型不会跑出 number 和 handle 两种

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setVec3 等那边合了我再单独处理吧,估计还得再声明一个 interface

@minggo minggo merged commit d0fd7eb into cocos:3d-v1.2 Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants