[SOLVED] Error: Trying to bind current color buffer as a texture

Hi, I am setting an entities render layer like so:

var countLayer = this.app.scene.layers.getLayerByName('CountedLayer');
entity.render.layers = [countLayer.id];//Trying to bind current color buffer as a texture.error

But I get the error: ‘Trying to bind current color buffer as a texture’.

Oddly, I am doing exactly the same thing in another script (setting an entities layer to the same counte layer and that works fine.)

Any ideas? Cheers

Hi @Grimmy,

Not sure what the cause may be. Are you rendering anywhere a render target on a camera that renders on that layer? Try sharing a sample project if possible, that may help troubleshoot this.

Yes, the camera is rendering to a renderTarget:

this.cameraEntity.camera.renderTarget=this.renderTarget;

It all works fine untill I try to add a bunch of new objects to the layer. RenderTarget code all looks like this:

this.renderTexture = new pc.Texture(this.app.graphicsDevice, {
        width: this.app.graphicsDevice.width/this.texture_downscaling,
        height: this.app.graphicsDevice.height/this.texture_downscaling,
        format: pc.PIXELFORMAT_R8_G8_B8_A8
    });

    //render target -  rectangular rendering surface.
    this.renderTarget = new pc.RenderTarget({     
        colorBuffer: this.renderTexture,
        flipY: true,
        samples: 0,
        depth: true
  
    });

Hmm, try doing a search in the forums with your exact topic title, that error. There has been a number of similar posts around, in case you something sticking out.

Another clue, if I disable my debug preview camera (cam_preview), I don’t get the error. Im using this camera to try to show what the renderTexture looks like…but maybe the material.update() for this is causing issues?

  //debug
    this.cam_preview=this.app.root.findByName("Camera_Preview");
    
    this.cam_preview.render.material.emissiveMap=this.renderTexture;
    this.cam_preview.render.material.diffuseMap=this.renderTexture;
    this.cam_preview.render.material.update();

EDIT: looks like the issue happens when I try to modify the material initially with: this.cam_preview.render.material.emissiveMap=this.renderTexture;

Ah you got it, you can’t use a render target as a texture while rendering to it.

Okay Thanks. Any idea how I would get around this?

Without seeing your project I’m not sure, but try studying how the camera/layer setup works in this project.

It does something similar, rendering to a texture and using that texture on an element:

https://playcanvas.com/project/855150/overview/render-3d-world-to-ui

I solved it. I was accidentally trying to add the entity which showed the texture preview itself…to itself. Something like that. Anyway, fixed.now.

Thanks

1 Like