[SOLVED] Drawing basis compressed textures into another texture

Hey hey :slight_smile:

We are currently working on adding basis compression to our game. At one point during our characters’ setup we are creating a custom texture atlas from multiple textures. We need to do this dynamicaly because of our customizer.

We did this by rendering each texture via pc.drawQuadWithShader into our dynamic texture at a specific position. This works pretty well so far.

CopyAndDrawTexture.prototype.createTextureAtlas = function() {
    var texture = this.textureAsset.resource;

    const atlas = new pc.Texture(this.app.graphicsDevice, {
      name: "copy",
      width: texture.width,
      height: texture.height,
      format: texture.format,
      mipmaps: false,
      minFilter: pc.FILTER_LINEAR,
      magFilter: pc.FILTER_LINEAR,
      addressU: pc.ADDRESS_CLAMP_TO_EDGE,
      addressV: pc.ADDRESS_CLAMP_TO_EDGE,
    });

    var renderTarget = new pc.RenderTarget({ colorBuffer: atlas, depth: false });

    this.textureUniform.setValue(texture);

    pc.drawQuadWithShader(
      this.app.graphicsDevice,
      renderTarget,
      this.shader,
      new pc.Vec4(0, 0, texture.width, texture.height)
    );
    
    renderTarget.destroy();

    return atlas;
};

But when we activate basis compression on the individual textures, pc.drawQuadWithShader throws the error “TypeError: Failed to execute ‘compressedTexImage2D’ on ‘WebGL2RenderingContext’: parameter 7 is not of type ‘ArrayBufferView’” at line 434 in webgl-texture. Here the variable mipObject (parameter 7) is null.

I also created a small reproduction project which creates this error, but also shows that it works if basis compression is disabled.

So we are wondering now, is this a bug, or are we missing some steps in our implementation? Is it even the right approach for basis compressed textures, or do we need to draw our textures in a different way into our dynamic texture?

Thanks for any kind of help :slight_smile:

Calling @mvaligursky @slimbuck they may know more on this.

Hi @AliMoe,

The texture you create for purposes of rendering into can’t have a compressed pixel format. If you change copyAndDrawTexture.js (around line 49) from:

format: texture.format,

to:

format: pc.PIXELFORMAT_R8_G8_B8_A8

it should work better.

Thanks!

2 Likes

Nice, that helped a lot.
Thanks

1 Like