Jump to content

pixi.js + expo getTestContext workaround


fxlr8
 Share

Recommended Posts

Hi, I am trying to make `pixi.js` work with `expo`. Current option `expo-pixi` is using pixi v4, not using Typescript and looks messy. I want to take a different approach and make my own version with pixi v5 and a helper/wrapper that will keep original pixi untouched. I am currently stuck at a moment where pixi tries to load a test context for inner needs. `expo-gl` component provides only one gl context so there is no second one for testing needs. Do you guys have any ideas how to workaround this issue? Do we really need tests here? I think native apps on modern phones should be able to provide any gl feature pixi needs. The most obvious is to disable the tests. Maybe you can come up with a better idea.

Link to comment
Share on other sites

Unfortunately, the only way is to rewrite pixi core that way test context assigned from renderer that is created. If there's no renderer, throw error. I tried to refactor it before but failed to produce something that can be merged into main repo . It worked, so its possible ;)

Edited by ivan.popelyshev
Link to comment
Share on other sites

What if we make Application constructor accept testContext along with the context? So I could pass or mock the testContext from the outside.
What if we keep testContext in some kind of testSystem class that performs all the tests?
I am really interested in this feature and I am ready to implement it, I just need your guidance so that everything happens the pixi way and runs smooth.

Link to comment
Share on other sites

Application is a mashup, you need a renderer parameter, and i think there was getTestContext() usage even without renderer - in shader constructor - so you have to do a global hack.

getTestContext() isn't exposed - yep, that's bad, expose it.

I dont know about renderer/app param, but PR exposing getTestContext is gonna be merged for sure, if you make it.

Link to comment
Share on other sites

instead of getTestContext the file should export the object that has it as a method. Make sure all pixi modules that use it actually refer as "myMagicObject.getTestContext"

Then re-export this object in packages/core/index.js file

then you can modify it from outside: "PIXI.myMagicObject.getTestContext()".

If you just expoet getTestContext itself - internal stuff wont notice your outer hack :(

I'm bad with names so you should choose where to put this thing or ask assistance when you make PR from the rest of pixijs team

Link to comment
Share on other sites

Is there any way to install my version of PIXI with npm? It is a monorepo and I can't figure out how to install it from git. It says that the package is missing version. How do you PIXI devs do it?

Link to comment
Share on other sites

I still struggle to link my custom PIXI version into test app. First I tried to import it with the relative path as offered in your issue. But Expo module resolution is a weird black box and I have no luck finding how resolve it correctly. I don't want to publish my own pixi as it is a lerna monorepo which will flood my npm registry with temporary packages.

Link to comment
Share on other sites

By the way, I found a couple of places in PIXI with direct calls to `document`. For example, `createWhiteTexture`. Is there a place for some abstraction to make PIXI run in `document`less environments? Or should I better mock a global document?

image.thumb.png.d32f7155e854f215a148fee7bed1b3f4.png

Link to comment
Share on other sites

I don't quite understand how objects end up inside PIXI object.
I created testContext object and exported it from core/src/shader/utils, then re-exported them in core/index.ts
But I still can't find it in bundles/pixi.js/index.d.ts type file after build.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...