Jump to content

Create texture from an Uint8Array


Recommended Posts

Hi, I have some (limited) experience with libgdx, and I'm currently experimenting with PixiJS v4.

I'm trying to create (and possibly update in time) a Texture/Sprite from raw RGB data (e.g. UInt8Array), please lmk if this is possible?


Link to comment
Share on other sites

We don't currently have an easy way to do data textures. This is something I do want to add soon, because it can be pretty useful for a variety of advanced scenarios.

You can always create a custom ObjectRenderer (see SpriteRenderer and MeshRenderer) and do anything you want with the GL context.

Link to comment
Share on other sites

Yeah, PIXI doesnt know about array textures. But pixi-gl-core does! Lets hack that way we have access and PIXI wont know about it:

var tempCanvas = document.createElement(canvas);
tempCanvas.width = 100;
tempCanvas.height = 100;

var baseTex = new BaseTexture(tempCanvas);
baseTex._glTextures[renderer.CONTEXT_UID].upload(100, 100, myDataUint8Array);

There's only one tempCanvas needed, but you have to change its width/height every time you create new texture. Data from tempCanvas wont be used anyway, instead after initial uploading you'll reupload uint8array version. Don't forget that its only BaseTexture, you still have to create Textures and Sprites out of it :)

P.S. Turn off the GC or it will ruin everything!

renderer.textureGC.mode = PIXI.GC_MODES.MANUAL;


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.

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.


  • Recently Browsing   0 members

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