Pixi.js: 透明的WebM视频不会清除以前的Alpha(已修复!)

创建于 2017-06-07  ·  14评论  ·  资料来源: pixijs/pixi.js

请参阅https://github.com/pixijs/pixi.js/issues/3526

我们的项目迫切需要将此修补程序实现到最新的Pixi.js版本中,我们不想修改自己。

谢谢。

Stale 💾 v4.x (Legacy) 🕷 Bug

最有用的评论

我为我的每个项目都在GLTexture中进行了此类修复。 有一种方法可以在v5中制作您的自定义上传器。

现在最好的策略是DIY:

PIXI.glCore.GLTexture.prototype.upload = function(source)
{
    this.bind();

    var gl = this.gl;

    gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);

        var isVideo = !!source.videoWidth;
    var newWidth = isVideo ? source.videoWidth : source.width;
    var newHeight = isVideo ? source.videoHeight : source.height;

    if(newHeight !== this.height || newWidth !== this.width || isVideo)
    {
        gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source);
    }
    else
    {
        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.format, this.type, source);
    }

    this.width = newWidth;
    this.height = newHeight;

};

将其放在项目的单独文件中,并将其命名为“ pixi-patch.js”。 我有数十个类似的补丁,分别用于我使用的不同库。

所有14条评论

我为我的每个项目都在GLTexture中进行了此类修复。 有一种方法可以在v5中制作您的自定义上传器。

现在最好的策略是DIY:

PIXI.glCore.GLTexture.prototype.upload = function(source)
{
    this.bind();

    var gl = this.gl;

    gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);

        var isVideo = !!source.videoWidth;
    var newWidth = isVideo ? source.videoWidth : source.width;
    var newHeight = isVideo ? source.videoHeight : source.height;

    if(newHeight !== this.height || newWidth !== this.width || isVideo)
    {
        gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source);
    }
    else
    {
        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.format, this.type, source);
    }

    this.width = newWidth;
    this.height = newHeight;

};

将其放在项目的单独文件中,并将其命名为“ pixi-patch.js”。 我有数十个类似的补丁,分别用于我使用的不同库。

我建议我们为V5默认上传器添加特殊标志,“始终使用texImage2D”

@kurozael ping

嗨,是的,这很好,还是我们可以检测它是否像您的示例一样是视频?

顺便说一句,此问题还导致视频纹理变得极其缓慢:

http://codeflow.org/issues/slow_video_to_texture/

@ivanpopelyshev非常感谢您。 让我发疯。 幸运的是,即使在TypeScript上修补upload工作。 希望这样的事情将很快合并。

@englercj我能否得到您的确认,请确认您已更改为使用v5的texImage2D? 各种不同的PR相互引用,我认为这对于v5已解决,并且已经为v4提供了解决方法,因此可以将其关闭! 谢谢

此修补程序在chrome 70上不再起作用…另外,在Windows上的pixi5 / chrome70重新引入了原始问题

确认上述解决方案由于仅在Window计算机上更新了Chrome 70而停止工作。 OSX仍然可以正常工作。 @ivanpopelyshev可以重新打开吗,还是应该创建一个新的期刊?

由于此问题最近没有活动,因此已被自动标记为陈旧。 如果没有进一步的活动,它将关闭。 感谢您的贡献。

万一它可以帮助仍然遇到此问题的任何人,那肯定是texSubImage2D和视频的问题。

@saschagehlich发布的链接对于帮助更深入地了解这一点非常有用。

上面的答案/补丁不再适用于PIXI v5,而是我们对BaseImageResource进行了补丁,进行了类似的更改。

import { resources } from 'pixi.js'

resources.BaseImageResource.prototype.upload = function(renderer, baseTexture, glTexture, source) {
  const gl = renderer.gl;
  const width = baseTexture.realWidth;
  const height = baseTexture.realHeight;

  source = source || this.source;

  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.premultiplyAlpha);

  // add this line, check for video
  const isVideo = !!source.videoWidth
  if (!isVideo && baseTexture.target === gl.TEXTURE_2D && glTexture.width === width && glTexture.height === height)
  {
    gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, baseTexture.type, source);
  }
  else
  {
    glTexture.width = width;
    glTexture.height = height;

    gl.texImage2D(baseTexture.target, 0, baseTexture.format, baseTexture.format, baseTexture.type, source);
  }

  return true
}

结果确实非常惊人。

之前
2019-09-11-082818_1058x748_scrot


2019-09-11-082725_1058x748_scrot

我知道这个问题是过时的,但是我想为某些资源类型绕过texSubImage2D选择大声疾呼。 否则,我希望该解决方案可以帮助其他任何处理性能问题和视频的人。

由于此问题最近没有活动,因此已被自动标记为陈旧。 如果没有进一步的活动,它将关闭。 感谢您的贡献。

我只是碰碰这个,因为它仍然需要解决。

由于此问题最近没有活动,因此已被自动标记为陈旧。 如果没有进一步的活动,它将关闭。 感谢您的贡献。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

trusktr picture trusktr  ·  30评论

winterNebs picture winterNebs  ·  43评论

themoonrat picture themoonrat  ·  29评论

GoodBoyDigital picture GoodBoyDigital  ·  31评论

manudurgoni picture manudurgoni  ·  24评论