cpdt Posted October 4, 2017 Share Posted October 4, 2017 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? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 4, 2017 Share Posted October 4, 2017 //lets use white 10x10 canvas as source var baseTex= new PIXI.BaseTexture(PIXI.Texture.WHITE.baseTexture.source); //initialize gl texture wrapper renderer.textureManager.updateTexture(baseTex); //now we have a wrapper in gl_textures, we need to swap its WebGLTexture renderer.gl.destroyTexture(baseTex._glTextures[renderer.CONTEXT_UID].texture); 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 cpdt 1 Quote Link to comment Share on other sites More sharing options...
xerver Posted October 4, 2017 Share Posted October 4, 2017 Note that you cannot share GLTextures between contexts. If you create a texture using a context it will not work if you try to render it with a different context. cpdt 1 Quote Link to comment Share on other sites More sharing options...
cpdt Posted October 9, 2017 Author Share Posted October 9, 2017 Ivan: Thanks! I'll check out those files too, just wasn't really sure where to look before. xerver: Good point. I think I should be able to work around that by just using PIXI's context everywhere though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.