# \[SOLVED\] Drawing basis compressed textures into another texture

**URL:** <https://forum.playcanvas.com/t/solved-drawing-basis-compressed-textures-into-another-texture/27311>\
**Category:** Help & Support\
**Tags:** textures, shaders\
**Created:** [August 31, 2022, 4:23pm UTC](https://forum.playcanvas.com/t/solved-drawing-basis-compressed-textures-into-another-texture/27311 "2022-08-31T16:23:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AliMoe](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/alimoe/32/6808_2.png) [@AliMoe](https://forum.playcanvas.com/u/AliMoe)\
**Post date:** [August 31, 2022, 4:23pm UTC](https://forum.playcanvas.com/t/solved-drawing-basis-compressed-textures-into-another-texture/27311/1 "2022-08-31T16:23:15Z")

</div>

Hey hey 🙂

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.

```javascript
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](https://github.com/playcanvas/engine/blob/a160fda3bbcc708d5977e5e8714daef8fbef4d65/src/graphics/webgl/webgl-texture.js#L433-L442). Here the variable `mipObject` (_parameter 7_) is null.

I also created a small [reproduction project](https://playcanvas.com/editor/scene/1516778) 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 🙂

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [August 31, 2022, 8:59pm UTC](https://forum.playcanvas.com/t/solved-drawing-basis-compressed-textures-into-another-texture/27311/2 "2022-08-31T20:59:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![slimbuck](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/slimbuck/32/6708_2.png) [@slimbuck](https://forum.playcanvas.com/u/slimbuck)\
**Post date:** [September 1, 2022, 7:48am UTC](https://forum.playcanvas.com/t/solved-drawing-basis-compressed-textures-into-another-texture/27311/3 "2022-09-01T07:48:20Z")

</div>

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:

```javascript
format: texture.format,

```

to:

```javascript
format: pc.PIXELFORMAT_R8_G8_B8_A8

```

it should work better.

Thanks!

---

<div class="post-metadata">

**Author:** ![AliMoe](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/alimoe/32/6808_2.png) [@AliMoe](https://forum.playcanvas.com/u/AliMoe)\
**Post date:** [September 1, 2022, 1:22pm UTC](https://forum.playcanvas.com/t/solved-drawing-basis-compressed-textures-into-another-texture/27311/4 "2022-09-01T13:22:55Z")

</div>

Nice, that helped a lot.  
Thanks
