Results 1 to 6 of 6

Thread: glAlphaFunc, reference and float<->integer

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    2

    glAlphaFunc, reference and float<->integer

    Hi.

    I'm interested in what happens to the alpha test reference value and an alpha value from texture when they have to be compared. For example, if texture format has 8 bit alpha (integer) and I provide some alpha function and reference value (as float), then somewhere there must be either float->integer conversion or vice versa to actually compare them. glAlphaFunc documentation unfortunately doesn't cover this in detail.

    If I want to test for e.g. equality to a certain integer alpha value, is there a general and reliable way to do so? I mean something like glAlphaFunc(GL_EQUAL, intval / 255.0f). Only that sometimes suffers from what I think is float<->int conversion precision issues in compiler or driver (it doesn't always work as expected). In the particular case where this didn't work, that involved GL_GEQUAL, adding a very small value (like 0.000001) after dividing by 255 did help. But I'm looking for some general and portable way of solving the problem, if any exist.

    I appreciate any help. Thanks.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: glAlphaFunc, reference and float<->integer

    Comparing floating point values with "==" is bad on any processor!
    You could do it inside a shader and use an interval test with an environment around your value which is small enough to reliably find your intval / 255.0f and big enough to not miss it.

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: glAlphaFunc, reference and float<->integer

    Equality is always very fragile between integers and floats.
    The classic (CPU) solution is to replace the equality test by a small range test.

  4. #4
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    2

    Re: glAlphaFunc, reference and float<->integer

    If things like GL_EQUAL are there at all, there got to be some way to use them reliably? Or they are mostly useless (at least in apps that must be portable)? I wonder if this kind of conversions inside OpenGL have to conform to something. If there is a standart then I can try to tweak compiler options or even write a custom conversion function to get exactly the value needed. Unfortunately, so far I've a bad feeling that this isn't defined, as this works on some implementations (software Mesa), but doesn't on others.

    I realize it may be not the best approach from OGL viewpoint. Unfortunately that's what I need to do if possible. It's for fixing a problem in Wine emulator (winehq.org) that does d3d->opengl translation for games. So I can't change the algorithm (it's decided by game).

  5. #5
    Senior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Brighton, UK
    Posts
    161

    Re: glAlphaFunc, reference and float<->integer

    You can use GL_EQUAL reliably for integer tests, like stencil for example, so other things like this are not so useless as you might think, just because they don't fit in a specific scenario.

  6. #6
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: glAlphaFunc, reference and float<->integer

    Quote Originally Posted by frostbite
    I wonder if this kind of conversions inside OpenGL have to conform to something. If there is a standart then I can try to tweak compiler options or even write a custom conversion function to get exactly the value needed. Unfortunately, so far I've a bad feeling that this isn't defined, as this works on some implementations (software Mesa), but doesn't on others.
    The specification defines (sections 4.1.4 and 2.14.9 of the OGL2.1 specification) how should be the float value passed to the AlphaFunc converted to fixed point value and how should be fragments alpha value rounded for comparison purposes. Of course it is always possible that some hw or driver does not implement some detail in the way described by the specification.

Similar Threads

  1. Replies: 4
    Last Post: 07-06-2015, 09:29 PM
  2. glClearColor and integer/float frambuffers
    By Jan in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-13-2009, 01:45 PM
  3. input integer, float and string under GLUT
    By blairon in forum OpenGL: General
    Replies: 2
    Last Post: 01-04-2006, 05:13 AM
  4. placing numbers either integer or float on screen
    By prashantgp in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-28-2002, 04:56 AM
  5. converting float to integer and nearest 10? like so
    By Schlogenburg in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-15-2000, 07:57 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
  •  
Proudly hosted by Digital Ocean