#include "dms/Transparency.h"

namespace dms
{

Transparency Transparency::StandardBlend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ALWAYS, 0.0);
Transparency Transparency::AlphaTestZero(GL_ONE, GL_ZERO, GL_GREATER, 0.0);


Transparency::Transparency(GLenum source, GLenum dest,GLenum func, GLclampf ref)
    {
    setBlend(source,dest);
    setAlphaTest(func,ref);
    }


void Transparency::apply(void)
    {
    if (blend_)
        {
        glEnable(GL_BLEND);
        glBlendFunc(blendSource_, blendDest_);
        }
    if (alphaTest_)
        {
        glEnable(GL_ALPHA_TEST);
        glAlphaFunc(alphaFunc_, alphaRef_);
        }
    }


void Transparency::disable(void)
    {
    if (blend_)
        glDisable(GL_BLEND);
    if (alphaTest_)
        glDisable(GL_ALPHA_TEST);
    }


void Transparency::setBlend(GLenum source, GLenum dest)
    {
    if ((source == GL_ONE) && (dest == GL_ZERO))
        blend_ = false;
    else
        blend_ = true;
    blendSource_ = source;
    blendDest_ = dest;
    }


void Transparency::setAlphaTest(GLenum func, GLclampf ref)
    {
    if (func == GL_ALWAYS)
        alphaTest_ = false;
    else
        alphaTest_ = true;
    alphaFunc_ = func;
    alphaRef_ = ref;
    }


void Transparency::setNoBlend(void)
    {
    blend_ = false;
    }


void Transparency::setNoAlphaTest(void)
    {
    alphaTest_ = false;
    }



}
