GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same.

1,094 views
Skip to first unread message

Alon Faraj

unread,
Apr 6, 2017, 7:00:07 AM4/6/17
to emscripten-discuss
I have c++ app that works in windows, Im using emscripten to render Webgl2  in  chrome but I get an error -

[.Offscreen-For-WebGL-0000000007A2F810]GL ERROR :GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same.

after that, the canvas is freezing.

everything works as expected in windows - how can I debug this? why its happen?

 PS - for unknown reasons I cant run the app in forefox to check if the problem is only in chrome or cross browsers.

Floh

unread,
Apr 6, 2017, 8:22:23 AM4/6/17
to emscripten-discuss
Reading and writing to the same texture at the same time is undefined behaviour in OpenGLES2 (but often works by accident), and was made illegal in WebGL, because WebGL tries to eliminate all undefined behaviour, see here for details:


One reason could be that you are trying toread from the depth buffer in a fragment shader which was written in a previous pass, but the same depth buffer is still bound because depth tests must happen. Only way out in this situation is to copy the depth information into a separate texture, I guess.

Or it is an oversight and you are accidently rendering to a framebuffer which has a color attachment texture which is also bound to a texture unit. For this case, I clear all texture bindings when binding a new framebuffer to make sure that a texture used to render to isn't still bound to a texture bind slot.

Cheers,
-Floh.

Nikola L.

unread,
Oct 30, 2017, 2:15:04 PM10/30/17
to emscripten-discuss


  Heres my example : 




App.scene.MySquareTexure1.fb = world.GL.gl.createFramebuffer();



App.scene.MySquareTexure1.custom.gl_texture = function ( object , t ) {
    
    world.GL.gl.bindTexture(world.GL.gl.TEXTURE_2D, object.textures[t] );
    world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MAG_FILTER, world.GL.gl.LINEAR);
    world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MIN_FILTER, world.GL.gl.LINEAR);

    world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_S, world.GL.gl.CLAMP_TO_EDGE);
    world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_T, world.GL.gl.CLAMP_TO_EDGE);
    
    world.GL.gl.texImage2D(
                  world.GL.gl.TEXTURE_2D,
                  0, // Level of details
                  world.GL.gl.RGBA, // Format
                  world.GL.gl.RGBA,
                  world.GL.gl.UNSIGNED_BYTE, // Size of each channel
                  object.textures[t].image
                  );
    
    world.GL.gl.generateMipmap(world.GL.gl.TEXTURE_2D);
    
//
try {
world.GL.gl.bindFramebuffer(world.GL.gl.FRAMEBUFFER, App.scene.MySquareTexure1.fb );
        world.GL.gl.framebufferTexture2D(  world.GL.gl.FRAMEBUFFER,   world.GL.gl.COLOR_ATTACHMENT0,   world.GL.gl.TEXTURE_2D, object.textures[t] , 0);
if (world.GL.gl.checkFramebufferStatus(world.GL.gl.FRAMEBUFFER) == world.GL.gl.FRAMEBUFFER_COMPLETE) {
  
 // var pixels = new Uint8Array(150 * 100 * 4);
  
 // world.GL.gl.readPixels(  100 , 100 , 150 , 100 , world.GL.gl.RGBA, world.GL.gl.UNSIGNED_BYTE, pixels);
  
  
}

}catch(e){ console.log(">>>>>this log not work>>>>>>>"+e)}
//
}



Error message : 


[.Offscreen-For-WebGL-0000021FD61FFD80]GL ERROR :GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same.

 Problem is in try { } .

 Any suggestion , please . 

 
  

 

キャロウ マーク

unread,
Oct 30, 2017, 8:29:57 PM10/30/17
to emscripte...@googlegroups.com


On Oct 31, 2017, at 3:15, Nikola L. <zlatna...@gmail.com> wrote:



  Heres my example : 



    
    world.GL.gl.bindTexture(world.GL.gl.TEXTURE_2D, object.textures[t] );

Here you set up textures[t] for sampling (reading).


try {
world.GL.gl.bindFramebuffer(world.GL.gl.FRAMEBUFFER, App.scene.MySquareTexure1.fb );
        world.GL.gl.framebufferTexture2D(  world.GL.gl.FRAMEBUFFER,   world.GL.gl.COLOR_ATTACHMENT0,   world.GL.gl.TEXTURE_2D, object.textures[t] , 0);

Here you set up the same texture for writing as your draw framebuffer.


Error message : 


[.Offscreen-For-WebGL-0000021FD61FFD80]GL ERROR :GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same.

 Problem is in try { } .

 Any suggestion , please . 

Hopefully the problem is obvious now.

This is what the OpenGL [,ES] specifications call a "Rendering feedback loop”. Look for a section with that heading. The specs say behavior with such a feedback loop is undefined except for a narrow set of circumstances described in later versions of the specification. As Floh said, WebGL has chosen the error you are seeing in preference to allowing undefined behavior.

Regards

    -Mark

--

Mark Callow
President
www.edgewise-consulting.com

Reply all
Reply to author
Forward
0 new messages