Jump to content

Use raw WebGL texture as sprite


Recommended Posts

I have a WebGL texture that has been rendered to by another (plain) WebGL program in my pipeline. Is there a relatively trivial way of taking this texture and rendering it as a sprite? I'm aware that sprites (in the WebGL renderer) are backed by GL textures, but I'm not really sure how one would go about setting this manually. Any ideas/thoughts?

Link to comment
Share on other sites

//lets use white 10x10 canvas as source
var baseTex= new PIXI.BaseTexture(PIXI.Texture.WHITE.baseTexture.source);
//initialize gl texture wrapper

//now we have a wrapper in gl_textures, we need to swap its WebGLTexture
baseTex._glTextures[renderer.CONTEXT_UID].texture = myOriginalTextureInTheSameContext;

//set the size
baseTex.width=baseTex.height=baseTex.realWidth=baseTex.realHeight = 512;

//create texture region to use with sprite
var tex = new PIXI.Texture(baseTex);

Its not pretty. PIXI doesnt have special methods for it, but there are hacks.

I didnt try that code yet, just wrote down according to https://github.com/pixijs/pixi.js/blob/dev/src/core/textures/BaseTexture.js  , https://github.com/pixijs/pixi.js/blob/dev/src/core/renderers/webgl/TextureManager.js#L60 and https://github.com/pixijs/pixi-gl-core/blob/master/src/GLTexture.js

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...