X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftests.cpp;fp=source%2Ftests.cpp;h=a741b268a998dd31aa425f7df2f647a3095ab2b2;hp=5b34bf69d9d37fc732c4f45c5ea1c55a41394be1;hb=f17794d55923d4fb4f63e9d082d8d84a735a04e8;hpb=02dad9779326e5b8acc1fddbaec3a2f36da15c16 diff --git a/source/tests.cpp b/source/tests.cpp index 5b34bf69..a741b268 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -10,9 +10,29 @@ Distributed under the LGPL namespace Msp { namespace GL { -void scissor(int left, int bottom, unsigned width, unsigned height) +AlphaTest::AlphaTest(): + pred(ALWAYS), + ref(0) +{ } + +AlphaTest::AlphaTest(Predicate p, float r): + pred(p), + ref(r) +{ } + +void AlphaTest::bind() const { - glScissor(left, bottom, width, height); + if(set_current(this)) + { + glEnable(GL_ALPHA_TEST); + glAlphaFunc(pred, ref); + } +} + +void AlphaTest::unbind() +{ + if(set_current(0)) + glDisable(GL_ALPHA_TEST); } void alpha_func(Predicate func, float ref) @@ -20,10 +40,78 @@ void alpha_func(Predicate func, float ref) glAlphaFunc(func, ref); } + +DepthTest::DepthTest(): + write(true), + pred(LESS) +{ } + +DepthTest::DepthTest(Predicate p, bool w): + write(w), + pred(p) +{ } + +void DepthTest::bind() const +{ + if(set_current(this)) + { + glEnable(GL_DEPTH_TEST); + glDepthFunc(pred); + glDepthMask(write); + } +} + +const DepthTest &DepthTest::lequal() +{ + static DepthTest test(LEQUAL); + return test; +} + +void DepthTest::unbind() +{ + if(set_current(0)) + glDisable(GL_DEPTH_TEST); +} + void depth_func(Predicate func) { glDepthFunc(func); } + +ScissorTest::ScissorTest(): + left(0), + bottom(0), + width(1), + height(1) +{ } + +ScissorTest::ScissorTest(int l, int b, unsigned w, unsigned h): + left(l), + bottom(b), + width(w), + height(h) +{ } + +void ScissorTest::bind() const +{ + if(set_current(this)) + { + glEnable(GL_SCISSOR_TEST); + glScissor(left, bottom, width, height); + } +} + +void ScissorTest::unbind() +{ + if(set_current(0)) + glDisable(GL_SCISSOR_TEST); +} + +void scissor(int left, int bottom, unsigned width, unsigned height) +{ + glScissor(left, bottom, width, height); +} + } // namespace GL } // namespace Msp