question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Texture: Using different wrapMode's with the same source

See original GitHub issue

Expected Behavior

When calling Texture.from(source, options) would expend the the options would be obeyed.

Current Behavior

Obeys the options when creating the initial baseTexture, but does not for future calls.

Possible Solution

Move wrapMode up to the Texture (from BaseTexture) so the same source can support multiple wrapModes

Steps to Reproduce

var canvas = document.createElement('canvas')
var a = PIXI.Texture.from(canvas, {wrapMode: PIXI.WRAP_MODES.CLAMP})
var b = PIXI.Texture.from(canvas, {wrapMode: PIXI.WRAP_MODES.REPEAT})

console.log(
    a.baseTexture.wrapMode === PIXI.WRAP_MODES.CLAMP, 
    b.baseTexture.wrapMode === PIXI.WRAP_MODES.REPEAT
)

Environment

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ShukantPalcommented, Sep 23, 2020

This is because of the TextureCache:

https://github.com/pixijs/pixi.js/blob/9ff49a23670bdb0ed864d4e53fb91d524eab59f2/packages/core/src/textures/Texture.ts#L383

For now, the better option would not to use the factory method and create the base-texture yourself:

const baseTexture = new BaseTexture(canvas as HTMLCanvasElement, { wrapMode: WRAP_MODES.REPEAT });
const texture = new Texture(baseTexture);

This will create two separate, independent textures. I don’t know if there is a better solution that can use the same WebGL texture, although I doubt it.

1reaction
bigtimebuddycommented, Sep 23, 2020

I agree @SukantPal.

Also, it’s important to note that wrapMode is a BaseTexture property not a Texture property. The Texture.from options are a pass-thru to BaseTexture (this is already noted in the docs for Texture.from), so what @mudcube wants here isn’t actually possible without having two BaseTexture objects.

PR is welcome if someone would like add more context about how Texture.from automatically adds things to the TextureCache. The caching behavior is already mentioned in BaseTexture.from.

@mudcube: I would suggest the above and not use Texture.from and manually create a new BaseTexture OR clone your canvas and pass each canvas into Texture.from and that should also work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scripting API: Texture.wrapMode - Unity - Manual
Using wrapMode sets the same wrapping mode on all axes. Different per-axis wrap modes can be set using wrapModeU, wrapModeV, wrapModeW.
Read more >
Setting texture wrap mode from script - Unity Answers
I want to set Texture2D wrap mode to Repeat from script. Unfortunately this does not seem to work. fillTexture.wrapMode = TextureWrapMode.
Read more >
PIXI.filters.DisplacementFilter Texture Not Repeating - Even ...
I came across a couple of example posts that had suggested that setting a texture's baseTexture wrapMode to PIXI.WRAP_MODES.
Read more >
PIXI.BaseTexture - PixiJS API Documentation
All textures have a base texture, which contains information about the source. Therefore you can have many textures all using a single BaseTexture ......
Read more >
Problem in tiling image starting at different height using ...
... 16); using (TextureBrush brush = new TextureBrush(myIcon, WrapMode. ... using TransalteTransform() to set up start point,if u do not do ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found