glDrawElements: Source and destination textures of the draw are the same?

Can someone please explain why I’m getting error: “256[.WebGL-0000020D0387DAA0]GL ERROR :GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same.” & how to fix?

Thank you!

In most cases, this error message pops up in context of RTT (rendering-to-texture). So you render to a render target but you use this particular render target as a texture for one of the 3D objects in the same draw call.

How to fix?

Well, don’t use the render target as a texture when rendering to it.

1 Like

for those confused why this is happening. Reading and writing to the same data produces garbage when read and write access different parts of the data.

You have you RnderTarget. You write something to pixel at index 0, then you want to write to pixel 1 and you’re sampling pixel 0 and 2, lets say, now you get overwritten value for pixel 0, since it was already written to, and you get an old value from pixel 2 since that was not written to yet. This basically corrupts your data.

There are ways around it, but for the purposes of this discussion - it’s why we use “ping pong” buffers, you read from one buffer, write to another, then swap the order, read from the one you just wrote to and write to the one you were reading from. If you have buffers A and B it’s like this:

Write to A
Write to B while reading A
Write to A while reading B
Write to B while reading A
etc.