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

Fix GFX object export on native platforms. #16481

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

dumganhar
Copy link
Contributor

@dumganhar dumganhar commented Nov 7, 2023

We exported GFX object which defined for Web, but they are not needed for native platforms.
The old code will cause texture instanceof Texture fails since texture is a native gfx.Texture type, but Texture is imported by import '../../gfx'

How to Reproduce

import { _decorator, Component, gfx, Material, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('TestMaterial')
export class TestMaterial extends Component {
    start() {
        const info = new gfx.TextureInfo(gfx.TextureType.TEX2D, gfx.TextureUsageBit.SAMPLED | gfx.TextureUsageBit.TRANSFER_DST, gfx.Format.RGBA8, 1, 1);
        this.texture = gfx.deviceManager.gfxDevice.createTexture(info);
        console.log('texture created');
        this.material.setProperty('mainTexture', this.texture);
        console.log('texture set to material, is gfx texture: ' + (this.texture instanceof gfx.Texture));
    }
    update(deltaTime: number) {
        
    }
    readonly material = new Material();
    texture: gfx.Texture | null = null; 
}

material.jsb.ts, setProperty will fail

matProto.setProperty = function (name: string, val: MaterialPropertyFull | MaterialPropertyFull[], passIdx?: number) {
    if (Array.isArray(val)) {
        const first = val[0];
        if (typeof first === 'number') {
            if (Number.isInteger(first)) {
                wrapSetProperty(this.setPropertyInt32Array, this, name, val, passIdx);
            } else {
                wrapSetProperty(this.setPropertyFloat32Array, this, name, val, passIdx);
            }
        } else if (first instanceof Vec2) {
            wrapSetProperty(this.setPropertyVec2Array, this, name, val, passIdx);
        } else if (first instanceof Vec3) {
            wrapSetProperty(this.setPropertyVec3Array, this, name, val, passIdx);
        } else if (first instanceof Vec4) {
            wrapSetProperty(this.setPropertyVec4Array, this, name, val, passIdx);
        } else if (first instanceof Color) {
            wrapSetProperty(this.setPropertyColorArray, this, name, val, passIdx);
        } else if (first instanceof Mat3) {
            wrapSetProperty(this.setPropertyMat3Array, this, name, val, passIdx);
        } else if (first instanceof Mat4) {
            wrapSetProperty(this.setPropertyMat4Array, this, name, val, passIdx);
        } else if (first instanceof Quat) {
            wrapSetProperty(this.setPropertyQuatArray, this, name, val, passIdx);
        } else if (first instanceof TextureBase) {
            wrapSetProperty(this.setPropertyTextureBaseArray, this, name, val, passIdx);
        } else if (first instanceof Texture) {
            wrapSetProperty(this.setPropertyGFXTextureArray, this, name, val, passIdx);
        } else {
            cclegacy.error(`Material.setProperty Unknown type: ${val}`);
        }
    } else if (typeof val === 'number') {
        if (Number.isInteger(val)) {
            wrapSetProperty(this.setPropertyInt32, this, name, val, passIdx);
        } else {
            wrapSetProperty(this.setPropertyFloat32, this, name, val, passIdx);
        }
    } else if (val instanceof Vec2) {
        wrapSetProperty(this.setPropertyVec2, this, name, val, passIdx);
    } else if (val instanceof Vec3) {
        wrapSetProperty(this.setPropertyVec3, this, name, val, passIdx);
    } else if (val instanceof Vec4) {
        wrapSetProperty(this.setPropertyVec4, this, name, val, passIdx);
    } else if (val instanceof Color) {
        wrapSetProperty(this.setPropertyColor, this, name, val, passIdx);
    } else if (val instanceof Mat3) {
        wrapSetProperty(this.setPropertyMat3, this, name, val, passIdx);
    } else if (val instanceof Mat4) {
        wrapSetProperty(this.setPropertyMat4, this, name, val, passIdx);
    } else if (val instanceof Quat) {
        wrapSetProperty(this.setPropertyQuat, this, name, val, passIdx);
    } else if (val instanceof TextureBase) {
        wrapSetProperty(this.setPropertyTextureBase, this, name, val, passIdx);
    } else if (val instanceof Texture) {
        wrapSetProperty(this.setPropertyGFXTexture, this, name, val, passIdx);
    } else if (val === null) {
        if (passIdx) {
            this.setPropertyNull(name, passIdx);
        } else {
            this.setPropertyNull(name);
        }
    }
    else {
        //-----------> Will trigger an error here.
        cclegacy.error(`Material.setProperty Unknown type: ${val}`);
    }
};

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@dumganhar dumganhar requested review from minggo and star-e November 7, 2023 10:15
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

github-actions bot commented Nov 7, 2023

Interface Check Report

This pull request does not change any public interfaces !

@dumganhar dumganhar marked this pull request as draft November 7, 2023 10:28
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

1 similar comment
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

github-actions bot commented Nov 9, 2023

@dumganhar, Please check the result of run test cases:

Task Details

Copy link

github-actions bot commented Nov 9, 2023

@dumganhar, Please check the result of run test cases:

Task Details

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

1 similar comment
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar dumganhar marked this pull request as ready for review November 10, 2023 01:47
@dumganhar dumganhar merged commit 02b838a into cocos:v3.8.2 Nov 10, 2023
22 checks passed
@sushanhong
Copy link
Contributor

@cocos-robot run test cases

1 similar comment
@sushanhong
Copy link
Contributor

@cocos-robot run test cases

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.

4 participants