Skip to content

Commit

Permalink
libgui|GLState: Added alpha test and alpha limit parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 22, 2015
1 parent 5afaeb4 commit bf52f1d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doomsday/sdk/libgui/include/de/graphics/glstate.h
Expand Up @@ -114,6 +114,8 @@ class LIBGUI_PUBLIC GLState
GLState &setDepthTest(bool enable);
GLState &setDepthFunc(gl::Comparison func);
GLState &setDepthWrite(bool enable);
GLState &setAlphaTest(bool enable);
GLState &setAlphaLimit(float greaterThanValue);
GLState &setBlend(bool enable);
GLState &setBlendFunc(gl::Blend src, gl::Blend dest);
GLState &setBlendFunc(gl::BlendFunc func);
Expand Down Expand Up @@ -149,6 +151,8 @@ class LIBGUI_PUBLIC GLState
bool depthTest() const;
gl::Comparison depthFunc() const;
bool depthWrite() const;
bool alphaTest() const;
float alphaLimit() const;
bool blend() const;
gl::Blend srcBlendFunc() const;
gl::Blend destBlendFunc() const;
Expand Down
41 changes: 40 additions & 1 deletion doomsday/sdk/libgui/src/graphics/glstate.cpp
Expand Up @@ -17,7 +17,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/GLState"
Expand All @@ -34,6 +34,8 @@ namespace internal
DepthTest,
DepthFunc,
DepthWrite,
AlphaTest,
AlphaLimit,
Blend,
BlendFuncSrc,
BlendFuncDest,
Expand All @@ -56,6 +58,8 @@ namespace internal
{ DepthTest, 1 },
{ DepthFunc, 3 },
{ DepthWrite, 1 },
{ AlphaTest, 1 },
{ AlphaLimit, 8 },
{ Blend, 1 },
{ BlendFuncSrc, 4 },
{ BlendFuncDest, 4 },
Expand Down Expand Up @@ -238,6 +242,17 @@ DENG2_PIMPL(GLState)
glDepthMask(GL_FALSE);
break;

case AlphaTest:
if(self.alphaTest())
glEnable(GL_ALPHA_TEST);
else
glDisable(GL_ALPHA_TEST);
break;

case AlphaLimit:
glAlphaFunc(GL_GREATER, self.alphaLimit());
break;

case Blend:
if(self.blend())
glEnable(GL_BLEND);
Expand Down Expand Up @@ -361,6 +376,8 @@ GLState::GLState() : d(new Instance(this))
setDepthTest (false);
setDepthFunc (gl::Less);
setDepthWrite(true);
setAlphaTest (true);
setAlphaLimit(0);
setBlend (true);
setBlendFunc (gl::One, gl::Zero);
setBlendOp (gl::Add);
Expand Down Expand Up @@ -402,6 +419,18 @@ GLState &GLState::setDepthWrite(bool enable)
return *this;
}

GLState &GLState::setAlphaTest(bool enable)
{
d->props.set(AlphaTest, enable);
return *this;
}

GLState &GLState::setAlphaLimit(float greaterThanValue)
{
d->props.set(AlphaLimit, unsigned(clamp(0.f, greaterThanValue, 1.f) * 255));
return *this;
}

GLState &GLState::setBlend(bool enable)
{
d->props.set(Blend, enable);
Expand Down Expand Up @@ -530,6 +559,16 @@ bool GLState::depthWrite() const
return d->props.asBool(DepthWrite);
}

bool GLState::alphaTest() const
{
return d->props.asBool(AlphaTest);
}

float GLState::alphaLimit() const
{
return float(d->props.asUInt(AlphaLimit)) / 255.f;
}

bool GLState::blend() const
{
return d->props.asBool(Blend);
Expand Down

0 comments on commit bf52f1d

Please sign in to comment.