Results 1 to 7 of 7

Thread: 3 questions

  1. #1

    3 questions

    Seems Im the only one asking things, anyways here goes

    1/ how to change a webgl canvas's AA value whilst it already exists?

    at start up either
    gl = canvas.getContext("experimental-webgl", { antialias:true } // works
    or
    gl = canvas.getContext("experimental-webgl", { antialias:false } // works

    but if it already exists how to change its value i.e. if its
    gl = canvas.getContext("experimental-webgl", { antialias:true }
    and the I call
    gl = canvas.getContext("experimental-webgl", { antialias:false }
    it will still stay true, I assume I have to destroy the webgl context first + then create a new one? If so whats the best way, or is it possible to change AA on the fly?

    2/ (not really webgl also only a minor thing) but how to set a canvas elements zdepth
    Ive tried canvas.setAttribute( "style","z-index: 0" ); + also here
    <canvas id="GLcanvas" style=" .. " as well, also
    document.getElementById("GLcanvas").style.zIndex="-1";

    but the values I give it are ignored, which means all the html text I have to give a higher value than the canvas's zvalue, Ild just prefer changing the single webgl canvas value. Note - I can change a canvas element z-value if its a 2d canvas i.e.
    document.getElementById('canvas2D').getContext('2d ');
    but it seems with webgl canvas's you cant

    3/ same scene drawing a blended (src_alpha,1-src_alpha) quad over the scene afterwards.
    but the background is showing through!
    This seems like its a bug in the brower implementation but it occurs both with chrome(*) + firefox, so is this expected behaviour.

    top gl = canvas.getContext("experimental-webgl", { alpha:true,
    top gl = canvas.getContext("experimental-webgl", { alpha:false,


    (*)though chrome doesnt run webgl anymore for me since yesterday, gah

    Lots of text, well cheers anyways Zed

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: 3 questions

    The problem with the background showing through is because you have created your WebGL canvas with an alpha plane. Bizarrely (because it's so rarely used), this is the default. There was a bug a while back where you got an alpha plane even when you explicitly turned it off...I worked around that by clearing the screen's alpha to fully opaque and then using the color mask to disable subsequent writes to the alpha plane. However, that's probably not needed anymore.

    You'll probably want:
    Code :
        gl = canvas.getContext ( "experimental-webgl",
               {
                 alpha             : false ,
                 antialias         : true  ,
                 depth             : true  ,
                 stencil           : false ,
                 premultipliedAlpha: false } ) ;

  3. #3

    Re: 3 questions

    Cheer once again Steve
    Im not 100% but I assume, the alphaplane is analogous to the alpha buffer in opengl but this is only used in opengl when you specify DST_ALPHA etc.
    Im using the common mode SRC_ALPHA, ONE_MINUS_SRC_ALPHA (src_alpha comes from the texture/shader it shouldnt come from the alphaplane/buffer)
    or is it different in webgl?

  4. #4

    Re: 3 questions

    spot the other copy/paste mistake I made in my first post
    top gl = canvas.getContext("experimental-webgl", { alpha:true,
    top gl = canvas.getContext("experimental-webgl", { alpha:false,

  5. #5
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: 3 questions

    Quote Originally Posted by zed
    Cheer once again Steve
    Im not 100% but I assume, the alphaplane is analogous to the alpha buffer in opengl but this is only used in opengl when you specify DST_ALPHA etc.
    Im using the common mode SRC_ALPHA, ONE_MINUS_SRC_ALPHA (src_alpha comes from the texture/shader it shouldnt come from the alphaplane/buffer)
    or is it different in webgl?
    Yeah - exactly - it's the "Destination Alpha" thing - and the blendmode stuff works just the same in WebGL.

    But if you write values into the destination alpha of the frame-buffer of a "real" GPU rendering context (like a Windows window or an X11 window) - nothing much happens.

    However, when you write to the destination alpha of a canvas, the canvas compositor treats your entire rendered image as translucent - and you see through to the underlying web page.

    Now, if you read very carefully the rules for the blend function - you'll find that in SRC_ALPHA/ONE_MINUS_SRC_ALPHA blend mode, the source alpha is written to the frame buffer...hence the destination alpha buffer has values less than one in it when you just render any old translucent polygons into it...and that's why you're seeing the underlying window through translucent polygons - even when there is an opaque polygon behind it.

    Quite honestly - I *NEVER* found a good use for destination alpha in regular OpenGL and Direct3D applications - and I was horrified to discover that it's the default in WebGL.

    I predict having this conversation many, MANY times over the coming months and years!

    -- Steve

  6. #6

    Re: 3 questions

    Cheer for the clarification, Ill just have to have it turned off then.
    I did use dst_alpha for a depth of field effect. But I suppose, practically anything you want to use dst_alpha for, you could use the stencil buffer instead (apart from the blending)

  7. #7
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: 3 questions

    Well, I suppose you could clear the alpha plane back to opaque after you've finished rendering.

Similar Threads

  1. 2 Questions???
    By qasim1981 in forum OpenGL ES general technical discussions
    Replies: 3
    Last Post: 02-15-2005, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •